Changeset 540 for trunk/thune/gl/gui.c
- Timestamp:
- 07/04/08 03:46:13 (5 months ago)
- Files:
-
- 1 modified
-
trunk/thune/gl/gui.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/gl/gui.c
r537 r540 59 59 #define WID(wp) (wp - ((GWidget*) ui->widgets.ptr.v)) 60 60 #define CLASS(wp) wclass[wp->classId] 61 #define IS_ENABLED(wp) (! (wp->flags & GW_DISABLED)) 61 62 62 63 #define EACH_CHILD(parent,it) \ … … 103 104 104 105 105 // Order must match gui-style-proto in gx.t.106 enum ContextIndexStyle107 {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 list116 CI_STYLE_BUTTON_SIZE, // coord!117 CI_STYLE_BUTTON_UP, // Draw list118 CI_STYLE_BUTTON_DOWN, // Draw list119 CI_STYLE_BUTTON_HOVER, // Draw list120 CI_STYLE_LABEL_DL // Draw list121 };122 123 124 106 #define WCLASS_MAX 24 125 107 static GWidgetClass wclass[ WCLASS_MAX ]; … … 256 238 257 239 258 static GWidget* base_parse( GUI* ui, GMakeState* ms , int classId)240 static GWidget* base_parse( GUI* ui, GMakeState* ms ) 259 241 { 260 242 GWidget* wp; … … 309 291 310 292 // Future... 293 UIndex eventN; 311 294 uint8_t layoutType; 312 295 uint8_t rows; 313 296 uint8_t cols; 314 uint8_t _pad[5];297 uint8_t _pad; 315 298 } 316 299 BoxData; … … 344 327 345 328 346 static GWidget* box_parse( GUI* ui, GMakeState* ms , int classId)329 static GWidget* box_parse( GUI* ui, GMakeState* ms ) 347 330 { 348 331 GWidget* wp; … … 721 704 722 705 723 static GWidget* window_parse( GUI* ui, GMakeState* ms , int classId)706 static GWidget* window_parse( GUI* ui, GMakeState* ms ) 724 707 { 725 708 GWidget* wp; 726 709 UAtom sel = ur_sel(ms->it); 727 wp = box_parse( ui, ms , classId);710 wp = box_parse( ui, ms ); 728 711 if( wp ) 729 712 { … … 740 723 BoxData* wd = BOX_DATA(wp); 741 724 (void) ui; 742 743 wp->flags |= GW_DISABLED; // Does not handle input.744 725 745 726 wd->marginL = 8; … … 769 750 770 751 752 static 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 771 767 static void window_sizeHint( GUI* ui, GWidget* wp, GSizeHint* size ) 772 768 { … … 825 821 #include "widgets/labelw.c" 826 822 #include "widgets/twidget.c" 823 #include "widgets/lineeditw.c" 827 824 //#include "widgets/listw.c" 828 825 … … 838 835 */ 839 836 840 static int wclassCount = 7;837 static int wclassCount = 8; 841 838 842 839 static GWidgetClass wclass[ WCLASS_MAX ] = … … 858 855 859 856 { "window", 860 window_parse, window_init, window_mark, no_event,857 window_parse, window_init, window_mark, window_event, 861 858 window_sizeHint, window_layout, window_render, base_select, 862 859 0, 0, 0 }, … … 875 872 twidget_parse, twidget_init, twidget_mark, twidget_event, 876 873 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, 877 879 0, 0, 0 }, 878 880 … … 972 974 973 975 976 static 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 974 991 void gui_setMouseFocus( GUI* ui, GWidgetId id ) 975 992 { 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 } 977 999 } 978 1000 … … 994 1016 995 1017 1018 /* 1019 Returns child of wp under event x,y, or wp if no child contains the point. 1020 */ 996 1021 static GWidget* childAt( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 997 1022 { … … 1030 1055 switch( ev->type ) 1031 1056 { 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 1032 1067 case GLV_EVENT_BUTTON_DOWN: 1033 1068 case GLV_EVENT_BUTTON_UP: … … 1051 1086 { 1052 1087 w = WPTR(ui->mouseFocus); 1053 if( ui->mouseGrabbed || 1054 gui_widgetContains( w, ev->x, ev->y ) ) 1088 if( ui->mouseGrabbed ) 1055 1089 { 1056 1090 goto dispatch; 1057 1091 } 1058 else 1092 else if( gui_widgetContains( w, ev->x, ev->y ) ) 1059 1093 { 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; 1064 1101 } 1065 1102 } 1066 1103 1067 ui->mouseFocus = widgetAt( ui, ev);1104 gui_setMouseFocus( ui, widgetAt( ui, ev ) ); 1068 1105 if( IS_VALID(ui->mouseFocus) ) 1069 1106 { 1070 1107 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; 1079 1109 } 1080 1110 break; … … 1363 1393 if( cl->nameAtom == atom ) 1364 1394 { 1365 wp = cl->parse( ui, ms, cl->id ); 1395 ms->classId = cl->id; 1396 wp = cl->parse( ui, ms ); 1366 1397 if( wp ) 1367 1398 { … … 1412 1443 /* 1413 1444 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. 1414 1446 */ 1415 1447 const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ) … … 1437 1469 if( argc ) 1438 1470 return 0; 1471 1439 1472 ms->it = it; 1440 1473 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 */ 1482 const 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 { 1489 valid: 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; 1441 1504 } 1442 1505 … … 1495 1558 1496 1559 1560 #ifdef DEBUG 1561 static void dumpIndent( int indent ) 1562 { 1563 while( indent-- ) 1564 printf( " " ); 1565 } 1566 1567 1568 void 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 1592 void 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 1497 1605 // EOF
