2014-08-27 15:55:57 +04:00
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2014-08-27 15:55:57 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2014-08-27 15:55:57 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2014-08-27 15:55:57 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl.H>
|
2016-03-10 16:22:29 +03:00
|
|
|
#include <FL/fl_draw.H>
|
2014-09-21 18:10:36 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
2014-08-27 15:55:57 +04:00
|
|
|
#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:
|
2021-08-27 15:52:43 +03:00
|
|
|
dragbox(int x, int y, int w, int h, const char *t=0) : Fl_Box(x,y,w,h,t) {}
|
2014-08-27 15:55:57 +04:00
|
|
|
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;
|
2015-12-08 12:39:42 +03:00
|
|
|
window()->position(winx + deltax, winy + deltay);
|
2014-08-27 15:55:57 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return Fl_Box::handle(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-30 17:51:29 +03:00
|
|
|
const float factor = 1.3f;
|
2014-08-27 15:55:57 +04:00
|
|
|
|
|
|
|
void shrink(Fl_Widget *wdgt, void *data)
|
|
|
|
{
|
|
|
|
Fl_Window *win = wdgt->window();
|
|
|
|
int old = win->w();
|
2021-08-30 17:51:29 +03:00
|
|
|
win->size(int(old/factor), int(old/factor));
|
2014-08-27 15:55:57 +04:00
|
|
|
if (win->w() <= *(int*)data) wdgt->deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void enlarge(Fl_Widget *wdgt, void *data)
|
|
|
|
{
|
|
|
|
Fl_Window *win = wdgt->window();
|
|
|
|
int old = win->w();
|
2021-08-30 17:51:29 +03:00
|
|
|
win->size(int(old*factor), int(old*factor));
|
2014-08-27 15:55:57 +04:00
|
|
|
((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);
|
2016-12-07 18:09:52 +03:00
|
|
|
Fl_Surface_Device::push_current(surf);
|
2014-08-27 15:55:57 +04:00
|
|
|
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);
|
2021-08-30 17:51:29 +03:00
|
|
|
fl_pie(int(0.7*w),w/2,w/4,w/4,0,360);
|
2014-08-27 15:55:57 +04:00
|
|
|
Fl_RGB_Image* img = surf->image();
|
|
|
|
delete surf;
|
2016-12-07 18:09:52 +03:00
|
|
|
Fl_Surface_Device::pop_current();
|
2016-02-01 17:24:24 +03:00
|
|
|
return img; // return white image on black background
|
2014-08-27 15:55:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int dim = 200;
|
2014-09-21 18:10:36 +04:00
|
|
|
Fl_Double_Window *win = new Fl_Double_Window(100, 100, dim, dim, "Testing1");
|
2014-08-27 15:55:57 +04:00
|
|
|
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;
|
|
|
|
}
|