diff examples/texteditor/Images.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children 8a1930f94cbb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/texteditor/Images.d	Sat May 10 13:32:45 2008 -0700
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Thomas Graber <d4rkdragon@gmail.com>
+ *******************************************************************************/
+module examples.texteditor.Images;
+
+import dwt.dwthelper.InputStream;
+
+import dwt.graphics.Image;
+import dwt.graphics.ImageData;
+import dwt.widgets.Display;
+import dwt.dwthelper.ByteArrayInputStream;
+
+import tango.core.Exception;
+import tango.io.Stdout;
+
+public class Images {
+
+    // Bitmap Images
+    public Image Bold;
+    public Image Italic;
+    public Image Underline;
+    public Image Strikeout;
+    public Image Red;
+    public Image Green;
+    public Image Blue;
+    public Image Erase;
+
+    Image[] AllBitmaps;
+
+    this () {
+    }
+
+    public void freeAll () {
+        for (int i=0; i<AllBitmaps.length; i++) AllBitmaps [i].dispose ();
+        AllBitmaps = null;
+    }
+
+    Image createBitmapImage(Display display, void[] iImage, void[] iMask) {
+        InputStream sourceStream = new ByteArrayInputStream(cast(byte[]) iImage);
+        InputStream maskStream  = new ByteArrayInputStream(cast(byte[])iMask );
+
+        ImageData source = new ImageData (sourceStream);
+        ImageData mask = new ImageData (maskStream);
+        Image result = new Image (null, source, mask);
+        try {
+            sourceStream.close ();
+            maskStream.close ();
+        } catch (IOException e) {
+            Stderr.formatln( "Stacktrace: {}", e.toString );
+        }
+        return result;
+    }
+
+    public void loadAll (Display display) {
+        // Bitmap Images
+        Bold = createBitmapImage (display, import( "dwtexamples.texteditor.bold.bmp" ), import( "dwtexamples.texteditor.bold_mask.bmp" ));
+        Italic = createBitmapImage (display, import( "dwtexamples.texteditor.italic.bmp" ), import( "dwtexamples.texteditor.italic_mask.bmp" ));
+        Underline = createBitmapImage (display, import( "dwtexamples.texteditor.underline.bmp" ), import( "dwtexamples.texteditor.underline_mask.bmp" ));
+        Strikeout = createBitmapImage (display, import( "dwtexamples.texteditor.strikeout.bmp" ), import( "dwtexamples.texteditor.strikeout_mask.bmp" ));
+        Red = createBitmapImage (display, import( "dwtexamples.texteditor.red.bmp" ), import( "dwtexamples.texteditor.red_mask.bmp" ));
+        Green = createBitmapImage (display, import( "dwtexamples.texteditor.green.bmp" ), import( "dwtexamples.texteditor.green_mask.bmp" ));
+        Blue = createBitmapImage (display, import( "dwtexamples.texteditor.blue.bmp" ), import( "dwtexamples.texteditor.blue_mask.bmp" ));
+        Erase = createBitmapImage (display, import( "dwtexamples.texteditor.erase.bmp" ), import( "dwtexamples.texteditor.erase_mask.bmp" ));
+
+        AllBitmaps = [ Bold,
+                       Italic,
+                       Underline,
+                       Strikeout,
+                       Red,
+                       Green,
+                       Blue,
+                       Erase
+                      ];
+    }
+}