Skip to content
Browse files

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...
1 parent 7e143bf commit d881ab0a13a2ce84fb69066bca7780f137294975 @LindseyB LindseyB committed Jul 23, 2009
View
87 examples/MoreDucks/MoreDucks.d
@@ -0,0 +1,87 @@
+import djehuty;
+
+import gui.application;
+import gui.window;
+import gui.button;
+import gui.widget;
+import gui.osbutton;
+
+import graphics.graphics;
+import resource.image;
+
+
+class MyControl : Widget {
+ this() {
+ super(0,50,360,297);
+ }
+
+ override void onAdd() {
+ images[0] = new Image("examples/MoreDucks/baby_ducks.png");
+ images[1] = new Image("examples/MoreDucks/duckling.png");
+ images[2] = new Image("examples/MoreDucks/ducks-cute.png");
+ }
+
+ override void onDraw(ref Graphics g) {
+ g.drawImage(this.left,this.top,images[curImage]);
+ }
+
+ void nextImage() {
+ if(curImage == images.length-1)
+ {
+ curImage = 0;
+ return;
+ }
+
+ curImage++;
+ }
+
+private:
+ Image[3] images;
+ int curImage = 0;
+}
+
+class MyWindow : Window {
+ this() {
+ super("OMG DUCKS",WindowStyle.Fixed,Color.Gray,0,0,360,347);
+ }
+
+ override void onAdd() {
+ push(button = new OSButton(0,0,360,50,"MORE DUCKS!"));
+ push(imageBox = new MyControl());
+ }
+
+ override bool onSignal(Dispatcher d, uint signal) {
+ if(d is button) {
+ if(signal == Button.Signal.Selected) {
+ imageBox.nextImage();
+ redraw();
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+private:
+ OSButton button;
+ MyControl imageBox;
+}
+
+class MyApp : GuiApplication {
+ // Start an application instance
+ static this() { new MyApp(); }
+
+ override void onApplicationStart() {
+ wnd = new MyWindow();
+ wnd.visible = true;
+
+ push(wnd);
+ }
+
+ override void onApplicationEnd() {
+ }
+
+private:
+ MyWindow wnd;
+}
View
BIN examples/MoreDucks/baby_ducks.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN examples/MoreDucks/duckling.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN examples/MoreDucks/ducks-cute.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
18 makefile
@@ -71,6 +71,7 @@ TOOLS_DSPEC = tools/dspec/main.d tools/dspec/feeder.d tools/dspec/filelist.d too
TOOLS_DSCRIBE = tools/dscribe/main.d tools/dscribe/lexer.d
EXAMPLES_TUITETRIS = examples/tuitetris/app.d examples/tuitetris/gamewindow.d examples/tuitetris/tetris.d examples/tuitetris/gamecontrol.d
+EXAMPLES_MOREDUCKS = examples/MoreDucks/MoreDucks.d
libdeps_linux: $(OBJS_LINUX)
@echo ">> framework compilation complete. <<"
@@ -259,6 +260,23 @@ endif
endif
endif
+moreducks: lib
+
+ @echo compiling MoreDucks example and linking...
+ifeq (${MY_ARCH},Darwin)
+ #@$(DC) $(LFLAGS_MAC) -o MoreDucks winsamp.o $(OBJS_MAC)
+else
+ifeq (${MY_ARCH},MINGW32_NT-6.0)
+ @dmd.exe -w -version=$(PLATFORM) -ofmoreducks.exe $(EXAMPLES_MOREDUCKS) $(OBJS_WIN) $(LFLAGS_WIN)
+else
+ifeq (${MY_ARCH},MINGW32_NT-6.1)
+ @dmd.exe -w -version=$(PLATFORM) -ofmoreducks.exe $(EXAMPLES_MOREDUCKS) $(OBJS_WIN) $(LFLAGS_WIN)
+else
+ @$(DC) $(LFLAGS_LINUX) -ofmoreducks -d-version=PlatformLinux $(EXAMPLES_MOREDUCKS) $(OBJS_LINUX)
+endif
+endif
+endif
+
clean:
ifeq (${MY_ARCH},Darwin)
View
21 moreducks.exe.manifest
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<assemblyIdentity
+version="1.0.0.0"
+processorArchitecture="X86"
+name="Digital Mars Compiler IDDE"
+type="win32"
+/>
+<dependency>
+<dependentAssembly>
+<assemblyIdentity
+type="win32"
+name="Microsoft.Windows.Common-Controls"
+version="6.0.0.0"
+processorArchitecture="X86"
+publicKeyToken="6595b64144ccf1df"
+language="*"
+/>
+</dependentAssembly>
+</dependency>
+</assembly>
View
59 winsamp.d
@@ -153,32 +153,71 @@ private:
class MyControl : Widget {
this() {
- super(200,200,100,100);
+ super(0,50,360,297);
}
-
+
override void onAdd() {
+ // create images array
+
+ images[0] = new Image("baby_ducks.png");
+ images[1] = new Image("duckling.png");
+ images[2] = new Image("ducks-cute.png");
+
+ /*
imgPNG = new Image("tests/test.png");
imgJPEG = new Image("tests/tiles.png"); // jpeg written as png
+ */
}
override void onDraw(ref Graphics g) {
- g.drawImage(this.left,this.top,imgPNG);
- g.drawImage(this.left,this.top,imgJPEG);
+
+ g.drawImage(this.left,this.top,images[curImage]);
+
+ /*g.drawImage(this.left,this.top,imgPNG);
+ g.drawImage(this.left,this.top,imgJPEG);*/
}
- Image imgPNG;
- Image imgJPEG;
+ void nextImage() {
+ if(curImage == images.length-1)
+ {
+ curImage = 0;
+ return;
+ }
+
+ curImage++;
+ }
+
+private:
+ Image[3] images;
+ int curImage = 0;
}
class MyWindow : Window {
this() {
- super("hey",WindowStyle.Fixed,Color.Red,0,0,300,300);
+ super("OMG DUCKS",WindowStyle.Fixed,Color.Gray,0,0,360,347);
}
-
+
override void onAdd() {
- push(new OSButton(0,0,100,50,"yo"));
- push(new MyControl());
+ push(button = new OSButton(0,0,360,50,"MORE DUCKS!"));
+ push(imageBox = new MyControl());
+ }
+
+ override bool onSignal(Dispatcher d, uint signal) {
+ if(d is button) {
+ if(signal == Button.Signal.Selected) {
+ imageBox.nextImage();
+ redraw();
+ return true;
+ }
+ }
+
+ return false;
}
+
+
+private:
+ OSButton button;
+ MyControl imageBox;
}
class MyApp : GuiApplication {

0 comments on commit d881ab0

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