Changeset 540

Show
Ignore:
Timestamp:
07/04/08 03:46:13 (2 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.
Location:
trunk/thune
Files:
4 added
34 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/array.c

    r255 r540  
    182182 
    183183 
     184/** 
     185  Create space in the array for count elements starting at index. 
     186  The memory in the new space is uninitialized. 
     187*/ 
     188void ur_arrayExpand( UArray* arr, int elemSize, int index, int count ) 
     189{ 
     190    ur_arrayReserve( arr, elemSize, arr->used + count ); 
     191 
     192    if( index < arr->used ) 
     193    { 
     194        char* buf = arr->ptr.c + (elemSize * index); 
     195        memMove( buf + (elemSize * count), buf, 
     196                 elemSize * (arr->used - index) ); 
     197    } 
     198 
     199    arr->used += count; 
     200} 
     201 
     202 
    184203/*EOF*/ 
  • trunk/thune/boot.c

    r539 r540  
    5959  "  to-block kernel-ops infuse\n" 
    6060  "] proc :load    ;(filename -- block)\n" 
     61  "[open swap string! to write close] proc :save    ;(value filename -- )\n" 
    6162  "[select if-some do] proc :case\n" 
    6263  "['break throw] proc :break\n" 
     
    7576  "[ser words block! body block!]\n" 
    7677  "[\n" 
    77   "    ser [words set body do] words length? iter\n" 
     78  "  ser [words set body do] words length? iter\n" 
    7879  "]\n" 
    7980  "'loop func :each.set    ;(ser words body -- )\n" 
     
    8485  "[[do dup iff return drop] each true] proc :all    ; (blk -- logic)\n" 
    8586  "[ser old new | len] [\n" 
    86   "    old length? :len\n" 
    87   "    ser old find if-some (new len change :ser recurse)\n" 
    88   "    ser\n" 
     87  "  old length? :len\n" 
     88  "  ser old find if-some (new len change :ser recurse)\n" 
     89  "  ser\n" 
    8990  "] func :replace.all     ;(ser old new -- ser)\n" 
    9091  "[reduce to-text console.out] proc :prin  ;(val -- )\n" 
  • trunk/thune/doc/GLManual

    r537 r540  
    6464:: 
    6565 
    66     (raster! w,h,b -- raster) 
     66    (raster! w,h,bpp -- raster) 
    6767 
    6868 
     
    7878Font 
    7979---- 
    80 :: 
    81  
    82     (font! ["font.name" 20 "chars abc" 256,128] -- font) 
     80 
     81Fonts can be created from a TrueType file or from a raster and binary:: 
     82 
     83    (font! ["font-file.ttf" 20 char-set 256,128] -- font) 
     84    (font! [raster!/texture! binary!] -- font) 
     85 
     86Font components can be selected with:: 
     87 
     88    font/raster 
     89    font/texture 
     90    font/binary     ; Glyph data 
    8391 
    8492 
     
    137145gl-max-textures   ( -- count)             GL_MAX_TEXTURE_UNITS 
    138146shadowmap         (size -- framebuffer)   Create shadowmap                
     147blit              (dst src coord -- dst)  Copy from one raster to another 
     148move-glyphs       (font offset -- font)   Move texture position of glyphs 
    139149================  ======================  ====================== 
    140150 
     
    261271scale             vec3!/number!           glScalef() 
    262272font              font!                   Set font used by text instruction 
     273font/no-bind      font!                   Set font, but don't bind texture 
    263274text              [coord!] text           Draw text in current font 
    264275sphere            radius slices,stacks    Draw textured GLUT sphere 
  • trunk/thune/doc/UserManual

    r539 r540  
    569569read         (file part -- data)     Read beginning of file. 
    570570write        (port data -- port)     Write data to port. 
    571 load         (file -- code)          Read script from file. 
    572571delete       (file -- )              Remove file. 
    573572rename       (file new -- )          Rename file. 
     
    599598Word         Stack Usage             Function 
    600599==========   ======================  ================= 
     600load         (file -- code)          Read script from file. 
     601save         (val file -- )          Save value to file. 
    601602split-path   (full -- path file)     Split full path into path & file. 
    602603dirize       (str -- str)            Ensure trailing slash is present. 
  • trunk/thune/eval.c

    r539 r540  
    764764                return 1; 
    765765            break; 
     766 
     767        case UT_DATE: 
     768        case UT_TIME: 
     769            if( ur_is(b, UT_DATE) || ur_is(b, UT_TIME) ) 
     770            { 
     771                if( ur_seconds(a) == ur_seconds(b) ) 
     772                    return 1; 
     773            } 
     774            break; 
    766775    } 
    767776    return 0; 
     
    832841            if( (a->ctx.wordBlk == b->ctx.wordBlk) && 
    833842                (a->ctx.valBlk == b->ctx.valBlk) ) 
     843                return 1; 
     844            break; 
     845 
     846        case UT_DATE: 
     847        case UT_TIME: 
     848            if( ur_seconds(a) == ur_seconds(b) ) 
    834849                return 1; 
    835850            break; 
     
    13571372                ur_initType(val, UT_VEC3); 
    13581373            } 
     1374            break; 
     1375 
     1376        case UT_DATE: 
     1377            if( ur_is(val, UT_TIME) ) 
     1378                ur_type(val) = UT_DATE; 
     1379            break; 
     1380 
     1381        case UT_TIME: 
     1382            if( ur_is(val, UT_DATE) ) 
     1383                ur_type(val) = UT_TIME; 
    13591384            break; 
    13601385    } 
  • trunk/thune/gl/CMakeLists.txt

    r537 r540  
    7070    png_save.c 
    7171    TexFont.c 
     72    raster.c 
    7273    rfont.c 
    7374    shader.c 
  • trunk/thune/gl/TexFont.c

    r533 r540  
    132132        it = (uint16_t*) KERN(tf); 
    133133        swap16( it, it + tf->kern_size ); 
     134    } 
     135} 
     136 
     137 
     138/** 
     139  Change the texture position of all glyphs. 
     140*/ 
     141void txf_moveGlyphs( TexFont* tf, int dx, int dy ) 
     142{ 
     143    TexFontGlyph* tgi = GLYPHS(tf); 
     144    TexFontGlyph* end = tgi + tf->glyph_count; 
     145    while( tgi != end ) 
     146    { 
     147        tgi->x += dx; 
     148        tgi->y += dy; 
     149        ++tgi; 
    134150    } 
    135151} 
     
    352368    // Most glyphs have no kerning adjustment, and those with it have only 
    353369    // a handful (at least at small font sizes). 
    354     kern_space = count * 5;     // 5 = 2 glyphs + terminator 
     370    kern_space = count * 7;     // 7 = 3 glyphs + terminator 
    355371 
    356372    txf = (TexFont*) malloc(  sizeof(TexFont) + 
     
    437453        tgi->advance = FT_PIXELS(glyph->metrics.horiAdvance); 
    438454        tgi->x       = x /*+ tgi->xoffset*/; 
     455#if 0 
    439456        tgi->y       = img->height - y + tgi->yoffset; 
     457#else 
     458        tgi->y       = y - tgi->yoffset; 
     459#endif 
    440460 
    441461#ifdef DUMP 
  • trunk/thune/gl/TexFont.h

    r533 r540  
    6161                         const TexFontGlyph* right ); 
    6262extern void txf_swap( TexFont* ); 
     63extern void txf_moveGlyphs( TexFont*, int dx, int dy ); 
    6364extern int  txf_width( const TexFont*, const char* it, const char* end ); 
    6465extern int  txf_lineSpacing( const TexFont* ); 
  • trunk/thune/gl/boot.c

    r533 r540  
    2727  "    none :control-font\n" 
    2828  "    none :title-font\n" 
     29  "    none :edit-font\n" 
    2930  "    none :label\n" 
    3031  "    none :area\n" 
    3132  "    none :window-margin\n" 
    3233  "    none :window\n" 
    33   "    none :button-size-limit\n" 
     34  "    none :button-size\n" 
    3435  "    none :button-up\n" 
    3536  "    none :button-down\n" 
    3637  "    none :button-hover\n" 
    3738  "    none :label-dl\n" 
     39  "    none :editor\n" 
     40  "    none :editor-active\n" 
     41  "    none :editor-cursor\n" 
    3842  "]\n" 
    3943  "context dup :gui-style-proto :gui-style\n" 
  • trunk/thune/gl/draw_list.c

    r536 r540  
    242242  Advances x. 
    243243*/ 
    244 static TexFontGlyph* renderGlyphXY( const TexFont* txf, int c, 
    245                                     GLfloat* xp, GLfloat y, 
     244static TexFontGlyph* renderGlyphXY( const TexFont* txf, 
     245                                    GLfloat texW, GLfloat texH, 
     246                                    int c, GLfloat* xp, GLfloat y, 
    246247                                    const TexFontGlyph* leftGI ) 
    247248{ 
    248     GLfloat w, h; 
    249     GLfloat tw, th; 
     249    GLfloat gw, gh; 
    250250    GLfloat gx, gy; 
    251251    GLfloat min_s, max_s; 
     
    257257    if( tgi ) 
    258258    { 
    259         w = (GLfloat) txf->tex_width; 
    260         h = (GLfloat) txf->tex_height; 
    261  
    262         tw = (GLfloat) tgi->width; 
    263         th = (GLfloat) tgi->height; 
    264  
     259        gw = (GLfloat) tgi->width; 
     260        gh = (GLfloat) tgi->height; 
    265261        gx = (GLfloat) tgi->x; 
    266262        gy = (GLfloat) tgi->y; 
    267263 
    268         min_s = gx / w; 
    269         min_t = 1.0f - (gy / h); 
    270         max_s = (gx + tw) / w; 
    271         max_t = 1.0f - ((gy + th) / h); 
     264        min_s = gx / texW; 
     265        max_s = (gx + gw) / texW; 
     266#if 0 
     267        min_t = 1.0f - (gy / texH); 
     268        max_t = 1.0f - ((gy + gh) / texH); 
     269#else 
     270        min_t = gy / texH; 
     271        max_t = (gy - gh) / texH; 
     272#endif 
    272273 
    273274        xkern = leftGI ? txf_kerning( txf, leftGI, tgi ) : 0; 
     
    278279 
    279280        glTexCoord2f( min_s, min_t );  glVertex2f( gx, gy ); 
    280         glTexCoord2f( max_s, min_t );  glVertex2f( gx + tw, gy ); 
    281         glTexCoord2f( max_s, max_t );  glVertex2f( gx + tw, gy + th ); 
    282         glTexCoord2f( min_s, max_t );  glVertex2f( gx, gy + th ); 
     281        glTexCoord2f( max_s, min_t );  glVertex2f( gx + gw, gy ); 
     282        glTexCoord2f( max_s, max_t );  glVertex2f( gx + gw, gy + gh ); 
     283        glTexCoord2f( min_s, max_t );  glVertex2f( gx, gy + gh ); 
    283284    } 
    284285    return tgi; 
     
    302303{ 
    303304    GLfloat x, y; 
     305    GLfloat tw, th; 
    304306    TexFontGlyph* prev = 0; 
     307 
     308    tw = (GLfloat) tf->tex_width; 
     309    th = (GLfloat) tf->tex_height; 
    305310 
    306311    if( (it != end) ) 
     
    317322            { 
    318323                x = (GLfloat) tf->max_ascent; 
    319                 y -= x * 1.5f;  // Estimate of line spacing. 
     324                y -= txf_lineSpacing( tf ); 
    320325                x = grState.penX; 
    321326                prev = 0; 
     
    328333            else 
    329334            { 
    330                 prev = renderGlyphXY( tf, *it, &x, y, prev ); 
     335                prev = renderGlyphXY( tf, tw, th, *it, &x, y, prev ); 
    331336            } 
    332337            ++it; 
  • 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 )