1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
//
// "$Id: shapedwindow.cxx 10325 2014-09-21 14:10:36Z manolo $"
//
// shapedwindow example source file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2014 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems to:
//
// http://www.fltk.org/str.php
//
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Image.H>
#include <FL/Fl_Tiled_Image.H>
#include <FL/Fl_Image_Surface.H>
#include "test/pixmaps/tile.xpm"
void cb(Fl_Widget *w, void *) {
w->window()->hide();
}
class dragbox : public Fl_Box {
public:
dragbox(int x, int y, int w, int h, const char *t=0) : Fl_Box(x,y,w,h,t) {};
int handle(int event) {
static int fromx, fromy, winx, winy;
if (event == FL_PUSH) {
fromx = Fl::event_x_root();
fromy = Fl::event_y_root();
winx = window()->x_root();
winy = window()->y_root();
return 1;
}
else if (event == FL_DRAG) {
int deltax = Fl::event_x_root() - fromx;
int deltay = Fl::event_y_root() - fromy;
window()->resize(winx + deltax, winy + deltay, window()->w(), window()->h());
return 1;
}
return Fl_Box::handle(event);
}
};
const float factor = 1.3;
void shrink(Fl_Widget *wdgt, void *data)
{
Fl_Window *win = wdgt->window();
int old = win->w();
win->size(old/factor, old/factor);
if (win->w() <= *(int*)data) wdgt->deactivate();
}
void enlarge(Fl_Widget *wdgt, void *data)
{
Fl_Window *win = wdgt->window();
int old = win->w();
win->size(old*factor, old*factor);
((Fl_Widget*)data)->activate();
}
Fl_RGB_Image* prepare_shape(int w)
{
// draw a white circle with a hole in it on black background
Fl_Image_Surface *surf = new Fl_Image_Surface(w, w);
Fl_Surface_Device* current = Fl_Surface_Device::surface();
surf->set_current();
fl_color(FL_BLACK);
fl_rectf(-1, -1, w+2, w+2);
fl_color(FL_WHITE);
fl_pie(2,2,w-4,w-4,0,360);
fl_color(FL_BLACK);
fl_pie(0.7*w,w/2,w/4,w/4,0,360);
Fl_RGB_Image* img = surf->image();
delete surf;
current->set_current();
return img; // return depth-3 white image on black background
}
int main(int argc, char **argv) {
int dim = 200;
Fl_Double_Window *win = new Fl_Double_Window(100, 100, dim, dim, "Testing1");
Fl_RGB_Image *img = prepare_shape(dim);
win->shape(img);
dragbox *box = new dragbox(0, 0, win->w(), win->h());
box->image(new Fl_Tiled_Image(new Fl_Pixmap((const char * const *)tile_xpm)));
Fl_Group *g = new Fl_Group(10, 20, 80, 20);
g->box(FL_NO_BOX);
Fl_Button *b = new Fl_Button(10, 20, 80, 20, "Close");
b->callback(cb);
g->end();
g->resizable(NULL);
g = new Fl_Group(60, 70, 80, 40, "Drag me");
g->box(FL_NO_BOX);
g->align(FL_ALIGN_TOP);
Fl_Button *bs = new Fl_Button(60, 70, 80, 20, "Shrink");
bs->callback(shrink, &dim);
bs->deactivate();
Fl_Button *be = new Fl_Button(60, 90, 80, 20, "Enlarge");
be->callback(enlarge, bs);
g->end();
g->resizable(NULL);
win->end();
win->resizable(win);
win->show(argc, argv);
Fl::run();
delete win;
return 0;
}
//
// End of "$Id: shapedwindow.cxx 10325 2014-09-21 14:10:36Z manolo $".
//
|