Changeset 528

Show
Ignore:
Timestamp:
05/30/08 18:36:20 (4 months ago)
Author:
krobillard
Message:

GL testfw reload works again.
Added UG_GUI_THROW macro to be used by widget event handlers.
Added gui_matchArgs() and GUI_PARSE macros.

Location:
trunk/thune
Files:
6 modified

Legend:

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

    r527 r528  
    2929  [x] Layout 
    3030  [/] Input 
    31   [ ] Replace old widget code (gx.t) with widget class for all-Thune code. 
    32      [ ] Convert all demos. 
    3331*/ 
    3432 
     
    9088    ms.x     = ex; \ 
    9189    ms.y     = ey 
     90 
    9291 
    9392#define SET_AREA(wp,rect) \ 
     
    201200static GWidget* base_parse( GUI* ui, GMakeState* ms, int classId ) 
    202201{ 
    203     GWidget* wp = gui_allocWidget( ui, classId ); 
    204     if( wp ) 
    205         ++ms->it; 
    206     else 
    207         ms->error = "allocWidget failed"; 
     202    GWidget* wp; 
     203    GUI_PARSE_ALLOC( wp ) 
     204    ++ms->it; 
    208205    return wp; 
    209206} 
     
    331328    { 
    332329no_block: 
    333         ms->error = "box requires block!"; 
    334         return 0; 
     330        GUI_PARSE_ERR( "box requires block!" ); 
    335331    } 
    336332    if( ur_is(bc, UT_COORD) ) 
     
    343339        goto no_block; 
    344340 
    345     wp = gui_allocWidget( ui, classId ); 
    346     if( wp ) 
     341    GUI_PARSE_ALLOC( wp ) 
     342 
    347343    { 
    348344        GMakeState cms; 
     
    364360        } 
    365361        ms->it = bc + 1; 
    366     } 
    367     else 
    368     { 
    369         ms->error = "allocWidget failed"; 
    370362    } 
    371363    return wp; 
     
    829821    GWidget* wp; 
    830822    ButtonData* wd; 
    831     //UThread* ut = ui->ut; 
    832     const UCell* sc = ms->it + 1; 
    833     const UCell* bc = ms->it + 2; 
    834  
    835     if( ((ms->end - ms->it) < 3) || 
    836         (! ur_is(sc, UT_STRING)) || 
    837         (! ur_is(bc, UT_BLOCK)) ) 
    838     { 
    839         ms->error = "button requires string! and block!"; 
    840         return 0; 
    841     } 
    842  
    843     wp = gui_allocWidget( ui, classId ); 
    844     if( ! wp ) 
    845     { 
    846         ms->error = "allocWidget failed"; 
    847         return 0; 
    848     } 
    849  
    850     wd = BUTTON_DATA(wp); 
    851     wd->labelN = sc->series.n; 
    852     wd->codeN  = bc->series.n; 
    853  
    854     ms->it += 3; 
    855     return wp; 
     823    const UCell* arg0; 
     824 
     825    arg0 = gui_matchArgs( ms, 2, UT_STRING, UT_BLOCK ); 
     826    if( arg0 ) 
     827    { 
     828        GUI_PARSE_ALLOC( wp ) 
     829 
     830        wd = BUTTON_DATA(wp); 
     831        wd->labelN = arg0->series.n; 
     832        wd->codeN  = (arg0 + 1)->series.n; 
     833        return wp; 
     834    } 
     835 
     836    GUI_PARSE_ERR( "button requires string! and block!" ); 
    856837} 
    857838 
     
    958939    if( wd->codeN ) 
    959940    { 
    960         if( UR_EVAL_ERROR == ur_eval( ui->ut, wd->codeN, 0 ) ) 
     941        if( UR_EVAL_OK != ur_eval( ui->ut, wd->codeN, 0 ) ) 
    961942        { 
    962             // TODO: Throw or catch error. 
     943            UG_GUI_THROW; 
    963944        } 
    964945    } 
     
    10621043 
    10631044#include "widgets/twidget.c" 
    1064  
    1065  
    1066 static int wclassCount = 6; 
     1045#include "widgets/listw.c" 
     1046 
     1047/* 
     1048   :tok 
     1049   'expand                   (tok make-widget) 
     1050 | 'hbox      block!         (tok make-widget) 
     1051 | 'vbox      block!         (tok make-widget) 
     1052 | 'window    block!         (tok make-widget) 
     1053 | 'button    string! block! (tok make-widget) 
     1054 | 't-widget  block!         (tok make-widget) 
     1055 | 'list      block!  block! (tok make-widget) 
     1056*/ 
     1057 
     1058static int wclassCount = 7; 
    10671059 
    10681060static GWidgetClass wclass[ WCLASS_MAX ] = 
     
    10981090    0, 0, 0 }, 
    10991091 
     1092  { "list", // "block! block!" 
     1093    listw_parse,      listw_init,     listw_mark,     listw_event, 
     1094    expand_sizeHint,  listw_layout,   listw_render, 
     1095    0, 0, 0 }, 
     1096 
    11001097  /* 
    11011098  { "option", 
    11021099  { "choice", 
    1103   { "list", 
    11041100  { "menu", 
    11051101  { "data",         // label 
     
    15881584 
    15891585/* 
     1586  Returns pointer to first arg if all types match, or zero. 
     1587*/ 
     1588const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ) 
     1589{ 
     1590    va_list args; 
     1591    int type; 
     1592    const UCell* it; 
     1593    const UCell* first = ms->it + 1; 
     1594 
     1595    if( (ms->end - first) < argc ) 
     1596        return 0; 
     1597    it = first; 
     1598 
     1599    va_start( args, argc ); 
     1600    while( argc ) 
     1601    { 
     1602        type = va_arg( args, int ); 
     1603        if( ur_type(it) != type ) 
     1604            break; 
     1605        ++it; 
     1606        --argc; 
     1607    } 
     1608    va_end( args ); 
     1609 
     1610    if( argc ) 
     1611        return 0; 
     1612    ms->it = it; 
     1613    return first; 
     1614} 
     1615 
     1616 
     1617/* 
    15901618  Only mark and sweep on top-level (parent-less) widgets. 
    15911619*/ 
  • trunk/thune/gl/gui.h

    r527 r528  
    6767    int16_t maxW; 
    6868    int16_t maxH; 
    69     int8_t weightX; 
    70     int8_t weightY; 
    71     int8_t policyX; 
    72     int8_t policyY; 
     69    uint8_t weightX; 
     70    uint8_t weightY; 
     71    uint8_t policyX; 
     72    uint8_t policyY; 
    7373} 
    7474GSizeHint; 
     
    149149 
    150150GWidget* gui_allocWidget( GUI*, int classId ); 
    151 //void     gui_freeWidget( GUI*, GWidgetId ); 
    152151GWidget* gui_widgetPtr( GUI*, GWidgetId ); 
    153152void     gui_link( GUI*, GWidget* parent, GWidgetId child ); 
    154 //void     gui_unlink( GUI*, GWidgetId ); 
    155153void     gui_enable( GUI*, GWidget*, int active ); 
    156154void     gui_show( GUI*, GWidget*, int show ); 
     
    158156void     gui_render( GUI*, GWidgetId ); 
    159157GWidget* gui_parseLayout( GUI*, GWidget* parent, GMakeState* ); 
     158const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ); 
    160159GWidget* gui_root( const GUI* ui, GWidgetId id ); 
    161160void     gui_initRectCoord( UCell*, GWidget*, int len ); 
     
    165164 
    166165 
     166#define GUI_PARSE_ERR(msg) \ 
     167    ms->error = msg; \ 
     168    return 0 
     169 
     170#define GUI_PARSE_ALLOC(wp) \ 
     171    wp = gui_allocWidget(ui, classId); \ 
     172    if(! wp) { GUI_PARSE_ERR( "allocWidget failed" ); } 
     173 
     174 
    167175#endif /*GUI_H*/ 
  • trunk/thune/gl/gx.c

    r527 r528  
    209209        { 
    210210#if 1 
    211             // Set mouse deltas here so no one else need to calculate them. 
     211            // Set mouse deltas here so no one else needs to calculate them. 
    212212            if( env->prevMouseX == MOUSE_UNSET ) 
    213213            { 
     
    500500 
    501501    UR_CALL_UNUSED_TOS 
     502 
     503    // Set handler in case UG_GUI_THROW has removed it. 
     504    glv_setEventHandler( gView, eventHandler ); 
    502505 
    503506    if( inv && (ur_sel(inv) == UR_ATOM_WAIT) ) 
  • trunk/thune/gl/gx.h

    r527 r528  
    208208#define ur_fboTexPool(c)    ((UCellFramebuffer*) (c))->glTexPool 
    209209 
     210#define UG_GUI_THROW        glv_setEventHandler(gxEnv.view, 0) 
     211 
    210212 
    211213#endif /*GX_H*/ 
  • trunk/thune/gl/widgets/twidget.c

    r527 r528  
    4949{ 
    5050    GWidget* wp; 
     51    int ok; 
     52    const UCell* arg0; 
    5153    UThread* ut = ui->ut; 
    52     int ok; 
    53     const UCell* bc = ms->it + 1; 
    54  
    55     if( ((ms->end - ms->it) < 2) || (! ur_is(bc, UT_BLOCK)) ) 
    56     { 
    57         ms->error = "t-widget requires block!"; 
    58         return 0; 
    59     } 
    60  
    61     wp = gui_allocWidget( ui, classId ); 
    62     if( ! wp ) 
    63     { 
    64         ms->error = "allocWidget failed"; 
    65         return 0; 
    66     } 
    67  
    68     UR_S_PUSH( *bc ); 
    69     ok = ur_evalCStr( ut, "t-widget-context", 16 ); 
    70     if( ok != UR_EVAL_OK ) 
    71         return 0; 
    72  
    73     assert( ur_is(UR_TOS, UT_CONTEXT) ); 
    74     ur_copyCell( wp->cell, *UR_TOS ); 
    75     UR_S_DROP; 
    76  
    77     ms->it += 2; 
    78     return wp; 
     54 
     55    arg0 = gui_matchArgs( ms, 1, UT_BLOCK ); 
     56    if( arg0 ) 
     57    { 
     58        GUI_PARSE_ALLOC( wp ) 
     59 
     60        UR_S_PUSH( *arg0 ); 
     61        ok = ur_evalCStr( ut, "t-widget-context", 16 ); 
     62        if( ok != UR_EVAL_OK ) 
     63            return 0; 
     64 
     65        assert( ur_is(UR_TOS, UT_CONTEXT) ); 
     66        ur_copyCell( wp->cell, *UR_TOS ); 
     67        UR_S_DROP; 
     68 
     69        return wp; 
     70    } 
     71    GUI_PARSE_ERR( "t-widget requires block!" ); 
    7972} 
    8073 
     
    233226            UR_S_DROP; 
    234227        } 
     228        else 
     229        { 
     230            UG_GUI_THROW; 
     231        } 
    235232    } 
    236233} 
  • trunk/thune/thune.c

    r527 r528  
    668668 
    669669                case OP_THROW:          // (val -- val) 
     670                    UR_CALL_OP = OP_THROW; 
    670671                    goto op_throw; 
    671672