[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51054] trunk/blender/source/blender/ editors: UI: buttons that open menus now align to the menu rather than looking disconnected .
Brecht Van Lommel
brechtvanlommel at pandora.be
Thu Oct 4 22:12:06 CEST 2012
Revision: 51054
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51054
Author: blendix
Date: 2012-10-04 20:12:05 +0000 (Thu, 04 Oct 2012)
Log Message:
-----------
UI: buttons that open menus now align to the menu rather than looking disconnected.
Also fixed some cases where the menu was offset 1 or 2 pixels wrong, though not
quite all of them, still off by 1 pixel sometimes.
http://www.pasteall.org/pic/show.php?id=38478
Modified Paths:
--------------
trunk/blender/source/blender/editors/include/UI_interface.h
trunk/blender/source/blender/editors/interface/interface.c
trunk/blender/source/blender/editors/interface/interface_handlers.c
trunk/blender/source/blender/editors/interface/interface_intern.h
trunk/blender/source/blender/editors/interface/interface_regions.c
trunk/blender/source/blender/editors/interface/interface_widgets.c
Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/include/UI_interface.h 2012-10-04 20:12:05 UTC (rev 51054)
@@ -421,7 +421,6 @@
void uiBlockFlipOrder(uiBlock *block);
void uiBlockSetFlag(uiBlock *block, int flag);
void uiBlockClearFlag(uiBlock *block, int flag);
-void uiBlockSetXOfs(uiBlock *block, int xofs);
int uiButGetRetVal(uiBut *but);
Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/interface/interface.c 2012-10-04 20:12:05 UTC (rev 51054)
@@ -996,24 +996,20 @@
/* project button or block (but==NULL) to pixels in regionspace */
static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, uiBut *but)
{
- float gx, gy;
- float getsizex, getsizey;
+ rctf rectf = (but)? but->rect: block->rect;
- getsizex = ar->winx;
- getsizey = ar->winy;
+ ui_block_to_window_fl(ar, block, &rectf.xmin, &rectf.ymin);
+ ui_block_to_window_fl(ar, block, &rectf.xmax, &rectf.ymax);
- gx = (but ? but->rect.xmin : block->rect.xmin) + (block->panel ? block->panel->ofsx : 0.0f);
- gy = (but ? but->rect.ymin : block->rect.ymin) + (block->panel ? block->panel->ofsy : 0.0f);
-
- rect->xmin = floorf(getsizex * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + block->winmat[3][0])));
- rect->ymin = floorf(getsizey * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + block->winmat[3][1])));
-
- gx = (but ? but->rect.xmax : block->rect.xmax) + (block->panel ? block->panel->ofsx : 0.0f);
- gy = (but ? but->rect.ymax : block->rect.ymax) + (block->panel ? block->panel->ofsy : 0.0f);
-
- rect->xmax = floorf(getsizex * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + block->winmat[3][0])));
- rect->ymax = floorf(getsizey * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + block->winmat[3][1])));
+ rectf.xmin -= ar->winrct.xmin;
+ rectf.ymin -= ar->winrct.ymin;
+ rectf.xmax -= ar->winrct.xmin;
+ rectf.ymax -= ar->winrct.ymin;
+ rect->xmin = floorf(rectf.xmin);
+ rect->ymin = floorf(rectf.ymin);
+ rect->xmax = floorf(rectf.xmax);
+ rect->ymax = floorf(rectf.ymax);
}
/* uses local copy of style, to scale things down, and allow widgets to change stuff */
@@ -2160,8 +2156,6 @@
wm_subwindow_getmatrix(window, region->swinid, block->winmat);
wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey);
- /* TODO - investigate why block->winmat[0][0] is negative
- * in the image view when viewRedrawForce is called */
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
}
else {
@@ -3423,11 +3417,6 @@
block->flag &= ~flag;
}
-void uiBlockSetXOfs(uiBlock *block, int xofs)
-{
- block->xofs = xofs;
-}
-
void uiButSetFlag(uiBut *but, int flag)
{
but->flag |= flag;
Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c 2012-10-04 20:12:05 UTC (rev 51054)
@@ -2167,6 +2167,16 @@
}
}
+int ui_button_open_menu_direction(uiBut *but)
+{
+ uiHandleButtonData *data = but->active;
+
+ if (data && data->menu)
+ return data->menu->direction;
+
+ return 0;
+}
+
/* ***************** events for different button types *************** */
static int ui_do_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data, wmEvent *event)
Modified: trunk/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_intern.h 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/interface/interface_intern.h 2012-10-04 20:12:05 UTC (rev 51054)
@@ -315,7 +315,6 @@
char tooltipdisabled; /* to avoid tooltip after click */
char endblock; /* uiEndBlock done? */
- float xofs, yofs; /* offset to parent button */
eBlockBoundsCalc bounds_type; /* for doing delayed */
int mx, my;
int bounds, minbounds; /* for doing delayed */
@@ -419,6 +418,9 @@
int menuretval;
float retvalue;
float retvec[4];
+
+ /* menu direction */
+ int direction;
};
uiBlock *ui_block_func_COLOR(struct bContext *C, uiPopupBlockHandle *handle, void *arg_but);
@@ -481,6 +483,7 @@
extern void ui_button_activate_do(struct bContext *C, struct ARegion *ar, uiBut *but);
extern void ui_button_active_free(const struct bContext *C, uiBut *but);
extern int ui_button_is_active(struct ARegion *ar);
+extern int ui_button_open_menu_direction(uiBut *but);
/* interface_widgets.c */
void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3);
Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c 2012-10-04 20:12:05 UTC (rev 51054)
@@ -1341,6 +1341,14 @@
ui_block_to_window_fl(butregion, but->block, &butrct.xmin, &butrct.ymin);
ui_block_to_window_fl(butregion, but->block, &butrct.xmax, &butrct.ymax);
+ /* widget_roundbox_set has this correction too, keep in sync */
+ if (but->type != PULLDOWN) {
+ if (but->flag & UI_BUT_ALIGN_TOP)
+ butrct.ymax += 1.0f;
+ if (but->flag & UI_BUT_ALIGN_LEFT)
+ butrct.xmin -= 1.0f;
+ }
+
/* calc block rect */
if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) {
if (block->buttons.first) {
@@ -1467,9 +1475,6 @@
}
}
- /* apply requested offset in the block */
- xof += block->xofs / block->aspect;
- yof += block->yofs / block->aspect;
#if 0
/* clamp to window bounds, could be made into an option if its ever annoying */
if ( (offscreen = (block->rect.ymin + yof)) < 0) yof -= offscreen; /* bottom */
@@ -1659,12 +1664,10 @@
/* if this is being created from a button */
if (but) {
- if (ELEM(but->type, BLOCK, PULLDOWN))
- block->xofs = -2; /* for proper alignment */
-
block->aspect = but->block->aspect;
ui_block_position(window, butregion, but, block);
+ handle->direction = block->direction;
}
else {
/* keep a list of these, needed for pulldown menus */
Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c 2012-10-04 20:11:54 UTC (rev 51053)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c 2012-10-04 20:12:05 UTC (rev 51054)
@@ -2702,16 +2702,16 @@
*wcol = wcol_backup;
}
-static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
+static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
{
if (state & UI_ACTIVE) {
uiWidgetBase wtb;
- float rad = 0.5f * BLI_rcti_size_y(rect); /* 4.0f */
-
+ float rad = 0.25f * BLI_rcti_size_y(rect); /* 4.0f */
+
widget_init(&wtb);
-
+
/* half rounded */
- round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
+ round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol);
}
@@ -3048,9 +3048,12 @@
static int widget_roundbox_set(uiBut *but, rcti *rect)
{
+ int roundbox = UI_CNR_ALL;
+
/* alignment */
- if (but->flag & UI_BUT_ALIGN) {
+ if ((but->flag & UI_BUT_ALIGN) && but->type != PULLDOWN) {
+ /* ui_block_position has this correction too, keep in sync */
if (but->flag & UI_BUT_ALIGN_TOP)
rect->ymax += 1;
if (but->flag & UI_BUT_ALIGN_LEFT)
@@ -3058,27 +3061,50 @@
switch (but->flag & UI_BUT_ALIGN) {
case UI_BUT_ALIGN_TOP:
- return UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT;
+ roundbox = UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT;
+ break;
case UI_BUT_ALIGN_DOWN:
- return UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT;
+ roundbox = UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT;
+ break;
case UI_BUT_ALIGN_LEFT:
- return UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT;
+ roundbox = UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT;
+ break;
case UI_BUT_ALIGN_RIGHT:
- return UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT;
+ roundbox = UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT;
+ break;
case UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_RIGHT:
- return UI_CNR_TOP_LEFT;
+ roundbox = UI_CNR_TOP_LEFT;
+ break;
case UI_BUT_ALIGN_DOWN | UI_BUT_ALIGN_LEFT:
- return UI_CNR_TOP_RIGHT;
+ roundbox = UI_CNR_TOP_RIGHT;
+ break;
case UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT:
- return UI_CNR_BOTTOM_LEFT;
+ roundbox = UI_CNR_BOTTOM_LEFT;
+ break;
case UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_LEFT:
- return UI_CNR_BOTTOM_RIGHT;
+ roundbox = UI_CNR_BOTTOM_RIGHT;
+ break;
default:
- return 0;
+ roundbox = 0;
+ break;
}
}
- return UI_CNR_ALL;
+ /* align with open menu */
+ if (but->active) {
+ int direction = ui_button_open_menu_direction(but);
+
+ if (direction == UI_TOP)
+ roundbox &= ~(UI_CNR_TOP_RIGHT|UI_CNR_TOP_LEFT);
+ else if (direction == UI_DOWN)
+ roundbox &= ~(UI_CNR_BOTTOM_RIGHT|UI_CNR_BOTTOM_LEFT);
+ else if (direction == UI_LEFT)
+ roundbox &= ~(UI_CNR_TOP_LEFT|UI_CNR_BOTTOM_LEFT);
+ else if (direction == UI_RIGHT)
+ roundbox &= ~(UI_CNR_TOP_RIGHT|UI_CNR_BOTTOM_RIGHT);
+ }
+
+ return roundbox;
}
/* conversion from old to new buttons, so still messy */
More information about the Bf-blender-cvs
mailing list