Changeset 540 for trunk/thune/gl/gui.c

Show
Ignore:
Timestamp:
07/04/08 03:46:13 (5 months ago)
Author:
krobillard
Message:

Thune

  • Implemented date!. Added ur_arrayExpand(), save.

ThuneGL

  • Added line-edit widget, blit, move-glyphs.
  • Can now make font from texture & binary.
  • Optimized renderGlyphXY() a bit.
  • twidget close event handler works again.
  • Updated thune-gl.spec for renamed glv RPM.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/gl/gui.c

    r537 r540  
    5959#define WID(wp)         (wp - ((GWidget*) ui->widgets.ptr.v)) 
    6060#define CLASS(wp)       wclass[wp->classId] 
     61#define IS_ENABLED(wp)  (! (wp->flags & GW_DISABLED)) 
    6162 
    6263#define EACH_CHILD(parent,it) \ 
     
    103104 
    104105 
    105 // Order must match gui-style-proto in gx.t. 
    106 enum ContextIndexStyle 
    107 { 
    108     CI_STYLE_TEXTURE,       // texture! 
    109     CI_STYLE_TEX_SIZE,      // coord! 
    110     CI_STYLE_CONTROL_FONT,  // font! 
    111     CI_STYLE_TITLE_FONT,    // font! 
    112     CI_STYLE_LABEL,         // Variable for use by draw lists. 
    113     CI_STYLE_AREA,          // Variable for use by draw lists. 
    114     CI_STYLE_WINDOW_MARGIN, // coord! 
    115     CI_STYLE_WINDOW,        // Draw list 
    116     CI_STYLE_BUTTON_SIZE,   // coord! 
    117     CI_STYLE_BUTTON_UP,     // Draw list 
    118     CI_STYLE_BUTTON_DOWN,   // Draw list 
    119     CI_STYLE_BUTTON_HOVER,  // Draw list 
    120     CI_STYLE_LABEL_DL       // Draw list 
    121 }; 
    122  
    123  
    124106#define WCLASS_MAX      24 
    125107static GWidgetClass wclass[ WCLASS_MAX ]; 
     
    256238 
    257239 
    258 static GWidget* base_parse( GUI* ui, GMakeState* ms, int classId ) 
     240static GWidget* base_parse( GUI* ui, GMakeState* ms ) 
    259241{ 
    260242    GWidget* wp; 
     
    309291 
    310292    // Future... 
     293    UIndex   eventN; 
    311294    uint8_t  layoutType; 
    312295    uint8_t  rows; 
    313296    uint8_t  cols; 
    314     uint8_t _pad[5]; 
     297    uint8_t  _pad; 
    315298} 
    316299BoxData; 
     
    344327 
    345328 
    346 static GWidget* box_parse( GUI* ui, GMakeState* ms, int classId ) 
     329static GWidget* box_parse( GUI* ui, GMakeState* ms ) 
    347330{ 
    348331    GWidget* wp; 
     
    721704 
    722705 
    723 static GWidget* window_parse( GUI* ui, GMakeState* ms, int classId ) 
     706static GWidget* window_parse( GUI* ui, GMakeState* ms ) 
    724707{ 
    725708    GWidget* wp; 
    726709    UAtom sel = ur_sel(ms->it); 
    727     wp = box_parse( ui, ms, classId ); 
     710    wp = box_parse( ui, ms ); 
    728711    if( wp ) 
    729712    { 
     
    740723    BoxData* wd = BOX_DATA(wp); 
    741724    (void) ui; 
    742  
    743     wp->flags |= GW_DISABLED;   // Does not handle input.  
    744725 
    745726    wd->marginL = 8; 
     
    769750 
    770751 
     752static void window_event( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
     753{ 
     754    BoxData* wd = BOX_DATA(wp); 
     755 
     756    (void) ui; 
     757 
     758    if( wd->eventN ) 
     759    { 
     760        if( ev->type == GLV_EVENT_CLOSE ) 
     761        { 
     762        } 
     763    } 
     764} 
     765 
     766 
    771767static void window_sizeHint( GUI* ui, GWidget* wp, GSizeHint* size ) 
    772768{ 
     
    825821#include "widgets/labelw.c" 
    826822#include "widgets/twidget.c" 
     823#include "widgets/lineeditw.c" 
    827824//#include "widgets/listw.c" 
    828825 
     
    838835*/ 
    839836 
    840 static int wclassCount = 7; 
     837static int wclassCount = 8; 
    841838 
    842839static GWidgetClass wclass[ WCLASS_MAX ] = 
     
    858855 
    859856  { "window", 
    860     window_parse,     window_init,    window_mark,    no_event, 
     857    window_parse,     window_init,    window_mark,    window_event, 
    861858    window_sizeHint,  window_layout,  window_render,  base_select, 
    862859    0, 0, 0 }, 
     
    875872    twidget_parse,    twidget_init,   twidget_mark,   twidget_event, 
    876873    expand_sizeHint,  twidget_layout, twidget_render, base_select, 
     874    0, 0, 0 }, 
     875 
     876  { "line-edit", 
     877    ledit_parse,      ledit_init,     ledit_mark,     ledit_event, 
     878    ledit_sizeHint,   ledit_layout,   ledit_render,   ledit_select, 
    877879    0, 0, 0 }, 
    878880 
     
    972974 
    973975 
     976static void gui_callFocus( GUI* ui, GWidgetId id, int eventType ) 
     977{ 
     978    if( IS_VALID(id) ) 
     979    { 
     980        GWidget* w = WPTR(id); 
     981        if( IS_ENABLED(w) ) 
     982        { 
     983            GLViewEvent me; 
     984            INIT_EVENT( me, eventType, 0, 0, 0, 0 ); 
     985            CLASS( w ).dispatch( ui, w, &me ); 
     986        } 
     987    } 
     988} 
     989 
     990 
    974991void gui_setMouseFocus( GUI* ui, GWidgetId id ) 
    975992{ 
    976     ui->mouseFocus = id; 
     993    if( ui->mouseFocus != id ) 
     994    { 
     995        gui_callFocus( ui, ui->mouseFocus, GLV_EVENT_FOCUS_OUT ); 
     996        ui->mouseFocus = id; 
     997        gui_callFocus( ui, id, GLV_EVENT_FOCUS_IN ); 
     998    } 
    977999} 
    9781000 
     
    9941016 
    9951017 
     1018/* 
     1019  Returns child of wp under event x,y, or wp if no child contains the point. 
     1020*/ 
    9961021static GWidget* childAt( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
    9971022{ 
     
    10301055    switch( ev->type ) 
    10311056    { 
     1057        case GLV_EVENT_CLOSE: 
     1058        { 
     1059            GWidgetIt it; 
     1060            EACH_SHOWN_ROOT( it ) 
     1061                w = it.w; 
     1062                goto dispatch; 
     1063            EACH_END 
     1064        } 
     1065            return; 
     1066 
    10321067        case GLV_EVENT_BUTTON_DOWN: 
    10331068        case GLV_EVENT_BUTTON_UP: 
     
    10511086            { 
    10521087                w = WPTR(ui->mouseFocus); 
    1053                 if( ui->mouseGrabbed || 
    1054                     gui_widgetContains( w, ev->x, ev->y ) ) 
     1088                if( ui->mouseGrabbed ) 
    10551089                { 
    10561090                    goto dispatch; 
    10571091                } 
    1058                 else 
     1092                else if( gui_widgetContains( w, ev->x, ev->y ) ) 
    10591093                { 
    1060                     GLViewEvent me; 
    1061                     INIT_EVENT( me, GLV_EVENT_FOCUS_OUT, 0, 
    1062                                 ev->state, ev->x, ev->y ); 
    1063                     CLASS( w ).dispatch( ui, w, &me ); 
     1094                    GWidget* cw = childAt( ui, w, ev ); 
     1095                    if( cw != w ) 
     1096                    { 
     1097                        gui_setMouseFocus( ui, WID(cw) ); 
     1098                        w = cw; 
     1099                    } 
     1100                    goto dispatch; 
    10641101                } 
    10651102            } 
    10661103 
    1067             ui->mouseFocus = widgetAt( ui, ev ); 
     1104            gui_setMouseFocus( ui, widgetAt( ui, ev ) ); 
    10681105            if( IS_VALID(ui->mouseFocus) ) 
    10691106            { 
    10701107                w = WPTR(ui->mouseFocus); 
    1071                 if( ! (w->flags & GW_DISABLED) ) 
    1072                 { 
    1073                     GLViewEvent me; 
    1074                     INIT_EVENT( me, GLV_EVENT_FOCUS_IN, 0, 
    1075                                 ev->state, ev->x, ev->y ); 
    1076                     CLASS( w ).dispatch( ui, w, &me ); 
    1077                     goto dispatch; 
    1078                 } 
     1108                goto dispatch; 
    10791109            } 
    10801110            break; 
     
    13631393                if( cl->nameAtom == atom ) 
    13641394                { 
    1365                     wp = cl->parse( ui, ms, cl->id ); 
     1395                    ms->classId = cl->id; 
     1396                    wp = cl->parse( ui, ms ); 
    13661397                    if( wp ) 
    13671398                    { 
     
    14121443/* 
    14131444  Returns pointer to first arg if all types match, or zero. 
     1445  Unlike gui_matchArg(), this function does not throw an error if it fails. 
    14141446*/ 
    14151447const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ) 
     
    14371469    if( argc ) 
    14381470        return 0; 
     1471 
    14391472    ms->it = it; 
    14401473    return first; 
     1474} 
     1475 
     1476 
     1477/* 
     1478  Get and verify next argument. 
     1479  Returns pointer to arg cell if type matches, or zero. 
     1480  Throws an error if fails. 
     1481*/ 
     1482const UCell* gui_matchArg( UThread* ut, GMakeState* ms, int type ) 
     1483{ 
     1484    const UCell* it = ms->it; 
     1485    if( it != ms->end ) 
     1486    { 
     1487        if( ur_is(it, type) ) 
     1488        { 
     1489valid: 
     1490            ++ms->it; 
     1491            return it; 
     1492        } 
     1493        if( ur_isAWord(it) ) 
     1494        { 
     1495            it = ur_wordCell(ut, it); 
     1496            if( it && ur_is(it, type) ) 
     1497                goto valid; 
     1498            return 0;   // ur_wordCell() throws error. 
     1499        } 
     1500    } 
     1501    ur_throwErr( UR_ERR_SCRIPT, "%s expected %s argument", 
     1502                 wclass[ ms->classId ].name, ur_typeName(type) ); 
     1503    return 0; 
    14411504} 
    14421505 
     
    14951558 
    14961559 
     1560#ifdef DEBUG 
     1561static void dumpIndent( int indent ) 
     1562{ 
     1563    while( indent-- ) 
     1564        printf( "    " ); 
     1565} 
     1566 
     1567 
     1568void gui_dumpWidget( const GUI* ui, const GWidget* wp, int indent ) 
     1569{ 
     1570    dumpIndent( indent ); 
     1571    printf( "%ld %s %d,%d,%d,%d $%02X", WID(wp), CLASS( wp ).name, 
     1572            wp->x, wp->y, wp->w, wp->h, wp->flags ); 
     1573    if( IS_VALID(wp->child) ) 
     1574    { 
     1575        GWidgetIt it; 
     1576        printf( " [\n" ); 
     1577        ++indent; 
     1578        EACH_CHILD( wp, it ) 
     1579            gui_dumpWidget( ui, it.w, indent ); 
     1580        EACH_END 
     1581        --indent; 
     1582        dumpIndent( indent ); 
     1583        printf( "]\n" ); 
     1584    } 
     1585    else 
     1586    { 
     1587        printf( "\n" ); 
     1588    } 
     1589} 
     1590 
     1591 
     1592void gui_dump( const GUI* ui ) 
     1593{ 
     1594    GWidgetIt it; 
     1595 
     1596    printf( "gui [\n" ); 
     1597    EACH_ROOT( it ) 
     1598        gui_dumpWidget( ui, it.w, 1 ); 
     1599    EACH_END 
     1600    printf( "]\n" ); 
     1601} 
     1602#endif 
     1603 
     1604 
    14971605// EOF