Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-15 22:19:39 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-15 22:19:39 +0300
commit6283b0c8c5a93baafa040c612ed356472b633582 (patch)
tree8b38ef8fbc1a0fef93418f249cd0860e5fe3f3a3 /source/blender/editors/interface/interface_regions.c
parentaad5e497013dc37acc1913fbbeec4bc0d16ccbc6 (diff)
UI: getting popup menus to work again, just the internal interface
and event handling code still, how it integrates with operators and handlers is not worked out yet. For testing, Ctrl+Q quit now shows a confirmation popup using the following call: okee_operator(C, "WM_OT_exit_blender", "Quit Blender");
Diffstat (limited to 'source/blender/editors/interface/interface_regions.c')
-rw-r--r--source/blender/editors/interface/interface_regions.c198
1 files changed, 41 insertions, 157 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index 2e01eb8c8b1..0c7613bbfcd 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -1,4 +1,5 @@
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@@ -585,10 +586,8 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
{
uiBlock *block;
- for(block=ar->uiblocks.first; block; block=block->next) {
- wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
+ for(block=ar->uiblocks.first; block; block=block->next)
uiDrawBlock(block);
- }
}
uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *but, uiBlockFuncFP block_func, void *arg)
@@ -666,6 +665,10 @@ uiMenuBlockHandle *ui_menu_block_create(bContext *C, ARegion *butregion, uiBut *
/* adds subwindow */
ED_region_init(C, ar);
+
+ /* get winmat now that we actually have the subwindow */
+ wm_subwindow_set(C->window, ar->swinid);
+ wm_subwindow_getmatrix(C->window, ar->swinid, block->winmat);
/* notify change and redraw */
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
@@ -1604,9 +1607,10 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiMenuBlockHandle *handle, void *
return block;
}
-uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow)
+void pupmenu_col(bContext *C, char *instr, int mx, int my, int maxrow, uiPupmenuFunc func, void *arg)
{
uiPupMenuInfo info;
+ uiMenuBlockHandle *menu;
memset(&info, 0, sizeof(info));
info.instr= instr;
@@ -1614,181 +1618,61 @@ uiMenuBlockHandle *pupmenu_col(bContext *C, char *instr, int mx, int my, int max
info.my= my;
info.maxrow= maxrow;
- return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
+ menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENUCOL, &info);
+ menu->popup= 1;
+
+ UI_add_popup_handlers(&C->window->handlers, menu);
+ WM_event_add_mousemove(C);
+
+ menu->popup_func= func;
+ menu->popup_arg= arg;
}
-uiMenuBlockHandle *pupmenu(bContext *C, char *instr, int mx, int my)
+void pupmenu(bContext *C, char *instr, int mx, int my, uiPupmenuFunc func, void *arg)
{
uiPupMenuInfo info;
+ uiMenuBlockHandle *menu;
memset(&info, 0, sizeof(info));
info.instr= instr;
info.mx= mx;
info.my= my;
- return ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
-}
+ menu= ui_menu_block_create(C, NULL, NULL, ui_block_func_PUPMENU, &info);
+ menu->popup= 1;
+ UI_add_popup_handlers(&C->window->handlers, menu);
+ WM_event_add_mousemove(C);
-void pupmenu_free(bContext *C, uiMenuBlockHandle *handle)
-{
- ui_menu_block_free(C, handle);
+ menu->popup_func= func;
+ menu->popup_arg= arg;
}
-/*************** Temporary Buttons Tests **********************/
-
-static uiBlock *test_submenu(bContext *C, uiMenuBlockHandle *handle, void *arg)
+/* XXX test */
+static void operator_callback(bContext *C, void *arg, int retval)
{
- ARegion *ar= handle->region;
- uiBlock *block;
- short yco= 0, menuwidth=120;
-
- block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
- //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
- menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
- "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
- "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
-
- uiBlockSetDirection(block, UI_RIGHT);
+ const char *opname= arg;
- uiTextBoundsBlock(block, 50);
- uiEndBlock(C, block);
-
- return block;
+ if(retval > 0)
+ WM_operator_call(C, opname);
}
-static uiBlock *test_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_area)
+void okee_operator(bContext *C, char *opname, char *str, ...)
{
- ScrArea *area= arg_area;
- ARegion *ar= handle->region;
- uiBlock *block;
- short yco= 0, menuwidth=120;
-
- block= uiBeginBlock(C, ar, "test_viewmenu", UI_EMBOSSP, UI_HELV);
- //uiBlockSetButmFunc(block, do_test_viewmenu, NULL);
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
- menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
- "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT,
- "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
-
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
- uiDefIconTextBlockBut(block, test_submenu, NULL, ICON_RIGHTARROW_THIN, "Sub Menu", 0, yco-=20, 120, 19, "");
- uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-
- if(area->headertype==HEADERTOP) {
- uiBlockSetDirection(block, UI_DOWN);
- }
- else {
- uiBlockSetDirection(block, UI_TOP);
- uiBlockFlipOrder(block);
- }
-
- uiTextBoundsBlock(block, 50);
- uiEndBlock(C, block);
-
- return block;
-}
-
-void uiTestRegion(const bContext *C)
-{
- uiBlock *block;
- short xco;
-
- static float testcol[3];
- static char testtext[64];
- static float testnumf=5.0f;
- static short testchoice= 0, testtog= 0, testicontog= 0;
-
-#if 0
- static CurveMapping *cumap= NULL;
- static ColorBand *coba= NULL;
-#endif
-
- block= uiBeginBlock(C, C->region, "header buttons", UI_EMBOSS, UI_HELV);
-
- uiDefPulldownBut(block, test_viewmenu, C->area, "View",
- 13, 1, 50, 24, "");
-
- uiDefBut(block, BUT, 31415, "Type BUT",
- 13+50+5, 3, 80, 20, NULL, 0, 0, 0, 0, "A tooltip.");
- uiDefButS(block, MENU, 31416, "Gather Method%t|Raytrace %x0|Approximate %x1",
- 13+50+5+80+5, 3, 100, 20, &testchoice, 0, 0, 0, 0, "Method for occlusion gathering");
- uiDefButBitS(block, TOG, 1, 31417, "Pixel Cache",
- 13+50+5+80+5+100+5, 3, 100, 20, &testtog, 0, 0, 0, 0, "Cache AO results in pixels and interpolate over neighbouring pixels for speedup.");
-
- uiDefBut(block, TEX, 31418, "Text: ",
- 13+50+5+80+5+100+5+100+5, 3, 200, 20, testtext, 0, sizeof(testtext), 0, 0, "User defined text");
-
- uiDefButF(block, NUMSLI, 31419, "Slider: ",
- 13+50+5+80+5+100+5+100+5+200+5, 3, 150, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
- uiDefButF(block, NUM, 31419, "N: ",
- 13+50+5+80+5+100+5+100+5+200+5+150+5, 3, 100, 20, &testnumf, 0.0, 10.0, 0, 0, "Some tooltip.");
+ va_list ap;
+ char *s, buf[512];
+ int mx, my;
- uiDefButF(block, COL, 3142, "",
- 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5, 3, 100, 20, testcol, 0, 0, 0, 0 /*B_BANDCOL*/, "");
+ mx= C->window->eventstate->x;
+ my= C->window->eventstate->y;
- xco = 13+50+5+80+5+100+5+100+5+200+5+150+5+100+5+100+5;
- uiDefIconButBitS(block, ICONTOG, 1 /*AUTOKEY_ON*/, REDRAWINFO, ICON_PYTHON,
- xco, 3, 20, 20, &testicontog, 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
- xco += 5;
+ va_start(ap, str);
-#if 0
- if(!cumap) {
- cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
- cumap->flag &= ~CUMA_DO_CLIP;
- }
- if(!coba)
- coba= add_colorband(0);
+ s= buf;
+ s += sprintf(s, "OK? %%i%d%%t|", ICON_HELP);
+ vsprintf(s, str, ap);
+ va_end(ap);
- uiDefBut(block, BUT_CURVE, 3143, "",
- 13+400, 33, 100, 100, cumap, 0.0f, 1.0f, 0, 0, "");
- uiDefBut(block, BUT_COLORBAND, 3143, "",
- 13+400+100+10, 33, 150, 30, coba, 0.0f, 1.0f, 0, 0, "");
-#endif
-
- uiEndBlock(C, block);
- uiDrawBlock(block);
+ pupmenu(C, buf, mx, my, operator_callback, opname);
}