Changeset 51

Show
Ignore:
Timestamp:
04/28/07 17:09:55 (1 year ago)
Author:
baxissimo
Message:

Various small fixes and improvements.
event.d: added is_left_press et al properties (I found myselft getting confused as to whether 'left_down' mean it was a left down event or just that left was generally down. Maybe that should become left_is_down...

gui.d: made mixins refer to fully qualified names. Fixes problems with mixing-in in a different context.

theme stuff: Fixed dxut to not crash when presented with an unknown subclass.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/luigi/event.d

    r47 r51  
    223223    bool alt_down() { return (mods & KeyMods.Alt)!=0; } 
    224224 
     225    bool is_left_press() { return (is_press && is_left); } 
     226    bool is_right_press() { return (is_press && is_right); } 
     227    bool is_middle_press() { return (is_press && is_middle); } 
     228    bool is_left_release() { return (is_release && is_left); } 
     229    bool is_right_release() { return (is_release && is_right); } 
     230    bool is_middle_release() { return (is_release && is_middle); } 
     231 
    225232    bool is_alive = false; 
    226233    bool alive(bool tf) { return is_alive=tf; } 
  • trunk/luigi/gui.d

    r50 r51  
    267267template WidgetMixin() 
    268268{ 
    269     alias typeof(this) T; 
    270     static assert(is(T:Widget), "WidgetMixin should be derived from Widget"); 
     269    alias typeof(this) WidgetType; 
     270    static assert(is(WidgetType:luigi.gui.Widget),  
     271                  "WidgetMixin should be derived from Widget"); 
    271272         
    272273    /**  
     
    284285    Returns: A pointer to 'this', with the proper derived type. 
    285286    */ 
    286     T arranged_(VArg...)(VArg varg) 
     287    WidgetType arranged_(VArg...)(VArg varg) 
    287288    { 
    288289        //static assert(is(T:Widget), "arranger_add requires a Widget as argument 0"); 
     
    296297template PanelMixin() 
    297298{ 
    298     alias typeof(this) T; 
    299     static assert(is(T:Panel), "PanelMixin should be derived from Panel"); 
     299    alias typeof(this) PanelType; 
     300    static assert(is(PanelType:luigi.gui.Panel),  
     301                  "PanelMixin should be derived from Panel"); 
    300302         
    301303    /** Add the widget to this panel. 
     
    312314    W add_widget(W)(W widget) 
    313315    { 
    314         static assert(is(W:Widget), "add_widget requires a Widget as argument"); 
     316        static assert(is(W:luigi.gui.Widget), "add_widget requires a Widget as argument"); 
    315317        add(widget); 
    316318        return widget; 
     
    331333    W add_arranged(W, Varg...)(W widget, Varg args) 
    332334    { 
    333         static assert(is(W:Widget), "add_arranged requires a Widget as argument"); 
     335        static assert(is(W:luigi.gui.Widget), 
     336                      "add_arranged requires a Widget as argument"); 
    334337        add(widget); 
    335338        assert(arranger, "add_arranged called with no arranger set"); 
     
    345348{ 
    346349    mixin WidgetMixin; 
     350 
     351    // Some handy aliases everyone should have 
     352    // This makes it so you can refer to these inside a Widget subclass 
     353    // without worry 
     354    alias luigi.base.Size Size; 
     355    alias luigi.base.Rect Rect; 
     356    alias luigi.base.Point Point; 
     357 
    347358 
    348359    this() {} 
     
    19701981 
    19711982    int checked_item(int v) { 
    1972         writefln("checked item(%d), cur = %d", v, m_checkedItem); 
    19731983        if (v == m_checkedItem) { return m_checkedItem; } 
    19741984        m_checkedItem = v; 
  • trunk/luigi/theme.d

    r48 r51  
    9696} 
    9797 
    98 template FuncDispatcher(FuncT) 
    99 
    100     FuncT lookup(Widget item) { 
     98/** This template/mixin provides helper functions used by themes to  
     99 *  manage per-class instance information. 
     100 */ 
     101template WidgetClassInfoDict(FuncT) 
     102
     103    /** Lookup Widget class-specific data in a table. 
     104     *   
     105     * This is like an ordinary AA lookup keyed on ClassInfo,  
     106     * but if a key is missing it recursively tries all the ClassInfo 
     107     * objects for the base classes as well.   
     108     * If it finds a match, that match is copied to  
     109     * table[item.classinfo] for faster future lookups. 
     110     */ 
     111    FuncT lookup(inout FuncT[ClassInfo] table, Widget item) { 
    101112        // Search for func in the table, going up class hierarchy 
    102113        ClassInfo start = item.classinfo; 
    103         if (start in m_table) return m_table[start]; 
     114        if (start in table) return table[start]; 
    104115        ClassInfo stop = Widget.classinfo; 
    105         for(auto cinfo=start.base; cinfo!=stop; cinfo=cinfo.base)  
     116        for(auto cinfo=start; cinfo!=stop; cinfo=cinfo.base)  
    106117        { 
    107             if (cinfo in m_table) { 
    108                 FuncT f = m_table[cinfo]; 
    109                 m_table[start] = f; // cache result for later 
     118            if (cinfo in table) { 
     119                FuncT f = table[cinfo]; 
     120                table[start] = f; // cache result for later 
    110121                return f; 
    111122            } 
    112             return null; 
    113123        } 
    114124        return null; 
    115125    }     
     126    /** Same as lookup(table,item) but use the mixin's builtin m_table */ 
     127    FuncT lookup(Widget item) { 
     128        return lookup(m_table,item);  
     129    } 
     130 
     131    /** Add an element to the ClassInfo-keyed table */ 
     132    void add(inout FuncT[ClassInfo] table, ClassInfo c, FuncT f) { 
     133        table[c] = f; 
     134    } 
     135    /** Same as add(table,c,f) but use the mixin's builtin m_table */ 
    116136    void add(ClassInfo c, FuncT f) { 
    117         m_table[c] = f
     137        add(m_table, c, f)
    118138    } 
    119139    FuncT[ClassInfo] m_table; 
    120140} 
     141 
    121142 
    122143class ThemeBase : AbstractTheme 
     
    145166 
    146167    protected: 
    147     mixin FuncDispatcher!(DrawFunc)   m_drawFuncs; 
    148     mixin FuncDispatcher!(SizeFunc)   m_minsizeFuncs; 
    149     mixin FuncDispatcher!(SizeFunc)   m_bestsizeFuncs; 
    150     mixin FuncDispatcher!(ButtonFunc) m_btnFuncs; 
    151     mixin FuncDispatcher!(MoveFunc)   m_moveFuncs; 
    152     mixin FuncDispatcher!(KeyFunc)    m_keyFuncs; 
     168    mixin WidgetClassInfoDict!(DrawFunc)   m_drawFuncs; 
     169    mixin WidgetClassInfoDict!(SizeFunc)   m_minsizeFuncs; 
     170    mixin WidgetClassInfoDict!(SizeFunc)   m_bestsizeFuncs; 
     171    mixin WidgetClassInfoDict!(ButtonFunc) m_btnFuncs; 
     172    mixin WidgetClassInfoDict!(MoveFunc)   m_moveFuncs; 
     173    mixin WidgetClassInfoDict!(KeyFunc)    m_keyFuncs; 
    153174 
    154175    public: 
  • trunk/luigi/themes/dxut.d

    r47 r51  
    105105} 
    106106 
     107alias DXUTTheme Theme; 
     108 
    107109class DXUTTheme : ThemeBase 
    108110{ 
     
    168170        } 
    169171        else { 
     172            // This means we haven't made it yet 
    170173            ThemeData td2 = new ThemeData; 
    171174            w.theme_instance_data = td2; 
    172             td2.elements = m_elements[w.classinfo].dup; 
     175            auto pElements = w.classinfo in m_elements; 
     176            if (pElements!=null) { 
     177                td2.elements = (*pElements).dup; 
     178            } 
     179            else { 
     180                // this is an unknown class  
     181                // -- find best match up class hierarchy 
     182                auto cinfo = w.classinfo; 
     183                while (cinfo != Widget.classinfo) { 
     184                    pElements = cinfo in m_elements; 
     185                    if (pElements) { 
     186                        td2.elements = (*pElements).dup; 
     187                        break; 
     188                    } 
     189                    cinfo = cinfo.base; 
     190                } 
     191                if (cinfo == Widget.classinfo) { 
     192                    // didn't find it. w is not a subclass of anything 
     193                    // we know how to draw. 
     194                    Element[] empty; 
     195                    m_elements[w.classinfo] = empty; 
     196                } 
     197            } 
    173198            return td2; 
    174199        } 
     
    935960    { 
    936961        auto w = cast(Slider)widget; assert(w); 
    937         if (ev.is_left && ev.is_press) { w.grab_mouse(); } 
     962        if (ev.is_left && ev.is_press) {  
     963            w.grab_mouse();  
     964        } 
    938965        else if (ev.is_left && ev.is_release) { w.release_mouse(); } 
    939966        double v = slider_map_mouse_to_value(w, ev.p); 
    940967        w.m_saveValue = w.value; 
    941968        w.value = v; 
     969        ev.alive = false; 
    942970    } 
    943971    void slider_mouse_move(Widget widget, MouseMoveEvent ev)  
     
    950978            double v = slider_map_mouse_to_value(w, ev.p); 
    951979            w.value = v; 
     980            ev.alive = false; 
    952981        } 
    953982    } 
  • trunk/luigi/themes/std.d

    r32 r51  
    3535import luigi.gui; 
    3636 
     37alias StdTheme Theme; 
    3738class StdTheme : ThemeBase 
    3839{