alternative to assert
[gtkD.git] / gtkD / demos / gtkD / TestImage.d
blob5e1156c7aebfce71b5ed120a27af21fa17ca84de
1 /*
2 * This file is part of gtkD.
3 *
4 * gtkD 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.
8 *
9 * gtkD 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 gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 module gtkD.TestImage;
21 //debug = trace
23 private import gtk.VBox;
25 private import gtk.Table;
26 private import gtk.FileChooserDialog;
27 private import gtk.Button;
28 private import gtk.Widget;
29 private import gtk.ScrolledWindow;
30 private import gtk.ButtonBox;
31 private import gtk.HButtonBox;
32 private import gtk.Image;
34 private import gtk.Window;
36 private import gtkc.gtktypes;
38 version(Tango) private import tango.io.Stdout;
39 version(Tango) private import tango.stdc.stdio;
40 else private import std.stdio;
42 private import glib.Str;
44 /**
45 * This tests the GtkD loading and display and image file
47 class TestImage : VBox
49 Table table;
50 FileChooserDialog fs;
51 ScrolledWindow sw;
53 Window window;
55 this(Window window)
57 this.window = window;
58 debug(1)
60 printf("instantiating TestImage\n");
63 super(false,8);
65 sw = new ScrolledWindow(null,null);
67 sw.addWithViewport(initTable());
69 ButtonBox hBox = HButtonBox.createActionBox();
70 Button loadDir = new Button("Load Files", &loadImages);
71 hBox.packStart(loadDir,false,false,0);
73 packStart(sw,true,true,0);
74 packStart(hBox,false,false,0);
78 Table initTable()
81 char[][] pngs;
83 pngs ~= "images/gtkD_bevel.png";
84 pngs ~= "images/gtkDlogo_a.png";
85 pngs ~= "images/gtkD_logo_plain.png";
86 pngs ~= "images/gtkD_logo_small.png";
87 pngs ~= "images/gtkD_icon_1.png";
88 pngs ~= "images/gtkDlogo_a_small.png";
89 pngs ~= "images/gtkD_logo.png";
90 pngs ~= "images/gtkD_logo_too_small.png";
93 return loadTable(pngs);
96 private Table loadTable(char[][] imageFiles)
98 //Table table = new Table(1,1,false);
99 if ( table is null )
101 table = new Table(1,1,false);
103 else
105 table.removeAll();
109 int row = 0;
110 int col = 0;
112 Image image;
115 // Window progressWindow = new Window();//WindowType.POPUP);
116 // progressWindow.setBorderWidth(10);
117 // ProgressBar progressBar = new ProgressBar();
118 // progressWindow.add(progressBar);
119 // progressWindow.show();
122 for ( int i=0 ; i<imageFiles.length ;i++)
124 char[] fileName = imageFiles[i];
125 if ( fileName[0] != '/' )
127 version(linux) fileName = fileName;
128 version(Windows) fileName = fileName;
130 image = new Image(fileName);
131 //image.addOnEnterNotify(&onEnter);
132 //image.addOnLeaveNotify(&onLeave);
133 debug(trace) version(Tango) Stdout.format("adding image {} to table at {},{}", fileName, col, row).newline;
134 else writefln("adding image %s to table at %s,%s", fileName, col, row);
135 table.resize(col+1, row+1);
136 table.attach(image,col,col+1,row,row+1,AttachOptions.FILL,AttachOptions.FILL,4,4);
137 ++col;
138 if ( col == 8 )
140 col = 0;
141 ++row;
145 return table;
148 private import glib.ListSG;
150 void loadImages(Button button)
152 if ( fs is null )
154 char[][] a;
155 ResponseType[] r;
156 a ~= "Lets go!";
157 a ~= "Please don't";
158 r ~= ResponseType.GTK_RESPONSE_ACCEPT;
159 r ~= ResponseType.GTK_RESPONSE_CANCEL;
160 fs = new FileChooserDialog("File Selection", window, FileChooserAction.OPEN, a, r);
162 fs.getFileChooser().setSelectMultiple(true);
163 ResponseType response = cast(ResponseType) fs.run();
164 if ( response == ResponseType.GTK_RESPONSE_ACCEPT )
166 char[][] fileNames;
167 ListSG list = fs.getFileChooser().getFilenames();
170 for ( int i = 0; i<list.length() ; i++)
172 debug(trace) version(Tango) Stdout.format("Testmage.loadImages.File selected = {}",
173 Str.toString(cast(char*)list.nthData(i))).newline;
174 else writefln("Testmage.loadImages.File selected = %s",
175 Str.toString(cast(char*)list.nthData(i)));
176 fileNames ~= Str.toString(cast(char*)list.nthData(i)).dup;
179 loadTable(fileNames);
181 fs.hide();
184 void onEnter(Widget widget)
186 printf("TestImage.mouseEnterNotify\n");
187 return true;
189 void onLeave(Widget widget)
191 printf("TestImage.mouseLeaveNotify\n");
192 return true;