Skip to content
This repository
Browse code

Added a new example program named more ducks which shows a simple usa…

…ge of djehuty to create a basic GUI app. It handles a basic event from a button and shows how images can be displayed.
  • Loading branch information...
commit d881ab0a13a2ce84fb69066bca7780f137294975 1 parent 7e143bf
Lindsey Bieda LindseyB authored
87 examples/MoreDucks/MoreDucks.d
... ... @@ -0,0 +1,87 @@
  1 +import djehuty;
  2 +
  3 +import gui.application;
  4 +import gui.window;
  5 +import gui.button;
  6 +import gui.widget;
  7 +import gui.osbutton;
  8 +
  9 +import graphics.graphics;
  10 +import resource.image;
  11 +
  12 +
  13 +class MyControl : Widget {
  14 + this() {
  15 + super(0,50,360,297);
  16 + }
  17 +
  18 + override void onAdd() {
  19 + images[0] = new Image("examples/MoreDucks/baby_ducks.png");
  20 + images[1] = new Image("examples/MoreDucks/duckling.png");
  21 + images[2] = new Image("examples/MoreDucks/ducks-cute.png");
  22 + }
  23 +
  24 + override void onDraw(ref Graphics g) {
  25 + g.drawImage(this.left,this.top,images[curImage]);
  26 + }
  27 +
  28 + void nextImage() {
  29 + if(curImage == images.length-1)
  30 + {
  31 + curImage = 0;
  32 + return;
  33 + }
  34 +
  35 + curImage++;
  36 + }
  37 +
  38 +private:
  39 + Image[3] images;
  40 + int curImage = 0;
  41 +}
  42 +
  43 +class MyWindow : Window {
  44 + this() {
  45 + super("OMG DUCKS",WindowStyle.Fixed,Color.Gray,0,0,360,347);
  46 + }
  47 +
  48 + override void onAdd() {
  49 + push(button = new OSButton(0,0,360,50,"MORE DUCKS!"));
  50 + push(imageBox = new MyControl());
  51 + }
  52 +
  53 + override bool onSignal(Dispatcher d, uint signal) {
  54 + if(d is button) {
  55 + if(signal == Button.Signal.Selected) {
  56 + imageBox.nextImage();
  57 + redraw();
  58 + return true;
  59 + }
  60 + }
  61 +
  62 + return false;
  63 + }
  64 +
  65 +
  66 +private:
  67 + OSButton button;
  68 + MyControl imageBox;
  69 +}
  70 +
  71 +class MyApp : GuiApplication {
  72 + // Start an application instance
  73 + static this() { new MyApp(); }
  74 +
  75 + override void onApplicationStart() {
  76 + wnd = new MyWindow();
  77 + wnd.visible = true;
  78 +
  79 + push(wnd);
  80 + }
  81 +
  82 + override void onApplicationEnd() {
  83 + }
  84 +
  85 +private:
  86 + MyWindow wnd;
  87 +}
BIN  examples/MoreDucks/baby_ducks.png
BIN  examples/MoreDucks/duckling.png
BIN  examples/MoreDucks/ducks-cute.png
18 makefile
@@ -71,6 +71,7 @@ TOOLS_DSPEC = tools/dspec/main.d tools/dspec/feeder.d tools/dspec/filelist.d too
71 71 TOOLS_DSCRIBE = tools/dscribe/main.d tools/dscribe/lexer.d
72 72
73 73 EXAMPLES_TUITETRIS = examples/tuitetris/app.d examples/tuitetris/gamewindow.d examples/tuitetris/tetris.d examples/tuitetris/gamecontrol.d
  74 +EXAMPLES_MOREDUCKS = examples/MoreDucks/MoreDucks.d
74 75
75 76 libdeps_linux: $(OBJS_LINUX)
76 77 @echo ">> framework compilation complete. <<"
@@ -259,6 +260,23 @@ endif
259 260 endif
260 261 endif
261 262
  263 +moreducks: lib
  264 +
  265 + @echo compiling MoreDucks example and linking...
  266 +ifeq (${MY_ARCH},Darwin)
  267 + #@$(DC) $(LFLAGS_MAC) -o MoreDucks winsamp.o $(OBJS_MAC)
  268 +else
  269 +ifeq (${MY_ARCH},MINGW32_NT-6.0)
  270 + @dmd.exe -w -version=$(PLATFORM) -ofmoreducks.exe $(EXAMPLES_MOREDUCKS) $(OBJS_WIN) $(LFLAGS_WIN)
  271 +else
  272 +ifeq (${MY_ARCH},MINGW32_NT-6.1)
  273 + @dmd.exe -w -version=$(PLATFORM) -ofmoreducks.exe $(EXAMPLES_MOREDUCKS) $(OBJS_WIN) $(LFLAGS_WIN)
  274 +else
  275 + @$(DC) $(LFLAGS_LINUX) -ofmoreducks -d-version=PlatformLinux $(EXAMPLES_MOREDUCKS) $(OBJS_LINUX)
  276 +endif
  277 +endif
  278 +endif
  279 +
262 280
263 281 clean:
264 282 ifeq (${MY_ARCH},Darwin)
21 moreducks.exe.manifest
... ... @@ -0,0 +1,21 @@
  1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2 +<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  3 +<assemblyIdentity
  4 +version="1.0.0.0"
  5 +processorArchitecture="X86"
  6 +name="Digital Mars Compiler IDDE"
  7 +type="win32"
  8 +/>
  9 +<dependency>
  10 +<dependentAssembly>
  11 +<assemblyIdentity
  12 +type="win32"
  13 +name="Microsoft.Windows.Common-Controls"
  14 +version="6.0.0.0"
  15 +processorArchitecture="X86"
  16 +publicKeyToken="6595b64144ccf1df"
  17 +language="*"
  18 +/>
  19 +</dependentAssembly>
  20 +</dependency>
  21 +</assembly>
59 winsamp.d
@@ -153,32 +153,71 @@ private:
153 153
154 154 class MyControl : Widget {
155 155 this() {
156   - super(200,200,100,100);
  156 + super(0,50,360,297);
157 157 }
158   -
  158 +
159 159 override void onAdd() {
  160 + // create images array
  161 +
  162 + images[0] = new Image("baby_ducks.png");
  163 + images[1] = new Image("duckling.png");
  164 + images[2] = new Image("ducks-cute.png");
  165 +
  166 + /*
160 167 imgPNG = new Image("tests/test.png");
161 168 imgJPEG = new Image("tests/tiles.png"); // jpeg written as png
  169 + */
162 170 }
163 171
164 172 override void onDraw(ref Graphics g) {
165   - g.drawImage(this.left,this.top,imgPNG);
166   - g.drawImage(this.left,this.top,imgJPEG);
  173 +
  174 + g.drawImage(this.left,this.top,images[curImage]);
  175 +
  176 + /*g.drawImage(this.left,this.top,imgPNG);
  177 + g.drawImage(this.left,this.top,imgJPEG);*/
167 178 }
168 179
169   - Image imgPNG;
170   - Image imgJPEG;
  180 + void nextImage() {
  181 + if(curImage == images.length-1)
  182 + {
  183 + curImage = 0;
  184 + return;
  185 + }
  186 +
  187 + curImage++;
  188 + }
  189 +
  190 +private:
  191 + Image[3] images;
  192 + int curImage = 0;
171 193 }
172 194
173 195 class MyWindow : Window {
174 196 this() {
175   - super("hey",WindowStyle.Fixed,Color.Red,0,0,300,300);
  197 + super("OMG DUCKS",WindowStyle.Fixed,Color.Gray,0,0,360,347);
176 198 }
177   -
  199 +
178 200 override void onAdd() {
179   - push(new OSButton(0,0,100,50,"yo"));
180   - push(new MyControl());
  201 + push(button = new OSButton(0,0,360,50,"MORE DUCKS!"));
  202 + push(imageBox = new MyControl());
  203 + }
  204 +
  205 + override bool onSignal(Dispatcher d, uint signal) {
  206 + if(d is button) {
  207 + if(signal == Button.Signal.Selected) {
  208 + imageBox.nextImage();
  209 + redraw();
  210 + return true;
  211 + }
  212 + }
  213 +
  214 + return false;
181 215 }
  216 +
  217 +
  218 +private:
  219 + OSButton button;
  220 + MyControl imageBox;
182 221 }
183 222
184 223 class MyApp : GuiApplication {

0 comments on commit d881ab0

Please sign in to comment.
Something went wrong with that request. Please try again.