2 * This file is part of dui.
4 * dui is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * dui is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with dui; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 private import gtk
.VBox
;
22 private import gtk
.HBox
;
23 private import gtk
.Box
;
25 private import gtk
.DrawingArea
;
26 private import gdk
.Event
;
27 private import gtk
.Widget
;
28 private import gtk
.ComboBox
;
29 private import gtk
.gtktypes
;
31 private import gdk
.Color
;
32 private import gdk
.Drawable
;
33 private import gdk
.GC
;
35 private import gtk
.SpinButton
;
36 private import gtk
.Adjustment
;
38 private import std
.stdio
;
40 private import gtk
.Idle
;
41 private import gtk
.Timeout
;
45 * This tests the DUI drawing area widget
50 SpinButton timeoutSpin
;
57 printf("instantiating TestTimeout\n");
62 TestDrawing drawingArea
= new TestDrawing();
64 ComboBox gcOptions
= new ComboBox();
65 gcOptions
.appendText("GC COPY");
66 gcOptions
.appendText("GC INVERT");
67 gcOptions
.appendText("GC XOR");
68 gcOptions
.appendText("GC CLEAR");
69 gcOptions
.appendText("GC AND");
70 gcOptions
.appendText("GC AND_REVERSE");
71 gcOptions
.appendText("GC AND_INVERT");
72 gcOptions
.appendText("GC NOOP");
73 gcOptions
.appendText("GC OR");
74 gcOptions
.appendText("GC EQUIV");
75 gcOptions
.appendText("GC OR_REVERSE");
76 gcOptions
.appendText("GC COPY_INVERT");
77 gcOptions
.appendText("GC OR_INVERT");
78 gcOptions
.appendText("GC NAND");
79 gcOptions
.appendText("GC NOR");
80 gcOptions
.appendText("GC SET");
81 gcOptions
.setActive(1);
82 gcOptions
.addOnChanged(&drawingArea
.onCGOptionsChanged
);
84 ComboBox callType
= new ComboBox();
85 callType
.appendText("Idle");
86 callType
.appendText("Timeout");
87 callType
.setActive(1);
88 callType
.addOnChanged(&drawingArea
.onCallTypeChanged
);
90 timeoutSpin
= new SpinButton(new Adjustment(200.0, 1.0, 1000.0, 1.0, 100.0, 1.0),1,0);
91 timeoutSpin
.addOnValueChanged(&drawingArea
.onTimeoutSpinValueChanged
);
92 Box controlBox
= new HBox(false, 7);
94 controlBox
.packStart(gcOptions
, false, false, 2);
95 controlBox
.packStart(callType
, false, false, 2);
96 controlBox
.packStart(timeoutSpin
, false, false, 2);
98 packStart(drawingArea
,true,true,0);
99 packStart(controlBox
,false,false,0);
102 class TestDrawing
: DrawingArea
108 bool continueIdleCallback
;
121 //Color color = new Color();
125 int callType
= 1; // ue 0 for Idle 1 for Timeout
129 setSizeRequest(333,334);
131 paintColor
= new Color(cast(ubyte)0,cast(ubyte)0,cast(ubyte)0);
132 black
= new Color(cast(ubyte)0,cast(ubyte)0,cast(ubyte)0);
134 addOnRealize(&onRealize
);
135 //addOnExpose(&exposeCallback);
137 addOnUnmap(&onUnmap
);
138 //addOnMotionNotify(&onMotionNotify);
139 addOnSizeAllocate(&onSizeAllocate
);
140 //addOnButtonPress(&onButtonPress);
141 //addOnButtonRelease(&onButtonRelease);
145 public void onRealize(Widget widget
)
147 //printf("TestTimeout.realizeCallback\n");
148 drawable
= getDrawable();
149 gc
= new GC(drawable
);
150 gc
.setFunction(GdkFunction
.INVERT
);
154 public void onMap(Widget widget
)
156 //writefln("idle.onMap");
157 continueIdleCallback
= true;
165 public void onUnmap(Widget widget
)
167 //writefln("idle.onUnmap");
168 continueIdleCallback
= false;
171 void onSizeAllocate(GtkAllocation
* allocation
, Widget widget
)
173 width
= allocation
.width
;
174 height
= allocation
.height
;
181 void onTimeoutSpinValueChanged(SpinButton spin
)
191 if ( mainIdle
!is null )
195 if ( mainTimeout
!is null )
201 case 0: mainIdle
= new Idle(&idleCallback
); break;
202 case 1: mainTimeout
= new Timeout(timeoutSpin
.getValueAsInt(),&idleCallback
, true); break;
203 default: mainIdle
= new Idle(&idleCallback
); break;
208 * This will be called from the expose event call back.
209 * \bug this is called on get or loose focus - review
211 // public bit exposeCallback(Widget widget)
213 // //printf("testWindow.exposed ----------------------------- \n");
214 // //drawPoins(widget.getDrawable());
221 //printf("%d %d\n",width,height);
222 //drawable.drawPoint(gc,x,y);
227 if ( xi
<0 )xf
= x
; // going back
230 if ( yi
<0 )yf
= y
; // going up
235 //writefln("%s %s -> %s %s (%s %s)\n",x,y,xf,yf,x+yf*xi, y+yf*yi);
236 drawable
.drawLine(gc
,x
,y
, x
+yf
*xi
, y
+yf
*yi
);
241 if ( x
>=width || x
<=0 ) xi
= -xi
;
242 if ( y
>=height || y
<=0 ) yi
= -yi
;
244 return continueIdleCallback
;
247 void onCallTypeChanged(ComboBox comboBox
)
249 writefln("gcOptions = %s", comboBox
.getActiveText());
250 switch ( comboBox
.getActiveText() )
252 case "Idle": callType
= 0; break;
253 case "Timeout": callType
= 1; break;
254 default: callType
= 0; break;
259 void onCGOptionsChanged(ComboBox comboBox
)
261 writefln("gcOptions = %s", comboBox
.getActiveText());
262 switch ( comboBox
.getActiveText() )
264 case "GC COPY": gc
.setFunction(GdkFunction
.COPY
); break;
265 case "GC INVERT": gc
.setFunction(GdkFunction
.INVERT
); break;
266 case "GC XOR": gc
.setFunction(GdkFunction
.XOR
); break;
267 case "GC CLEAR": gc
.setFunction(GdkFunction
.CLEAR
); break;
268 case "GC AND": gc
.setFunction(GdkFunction
.AND
); break;
269 case "GC AND_REVERSE": gc
.setFunction(GdkFunction
.AND_REVERSE
);break;
270 case "GC AND_INVERT": gc
.setFunction(GdkFunction
.AND_INVERT
); break;
271 case "GC NOOP": gc
.setFunction(GdkFunction
.NOOP
); break;
272 case "GC OR": gc
.setFunction(GdkFunction
.OR
); break;
273 case "GC EQUIV": gc
.setFunction(GdkFunction
.EQUIV
); break;
274 case "GC OR_REVERSE": gc
.setFunction(GdkFunction
.OR_REVERSE
); break;
275 case "GC COPY_INVERT": gc
.setFunction(GdkFunction
.COPY_INVERT
);break;
276 case "GC OR_INVERT": gc
.setFunction(GdkFunction
.OR_INVERT
); break;
277 case "GC NAND": gc
.setFunction(GdkFunction
.NAND
); break;
278 case "GC NOR": gc
.setFunction(GdkFunction
.NOR
); break;
279 case "GC SET": gc
.setFunction(GdkFunction
.SET
); break;
280 default: gc
.setFunction(GdkFunction
.INVERT
); break;