Changeset 527

Show
Ignore:
Timestamp:
07/11/08 15:21:05 (3 months ago)
Author:
Mike Wey
Message:

replace the gtk/DrawRect demo with the one written by Unarmed - see ticket #12

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demos/gtk/DrawRect.d

    r322 r527  
    1 module gtk.DrawRect; 
     1module DraRect; 
    22 
    3 import gdk.Window; 
    4 import glib.ListG; 
    5 import glib.ListSG; 
    6 import glib.Source; 
     3import gtk.Main; 
     4import gtk.MainWindow; 
     5import gtk.Widget; 
     6import gdk.GC; 
     7import gdk.Drawable; 
     8import gdk.Color; 
    79 
     10void main (string[] args) 
     11{ 
     12    Main.init(args); 
     13    MainWindow window = new MainWindow("Gtkd draw rect example"); 
     14     
     15    window.addOnHide( 
     16        delegate void (in Widget whatever) 
     17        { 
     18            Main.exit(0); 
     19        } 
     20    ); 
    821 
    9 void main(char[][] args) 
    10 
    11     (new Window(null)).drawRectangle(null, false, 0,0,0,0); 
     22    window.addOnExpose( 
     23        delegate int (GdkEventExpose * whatever_II, in Widget widget) 
     24        { 
     25            Drawable da = widget.getDrawable(); 
     26            da.drawRectangle(   gcFgColor(da, 0, 255, 255), true, 
     27                                0, 0, window.getHeight(), window.getWidth() 
     28            ); 
     29            return 1; 
     30        } 
     31    ); 
     32 
     33    window.showAll(); 
     34    Main.run(); 
    1235} 
    1336 
     37GC gcFgColor (in Drawable da, int r, int g, int b) 
     38{ 
     39    if (r<0) r=0;   if (r>255) r=255; 
     40    if (g<0) r=0;   if (g>255) g=255; 
     41    if (b<0) r=0;   if (b>255) b=255; 
     42 
     43    GC rt = new GC(da); 
     44    rt.setRgbFgColor( new Color(cast(ubyte)r, cast(ubyte)g, cast(ubyte)b) ); 
     45 
     46    return rt; 
     47}