Changeset 527

Show
Ignore:
Timestamp:
05/26/08 17:22:18 (5 months ago)
Author:
krobillard
Message:

Added thune-gl widget! datatype.

Location:
trunk/thune
Files:
6 added
28 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/CMakeLists.txt

    r518 r527  
    11project(Thune C) 
    22 
    3 # set(CMAKE_BUILD_TYPE Debug) 
    4 set(CMAKE_BUILD_TYPE Release) 
    5  
    6 # Config defines 
    7 add_definitions( 
    8         -DLANG_THUNE 
    9         -DUR_CONFIG_BZIP2 
    10         -DUR_CONFIG_TRIG 
    11         -DUR_CONFIG_MATH3D 
    12         -DUR_CONFIG_DATAFLOW 
    13         -DUR_CONFIG_NET 
    14         -DUR_CONFIG_MACROS 
    15 ) 
     3#set(CMAKE_BUILD_TYPE Debug) 
     4 set(CMAKE_BUILD_TYPE Release) 
    165 
    176 
     
    2211set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/") 
    2312 
     13 
     14# Config defines 
     15add_definitions( 
     16    -DLANG_THUNE 
     17    -DUR_CONFIG_BZIP2 
     18    -DUR_CONFIG_TRIG 
     19    -DUR_CONFIG_MATH3D 
     20    -DUR_CONFIG_DATAFLOW 
     21    -DUR_CONFIG_FCALC 
     22    -DUR_CONFIG_NET 
     23    -DUR_CONFIG_MACROS 
     24) 
     25 
     26if(CMAKE_BUILD_TYPE STREQUAL "Debug") 
     27    add_definitions(-DDEBUG) 
     28endif () 
     29 
     30 
    2431if (UNIX) 
    25         include_directories(. unix) 
    26         add_definitions(-std=c99 -pedantic -D_GNU_SOURCE) 
     32    include_directories(. unix) 
     33    add_definitions(-std=c99 -pedantic -D_GNU_SOURCE) 
    2734    set(OS_FILE unix/os.c) 
    2835endif () 
    2936 
    3037if (WIN32) 
    31         include_directories(. win32) 
     38    include_directories(. win32) 
    3239    set(OS_FILE win32/os.c) 
    3340endif () 
     
    3542 
    3643add_library(thune-lib SHARED 
    37         urlan.c 
    38         array.c 
    39         list.c 
    40         make.c 
    41         eval.c 
    42         thread.c 
    43         gc.c 
    44         tokenize.c 
    45         charset.c 
    46         context.c 
    47         print.c 
    48         series.c 
    49         parse.c 
    50         stdio.c 
    51         files.c 
    52         math.c 
    53         bignum.c 
    54         support/mt19937ar.c 
     44    urlan.c 
     45    array.c 
     46    list.c 
     47    make.c 
     48    eval.c 
     49    thread.c 
     50    gc.c 
     51    tokenize.c 
     52    charset.c 
     53    context.c 
     54    print.c 
     55    series.c 
     56    parse.c 
     57    stdio.c 
     58    files.c 
     59    math.c 
     60    bignum.c 
     61    support/mt19937ar.c 
    5562    ${OS_FILE} 
    5663) 
  • trunk/thune/boot.c

    r516 r527  
    128128  "]\n" 
    129129  "func :replace   ; (ser pat rep -- ser)\n" 
     130  "[bind [dup second swap first set] iter/2] proc :set-key-values ; (blk ctx -- )\n" 
    130131  "[now swap do now swap sub] proc :time-blk\n" 
    131132  "[\n" 
  • trunk/thune/eval.c

    r516 r527  
    352352 
    353353 
    354 static void _appendTraceBlk( UThread* ut, UCellError* err, int n, int it ) 
     354void ur_appendTraceT( UThread* ut, UCellError* err, UIndex blkN, UIndex it ) 
    355355{ 
    356356    if( err->traceBlk ) 
     
    361361        blk = ur_blockPtr( err->traceBlk ); 
    362362        cell = ur_appendCell( blk, UT_BLOCK ); 
    363         ur_setSeries( cell, n, it ); 
     363        ur_setSeries( cell, blkN, it ); 
    364364    } 
    365365} 
     
    504504 
    505505 
     506/** 
     507  Evaluate C string. 
     508 
     509  \param cmd  String to evaluate. 
     510  \param len  Length of cmd string.  May be -1 if cmd is null terminated. 
     511 
     512  \return UR_EVAL_ code. 
     513*/ 
    506514int ur_evalCStr( UThread* ut, const char* cmd, int len ) 
    507515{ 
     
    16171625        res->func.closureN  = 0; 
    16181626        res->func.sigN      = sigN; 
    1619     } 
    1620     UR_S_DROP; 
     1627 
     1628        UR_S_DROP; 
     1629    } 
     1630    else 
     1631    { 
     1632        ur_throwErr( UR_ERR_DATATYPE, "func expected two block! values" ); 
     1633    } 
    16211634} 
    16221635 
  • trunk/thune/gc.c

    r510 r527  
    231231 
    232232 
    233 static void _checkCells( UThread* ut, UCollector* gc, UCell* it, UCell* end ); 
    234  
    235233static void _checkBlock( UThread* ut, UCollector* gc, UBlock* blk ) 
    236234{ 
     
    242240 
    243241    if( it ) 
    244         _checkCells( ut, gc, it, it + blk->used ); 
    245 } 
    246  
    247  
    248 static void _checkCells( UThread* ut, UCollector* gc, UCell* it, UCell* end ) 
     242        ur_gcMarkCells( ut, gc, it, it + blk->used ); 
     243} 
     244 
     245 
     246void ur_gcMarkCells( UThread* ut, UCollector* gc, UCell* it, const UCell* end ) 
    249247{ 
    250248    int idx; 
     
    410408                UCell* cell = ((UCell*) it) - 1; 
    411409                SET_BIT_BLOCK_L( it->cp.n ) 
    412                 _checkCells( ut, gc, cell, cell + 1 ); 
     410                ur_gcMarkCells( ut, gc, cell, cell + 1 ); 
    413411                it -= CC_LEN_ITER; 
    414412            } 
     
    439437    assert( UR_TOC >= UR_BOC ); 
    440438 
    441     _checkCells( ut, gc, UR_BOC, UR_TOC ); 
     439    ur_gcMarkCells( ut, gc, UR_BOC, UR_TOC ); 
    442440} 
    443441#endif 
     
    451449    assert( UR_TOS >= UR_BOS ); 
    452450 
    453     _checkCells( ut, gc, UR_BOS + 1, UR_TOS + 1 ); 
     451    ur_gcMarkCells( ut, gc, UR_BOS + 1, UR_TOS + 1 ); 
    454452} 
    455453 
  • trunk/thune/gl/CMakeLists.txt

    r518 r527  
    11project(ThuneGL C) 
    22 
    3 # set(CMAKE_BUILD_TYPE Debug) 
    4 set(CMAKE_BUILD_TYPE Release) 
     3#set(CMAKE_BUILD_TYPE Debug) 
     4 set(CMAKE_BUILD_TYPE Release) 
    55 
    66 
     
    2727 
    2828if (UNIX AND NOT APPLE) 
    29         find_package( X11 REQUIRED ) 
     29    find_package( X11 REQUIRED ) 
    3030    include_directories(../unix) 
    3131    include_directories(/usr/include/freetype2) 
     
    4545    -DTHUNE_GL 
    4646) 
     47 
     48if(CMAKE_BUILD_TYPE STREQUAL "Debug") 
     49    add_definitions(-DDEBUG) 
     50endif () 
    4751 
    4852include_directories( 
     
    6872    rfont.c 
    6973    shader.c 
    70 #    gui.c 
     74#   gui.c 
    7175    ${GLV_FILE} 
    7276    ${JOYSTICK_FILE} 
  • trunk/thune/gl/TexFont.c

    r512 r527  
    481481 
    482482 
     483int txf_width( const TexFont* tf, const char* it, const char* end ) 
     484{ 
     485    TexGlyphInfo* prev = 0; 
     486    TexGlyphInfo* tgi; 
     487    int width = 0; 
     488 
     489    while( it != end ) 
     490    { 
     491        if( *it == '\n' ) 
     492            break; 
     493        if( *it == ' ' ) 
     494        { 
     495            tgi = txf_glyph( tf, ' ' ); 
     496            if( tgi ) 
     497                width += tgi->advance; 
     498            prev = 0; 
     499        } 
     500        else 
     501        { 
     502            tgi = txf_glyph( tf, *it ); 
     503            if( tgi ) 
     504            { 
     505                width += tgi->advance; 
     506                if( prev ) 
     507                    width += txf_kerning( tf, prev, tgi ); 
     508                prev = tgi; 
     509            } 
     510        } 
     511        ++it; 
     512    } 
     513 
     514    return width; 
     515} 
     516 
     517 
     518int txf_linespacing( const TexFont* tf ) 
     519{ 
     520    return tf->max_ascent + (tf->max_ascent / 2); 
     521} 
     522 
     523 
    483524/*EOF*/ 
  • trunk/thune/gl/TexFont.h

    r512 r527  
    5252                         const TexGlyphInfo* right ); 
    5353extern void txf_swap( TexFont* ); 
     54extern int  txf_width( const TexFont*, const char* it, const char* end ); 
     55extern int  txf_linespacing( const TexFont* ); 
    5456 
    5557#ifdef __cplusplus 
  • trunk/thune/gl/boot.c

    r516 r527  
    1   "[file string!] [\n" 
    2   "    file 16 read\n" 
    3   "    dup \"RIFF\" match ift (file load-wav return)\n" 
    4   "    file read\n" 
    5   "    dup \"#!\" match ift (eol find)\n" 
    6   "    to-block kernel-ops infuse\n" 
    7   "] func :load\n" 
    81  "[\n" 
    92  "    none :orient\n" 
     
    169  "context :camera\n" 
    1710  "[\n" 
    18   "    none :parent\n" 
    19   "    none :children\n" 
    2011  "    0,0 :area\n" 
    2112  "    none :key-down\n" 
     
    3021  "    none :draw\n" 
    3122  "]\n" 
    32   "context :widget-proto\n" 
     23  "context :t-widget-proto\n" 
     24  "[\n" 
     25  "    none :texture\n" 
     26  "    none :tex-size\n" 
     27  "    none :control-font\n" 
     28  "    none :title-font\n" 
     29  "    none :label\n" 
     30  "    none :area\n" 
     31  "    none :window-margin\n" 
     32  "    none :window\n" 
     33  "    none :button-size-limit\n" 
     34  "    none :button-up\n" 
     35  "    none :button-down\n" 
     36  "    none :button-hover\n" 
     37  "]\n" 
     38  "context dup :gui-style-proto :gui-style\n" 
    3339  "[\n" 
    3440  "    none :value\n" 
     
    4753  "        3 :mouse-mb]\n" 
    4854  "] case\n" 
    49   "[\n" 
    50   "    copy\n" 
    51   "    dup [dup first key-code 1 poke drop] iter/2\n" 
    52   "    [dup none select do] copy swap 2 poke\n" 
    53   "]\n" 
    54   "proc :key-handler\n" 
    55   "[wid | handler]\n" 
    56   "[\n" 
    57   "    [] display.events [\n" 
    58   "        dup first wid get dup :handler\n" 
    59   "        ift (second handler do) drop\n" 
    60   "    ] iter/2\n" 
    61   "]\n" 
    62   "func :handle.events\n" 
    63   "[wid | handler]\n" 
    64   "[\n" 
    65   "    [] 'wait display.events [\n" 
    66   "        dup first wid get dup :handler\n" 
    67   "        ift (second handler do) drop\n" 
    68   "    ] iter/2\n" 
    69   "]\n" 
    70   "func :wait-events\n" 
     55  "[drop display.events] proc :handle-events\n" 
     56  "[drop display.events/wait] proc :wait-events\n" 
    7157  "[list block! | ctx wrd n]\n" 
    7258  "[\n" 
     
    128114  "]\n" 
    129115  "make-opcodes :draw-list-opcodes\n" 
     116  "[draw-list! swap make] proc :draw-list\n" 
     117  "[draw-list! swap paren! as make] proc :draw-list.compile\n" 
    130118  "[\n" 
    131   "    draw-list! swap make\n" 
     119  "    copy\n" 
     120  "    dup [dup first key-code 1 poke drop] iter/2\n" 
    132121  "]\n" 
    133   "proc :draw-list\n" 
     122  "proc :key-handler\n" 
     123  "[desc | wid]\n" 
    134124  "[\n" 
    135   "    draw-list! swap paren! as make\n" 
    136   "]\n" 
    137   "proc :draw-list.compile\n" 
    138   "[desc | tok wid]\n" 
    139   "[\n" 
    140   "    widget-proto [] make :wid\n" 
    141   "    desc wid bind [\n" 
    142   "        :tok\n" 
    143   "        'key-down block! (tok/2 key-handler :wid/key-down)\n" 
    144   "        | 'key-up block! (tok/2 key-handler :wid/key-up)\n" 
    145   "        | 'mouse-move block! (tok/2 :wid/mouse-move)\n" 
    146   "        | 'mouse-down block! (tok/2 :wid/mouse-down)\n" 
    147   "        | 'mouse-up block! (tok/2 :wid/mouse-up)\n" 
    148   "        | 'mouse-wheel block! (tok/2 :wid/mouse-wheel)\n" 
    149   "        | 'close block! (tok/2 :wid/close)\n" 
    150   "        | 'resize block! (tok/2 :wid/resize)\n" 
    151   "        | 'joystick block! (tok/2 :wid/joystick)\n" 
    152   "        | 'draw block! (tok/2 :wid/draw)\n" 
    153   "        | 'draw-list block! (tok/2 draw-list :wid/draw)\n" 
    154   "        | 'parent word! (tok/2 get :wid/parent)\n" 
    155   "    ] parse.some\n" 
    156   "    wid/parent\n" 
    157   "    ['area wid/parent get :wid/area]\n" 
    158   "    [display.area :wid/area]\n" 
    159   "    either\n" 
    160   "    wid/resize ift (wid/area wid/resize do drop)\n" 
     125  "    desc t-widget-proto copy dup :wid set-key-values\n" 
     126  "    wid/key-down if-some (key-handler :wid/key-down)\n" 
     127  "    wid/key-up if-some (key-handler :wid/key-up)\n" 
     128  "    wid/draw if-some (draw-list :wid/draw)\n" 
    161129  "    wid\n" 
    162130  "]\n" 
    163   "func :make-widget\n" 
     131  "func :t-widget-context\n" 
     132  "[widget! [t-widget none] rot 2 poke make] proc :make-widget\n" 
     133  "[file string!] [\n" 
     134  "    file 16 read\n" 
     135  "    dup \"RIFF\" match ift (file load-wav return)\n" 
     136  "    file read\n" 
     137  "    dup \"#!\" match ift (eol find)\n" 
     138  "    to-block kernel-ops infuse\n" 
     139  "] func :load\n" 
    164140  "[load shader! swap make] proc :load.shader\n" 
    165141  "[load.png texture! swap make] proc :load.tex\n" 
     
    180156  "    0.0 0.0 0.0 1.0 \n" 
    181157  "] :unit-matrix\n" 
    182   "[\n" 
    183   "    unit-matrix copy swap 13 poke\n" 
    184   "]\n" 
    185   "proc :make-matrix\n" 
     158  "[unit-matrix copy swap 13 poke] proc :make-matrix\n" 
  • trunk/thune/gl/draw_list.c

    r516 r527  
    7272 
    7373 
    74 struct GrRenderState grState; 
    75  
    76  
    77 #if 0 
     74GrRenderState grState; 
     75 
     76 
     77#if 1 
    7878void gr_disableTexture() 
    7979{ 
     
    132132        case GRS_SOLID: 
    133133            glDepthMask( GL_FALSE ); 
     134#if 0 
    134135            gr_disable( "lbct" ); 
    135             /* 
     136#else 
    136137            glDisable( GL_LIGHTING ); 
    137138            glDisable( GL_BLEND ); 
    138139            glDisable( GL_CULL_FACE ); 
    139140            gr_disableTexture(); 
    140             */ 
     141 
     142            grState.enableMask &= 
     143                ~(EN_LIGHTING | EN_BLEND | EN_CULL_FACE | EN_TEXTURE_2D); 
     144#endif 
    141145            break; 
    142146 
     
    163167 
    164168            // NOTE: Must disable all texture units but GL_TEXTURE0 if not 
    165             // using a shader or text may not render properly. 
     169            //       using a shader or text may not render properly. 
    166170            gr_enableTexture0(); 
    167171 
     
    235239 
    236240 
    237 int gr_textWidth( const TexFont* tf, const char* it, const char* end ) 
    238 { 
    239     TexGlyphInfo* prev = 0; 
    240     TexGlyphInfo* tgi; 
    241     int width = 0; 
    242  
    243     while( it != end ) 
    244     { 
    245         if( *it == '\n' ) 
    246             break; 
    247         if( *it == ' ' ) 
    248         { 
    249             tgi = txf_glyph( tf, ' ' ); 
    250             if( tgi ) 
    251                 width += tgi->advance; 
    252             prev = 0; 
    253         } 
    254         else 
    255         { 
    256             tgi = txf_glyph( tf, *it ); 
    257             if( tgi ) 
    258             { 
    259                 width += tgi->advance; 
    260                 if( prev ) 
    261                     width += txf_kerning( tf, prev, tgi ); 
    262                 prev = tgi; 
    263             } 
    264         } 
    265         ++it; 
    266     } 
    267  
    268     return width; 
    269 } 
    270  
    271  
    272241/* 
    273242  Returns TexGlyphInfo of rendered glyph. 
     
    395364    { 
    396365        int16_t* rect = area->coord.elem; 
    397         int w = gr_textWidth( tf, cpA, cpB ); 
     366        int w = txf_width( tf, cpA, cpB ); 
    398367        int h = tf->max_ascent - (tf->max_ascent >> 1); 
    399368 
     
    646615 
    647616        blk = ur_block(val); 
    648         UR_ITER_BLOCK( it, end, blk, val ); 
     617        UR_ITER_BLOCK( it, end, blk, val ) 
    649618        while( it != end ) 
    650619        { 
     
    826795    COW_VALUE(pc, ts); 
    827796    if( ! ur_is(ts, UT_COORD) ) 
     797    { 
     798bad_dt: 
     799        ur_throwErr( UR_ERR_DATATYPE, "qaud-skin expected coord!" ); 
    828800        return 0; 
     801    } 
    829802    ++pc; 
    830803    COW_VALUE(pc, tc); 
    831804    if( ! ur_is(tc, UT_COORD) ) 
    832         return 0; 
     805        goto bad_dt; 
    833806    ++pc; 
    834807    COW_VALUE(pc, vc); 
    835808    if( ! ur_is(vc, UT_COORD) ) 
    836         return 0; 
     809        goto bad_dt; 
    837810 
    838811    { 
     
    11631136        glEnable( e ); } 
    11641137 
     1138#if 1 
    11651139#define DISABLE(f,e) \ 
    11661140    if( grState.enableMask & f ) { \ 
    11671141        grState.enableMask &= ~f; \ 
    11681142        glDisable( e ); } 
     1143#else 
     1144#define DISABLE(f,e)    glDisable( e ); 
     1145#endif 
     1146 
    11691147 
    11701148static void gr_enable( const char* cp ) 
     
    12881266   Returns zero if an error occurred. 
    12891267*/ 
    1290 static int _runDrawList( UThread* ut, UCell* val ) 
     1268int ug_runDrawList( UThread* ut, UCell* val ) 
    12911269{ 
    12921270    UBlock* blk = ur_blockPtr( val->series.n ); 
     
    13371315                        glCallList( ur_dlGL(val) ); 
    13381316                    } 
    1339                     else if( ! _runDrawList( ut, val ) ) 
     1317                    else if( ! ug_runDrawList( ut, val ) ) 
    13401318                        return 0; 
     1319                } 
     1320                else if( ur_is(val, UT_WIDGET) ) 
     1321                { 
     1322                    // NOTE: Compiliation of widget draw lists will happen 
     1323                    //       inside gui_render(). 
     1324                    gui_render( &gxEnv.gui, ur_int(val) ); 
    13411325                } 
    13421326                break; 
     
    16541638                { 
    16551639                    if( ! ur_is(val, UT_COORD) || (val->coord.len < 4) ) 
     1640                    { 
     1641                        ur_throwErr( UR_ERR_DATATYPE, 
     1642                                     "text expected area coord!" ); 
    16561643                        return 0; 
     1644                    } 
    16571645                    area = val; 
    16581646                    ++pc; 
     
    16891677                loadShader( ut, val ); 
    16901678                break; 
    1691 #if 0 
     1679#if 1 
    16921680            case DOP_UNIFORM: 
    16931681            { 
     
    17371725                if( ur_is(pc, UT_BLOCK) ) 
    17381726                { 
    1739                     if( ! _runDrawList( ut, pc ) ) 
     1727                    if( ! ug_runDrawList( ut, pc ) ) 
    17401728                        return 0; 
    17411729                } 
     
    18051793 
    18061794 
     1795int ug_compileDrawList( UThread* ut, UCell* blkCell, GLuint dl ) 
     1796{ 
     1797    int ok; 
     1798 
     1799    //printf( "KR compile DL %d\n", dl ); 
     1800 
     1801    // Need to keep grState.shaderProg for uniform to work in compiled list. 
     1802    //gr_clearState(); 
     1803 
     1804    glNewList( dl, GL_COMPILE ); 
     1805    ok = ug_runDrawList( ut, blkCell ); 
     1806    glEndList(); 
     1807 
     1808    return ok; 
     1809} 
     1810 
     1811 
    18071812