Changeset 28:b5fadd8d930b

Show
Ignore:
Timestamp:
04/08/08 10:52:21 (9 months ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
branch:
default
convert_revision:
f72a3976a5547b70cd6535d5ab287336c369e7d0
Message:

Small addition to GUI, paths work-around for Windows.

New GUI widget containing a widget.
Paths on windows now uses "." and "./user" as a temporary measure.

committer: Diggory Hardy <diggory.hardy@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • data/conf/gui.mtt

    r27 r28  
    33<int|x=10> 
    44<int|y=50> 
    5 <int[][int]|widgetData=[0:[1,200,200]]> 
     5<int[][int]|widgetData=[0:[1001,200,200]]> 
     6{W2} 
     7<int|x=150> 
     8<int|y=200> 
     9<int[][int]|widgetData=[0:[1002,2],2:[1001,150,150]]> 
  • mde/gui/Widget.d

    r27 r28  
    1717module mde.gui.Widget; 
    1818 
     19import mde.gui.IWindow; 
    1920import mde.gui.exception; 
    2021 
     
    2829interface Widget 
    2930{ 
     31    /* this() should look like this: 
     32    this (IWindow window, int[] data) 
     33    * where: 
     34    *   window is the parent window (only needed for getting sub-widgets, hence no need to store) 
     35    *   data is the widget creation data, stripped of the widget type (see createWidget). 
     36    */ 
     37     
    3038    /** Draw, starting from given x and y. 
    3139    * 
     
    4553    int w, h;   // size 
    4654     
    47     this (int[] data) { 
     55    this (IWindow, int[] data) { 
    4856        if (data.length != 2) throw new WidgetDataException; 
    4957         
     
    6371} 
    6472 
    65 enum WIDGET_TYPES : int { 
    66     BOX = 1 
     73/// Encapsulates another widget 
     74class SingleWidget : Widget 
     75
     76    int w, h;           // size 
     77    Widget subWidget; 
     78     
     79    this (IWindow window, int[] data) { 
     80        if (data.length != 1) throw new WidgetDataException; 
     81         
     82        subWidget = window.getWidget (data[0]); 
     83         
     84        subWidget.getSize (w,h); 
     85        w += 10; 
     86        h += 10; 
     87    } 
     88     
     89    void draw (int x, int y) { 
     90        gl.setColor (1.0f, 0.6f, 0.0f); 
     91        gl.drawBox (x,x+w, y,y+h); 
     92         
     93        subWidget.draw (x+5, y+5); 
     94    } 
     95     
     96    void getSize (out int w, out int h) { 
     97        w = this.w; 
     98        h = this.h; 
     99    } 
    67100} 
    68101 
    69 Widget createWidget (int[] data) { 
     102// Widget types. Start high so they can be reordered easily later. 
     103enum WIDGET_TYPES : int { 
     104    BOX = 1001, SINGLE 
     105
     106 
     107Widget createWidget (IWindow window, int[] data) { 
    70108    if (data.length < 1) throw new WidgetDataException ("No widget data"); 
    71109    int type = data[0];     // type is first element of data 
    72110    data = data[1..$];      // the rest is passed to the Widget 
    73111     
    74     if (type == WIDGET_TYPES.BOX) return new BoxWidget (data); 
     112    if (type == WIDGET_TYPES.BOX) return new BoxWidget (window, data); 
     113    else if (type == WIDGET_TYPES.SINGLE) return new SingleWidget (window, data); 
    75114    else throw new WidgetDataException ("Bad widget type"); 
    76115} 
  • mde/gui/gui.d

    r27 r28  
    1717module mde.gui.gui; 
    1818 
     19import mde.gui.IWindow; 
    1920import mde.gui.Widget; 
    2021import mde.gui.exception; 
     
    6970                try { 
    7071                    w.finalise(); 
     72                     
     73                    gl.addDrawCallback (&w.draw); 
    7174                } catch (WindowLoadException e) { 
    7275                    logger.error ("Window failed to load: " ~ e.msg); 
    7376                } 
    74                  
    75                 gl.addDrawCallback (&w.draw); 
    7677            } 
    7778        } 
     
    9293* created, be given its int[] of data, which this() must confirm is valid (or throw). 
    9394*/ 
    94 class Window : mt.IDataSection 
     95class Window : mt.IDataSection, IWindow 
    9596{ 
    9697    alias int widgetID;     // Widget ID type. Each ID is unique under this window. Type is int since this is the widget data type. 
     
    102103    int w,h;                        // Window size (calculated from Widgets) 
    103104     
    104     const BORDER_WIDTH = 5;         // Temporary way to handle window decorations 
     105    const BORDER_WIDTH = 8;         // Temporary way to handle window decorations 
    105106     
    106107     
     
    123124             
    124125            // Throws WidgetDataException (a WindowLoadException) if bad data: 
    125             Widget w = createWidget (*d); 
     126            Widget w = createWidget (this, *d); 
    126127            widgets[i] = w; 
    127128            return w; 
  • mde/resource/paths.d

    r27 r28  
    3838import mde.mergetag.exception; 
    3939 
     40import tango.io.Console; 
    4041import tango.io.FilePath; 
    41 import tango.util.log.Log : Log, Logger; 
    4242import tango.stdc.stdlib; 
    4343import tango.stdc.stringz; 
     44//import tango.scrapple.sys.win32.Registry;     // Trouble getting this to work 
    4445 
    4546/** Order to read files in. 
     
    125126                return true; 
    126127            } catch (Exception e) { 
    127                 logger.error ("Creating path "~path~" failed:"); 
    128                 logger.error (e.msg)
     128                // No logging avaiable yet: Use Stdout/Cout 
     129                Cout ("Creating path "~path~" failed:" ~ e.msg).newline
    129130            } 
    130131        } 
     
    143144 
    144145//BEGIN Path resolution 
    145 static this() { 
    146     logger = Log.getLogger ("mde.resource.paths"); 
    147 } 
    148  
    149146// These are used several times: 
    150147const DATA = "/data"; 
    151148const CONF = "/conf"; 
     149 
     150/** Find at least one path for each required directory. 
     151* 
     152* Note: the logger cannot be used yet, so only output is exception messages. */ 
    152153 
    153154version (linux) { 
     
    178179} else version (Windows) { 
    179180    void resolvePaths () { 
    180         static assert (false, "No registry code"); 
     181        //FIXME: Get path from registry 
     182        //FIXME: Get user path (Docs&Settings/USER/Local Settings/Application data/mde) 
    181183         
    182184        // Base paths: 
    183         char[] userPath = `...`
    184         char[] installPath = `registryInstallPath or "."`; 
    185         char[] staticPath = findPath (installPath ~ DATA); 
     185        PathView installPath = findPath (false, "");
     186        PathView userPath = findPath (true, "user");   // FIXME: see above 
     187        PathView staticPath = findPath (false, "data"); 
    186188         
    187189        // Static data paths: 
     
    189191        dataDir.tryPath (userPath.toString ~ DATA); 
    190192        if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); 
    191                  
     193         
    192194        // Configuration paths: 
    193195        confDir.tryPath (staticPath.toString ~ CONF); 
    194         bool sysConf = confDir.tryPath (installPath ~ CONF); 
    195         confDir.tryPath (userPath.toString ~ CONF, !sysConf);   // create if no system conf dir 
     196        confDir.tryPath ("conf"); 
     197        confDir.tryPath (userPath.toString ~ CONF, true); 
    196198        if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!"); 
    197199         
    198200        // Logging path: 
    199         logDir = userPath
     201        logDir = userPath.toString
    200202    } 
    201203} else { 
     
    207209// There are NO CHECKS that this is not exceeded. 
    208210const MAX_PATHS = 3; 
    209  
    210 Logger logger; 
    211211 
    212212/* Try each path in succession, returning the first to exist and be a folder. 
     
    220220    if (create) {   // try to create a folder, using each path in turn until succesful 
    221221        foreach (path; paths) { 
    222             PathView pv = new FilePath (path); 
     222            FilePath fp = new FilePath (path); 
    223223            try { 
    224                 return pv
     224                return fp.create
    225225            } 
    226226            catch (Exception e) {} 
     
    228228    } 
    229229    // no valid path... 
    230     logger.fatal ("Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:")
    231     foreach (path; paths) logger.fatal ('\t' ~ path)
    232     throw new mdeException ("Unable to resolve a required path (see log for details)."); 
     230    char[] msg = "Unable to find"~(create ? " or create" : "")~" a required path! The following were tried:"
     231    foreach (path; paths) msg ~= "  \"" ~ path ~ '\"'
     232    throw new mdeException (msg); 
    233233} 
    234234//END Path resolution 
  • mde/scheduler/Init.d

    r26 r28  
    5656        paths.resolvePaths(); 
    5757    } catch (Exception e) { 
     58        // NOTE: an exception thrown here cannot be caught by main()! 
    5859        throw new InitException ("Resolving paths failed: " ~ e.msg); 
    5960    }