Changeset 10

Show
Ignore:
Timestamp:
11/23/06 21:25:48 (2 years ago)
Author:
baxissimo
Message:

Slider kinda works now.
Have to figure out the best way to pass mouse events to the theme still, though.

Files:

Legend:

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

    r7 r10  
    6565    Size preferred_size(Size bounds); 
    6666 
     67    /** Return stretch factor in x and y directions. 
     68     *  If component is fixed size, then should be 0. 
     69     *  If nonzero then all nonzero elements share the  
     70     *  available space in proportion with their stretch  
     71     *  factors.  So a stretch=2 gets twice as much  
     72     *  space as a stretch=1. 
     73     */ 
     74    int stretch_x(); 
     75    int stretch_y(); 
     76 
    6777    void set_rect(Rect s); 
    68     void set_position(Point p);  
     78    void set_position(Point p); 
    6979    void set_size(Size sz); 
    7080 
  • trunk/luigi/bitmaps.d

    r7 r10  
    197197}; 
    198198  
    199  Orion Sky Lawlor, olawlor@acm.org, 2006/05/04 (LGPL) 
     199 Orion Sky Lawlor, olawlor@acm.org 
     200 @ This stuff was orignally in C++ and labelled LGPL, but Bill Baxter  
     201 @ got Lawlor's permission to make it ZLIB via email on Aug 13, 2006 
    200202*/ 
    201203 
  • trunk/luigi/example1.brf

    r5 r10  
    1 # Damn, envvars like %DMDDIR% don't work 
    21-g 
    32-debug 
    4 -I..\..\baxissimo 
    5 -I..\..\ext 
     3-I$(DMDDIR)\baxissimo 
     4-I$(DMDDIR)\ext 
    65-full 
    76-cleanup 
  • trunk/luigi/example1.d

    r7 r10  
    6060class CoolTarget(T...) 
    6161{ 
    62     this( void delegate(T...) dg) { fn = dg; } 
     62    this( void delegate(T) dg) { fn = dg; } 
    6363    void slot(T args) { 
    6464        fn(args); 
    6565    } 
    66     void delegate(T...) fn; 
     66    void delegate(T) fn; 
    6767} 
    6868class BDelegate 
     
    194194            Button b28 = arranged( g.add_widget(new Button("Tool8"))); 
    195195            Button b29 = arranged( g.add_widget(new Button("Tool9"))); 
     196            Slider s01 = arranged( g.add_widget(new Slider("Thingy"))); 
     197            auto T = new CoolTarget!(double)((double d){ writefln("Slider now %s",d); } ); 
     198            s01.value_changed.fconnect!(typeof(&T.slot),1)(&T.slot); 
    196199        } 
    197200 
  • trunk/luigi/gldraw.d

    r7 r10  
    246246{ 
    247247    r.inset(0.5); 
    248     float x = r.x; 
    249     float y = r.y; 
    250     float x2 = r.x2; 
    251     float y2 = r.y2; 
    252  
    253     translate(0.5,0.5); scope(exit) untranslate(0.5,0.5); 
    254     glColor4ubv( bkg.ptr ); 
    255     glBegin( GL_LINE_LOOP ); 
    256     glVertex2f( x+1, y+1 );  glVertex2f( x2-1, y+1 ); 
    257     glVertex2f( x2-1, y2-1 );  glVertex2f( x+1, y2-1 ); 
    258     glEnd(); 
    259  
    260     glColor4ubv( light.ptr ); 
    261     glBegin( GL_LINE_STRIP ); 
    262     glVertex2f( x, y2 );  glVertex2f( x, y );  glVertex2f( x2, y ); 
    263     glEnd(); 
    264  
    265     glColor4ubv( dark.ptr ); 
    266     glBegin( GL_LINE_STRIP ); 
    267     glVertex2f( x2, y );  glVertex2f( x2, y2 );  glVertex2f( x, y2 ); 
    268     glEnd(); 
    269  
    270     glColor4ubv( medium.ptr ); 
    271     glBegin( GL_LINE_STRIP ); 
    272     glVertex2f( x2-1, y+1 );  glVertex2f( x2-1, y2-1 );  glVertex2f( x+1, y2-1 ); 
    273     glEnd(); 
     248 
     249    with (r) { 
     250        translate(0.5,0.5); scope(exit) untranslate(0.5,0.5); 
     251        glColor4ubv( bkg.ptr ); 
     252        glBegin( GL_LINE_LOOP ); 
     253        glVertex2f( x+1, y+1 );  glVertex2f( x2-1, y+1 ); 
     254        glVertex2f( x2-1, y2-1 );  glVertex2f( x+1, y2-1 ); 
     255        glEnd(); 
     256 
     257        glColor4ubv( light.ptr ); 
     258        glBegin( GL_LINE_STRIP ); 
     259        glVertex2f( x, y2 );  glVertex2f( x, y );  glVertex2f( x2, y ); 
     260        glEnd(); 
     261 
     262        glColor4ubv( dark.ptr ); 
     263        glBegin( GL_LINE_STRIP ); 
     264        glVertex2f( x2, y );  glVertex2f( x2, y2 );  glVertex2f( x, y2 ); 
     265        glEnd(); 
     266 
     267        glColor4ubv( medium.ptr ); 
     268        glBegin( GL_LINE_STRIP ); 
     269        glVertex2f( x2-1, y+1 );  glVertex2f( x2-1, y2-1 );  glVertex2f( x+1, y2-1 ); 
     270        glEnd(); 
     271    } 
    274272} 
    275273 
     
    277275{ 
    278276    r.inset(0.5); 
     277     
     278    with(r) { 
     279        // inner loop 
     280        glBegin( GL_LINE_STRIP ); 
     281        glColor4ubv( medium.ptr ); 
     282        glVertex2f( x +1, y2-1 ); 
     283        glVertex2f( x +1, y +1 ); 
     284        glVertex2f( x2-1, y +1 ); 
     285 
     286        glColor4ubv( bkg.ptr ); 
     287        glVertex2f( x2-1, y +1 ); 
     288        glVertex2f( x2-1, y2-1 ); 
     289        glVertex2f( x +1, y2-1 ); 
     290        glEnd(); 
     291 
     292        // outer loop 
     293        glBegin( GL_LINE_STRIP ); 
     294        glColor4ubv( dark.ptr ); 
     295        glVertex2f( x , y2 ); 
     296        glVertex2f( x , y  ); 
     297        glVertex2f( x2, y  ); 
     298 
     299        glColor4ubv( light.ptr ); 
     300        glVertex2f( x2, y  ); 
     301        glVertex2f( x2, y2 ); 
     302        glVertex2f( x , y2 ); 
     303        glEnd(); 
     304    } 
    279305//    stroke_raised_rect(r, bkg, light, medium, dark); 
     306/* 
    280307    glColor3ubv(dark.ptr); 
    281308    glBegin( GL_LINE_LOOP ); 
     
    288315    glVertex2f( r.x2-1, r.y2-1 );     glVertex2f( r.x+1, r.y2-1 ); 
    289316    glEnd(); 
    290  
     317*/ 
    291318 
    292319/* 
  • trunk/luigi/gui.d

    r7 r10  
    207207    S add_widget(S)(S w) 
    208208    { 
    209         static assert(is(S:Widget), "add requires a Widget as argument"); 
     209        static assert(is(S:Widget), "add_widget requires a Widget as argument"); 
    210210        add(w); 
    211211        return w; 
     
    566566    } 
    567567 
     568    int stretch_x() { return m_stretchx; } 
     569    int stretch_y() { return m_stretchy; } 
     570    void stretch(ubyte both)       { m_stretchx = m_stretchy = both; } 
     571    void stretch(ubyte x, ubyte y) { m_stretchx = x; m_stretchy = y; } 
     572 
    568573    //------------------------------------------------------------------------ 
    569574    // Hooks for the theme 
     
    580585    bool m_focused = false; 
    581586    Arranger m_arranger = null; 
     587    ubyte m_stretchx = 0; // stretchyness for arrangement  
     588    ubyte m_stretchy = 0; 
    582589 
    583590    // for any per-instance data needed by theme 
     
    15231530    override double value() { return m_value; } 
    15241531    override double value(double v) {  
     1532        if (v<m_min) v=m_min; 
     1533        if (v>m_max) v=m_max; 
    15251534        if (v==m_value) return m_value; 
    15261535        m_value = v; 
     
    15331542        label = label_; 
    15341543        value_changed = new ValueChangedSignal; 
    1535     } 
     1544        m_focusable = true; 
     1545    } 
     1546 
     1547    int on_key(inout KeyEvent ev) { 
     1548        if (ev.is_press) { 
     1549            switch(ev.key)  
     1550            { 
     1551            case Key.Right: 
     1552            case Key.Up: 
     1553                value = value + m_increment; break; 
     1554            case Key.Left: 
     1555            case Key.Down: 
     1556                value = value - m_increment; break; 
     1557            case Key.PageUp: 
     1558                value = value + m_page; break; 
     1559            case Key.PageDown: 
     1560                value = value - m_page; break; 
     1561            default: 
     1562                // pass 
     1563            } 
     1564        } 
     1565        return 0; 
     1566    } 
     1567 
     1568    double value_max() { return m_max; } 
     1569    double value_min() { return m_min; } 
     1570    double increment() { return m_increment; } 
     1571    double page_increment() { return m_page; } 
    15361572 
    15371573    char[] label; 
     
    15431579private: 
    15441580    double m_value = 0; 
     1581    double m_saveValue = 0; 
     1582    double m_max = 100; 
     1583    double m_min = 0; 
     1584    double m_increment = 1; 
     1585    double m_page = 10; 
     1586    bool m_horizontal = true; 
    15451587} 
    15461588 
  • trunk/luigi/theme.d

    r7 r10  
    7070            return null; 
    7171        } 
     72        return null; 
    7273    }     
    7374    void add(ClassInfo c, FuncT f) { 
     
    9293        _addFuncs!(TextField)(&textfield_draw, &textfield_best_size, &textfield_min_size); 
    9394        m_drawFuncs.add(Panel.classinfo, &panel_draw); 
    94         //_addFuncs!(Slider)(&slider_draw, &slider_best_size); 
     95        _addFuncs!(Slider)(&slider_draw, &slider_best_size, &slider_min_size); 
    9596        //_addFuncs!(Spinner)(&spinner_draw, &spinner_best_size); 
    9697        //_addFuncs!(RadioButton)(&radiobutton_draw, &radiobutton_best_size); 
     
    555556 
    556557    //----SLIDER---------------------------------------------------------------- 
    557     /* 
     558    static const int scroll_thumb_w =  8; 
     559    static const int scroll_thumb_h = 18; 
    558560    Size slider_min_size(Widget widget, Size bounds) { 
    559561        auto w = cast(Slider)widget; assert(w); 
    560         return Size(0,0); 
     562        return Size(scroll_thumb_w+20, scroll_thumb_h+5); 
    561563    } 
    562564    Size slider_best_size(Widget widget, Size bounds) { 
    563565        auto w = cast(Slider)widget; assert(w); 
    564         return Size(0,0); 
     566        return Size(100,scroll_thumb_h+5); 
    565567    } 
    566568    void slider_draw(Widget widget) { 
     
    568570        set_color(get_background_color(widget)); 
    569571        fill_rect(w.rect); 
    570     } 
    571     */ 
     572        translate(widget.rect.pos); scope(exit) untranslate(widget.rect.pos); 
     573        { 
     574            Rect rect = w.rect; 
     575 
     576            float ctr = 0.5*(rect.h); 
     577            const int tw = 2; 
     578            Rect rtrack = Rect(tw, ctr-tw, rect.w-tw-tw, tw+tw); 
     579            stroke_sunken_rect( 
     580                rtrack, bkg_color,hilite_color[0],hilite_color[1],hilite_color[2]); 
     581 
     582            Rect rthumb; rthumb.size = Size(scroll_thumb_w,scroll_thumb_h); 
     583            float t = w.value/(w.value_max-w.value_min); 
     584            float vpos = tw + t*(rtrack.w-rthumb.w); 
     585            rthumb.x = lrint(vpos); 
     586            rthumb.y = lrint(rect.h-rthumb.h)/2; 
     587            set_color(bkg_color); 
     588             
     589            fill_rect(rthumb); 
     590            stroke_raised_rect( 
     591                rthumb, bkg_color,hilite_color[0],hilite_color[1],hilite_color[2]); 
     592 
     593            if (w.focused()) { 
     594                set_color(hilite_color[0]); 
     595                Rect r; r.x = 0; r.y = 0; r.size = rect.size; 
     596                r.inset(1); 
     597                glEnable(GL_LINE_STIPPLE); 
     598                glLineStipple( 1, 0x5555 ); 
     599                stroke_rect(r); 
     600                glDisable(GL_LINE_STIPPLE); 
     601            } 
     602        } 
     603    } 
    572604    //----SPINNER---------------------------------------------------------------- 
    573605    /*