Changeset 533

Show
Ignore:
Timestamp:
06/06/08 15:35:02 (3 months ago)
Author:
krobillard
Message:

Thune

Added 'any and 'all helpers.
Quit selector is now returned as exit status.
.t is now built in.

Thune-GL

vbox layout is now top to bottom.
Added label widget. Moved button code to its own file.
TexFont?.h no longer includes freetype header.
Code cleanup.
Added widget select method.
Button uses UG_GUI_THROW

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/thune/boot.c

    r527 r533  
    8181  "  ser [dup first comb do 1 poke drop] iter\n" 
    8282  "] 'loop func :map       ;(ser comb -- )\n" 
     83  "[[do if-some return] each false] proc :any    ; (blk -- logic)\n" 
     84  "[[do dup iff return drop] each true] proc :all    ; (blk -- logic)\n" 
    8385  "[ser old new | len] [\n" 
    8486  "    old length? :len\n" 
     
    8991  "[reduce [first to-text console.out] iter] proc :prin.pack  ;(val -- )\n" 
    9092  "[reduce to-text console.out eol console.out] proc :print   ;(val -- )\n" 
    91   "[dup .] proc :.t\n" 
    9293  "[error! swap make throw] proc :error\n" 
    9394  "[swap context bind proc] proc :proc.env      ;(env body -- proc)\n" 
     
    105106  "proc :parse.some  ;(data rules -- )\n" 
    106107  "[\n" 
    107   "  0,0,4 :version\n" 
     108  "  0,0,5 :version\n" 
    108109  "  none :os\n" 
    109110  "  [] :devices\n" 
  • trunk/thune/console.c

    r518 r533  
    5656            "  -h     Show this help and exit\n" 
    5757          ); 
     58} 
     59 
     60 
     61int quitResult( UThread* ut ) 
     62{ 
     63    UCell* val = ur_result( ut, 0 ); 
     64    return ur_sel(val); 
    5865} 
    5966 
     
    210217                goto prompt; 
    211218 
     219            case UR_EVAL_QUIT: 
     220                ret = quitResult( ut ); 
     221                goto quit; 
     222 
    212223            case UR_EVAL_ERROR: 
    213224                reportError( ut ); 
     
    282293 
    283294                    case UR_EVAL_QUIT: 
     295                        ret = quitResult( ut ); 
    284296                        goto quit; 
    285297 
  • trunk/thune/doc/UserManual

    r512 r533  
    337337===========  =================  ============================ 
    338338.            (val -- )          Remove value on top of stack and print it. 
     339.t           (val -- val)       Show top value of stack. 
    339340.s           ()                 Show values on stack. 
    340341dup          (a -- a a)         Duplicate value on top of stack. 
     
    347348rot          (a b c -- b c a)   Rotate third value to top. 
    348349rot.r        (a b c -- c a b)   Rotate top of stack to third position. 
    349 stack.level  ( -- level)        Returns depth of data stack. 
     350stack-level  ( -- level)        Returns depth of data stack. 
    350351===========  =================  ============================ 
    351352 
     
    393394verify    (a type -- a)              Throw error if datatype does not match. 
    394395verify/N  (a1-aN t1-tN -- a1-aN)     Throw error if datatypes do not match. 
    395 quit      ()                         Quit program 
     396quit/N    ( -- quit/N)               Quit program. Exit status is optional. 
    396397========  =========================  ============================ 
    397398 
     
    409410func.env  (env sig body -- func)     Create function with private context. 
    410411q         ()                         Quit 
     412any       (block -- logic)           True if any block values are true. 
     413all       (block -- logic)           True if all block values are true. 
    411414========  =========================  ============================ 
    412415 
  • trunk/thune/eval.c

    r527 r533  
    943943    _probe( ut, tos ); 
    944944    UR_S_SAFE_DROP; 
     945} 
     946 
     947 
     948UR_CALL( uc_printTOS ) 
     949{ 
     950    _probe( ut, tos ); 
    945951} 
    946952 
     
    18121818#endif 
    18131819    { uc_showTOS,      "." }, 
    1814     { uc_stack_level,  "stack.level" }, 
     1820    { uc_printTOS,     ".t" }, 
     1821    { uc_stack_level,  "stack-level" }, 
    18151822    { uc_lift_local,   "lift-local" }, 
    18161823    //{ uc_enclose,      "enclose" }, 
  • trunk/thune/gl/TexFont.c

    r527 r533  
    1919#include <string.h> 
    2020#include "TexFont.h" 
     21#include <ft2build.h> 
     22#include FT_FREETYPE_H 
    2123 
    2224 
     
    2527#define FT_PIXELS(x)    (x >> 6) 
    2628 
    27 #define GLYPHS(tf)      ((TexGlyphInfo*) (tf + 1)) 
     29#define GLYPHS(tf)      ((TexFontGlyph*) (tf + 1)) 
    2830#define TABLE(tf)       (((uint16_t*) tf) + tf->table_offset) 
    2931#define KERN(tf)        (((int16_t*) tf) + tf->kern_offset) 
     
    3436 
    3537/** 
    36   Returns the TexGlyphInfo for a glyph or zero if it is not available. 
     38  Returns the TexFontGlyph for a glyph or zero if it is not available. 
    3739  Automatically substitutes uppercase letters with lowercase if 
    3840  uppercase not available (and vice versa). 
    3941*/ 
    40 TexGlyphInfo* txf_glyph( const TexFont* tf, int c ) 
     42TexFontGlyph* txf_glyph( const TexFont* tf, int c ) 
    4143{ 
    4244    uint16_t n; 
     
    6870 
    6971 
    70 int txf_kerning( const TexFont* tf, const TexGlyphInfo* left, 
    71                                     const TexGlyphInfo* right ) 
     72int txf_kerning( const TexFont* tf, const TexFontGlyph* left, 
     73                                    const TexFontGlyph* right ) 
    7274{ 
    7375    const int16_t* table;  
     
    109111    if( tf && (tf->glyph_offset == (sizeof(TexFont) << 8))  ) 
    110112    { 
    111         TexGlyphInfo* tgi; 
    112         TexGlyphInfo* end; 
     113        TexFontGlyph* tgi; 
     114        TexFontGlyph* end; 
    113115        uint16_t* it; 
    114116 
     
    160162 
    161163 
    162 static void blitGlyphToBitmap( FT_Bitmap* src, FT_Bitmap* dst, int x, int y ) 
     164static void blitGlyphToBitmap( FT_Bitmap* src, TexFontImage* dst, int x, int y ) 
    163165{ 
    164166    unsigned char* s; 
     
    168170 
    169171    s = src->buffer; 
    170     d = dst->buffer + (y * dst->pitch) + x; 
    171     dend = dst->buffer + (dst->rows * dst->pitch); 
     172    d = dst->pixels + (y * dst->pitch) + x; 
     173    dend = dst->pixels + (dst->height * dst->pitch); 
    172174 
    173175    r = src->rows; 
     
    182184 
    183185 
    184 static FT_Error _renderGlyph( FT_Bitmap* img, FT_GlyphSlot glyph, 
     186static FT_Error _renderGlyph( TexFontImage* img, FT_GlyphSlot glyph, 
    185187                              int x_offset, int y_offset, int antialias ) 
    186188{ 
     
    278280*/ 
    279281TexFont* txf_build( const char* file, const char* codes, 
    280                     FT_Bitmap* img, int psize, int gap, int antialias ) 
     282                    TexFontImage* img, int psize, int gap, int antialias ) 
    281283{ 
    282284    FT_Library library; 
     
    295297    const char* ci; 
    296298    uint16_t* table; 
    297     TexGlyphInfo* tgi; 
     299    TexFontGlyph* tgi; 
    298300    TexFont* txf = 0; 
    299301    int count; 
     
    353355 
    354356    txf = (TexFont*) malloc(  sizeof(TexFont) + 
    355                              (sizeof(TexGlyphInfo) * count) + 
     357                             (sizeof(TexFontGlyph) * count) + 
    356358                             (sizeof(uint16_t) * (gmax - gmin + 1)) + 
    357359                             (sizeof(int16_t) * kern_space) ); 
     
    359361    txf->glyph_offset = sizeof(TexFont); 
    360362    txf->glyph_count  = count; 
    361     txf->table_offset = (txf->glyph_offset + (sizeof(TexGlyphInfo) * count)) 
     363    txf->table_offset = (txf->glyph_offset + (sizeof(TexFontGlyph) * count)) 
    362364                            / sizeof(uint16_t); 
    363365    txf->table_size   = gmax - gmin + 1; 
     
    371373    txf->min_glyph   = gmin; 
    372374    txf->tex_width   = img->pitch; 
    373     txf->tex_height  = img->rows
     375    txf->tex_height  = img->height
    374376 
    375377    table = TABLE(txf); 
     
    378380 
    379381    // Clear bitmap. 
    380     memset( img->buffer, 0, img->rows * img->pitch ); 
     382    memset( img->pixels, 0, img->height * img->pitch ); 
    381383 
    382384 
     
    417419 
    418420            //if( (y + step_y) >= img->rows ) 
    419             if( y >= img->rows
     421            if( y >= img->height
    420422            { 
    421423                fprintf( stderr, "txf_build: Texture too small\n" ); 
     
    435437        tgi->advance = FT_PIXELS(glyph->metrics.horiAdvance); 
    436438        tgi->x       = x /*+ tgi->xoffset*/; 
    437         tgi->y       = img->rows - y + tgi->yoffset; 
     439        tgi->y       = img->height - y + tgi->yoffset; 
    438440 
    439441#ifdef DUMP 
     
    483485int txf_width( const TexFont* tf, const char* it, const char* end ) 
    484486{ 
    485     TexGlyphInfo* prev = 0; 
    486     TexGlyphInfo* tgi; 
     487    TexFontGlyph* prev = 0; 
     488    TexFontGlyph* tgi; 
    487489    int width = 0; 
    488490 
     
    516518 
    517519 
    518 int txf_linespacing( const TexFont* tf ) 
     520int txf_lineSpacing( const TexFont* tf ) 
    519521{ 
    520522    return tf->max_ascent + (tf->max_ascent / 2); 
  • trunk/thune/gl/TexFont.h

    r527 r533  
    44 
    55#include <stdint.h> 
    6 #include <ft2build.h> 
    7 #include FT_FREETYPE_H 
     6 
     7 
     8typedef struct 
     9
     10    void*    pixels; 
     11    uint16_t width; 
     12    uint16_t height; 
     13    uint16_t pitch; 
     14
     15TexFontImage; 
    816 
    917 
     
    2129    int8_t   _pad; 
    2230} 
    23 TexGlyphInfo
     31TexFontGlyph
    2432 
    2533 
    2634typedef struct 
    2735{ 
    28     uint16_t glyph_offset;      // Array of TexGlyphInfo
     36    uint16_t glyph_offset;      // Array of TexFontGlyph
    2937    uint16_t glyph_count; 
    3038    uint16_t table_offset;      // Lookup table; array of uint16_t. 
     
    4755 
    4856extern TexFont* txf_build( const char* file, const char* codes, 
    49                            FT_Bitmap* img, int psize, int gap, int antialias ); 
    50 extern TexGlyphInfo* txf_glyph( const TexFont*, int c ); 
    51 extern int  txf_kerning( const TexFont*, const TexGlyphInfo* left, 
    52                          const TexGlyphInfo* right ); 
     57                           TexFontImage* img, int psize, 
     58                           int gap, int antialias ); 
     59extern TexFontGlyph* txf_glyph( const TexFont*, int c ); 
     60extern int  txf_kerning( const TexFont*, const TexFontGlyph* left, 
     61                         const TexFontGlyph* right ); 
    5362extern void txf_swap( TexFont* ); 
    5463extern int  txf_width( const TexFont*, const char* it, const char* end ); 
    55 extern int  txf_linespacing( const TexFont* ); 
     64extern int  txf_lineSpacing( const TexFont* ); 
    5665 
    5766#ifdef __cplusplus 
  • trunk/thune/gl/boot.c

    r527 r533  
    3535  "    none :button-down\n" 
    3636  "    none :button-hover\n" 
     37  "    none :label-dl\n" 
    3738  "]\n" 
    3839  "context dup :gui-style-proto :gui-style\n" 
  • trunk/thune/gl/draw_list.c

    r527 r533  
    2727#include "math3d.h" 
    2828#include "shader.h" 
    29 #include "TexFont.h" 
    3029 
    3130 
     
    240239 
    241240/* 
    242   Returns TexGlyphInfo of rendered glyph. 
     241  Returns TexFontGlyph of rendered glyph. 
    243242  Advances x. 
    244243*/ 
    245 static TexGlyphInfo* renderGlyphXY( const TexFont* txf, int c, 
     244static TexFontGlyph* renderGlyphXY( const TexFont* txf, int c, 
    246245                                    GLfloat* xp, GLfloat y, 
    247                                     const TexGlyphInfo* leftGI ) 
     246                                    const TexFontGlyph* leftGI ) 
    248247{ 
    249248    GLfloat w, h; 
     
    252251    GLfloat min_s, max_s; 
    253252    GLfloat min_t, max_t; 
    254     TexGlyphInfo* tgi; 
     253    TexFontGlyph* tgi; 
    255254    int xkern; 
    256255 
     
    289288static GLfloat advanceGlyph( TexFont* txf, int c ) 
    290289{ 
    291     TexGlyphInfo* tgi = txf_glyph( txf, c ); 
     290    TexFontGlyph* tgi = txf_glyph( txf, c ); 
    292291    if( tgi ) 
    293292        return (GLfloat) tgi->advance; 
     
    303302{ 
    304303    GLfloat x, y; 
    305     TexGlyphInfo* prev = 0; 
     304    TexFontGlyph* prev = 0; 
    306305 
    307306    if( (it != end) ) 
     
    342341 
    343342 
    344 void gr_drawTextCell( UThread* ut, UCell* cell, UAtom sel, UCell* area ) 
    345 
    346     TexFont* tf; 
     343void gr_drawTextCell( UThread* ut, TexFont* tf, UCell* cell, UAtom sel, 
     344                      UCell* area ) 
     345
    347346    char* cpA; 
    348347    char* cpB; 
    349348 
    350     if( ! grState.fontN ) 
    351         return; 
    352     tf = (TexFont*) ur_binPtr(grState.fontN)->ptr.v; 
    353349 
    354350    if( ! ur_stringSlice( ut, cell, &cpA, &cpB ) ) 
     
    11001096 
    11011097#ifdef DEBUG 
     1098#include <stdio.h> 
    11021099#define PRINT_STATE(txt,f,e) \ 
    11031100    s = glIsEnabled( e ); \ 
     
    16681665                } 
    16691666 
    1670                 gr_drawTextCell( ut, val, sel, area ); 
     1667                if( grState.fontN ) 
     1668                { 
     1669                    gr_drawTextCell( ut, 
     1670                            (TexFont*) ur_binPtr(grState.fontN)->ptr.v, 
     1671                            val, sel, area ); 
     1672                } 
    16711673            } 
    16721674                break; 
  • trunk/thune/gl/gllist.c

    r458 r533  
    11/*============================================================================ 
    22    Thune Interpreter 
    3     Copyright (C) 2005-2007  Karl Robillard 
     3    Copyright (C) 2005-2008  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    121121        { 
    122122            // Compile empty list to reduce memory usage. 
     123            // Well, hopefully that is what OpenGL will do... 
    123124            glNewList( listBase + i, GL_COMPILE ); 
    124125            glEndList(); 
  • trunk/thune/gl/gui.c

    r528 r533  
    4242#include <GL/glv_keys.h> 
    4343#include "gx.h" 
     44#include "gx_atoms.h" 
    4445#include "gui.h" 
    4546#include "os.h" 
    46 #include "TexFont.h" 
    4747#include "gllist.h" 
    4848 
     
    8888    ms.x     = ex; \ 
    8989    ms.y     = ey 
    90  
    91  
    92 #define SET_AREA(wp,rect) \ 
    93     wp->x = rect->x; \ 
    94     wp->y = rect->y; \ 
    95     wp->w = rect->w; \ 
    96     wp->h = rect->h 
    97  
    98 #define AREA_CHANGED(wp,rect) \ 
    99     ((wp->x != rect->x) || (wp->y != rect->y) || \ 
    100      (wp->w != rect->w) || (wp->h != rect->h)) 
    10190 
    10291 
     
    123112    CI_STYLE_BUTTON_UP,     // Draw list 
    124113    CI_STYLE_BUTTON_DOWN,   // Draw list 
    125     CI_STYLE_BUTTON_HOVER   // Draw list 
     114    CI_STYLE_BUTTON_HOVER,  // Draw list 
     115    CI_STYLE_LABEL_DL       // Draw list 
    126116}; 
    127117 
     
    159149 
    160150 
    161 // styleCell() may only be used by sizeHint, layout, & render methods. 
    162 #define styleCell(index)        (ui->style + index) 
    163  
    164  
    165151static UCell* setStyleCells( GUI* ui ) 
    166152{ 
     
    176162    } 
    177163    return 0; 
    178 } 
    179  
    180  
    181 #define no_mark     0 
    182 #define no_render   0 
    183  
    184  
    185 static void no_event( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
    186 { 
    187     (void) ui; 
    188     (void) wp; 
    189     (void) ev; 
    190 } 
    191  
    192  
    193 static void no_layout( GUI* ui, GWidget* wp, GRect* rect ) 
    194 { 
    195     (void) ui; 
    196     SET_AREA( wp, rect ); 
    197 } 
    198  
    199  
    200 static GWidget* base_parse( GUI* ui, GMakeState* ms, int classId ) 
    201 { 
    202     GWidget* wp; 
    203     GUI_PARSE_ALLOC( wp ) 
    204     ++ms->it; 
    205     return wp; 
    206164} 
    207165 
     
    224182  Set cell to coord! holding widget area. 
    225183*/ 
    226 void gui_initRectCoord( UCell* cell, GWidget* w, int len
     184static void gui_initRectCoord( UCell* cell, GWidget* w, UAtom what
    227185{ 
    228186    ur_initType(cell, UT_COORD); 
    229     cell->coord.len = len; 
    230     cell->coord.elem[ 0 ] = w->x; 
    231     cell->coord.elem[ 1 ] = w->y; 
    232     if( len > 2 ) 
    233     { 
     187    if( what == UR_ATOM_SIZE ) 
     188    { 
     189        cell->coord.len = 2; 
     190        cell->coord.elem[0] = w->w; 
     191        cell->coord.elem[1] = w->h; 
     192    } 
     193    else if( what == UR_ATOM_POS ) 
     194    { 
     195        cell->coord.len = 2; 
     196        cell->coord.elem[0] = w->x; 
     197        cell->coord.elem[1] = w->y; 
     198    } 
     199    else 
     200    { 
     201        cell->coord.len = 4; 
     202        cell->coord.elem[ 0 ] = w->x; 
     203        cell->coord.elem[ 1 ] = w->y; 
    234204        cell->coord.elem[ 2 ] = w->w; 
    235205        cell->coord.elem[ 3 ] = w->h; 
    236206    } 
     207} 
     208 
     209 
     210//---------------------------------------------------------------------------- 
     211 
     212 
     213#define no_mark     0 
     214#define no_render   0 
     215 
     216 
     217static void no_event( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
     218{ 
     219    (void) ui; 
     220    (void) wp; 
     221    (void) ev; 
     222} 
     223 
     224 
     225static void base_layout( GUI* ui, GWidget* wp, GRect* rect ) 
     226{ 
     227    (void) ui; 
     228    gui_setArea( wp, rect ); 
     229} 
     230 
     231 
     232static int base_select( GUI* ui, GWidget* wp, UAtom atom, UCell* result ) 
     233{ 
     234    (void) ui; 
     235    switch( atom ) 
     236    { 
     237        case UR_ATOM_RECT: 
     238        case UR_ATOM_SIZE: 
     239        case UR_ATOM_POS: 
     240            gui_initRectCoord( result, wp, atom ); 
     241            return 1; 
     242    } 
     243    return 0; 
     244} 
     245 
     246 
     247static GWidget* base_parse( GUI* ui, GMakeState* ms, int classId ) 
     248{ 
     249    GWidget* wp; 
     250    GUI_PARSE_ALLOC( wp ) 
     251    ++ms->it; 
     252    return wp; 
    237253} 
    238254 
     
    542558    } 
    543559 
    544     SET_AREA( wp, rect ); 
     560    gui_setArea( wp, rect ); 
    545561 
    546562    dim = wp->x + wd->marginL; 
     
    665681    } 
    666682 
    667     SET_AREA( wp, rect ); 
    668  
    669     dim = wp->y + wd->marginB
     683    gui_setArea( wp, rect ); 
     684 
     685    dim = wp->y + wp->h - wd->marginT
    670686    room = wp->w - wd->marginL - wd->marginR; 
    671687    hint = lo.hint; 
    672688    EACH_SHOWN_CHILD( wp, it ) 
    673689        cr.x = wp->x + wd->marginL; 
    674         cr.y = dim; 
    675690        cr.w = MIN( hint->maxW, room ); 
    676691        cr.h = hint->minH; 
    677  
    678         dim += cr.h + wd->spacing; 
     692        cr.y = dim - cr.h; 
     693 
     694        dim -= cr.h + wd->spacing; 
    679695 
    680696#ifdef REPORT_LAYOUT 
     
    755771    UCell* rc; 
    756772    BoxData* wd = BOX_DATA(wp); 
    757     int changed = AREA_CHANGED( wp, rect ); 
    758  
    759     rc = styleCell( CI_STYLE_WINDOW_MARGIN ); 
     773    int changed = gui_areaChanged( wp, rect ); 
     774 
     775    rc = gui_styleCell( CI_STYLE_WINDOW_MARGIN ); 
    760776    if( ur_is(rc, UT_COORD) ) 
    761777        setBoxMargins( wd, rc ); 
     
    769785    { 
    770786        // Set draw list variables. 
    771         rc = styleCell( CI_STYLE_LABEL ); 
     787        rc = gui_styleCell( CI_STYLE_LABEL ); 
    772788        ur_initString( rc, wd->titleN, 0 ); 
    773789 
    774         rc = styleCell( CI_STYLE_AREA ); 
    775         gui_initRectCoord( rc, wp, 4 ); 
     790        rc = gui_styleCell( CI_STYLE_AREA ); 
     791        gui_initRectCoord( rc, wp, UR_ATOM_RECT ); 
    776792 
    777793        // Compile draw list. 
    778         rc = styleCell( CI_STYLE_WINDOW ); 
     794        rc = gui_styleCell( CI_STYLE_WINDOW ); 
    779795        if( ur_is(rc, UT_DRAWLIST) ) 
    780796            ug_compileDrawList( ui->ut, rc, wd->dl[ 0 ] ); 
     
    795811 
    796812 
    797 //#define BTN_PRESSED         GW_FLAG_USER1 
    798  
    799 #define BTN_STATE_UP        0 
    800 #define BTN_STATE_DOWN      1 
    801  
    802  
    803 typedef struct 
    804 
    805     UIndex  labelN; 
    806     UIndex  codeN; 
    807     GLuint  dl[4]; 
    808     uint8_t pool[4];    // LIMIT: 256 gllist pools. 
    809     uint8_t state; 
    810     uint8_t held; 
    811  
    812     uint8_t _pad[2]; 
    813 
    814 ButtonData; 
    815  
    816 #define BUTTON_DATA(wp)    ((ButtonData*) (wp)->cell) 
    817  
    818  
    819 static GWidget* button_parse( GUI* ui, GMakeState* ms, int classId ) 
    820 
    821     GWidget* wp; 
    822     ButtonData* wd; 
    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!" ); 
    837 
    838  
    839  
    840 static void button_init( GUI* ui, GWidget* wp ) 
    841 
    842     int i; 
    843     int pool; 
    844     ButtonData* wd = BUTTON_DATA(wp); 
    845     (void) ui; 
    846  
    847     memSet( wd, 0, sizeof(ButtonData) ); 
    848  
    849     for( i = 0; i < 2; ++i ) 
    850     { 
    851         wd->dl[ i ] = gllist_alloc( &pool ); 
    852         wd->pool[ i ] = pool; 
    853     } 
    854  
    855     wd->state = BTN_STATE_UP; 
    856     wd->held  = 0; 
    857 
    858  
    859  
    860 static void button_mark( GUI* ui, UCollector* gc, GWidget* wp ) 
    861 
    862     UIndex n; 
    863     ButtonData* wd = BUTTON_DATA(wp); 
    864     (void) ui; 
    865  
    866     n = wd->labelN; 
    867     if( n ) 
    868         ur_gcMarkBin( gc, n ); 
    869  
    870     n = wd->codeN; 
    871     if( n ) 
    872         ur_gcMarkBlock( gc, n ); 
    873  
    874     for( n = 0; n < 2; ++n ) 
    875         gllist_gcMark( wd->pool[ n ], wd->dl[ n ] ); 
    876 
    877  
    878  
    879 static void button_event( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
    880 
    881     ButtonData* wd = BUTTON_DATA(wp); 
    882     //printf( "KR button %d\n", ev->type ); 
    883  
    884     switch( ev->type ) 
    885     { 
    886         case GLV_EVENT_BUTTON_DOWN: 
    887             if( ev->code == GLV_BUTTON_LEFT ) 
    888             { 
    889                 GWidgetId id = WID(wp); 
    890  
    891                 wd->state = BTN_STATE_DOWN; 
    892                 wd->held  = 1; 
    893                 gui_grabMouse( ui, id ); 
    894                 gui_setKeyFocus( ui, id ); 
    895             } 
    896             break; 
    897  
    898         case GLV_EVENT_BUTTON_UP: 
    899             if( ev->code == GLV_BUTTON_LEFT ) 
    900             { 
    901                 int pressed = (wd->state == BTN_STATE_DOWN); 
    902                 gui_ungrabMouse( ui, WID(wp) ); 
    903                 wd->state = BTN_STATE_UP; 
    904                 wd->held  = 0; 
    905                 if( pressed && gui_widgetContains( wp, ev->x, ev->y ) ) 
    906                     goto activate; 
    907             } 
    908             break; 
    909  
    910         case GLV_EVENT_MOTION: 
    911             if( wd->held ) 
    912             { 
    913                 if( gui_widgetContains( wp, ev->x, ev->y ) ) 
    914                     wd->state = BTN_STATE_DOWN; 
    915                 else 
    916                     wd->state = BTN_STATE_UP; 
    917             } 
    918             break; 
    919  
    920         case GLV_EVENT_KEY_DOWN: 
    921             if( ev->code == KEY_Return ) 
    922             { 
    923                 wd->state = BTN_STATE_UP; 
    924                 goto activate; 
    925             } 
    926             break; 
    927  
    928         case GLV_EVENT_FOCUS_IN: 
    929             break; 
    930  
    931         case GLV_EVENT_FOCUS_OUT: 
    932             wd->state = BTN_STATE_UP; 
    933             break; 
    934     } 
    935     return; 
    936  
    937 activate: 
    938  
    939     if( wd->codeN ) 
    940     { 
    941         if( UR_EVAL_OK != ur_eval( ui->ut, wd->codeN, 0 ) ) 
    942         { 
    943             UG_GUI_THROW; 
    944         } 
    945     } 
    946 
    947  
    948  
    949 static void button_sizeHint( GUI* ui, GWidget* wp, GSizeHint* size ) 
    950 
    951     UCell* wfont; 
    952     UCell* rc; 
    953     UString* str; 
    954     TexFont* tf; 
    955     UThread* ut = ui->ut; 
    956     ButtonData* wd = BUTTON_DATA(wp); 
    957     int width; 
    958  
    959     rc = styleCell( CI_STYLE_BUTTON_SIZE ); 
    960     if( ur_is(rc, UT_COORD) ) 
    961     { 
    962         size->minW = rc->coord.elem[0]; 
    963         size->minH = rc->coord.elem[1]; 
    964         size->maxW = rc->coord.elem[2]; 
    965     } 
    966     else 
    967     { 
    968         size->minW = 32; 
    969         size->minH = 20; 
    970         size->maxW = 100; 
    971     } 
    972  
    973     size->maxH    = size->minH; 
    974     size->weightX = 2; 
    975     size->weightY = 1; 
    976     size->policyX = GW_WEIGHTED; 
    977     size->policyY = GW_FIXED; 
    978  
    979     if( wd->labelN ) 
    980     { 
    981         str = ur_binPtr( wd->labelN ); 
    982         wfont = styleCell( CI_STYLE_CONTROL_FONT ); 
    983         if( ur_is(wfont, UT_FONT) ) 
    984         { 
    985             tf = (TexFont*) ur_binPtr( ur_fontTF(wfont) )->ptr.v; 
    986             width = txf_width( tf, str->ptr.c, str->ptr.c + str->used ); 
    987             if( width > size->minW ) 
    988                 size->minW += width; 
    989             if( size->maxW < size->minW ) 
    990                 size->maxW = size->minW; 
    991         } 
    992     } 
    993 
    994  
    995  
    996 static void button_buildLists( GUI* ui, GWidget* wp ) 
    997 
    998     UCell* rc; 
    999     ButtonData* wd = BUTTON_DATA(wp); 
    1000  
    1001  
    1002     // Set draw list variables. 
    1003  
    1004     rc = styleCell( CI_STYLE_LABEL ); 
    1005     ur_initString( rc, wd->labelN, 0 ); 
    1006  
    1007     rc = styleCell( CI_STYLE_AREA ); 
    1008     gui_initRectCoord( rc, wp, 4 ); 
    1009  
    1010  
    1011     // Compile draw lists. 
    1012  
    1013     rc = styleCell( CI_STYLE_BUTTON_UP ); 
    1014     if( ur_is(rc, UT_DRAWLIST) ) 
    1015         ug_compileDrawList( ui->ut, rc, wd->dl[ BTN_STATE_UP ] ); 
    1016  
    1017     rc = styleCell( CI_STYLE_BUTTON_DOWN ); 
    1018     if( ur_is(rc, UT_DRAWLIST) ) 
    1019         ug_compileDrawList( ui->ut, rc, wd->dl[ BTN_STATE_DOWN ] ); 
    1020 
    1021  
    1022  
    1023 static void button_layout( GUI* ui, GWidget* wp, GRect* rect ) 
    1024 
    1025     if( AREA_CHANGED( wp, rect ) ) 
    1026     { 
    1027         SET_AREA( wp, rect ); 
    1028         button_buildLists( ui, wp ); 
    1029     } 
    1030 
    1031  
    1032  
    1033 static void button_render( GUI* ui, GWidget* wp ) 
    1034 
    1035     (void) ui; 
    1036     ButtonData* wd = BUTTON_DATA(wp); 
    1037     glCallList( wd->dl[ wd->state ] ); 
    1038 
    1039  
    1040  
    1041 //---------------------------------------------------------------------------- 
    1042  
    1043  
     813#include "widgets/buttonw.c" 
     814#include "widgets/labelw.c" 
    1044815#include "widgets/twidget.c" 
    1045 #include "widgets/listw.c" 
     816//#include "widgets/listw.c" 
    1046817 
    1047818/* 
     
    1062833  { "expand", 
    1063834    base_parse,       expand_init,    no_mark,        no_event, 
    1064     expand_sizeHint,  no_layout,      no_render
     835    expand_sizeHint,  base_layout,    no_render,      base_select
    1065836    0, 0, 0 }, 
    1066837 
    1067838  { "hbox", 
    1068839    box_parse,        box_init,       box_mark,       no_event, 
    1069     hbox_sizeHint,    hbox_layout,    box_render, 
     840    hbox_sizeHint,    hbox_layout,    box_render,     base_select, 
    1070841    0, 0, 0 }, 
    1071842 
    1072843  { "vbox", 
    1073844    box_parse,        box_init,       box_mark,       no_event, 
    1074     vbox_sizeHint,    vbox_layout,    box_render, 
     845    vbox_sizeHint,    vbox_layout,    box_render,     base_select, 
    1075846    0, 0, 0 }, 
    1076847 
    1077848  { "window", 
    1078849    window_parse,     window_init,    window_mark,    no_event, 
    1079     window_sizeHint,  window_layout,  window_render, 
     850    window_sizeHint,  window_layout,  window_render,  base_select, 
    1080851    0, 0, 0 }, 
    1081852 
    1082853  { "button", 
    1083854    button_parse,     button_init,    button_mark,    button_event, 
    1084     button_sizeHint,  button_layout,  button_render, 
     855    button_sizeHint,  button_layout,  button_render,  button_select, 
     856    0, 0, 0 }, 
     857 
     858  { "label", 
     859    label_parse,      label_init,     label_mark,     no_event, 
     860    label_sizeHint,   label_layout,   label_render,   label_select, 
    1085861    0, 0, 0 }, 
    1086862 
    1087863  { "t-widget", 
    1088864    twidget_parse,    twidget_init,   twidget_mark,   twidget_event, 
    1089     expand_sizeHint,  twidget_layout, twidget_render, 
     865    expand_sizeHint,  twidget_layout, twidget_render, base_select, 
    1090866    0, 0, 0 }, 
    1091867 
     868  /* 
    1092869  { "list", // "block! block!" 
    1093870    listw_parse,      listw_init,     listw_mark,     listw_event, 
    1094     expand_sizeHint,  listw_layout,   listw_render, 
     871    expand_sizeHint,  listw_layout,   listw_render,   base_select, 
    1095872    0, 0, 0 }, 
    1096873 
    1097   /* 
    1098   { "option", 
    1099   { "choice", 
    1100   { "menu", 
    1101   { "data",         // label 
    1102   { "data-edit",    // spin box, line editor 
     874    "option", 
     875    "choice", 
     876    "menu", 
     877    "data",         // label 
     878    "data-edit",    // spin box, line editor 
    1103879  */ 
    1104880}; 
     
    1116892    assert( sizeof(BoxData) == 32 ); 
    1117893    assert( sizeof(ButtonData) == 32 ); 
     894    assert( sizeof(LabelData) == 32 ); 
    1118895 
    1119896    ui->ut         = ut; 
     
    1125902    ui->rootList   = NO_WID; 
    1126903    ui->atom_gui_style = ur_intern( "gui-style", 9 ); 
    1127     ui->atom_hbox      = ur_intern( "hbox", 4 ); 
     904    ui->atom_hbox      = ur_intern( "hbox",      4 ); 
     905    ui->atom_action    = ur_intern( "action",    6 ); 
     906    ui->atom_text      = ur_intern( "text",      4 ); 
    1128907    ui->rootW          = 0; 
    1129908    ui->rootH          = 0; 
     
    14931272 
    14941273 
     1274/* 
     1275  The select method returns non-zero if result is set, or zero if error. 
     1276  The select method must not throw errors. 
     1277*/ 
     1278int gui_selectAtom( GUI* ui, GWidget* wp, UAtom atom, UCell* result ) 
     1279{ 
     1280    return CLASS( wp ).select( ui, wp, atom, result ); 
     1281} 
     1282 
     1283 
    14951284static inline void linkRoot( GUI* ui, GWidget* wp, GWidgetId id ) 
    14961285{ 
     
    15011290 
    15021291/* 
    1503   Returns zero and throws error if fails. 
     1292  This implements the GUI layout dialect, which supports custom widget 
     1293  classes. 
    15041294 
    15051295  Calls the parse method of each widget to read from ms->it to ms->end. 
    1506    
     1296 
    15071297  If the parse method fails it should return zero and either throw an 
    15081298  error or point ms->error to an error message. 
     1299 
     1300  \param ms   The blkN, it, & end members must be initialized for layout block. 
     1301 
     1302  \return     Widget pointer or zero (and throws error) if fails. 
    15091303*/ 
    15101304GWidget* gui_parseLayout( GUI* ui, GWidget* parent, GMakeState* ms ) 
  • trunk/thune/gl/gui.h

    r528 r533  
    4242    UAtom     atom_gui_style; 
    4343    UAtom     atom_hbox; 
     44    UAtom     atom_action; 
     45    UAtom     atom_text; 
    4446    GWidgetId root; 
    4547    GWidgetId keyFocus; 
     
    103105    void     (*layout)  ( GUI*, GWidget*, GRect* ); 
    104106    void     (*render)  ( GUI*, GWidget* ); 
     107    int      (*select)  ( GUI*, GWidget*, UAtom, UCell* ); 
    105108    /* 
    106109    uint8_t       sizeH; 
     
    155158int      gui_widgetContains( GWidget*, int x, int y ); 
    156159void     gui_render( GUI*, GWidgetId ); 
     160int      gui_selectAtom( GUI*, GWidget*, UAtom atom, UCell* result ); 
    157161GWidget* gui_parseLayout( GUI*, GWidget* parent, GMakeState* ); 
    158162const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ); 
    159163GWidget* gui_root( const GUI* ui, GWidgetId id ); 
    160 void     gui_initRectCoord( UCell*, GWidget*, int len ); 
    161164void     gui_setKeyFocus( GUI*, GWidgetId ); 
    162165void     gui_grabMouse( GUI*, GWidgetId ); 
     
    172175    if(! wp) { GUI_PARSE_ERR( "allocWidget failed" ); } 
    173176 
     177// gui_styleCell may only be used by sizeHint, layout, &am