diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-29 23:44:39 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-03-29 23:44:39 +0400 |
commit | 6705b6f96ea4255f6bd69a039562ed603a83a83e (patch) | |
tree | d8859110c9810e66666ba8add287ca201a0d6238 /source/blender/editors/space_text | |
parent | 9b7f44ceb56c741af10459924be7775ea91bfa68 (diff) |
UI:
* Added a PanelType and HeaderType for registering panels
and headers in regions. When the region draws, it will
then automatically draw the ones that were registerd with
poll and draw callbacks.
Used for text header, properties and object buttons now.
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 61 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_header.c | 50 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 6 |
3 files changed, 58 insertions, 59 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 90abd516c5a..89852955ca3 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -344,28 +344,12 @@ static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar) static void text_header_area_init(wmWindowManager *wm, ARegion *ar) { UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy); + ar->v2d.flag &= ~(V2D_PIXELOFS_X|V2D_PIXELOFS_Y); // XXX temporary } static void text_header_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - if(ED_screen_area_active(C)) - UI_GetThemeColor3fv(TH_HEADER, col); - else - UI_GetThemeColor3fv(TH_HEADERDESEL, col); - - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - text_header_buttons(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + uiRegionHeaderLayout(C, ar); } /****************** properties region ******************/ @@ -378,20 +362,7 @@ static void text_properties_area_init(wmWindowManager *wm, ARegion *ar) static void text_properties_area_draw(const bContext *C, ARegion *ar) { - float col[3]; - - /* clear */ - UI_GetThemeColor3fv(TH_HEADER, col); - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); - - /* set view2d view matrix for scrolling (without scrollers) */ - UI_view2d_view_ortho(C, &ar->v2d); - - text_properties_buttons(C, ar); - - /* restore view matrix? */ - UI_view2d_view_restore(C); + uiRegionPanelLayout(C, ar, 1, NULL); } /********************* registration ********************/ @@ -422,17 +393,6 @@ void ED_spacetype_text(void) BLI_addhead(&st->regiontypes, art); - /* regions: header */ - art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); - art->regionid = RGN_TYPE_HEADER; - art->minsizey= HEADERY; - art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; - - art->init= text_header_area_init; - art->draw= text_header_area_draw; - - BLI_addhead(&st->regiontypes, art); - /* regions: properties */ art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); art->regionid = RGN_TYPE_UI; @@ -442,8 +402,23 @@ void ED_spacetype_text(void) art->init= text_properties_area_init; art->draw= text_properties_area_draw; + text_properties_register(art); + BLI_addhead(&st->regiontypes, art); + + /* regions: header */ + art= MEM_callocN(sizeof(ARegionType), "spacetype text region"); + art->regionid = RGN_TYPE_HEADER; + art->minsizey= HEADERY; + art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; + art->init= text_header_area_init; + art->draw= text_header_area_draw; + + text_header_register(art); + + BLI_addhead(&st->regiontypes, art); + BKE_spacetype_register(st); } diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index 63fd5e6dae6..63e3bca1ad0 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -93,7 +93,7 @@ static void do_text_template_scriptsmenu(bContext *C, void *arg, int event) // XXX BPY_menu_do_python(PYMENU_SCRIPTTEMPLATE, event); } -uiBlock *text_template_scriptsmenu(bContext *C, void *args_unused) +static uiBlock *text_template_scriptsmenu(bContext *C, void *args_unused) { ARegion *ar= CTX_wm_region(C); uiBlock *block; @@ -126,7 +126,7 @@ static void do_text_plugin_scriptsmenu(bContext *C, void *arg, int event) // XXX BPY_menu_do_python(PYMENU_TEXTPLUGIN, event); } -uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused) +static uiBlock *text_plugin_scriptsmenu(bContext *C, void *args_unused) { ARegion *ar= CTX_wm_region(C); uiBlock *block; @@ -195,6 +195,11 @@ static void text_editmenu_to3dmenu(bContext *C, uiMenuItem *head, void *arg_unus uiMenuItemBooleanO(head, "One Object Per Line", 0, "TEXT_OT_to_3d_object", "split_lines", 1); } +static int text_menu_edit_poll(bContext *C) +{ + return (CTX_data_edit_text(C) != NULL); +} + static void text_editmenu(bContext *C, uiMenuItem *head, void *arg_unused) { uiMenuItemO(head, 0, "ED_OT_undo"); @@ -353,7 +358,7 @@ static void text_idpoin_handle(bContext *C, ID *id, int event) /********************** header buttons ***********************/ -static void header_buttons(const bContext *C, uiLayout *layout) +static void text_header_draw(const bContext *C, uiLayout *layout) { bScreen *sc= CTX_wm_screen(C); SpaceText *st= (SpaceText*)CTX_wm_space_data(C); @@ -411,17 +416,25 @@ static void header_buttons(const bContext *C, uiLayout *layout) } } -void text_header_buttons(const bContext *C, ARegion *ar) +void text_header_register(ARegionType *art) { - uiHeaderLayout(C, ar, header_buttons); + HeaderType *ht; + + /* header */ + ht= MEM_callocN(sizeof(HeaderType), "spacetype text header"); + ht->idname= "TEXT_HT_header"; + ht->name= "Header"; + ht->draw= text_header_draw; + BLI_addhead(&art->headertypes, ht); } /************************** properties ******************************/ -void properties_buttons(const bContext *C, uiLayout *layout) +static void text_properties_panel_draw(const bContext *C, Panel *panel) { bScreen *sc= CTX_wm_screen(C); SpaceText *st= CTX_wm_space_text(C); + uiLayout *layout= panel->layout; PointerRNA spaceptr; RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr); @@ -436,10 +449,11 @@ void properties_buttons(const bContext *C, uiLayout *layout) uiItemR(layout, UI_TSLOT_COLUMN_1, NULL, 0, &spaceptr, "tab_width"); } -void find_buttons(const bContext *C, uiLayout *layout) +static void text_find_panel_draw(const bContext *C, Panel *panel) { bScreen *sc= CTX_wm_screen(C); SpaceText *st= CTX_wm_space_text(C); + uiLayout *layout= panel->layout; PointerRNA spaceptr; RNA_pointer_create(&sc->id, &RNA_SpaceTextEditor, st, &spaceptr); @@ -468,13 +482,23 @@ void find_buttons(const bContext *C, uiLayout *layout) uiItemR(layout, UI_TSLOT_COLUMN_2, "All", 0, &spaceptr, "find_all"); } -void text_properties_buttons(const bContext *C, ARegion *ar) +void text_properties_register(ARegionType *art) { - uiCompactPanelLayout(C, ar, "TEXT_OT_properties", "Properties", "Text", properties_buttons, 0); - uiCompactPanelLayout(C, ar, "TEXT_OT_find", "Find", "Text", find_buttons, 1); - - uiDrawPanels(C, 1); - uiMatchPanelsView2d(ar); + PanelType *pt; + + /* panels: properties */ + pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); + pt->idname= "TEXT_PT_properties"; + pt->name= "Properties"; + pt->draw= text_properties_panel_draw; + BLI_addtail(&art->paneltypes, pt); + + /* panels: find */ + pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); + pt->idname= "TEXT_PT_find"; + pt->name= "Find"; + pt->draw= text_find_panel_draw; + BLI_addtail(&art->paneltypes, pt); } ARegion *text_has_properties_region(ScrArea *sa) diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 746858a9fdd..7ec75e292ce 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -31,6 +31,7 @@ /* internal exports only */ struct ARegion; +struct ARegionType; struct bContext; struct BMF_Font; struct ReportList; @@ -42,9 +43,8 @@ struct wmOperatorType; struct wmWindowManager; /* text_header.c */ -void text_header_buttons(const struct bContext *C, struct ARegion *ar); -void text_find_buttons(const struct bContext *C, struct ARegion *ar); -void text_properties_buttons(const struct bContext *C, struct ARegion *ar); +void text_properties_register(struct ARegionType *art); +void text_header_register(struct ARegionType *art); /* text_draw.c */ void draw_text_main(struct SpaceText *st, struct ARegion *ar); |