Commit: 74432c94f32735ca6678eaaf270acc323fd8a4c6
Author: Campbell Barton
Date:   Sun Jun 15 15:26:45 2014 +1000
https://developer.blender.org/rB74432c94f32735ca6678eaaf270acc323fd8a4c6

Merge branch 'master' into pie-menus

Conflicts:
        source/blender/editors/interface/interface.c

===================================================================



===================================================================

diff --cc source/blender/editors/interface/interface.c
index 9d3fb7c,0f4bba8..221304a
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@@ -322,43 -321,9 +321,41 @@@ static void ui_centered_bounds_block(wm
        ui_bounds_block(block);
        
  }
 +
- static void ui_centered_pie_bounds_block(const bContext *C, uiBlock *block)
++static void ui_centered_pie_bounds_block(uiBlock *block, const int xy[2])
 +{
-       wmWindow *window = CTX_wm_window(C);
 +      int x, y;
 +      int startx;
 +      int width, height;
 +
 +      /* note: this is used for the splash where window bounds event has not 
been
 +       * updated by ghost, get the window bounds from ghost directly */
 +
-       x = window->eventstate->x;
-       y = window->eventstate->y;
++      x = xy[0];
++      y = xy[1];
 +
 +      ui_bounds_block(block);
 +
 +      width  = BLI_rctf_size_x(&block->rect);
 +      height = BLI_rctf_size_y(&block->rect);
 +
 +      startx = x - (width * 0.5f);
 +
 +      /* special case, 3 items means no top, make it so we are going down the 
full height */
 +      if (block->pie_data.flags & UI_PIE_3_ITEMS)
 +              ui_block_translate(block, startx - block->rect.xmin, y);
 +      else {
 +              int starty = y - (height * 0.5f);
 +              ui_block_translate(block, startx - block->rect.xmin, starty - 
block->rect.ymin);
 +      }
 +
 +      /* now recompute bounds and safety */
 +      ui_bounds_block(block);
 +}
 +
- 
- static void ui_popup_bounds_block(const bContext *C, uiBlock *block, 
eBlockBoundsCalc bounds_calc)
+ static void ui_popup_bounds_block(wmWindow *window, uiBlock *block,
+                                   eBlockBoundsCalc bounds_calc, const int 
xy[2])
  {
-       wmWindow *window = CTX_wm_window(C);
        int startx, starty, endx, endy, width, height, oldwidth, oldheight;
        int oldbounds, xmax, ymax;
        const int margin = UI_SCREEN_MARGIN;
@@@ -1195,11 -1171,8 +1205,11 @@@ void uiEndBlock_ex(const bContext *C, u
                        ui_text_bounds_block(block, 0.0f);
                        break;
                case UI_BLOCK_BOUNDS_POPUP_CENTER:
-                       ui_centered_bounds_block(C, block);
+                       ui_centered_bounds_block(window, block);
                        break;
 +              case UI_BLOCK_BOUNDS_PIE_CENTER:
-                       ui_centered_pie_bounds_block(C, block);
++                      ui_centered_pie_bounds_block(block, xy);
 +                      break;
  
                        /* fallback */
                case UI_BLOCK_BOUNDS_POPUP_MOUSE:
diff --cc source/blender/editors/interface/interface_regions.c
index 22d7fd5,cc5a4be..f4afcc3
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@@ -1577,59 -1596,25 +1598,62 @@@ uiBlock *ui_popup_block_refresh
                saferct->safety = block->safety;
                BLI_addhead(&block->saferct, saferct);
        }
 -
 -      /* clip block with window boundary */
 -      ui_popup_block_clip(window, block);
        
 -      /* the block and buttons were positioned in window space as in 2.4x, now
 -       * these menu blocks are regions so we bring it back to region space.
 -       * additionally we add some padding for the menu shadow or rounded 
menus */
 -      ar->winrct.xmin = block->rect.xmin - width;
 -      ar->winrct.xmax = block->rect.xmax + width;
 -      ar->winrct.ymin = block->rect.ymin - width;
 -      ar->winrct.ymax = block->rect.ymax + MENU_TOP;
 -      
 -      ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin);
 +      if (block->flag & UI_BLOCK_RADIAL) {
 +              /* find area that spawned this menu, keep it inside */
 +              ScrArea *sa = CTX_wm_area(C);
 +              int ar_w = BLI_rcti_size_x(&sa->totrct);
 +              int ar_h = BLI_rcti_size_y(&sa->totrct);
 +              int x_offset = 0, y_offset = 0;
 +
 +              ar->winrct = sa->totrct;
 +
 +              ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin);
 +
 +              /* spawned coordinates still in window space, convert to screen 
*/
 +              block->pie_data.pie_center_spawned[0] -= ar->winrct.xmin;
 +              block->pie_data.pie_center_spawned[1] -= ar->winrct.ymin;
 +
 +              copy_v2_v2(block->pie_data.pie_center_init, 
block->pie_data.pie_center_spawned);
 +
 +              /* only try translation if area is large enough */
 +              if (BLI_rctf_size_x(&block->rect) < ar_w) {
 +                      if (block->rect.xmin < 0 )   x_offset -= 
block->rect.xmin;
 +                      if (block->rect.xmax > ar_w) x_offset += ar_w - 
block->rect.xmax;
 +              }
 +
 +              if (BLI_rctf_size_y(&block->rect) < ar_h) {
 +                      if (block->rect.ymin < 0 )   y_offset -= 
block->rect.ymin;
 +                      if (block->rect.ymax > ar_h) y_offset += ar_h - 
block->rect.ymax;
 +              }
 +              /* if we are offsetting set up initial data for timeout 
functionality */
 +              if ((x_offset != 0) || (y_offset != 0)) {
 +                      block->pie_data.pie_center_spawned[0] += x_offset;
 +                      block->pie_data.pie_center_spawned[1] += y_offset;
 +
 +                      ui_block_translate(block, x_offset, y_offset);
 +                      block->pie_data.flags |= UI_PIE_INITIAL_DIRECTION;
 +              }
 +      }
 +      else {
 +              /* clip block with window boundary */
 +              ui_popup_block_clip(window, block);
 +              /* the block and buttons were positioned in window space as in 
2.4x, now
 +               * these menu blocks are regions so we bring it back to region 
space.
 +               * additionally we add some padding for the menu shadow or 
rounded menus */
 +              ar->winrct.xmin = block->rect.xmin - width;
 +              ar->winrct.xmax = block->rect.xmax + width;
 +              ar->winrct.ymin = block->rect.ymin - width;
 +              ar->winrct.ymax = block->rect.ymax + MENU_TOP;
 +
 +              ui_block_translate(block, -ar->winrct.xmin, -ar->winrct.ymin);
 +      }
  
-       /* adds subwindow */
-       ED_region_init(C, ar);
+       if (block_old) {
+               block->oldblock = block_old;
+               uiBlockUpdateFromOld(C, block);
+               uiFreeInactiveBlocks(C, &ar->uiblocks);
+       }
  
        /* checks which buttons are visible, sets flags to prevent draw (do 
after region init) */
        ui_popup_block_scrolltest(block);
@@@ -2449,136 -2473,6 +2518,134 @@@ uiLayout *uiPupMenuLayout(uiPopupMenu *
        return pup->layout;
  }
  
 +/*************************** Pie Menus 
***************************************/
- static uiBlock *ui_block_func_PIE(bContext *C, uiPopupBlockHandle *handle, 
void *arg_pie)
++static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle 
*handle, void *arg_pie)
 +{
 +      uiBlock *block;
 +      uiPieMenu *pie = arg_pie;
 +      int minwidth, width, height;
 +
 +      minwidth = 50;
 +      block = pie->block_radial;
 +
 +      /* in some cases we create the block before the region,
 +       * so we set it delayed here if necessary */
 +      if (BLI_findindex(&handle->region->uiblocks, block) == -1)
 +              uiBlockSetRegion(block, handle->region);
 +
 +      uiBlockLayoutResolve(block, &width, &height);
 +
 +      uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW | 
UI_BLOCK_NUMSELECT);
 +
 +      block->minbounds = minwidth;
 +      block->bounds = 1;
 +      block->mx = 0;
 +      block->my = 0;
 +      block->bounds_type = UI_BLOCK_BOUNDS_PIE_CENTER;
 +
 +      block->pie_data.pie_center_spawned[0] = pie->mx;
 +      block->pie_data.pie_center_spawned[1] = pie->my;
 +
-       uiEndBlock(C, block);
- 
 +      return pie->block_radial;
 +}
 +
 +static float uiPieTitleWidth(const char *name, int icon)
 +{
 +      return UI_GetStringWidth(name) +
 +                      (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)));
 +}
 +
 +struct uiPieMenu *uiPieMenuBegin(struct bContext *C, const char *title, int 
icon, short event)
 +{
 +      uiStyle *style = UI_GetStyleDraw();
 +      uiPieMenu *pie = MEM_callocN(sizeof(uiPopupMenu), "pie menu");
 +      uiBut *but;
 +
 +      pie->block_radial = uiBeginBlock(C, NULL, __func__, UI_EMBOSS);
 +      /* may be useful later to allow spawning pies
 +       * from old positions */
 +      /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */
 +      pie->block_radial->puphash = ui_popup_menu_hash(title);
 +      pie->block_radial->flag |= UI_BLOCK_RADIAL;
 +      pie->block_radial->pie_data.event = event;
 +
 +      pie->layout = uiBlockLayout(pie->block_radial, UI_LAYOUT_VERTICAL, 
UI_LAYOUT_PIEMENU, 0, 0, 200, 0, 0, style);
 +
 +
 +      /* create title button */
 +      if (title[0]) {
 +              char titlestr[256];
 +              int w;
 +              if (icon) {
 +                      BLI_snprintf(titlestr, sizeof(titlestr), " %s", title);
 +                      w = uiPieTitleWidth(titlestr, icon);
 +                      uiDefIconTextBut(pie->block_radial, LABEL, 0, icon, 
titlestr, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 +              }
 +              else {
 +                      w = uiPieTitleWidth(title, 0);
 +                      but = uiDefBut(pie->block_radial, LABEL, 0, title, 0, 
0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 +                      /* hack, draw label with default transparent style */
 +                      but->dt = UI_EMBOSSP;
 +              }
 +      }
 +
 +      return pie;
 +}
 +
 +void uiPieMenuEnd(bContext *C, uiPieMenu *pie)
 +{
 +      wmWindow *window = CTX_wm_window(C);
 +      uiPopupBlockHandle *menu;
 +      pie->mx = window->eventstate->x;
 +      pie->my = window->eventstate->y;
 +
 +      menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, 
pie);
 +      menu->popup = true;
 +      menu->towardstime = PIL_check_seconds_timer();
 +
 +      UI_add_pie_handlers(C, &window->modalhandlers, menu);
 +      WM_event_add_mousemove(C);
 +
 +      MEM_freeN(pie);
 +}
 +
 +
 +uiLayout *uiPieMenuLayout(uiPieMenu *pie)
 +{
 +      return pie->layout;
 +}
 +
 +void uiPieMenuInvoke(struct bContext *C, const char *idname, short event)
 +{
 +      uiPieMenu *pie;
 +      uiLayout *layout;
 +      Menu menu;
 +      MenuType *mt = WM_menutype_find(idname, true);
 +
 +      if (mt == NULL) {
 +              printf("%s: named menu \"%s\" not found\n", __func__, idname);
 +              return;
 +      }
 +
 +      if (mt->poll && mt->poll(C, mt) == 0)
 +              return;
 +
 +      pie = uiPieMenuBegin(C, IFACE_(mt->label), ICON_NONE, event);
 +      layout = uiPieMenuLayout(pie);
 +
 +      menu.layout = layout;
 +      menu.type = mt;
 +
 +      if (G.debug & G_DEBUG_WM) {
 +              printf("%s: opening menu \"%s\"\n", __func__, idname);
 +      }
 +
 +      mt->draw(C, &menu);
 +
 +      uiPieMenuEnd(C, pie);
 +}
 +
 +
  /*************************** Standard Popup Menus 
****************************/
  
  void uiPupMenuReports(bContext *C, ReportList *reports)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to