2 #include "../wmwindow.h"
3 #include "../wmframe.h"
4 #include "../wmcanvas.h"
5 #include "../wmbutton.h"
6 #include "../wmellipse.h"
7 #include "debian-tiny.xpm"
9 // This file creates a window with a small, very simple paint program.
11 // Define a class that will be a WMCanvas widget with callbacks
12 class WMPainter
: public WMCallback
, public WMCanvas
, public WMEllipse
{
13 public: WMPainter() : WMCallback(), WMCanvas() { }
16 // Make one of the buttons elliptical.
17 class WMEllipticalButton
: public WMEllipse
, public WMButton
{
18 public: WMEllipticalButton() : WMEllipse(), WMButton() { }
21 // Callback to paint onto this widget when it's clicked on
23 paint(const WMApp
*a
, WMWidget
*w
, void *)
25 WMMouseClick click
= a
->mouseclick().b_relative_to(w
);
26 WMPainter
*p
= dynamic_cast<WMPainter
*>(w
);
27 // draw a 3x3 square at the mouse location clicked upon
28 if (p
) p
->fill_rectangle(click
.x
- 2, click
.y
- 2, 3, 3);
32 // Callbacks for the buttons -----------------------------------------------
34 // This callback changes the current paint color of the WMCanvas, depending
35 // upon which button was pressed.
37 changecolor(const WMApp
*a
, WMWidget
*w
, void *color
)
39 WMColor::WMColor c
= *static_cast<WMColor::WMColor
*>(color
);
40 WMPainter
*wp
= dynamic_cast<WMPainter
*>(w
);
41 if (wp
) wp
->setcolor(c
);
44 // This callback will be attached to the big button
45 // on the second window. It switches between windows.
46 // Note: if the last statement in a callback function requests
47 // a switch to a new window, you don't need a "repaint()".
49 switch_to_0(const WMApp
*a
, void *)
52 void makewindow1(WMWindow
*w1
)
54 static WMEllipticalButton debianwin
;
55 static WMEllipticalButton colorbutton
[4];
56 static WMFrame top
, topleft
, bottom
;
57 static WMPainter drawing
;
58 static int colors
[4] = { 0x000000, 0xFF0000, 0x00FF00, 0x0000FF };
62 w1
->setorientation(Orientation::Vertical
);
63 w1
->setaspectratios(1, 3);
65 top
.addchild(topleft
);
66 top
.addchild(debianwin
);
67 top
.setaspectratios(4, 1);
69 topleft
.setpadding(0);
71 topleft
.settransparency(false);
73 for (unsigned int i
= 0; i
< 4; i
++) {
74 colorbutton
[i
].setbgcolor(colors
[i
]);
75 colorbutton
[i
].addcallback(changecolor
, &drawing
, colors
+ i
);
76 topleft
.addchild(colorbutton
[i
]);
79 debianwin
.seticon(debian_tiny_xpm
);
80 debianwin
.addcallback(switch_to_0
, 0);
82 drawing
.addcallback(paint
, &drawing
);
83 bottom
.addchild(drawing
);