Cleanup: Rename ARegion variables from ar to region
The old convention was easy to confuse with ScrArea. Part of https://developer.blender.org/T74432. This is mostly a batch rename with some manual fixing. Only single word variable names are changed, no prefixed/suffixed names. Brecht van Lommel and Campbell Barton both gave me a green light for this convention change. Also ran clan clang format on affected files.
This commit is contained in:
		@@ -87,12 +87,12 @@ static bool last_redo_poll(const bContext *C, short region_type)
 | 
			
		||||
  return success;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void hud_region_hide(ARegion *ar)
 | 
			
		||||
static void hud_region_hide(ARegion *region)
 | 
			
		||||
{
 | 
			
		||||
  ar->flag |= RGN_FLAG_HIDDEN;
 | 
			
		||||
  region->flag |= RGN_FLAG_HIDDEN;
 | 
			
		||||
  /* Avoids setting 'AREA_FLAG_REGION_SIZE_UPDATE'
 | 
			
		||||
   * since other regions don't depend on this. */
 | 
			
		||||
  BLI_rcti_init(&ar->winrct, 0, 0, 0, 0);
 | 
			
		||||
  BLI_rcti_init(®ion->winrct, 0, 0, 0, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** \} */
 | 
			
		||||
@@ -104,9 +104,9 @@ static void hud_region_hide(ARegion *ar)
 | 
			
		||||
static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt))
 | 
			
		||||
{
 | 
			
		||||
  ScrArea *sa = CTX_wm_area(C);
 | 
			
		||||
  ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HUD);
 | 
			
		||||
  if (ar != NULL) {
 | 
			
		||||
    struct HudRegionData *hrd = ar->regiondata;
 | 
			
		||||
  ARegion *region = BKE_area_find_region_type(sa, RGN_TYPE_HUD);
 | 
			
		||||
  if (region != NULL) {
 | 
			
		||||
    struct HudRegionData *hrd = region->regiondata;
 | 
			
		||||
    if (hrd != NULL) {
 | 
			
		||||
      return last_redo_poll(C, hrd->regionid);
 | 
			
		||||
    }
 | 
			
		||||
@@ -156,76 +156,76 @@ static void hud_panels_register(ARegionType *art, int space_type, int region_typ
 | 
			
		||||
/** \name Callbacks for Floating Region
 | 
			
		||||
 * \{ */
 | 
			
		||||
 | 
			
		||||
static void hud_region_init(wmWindowManager *wm, ARegion *ar)
 | 
			
		||||
static void hud_region_init(wmWindowManager *wm, ARegion *region)
 | 
			
		||||
{
 | 
			
		||||
  ED_region_panels_init(wm, ar);
 | 
			
		||||
  UI_region_handlers_add(&ar->handlers);
 | 
			
		||||
  ar->flag |= RGN_FLAG_TEMP_REGIONDATA;
 | 
			
		||||
  ED_region_panels_init(wm, region);
 | 
			
		||||
  UI_region_handlers_add(®ion->handlers);
 | 
			
		||||
  region->flag |= RGN_FLAG_TEMP_REGIONDATA;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void hud_region_free(ARegion *ar)
 | 
			
		||||
static void hud_region_free(ARegion *region)
 | 
			
		||||
{
 | 
			
		||||
  MEM_SAFE_FREE(ar->regiondata);
 | 
			
		||||
  MEM_SAFE_FREE(region->regiondata);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void hud_region_layout(const bContext *C, ARegion *ar)
 | 
			
		||||
static void hud_region_layout(const bContext *C, ARegion *region)
 | 
			
		||||
{
 | 
			
		||||
  struct HudRegionData *hrd = ar->regiondata;
 | 
			
		||||
  struct HudRegionData *hrd = region->regiondata;
 | 
			
		||||
  if (hrd == NULL || !last_redo_poll(C, hrd->regionid)) {
 | 
			
		||||
    ED_region_tag_redraw(ar);
 | 
			
		||||
    hud_region_hide(ar);
 | 
			
		||||
    ED_region_tag_redraw(region);
 | 
			
		||||
    hud_region_hide(region);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int size_y = ar->sizey;
 | 
			
		||||
  int size_y = region->sizey;
 | 
			
		||||
 | 
			
		||||
  ED_region_panels_layout(C, ar);
 | 
			
		||||
  ED_region_panels_layout(C, region);
 | 
			
		||||
 | 
			
		||||
  if (ar->panels.first && (ar->sizey != size_y)) {
 | 
			
		||||
    int winx_new = UI_DPI_FAC * (ar->sizex + 0.5f);
 | 
			
		||||
    int winy_new = UI_DPI_FAC * (ar->sizey + 0.5f);
 | 
			
		||||
    View2D *v2d = &ar->v2d;
 | 
			
		||||
  if (region->panels.first && (region->sizey != size_y)) {
 | 
			
		||||
    int winx_new = UI_DPI_FAC * (region->sizex + 0.5f);
 | 
			
		||||
    int winy_new = UI_DPI_FAC * (region->sizey + 0.5f);
 | 
			
		||||
    View2D *v2d = ®ion->v2d;
 | 
			
		||||
 | 
			
		||||
    if (ar->flag & RGN_FLAG_SIZE_CLAMP_X) {
 | 
			
		||||
      CLAMP_MAX(winx_new, ar->winx);
 | 
			
		||||
    if (region->flag & RGN_FLAG_SIZE_CLAMP_X) {
 | 
			
		||||
      CLAMP_MAX(winx_new, region->winx);
 | 
			
		||||
    }
 | 
			
		||||
    if (ar->flag & RGN_FLAG_SIZE_CLAMP_Y) {
 | 
			
		||||
      CLAMP_MAX(winy_new, ar->winy);
 | 
			
		||||
    if (region->flag & RGN_FLAG_SIZE_CLAMP_Y) {
 | 
			
		||||
      CLAMP_MAX(winy_new, region->winy);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ar->winx = winx_new;
 | 
			
		||||
    ar->winy = winy_new;
 | 
			
		||||
    region->winx = winx_new;
 | 
			
		||||
    region->winy = winy_new;
 | 
			
		||||
 | 
			
		||||
    ar->winrct.xmax = (ar->winrct.xmin + ar->winx) - 1;
 | 
			
		||||
    ar->winrct.ymax = (ar->winrct.ymin + ar->winy) - 1;
 | 
			
		||||
    region->winrct.xmax = (region->winrct.xmin + region->winx) - 1;
 | 
			
		||||
    region->winrct.ymax = (region->winrct.ymin + region->winy) - 1;
 | 
			
		||||
 | 
			
		||||
    UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_PANELS_UI, ar->winx, ar->winy);
 | 
			
		||||
    UI_view2d_region_reinit(v2d, V2D_COMMONVIEW_PANELS_UI, region->winx, region->winy);
 | 
			
		||||
 | 
			
		||||
    /* Weak, but needed to avoid glitches, especially with hi-dpi
 | 
			
		||||
     * (where resizing the view glitches often).
 | 
			
		||||
     * Fortunately this only happens occasionally. */
 | 
			
		||||
    ED_region_panels_layout(C, ar);
 | 
			
		||||
    ED_region_panels_layout(C, region);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* restore view matrix */
 | 
			
		||||
  UI_view2d_view_restore(C);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void hud_region_draw(const bContext *C, ARegion *ar)
 | 
			
		||||
static void hud_region_draw(const bContext *C, ARegion *region)
 | 
			
		||||
{
 | 
			
		||||
  UI_view2d_view_ortho(&ar->v2d);
 | 
			
		||||
  wmOrtho2_region_pixelspace(ar);
 | 
			
		||||
  UI_view2d_view_ortho(®ion->v2d);
 | 
			
		||||
  wmOrtho2_region_pixelspace(region);
 | 
			
		||||
  GPU_clear_color(0, 0, 0, 0.0f);
 | 
			
		||||
  GPU_clear(GPU_COLOR_BIT);
 | 
			
		||||
 | 
			
		||||
  if ((ar->flag & RGN_FLAG_HIDDEN) == 0) {
 | 
			
		||||
  if ((region->flag & RGN_FLAG_HIDDEN) == 0) {
 | 
			
		||||
    ui_draw_menu_back(NULL,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      &(rcti){
 | 
			
		||||
                          .xmax = ar->winx,
 | 
			
		||||
                          .ymax = ar->winy,
 | 
			
		||||
                          .xmax = region->winx,
 | 
			
		||||
                          .ymax = region->winy,
 | 
			
		||||
                      });
 | 
			
		||||
    ED_region_panels_draw(C, ar);
 | 
			
		||||
    ED_region_panels_draw(C, region);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -252,28 +252,28 @@ ARegionType *ED_area_type_hud(int space_type)
 | 
			
		||||
 | 
			
		||||
static ARegion *hud_region_add(ScrArea *sa)
 | 
			
		||||
{
 | 
			
		||||
  ARegion *ar = MEM_callocN(sizeof(ARegion), "area region");
 | 
			
		||||
  ARegion *region = MEM_callocN(sizeof(ARegion), "area region");
 | 
			
		||||
  ARegion *ar_win = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
 | 
			
		||||
  if (ar_win) {
 | 
			
		||||
    BLI_insertlinkbefore(&sa->regionbase, ar_win, ar);
 | 
			
		||||
    BLI_insertlinkbefore(&sa->regionbase, ar_win, region);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    BLI_addtail(&sa->regionbase, ar);
 | 
			
		||||
    BLI_addtail(&sa->regionbase, region);
 | 
			
		||||
  }
 | 
			
		||||
  ar->regiontype = RGN_TYPE_HUD;
 | 
			
		||||
  ar->alignment = RGN_ALIGN_FLOAT;
 | 
			
		||||
  ar->overlap = true;
 | 
			
		||||
  ar->flag |= RGN_FLAG_DYNAMIC_SIZE;
 | 
			
		||||
  region->regiontype = RGN_TYPE_HUD;
 | 
			
		||||
  region->alignment = RGN_ALIGN_FLOAT;
 | 
			
		||||
  region->overlap = true;
 | 
			
		||||
  region->flag |= RGN_FLAG_DYNAMIC_SIZE;
 | 
			
		||||
 | 
			
		||||
  if (ar_win) {
 | 
			
		||||
    float x, y;
 | 
			
		||||
 | 
			
		||||
    UI_view2d_scroller_size_get(&ar_win->v2d, &x, &y);
 | 
			
		||||
    ar->runtime.offset_x = x;
 | 
			
		||||
    ar->runtime.offset_y = y;
 | 
			
		||||
    region->runtime.offset_x = x;
 | 
			
		||||
    region->runtime.offset_y = y;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return ar;
 | 
			
		||||
  return region;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ED_area_type_hud_clear(wmWindowManager *wm, ScrArea *sa_keep)
 | 
			
		||||
@@ -282,11 +282,11 @@ void ED_area_type_hud_clear(wmWindowManager *wm, ScrArea *sa_keep)
 | 
			
		||||
    bScreen *screen = WM_window_get_active_screen(win);
 | 
			
		||||
    for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 | 
			
		||||
      if (sa != sa_keep) {
 | 
			
		||||
        for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
 | 
			
		||||
          if (ar->regiontype == RGN_TYPE_HUD) {
 | 
			
		||||
            if ((ar->flag & RGN_FLAG_HIDDEN) == 0) {
 | 
			
		||||
              hud_region_hide(ar);
 | 
			
		||||
              ED_region_tag_redraw(ar);
 | 
			
		||||
        for (ARegion *region = sa->regionbase.first; region; region = region->next) {
 | 
			
		||||
          if (region->regiontype == RGN_TYPE_HUD) {
 | 
			
		||||
            if ((region->flag & RGN_FLAG_HIDDEN) == 0) {
 | 
			
		||||
              hud_region_hide(region);
 | 
			
		||||
              ED_region_tag_redraw(region);
 | 
			
		||||
              ED_area_tag_redraw(sa);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
@@ -306,49 +306,49 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *sa)
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HUD);
 | 
			
		||||
  ARegion *region = BKE_area_find_region_type(sa, RGN_TYPE_HUD);
 | 
			
		||||
 | 
			
		||||
  if (ar && (ar->flag & RGN_FLAG_HIDDEN_BY_USER)) {
 | 
			
		||||
  if (region && (region->flag & RGN_FLAG_HIDDEN_BY_USER)) {
 | 
			
		||||
    /* The region is intentionally hidden by the user, don't show it. */
 | 
			
		||||
    hud_region_hide(ar);
 | 
			
		||||
    hud_region_hide(region);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool init = false;
 | 
			
		||||
  bool was_hidden = ar == NULL || ar->visible == false;
 | 
			
		||||
  bool was_hidden = region == NULL || region->visible == false;
 | 
			
		||||
  ARegion *ar_op = CTX_wm_region(C);
 | 
			
		||||
  BLI_assert((ar_op == NULL) || (ar_op->regiontype != RGN_TYPE_HUD));
 | 
			
		||||
  if (!last_redo_poll(C, ar_op ? ar_op->regiontype : -1)) {
 | 
			
		||||
    if (ar) {
 | 
			
		||||
      ED_region_tag_redraw(ar);
 | 
			
		||||
      hud_region_hide(ar);
 | 
			
		||||
    if (region) {
 | 
			
		||||
      ED_region_tag_redraw(region);
 | 
			
		||||
      hud_region_hide(region);
 | 
			
		||||
    }
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (ar == NULL) {
 | 
			
		||||
  if (region == NULL) {
 | 
			
		||||
    init = true;
 | 
			
		||||
    ar = hud_region_add(sa);
 | 
			
		||||
    ar->type = art;
 | 
			
		||||
    region = hud_region_add(sa);
 | 
			
		||||
    region->type = art;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /* Let 'ED_area_update_region_sizes' do the work of placing the region.
 | 
			
		||||
   * Otherwise we could set the 'ar->winrct' & 'ar->winx/winy' here. */
 | 
			
		||||
   * Otherwise we could set the 'region->winrct' & 'region->winx/winy' here. */
 | 
			
		||||
  if (init) {
 | 
			
		||||
    sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    if (ar->flag & RGN_FLAG_HIDDEN) {
 | 
			
		||||
    if (region->flag & RGN_FLAG_HIDDEN) {
 | 
			
		||||
      sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
 | 
			
		||||
    }
 | 
			
		||||
    ar->flag &= ~RGN_FLAG_HIDDEN;
 | 
			
		||||
    region->flag &= ~RGN_FLAG_HIDDEN;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    struct HudRegionData *hrd = ar->regiondata;
 | 
			
		||||
    struct HudRegionData *hrd = region->regiondata;
 | 
			
		||||
    if (hrd == NULL) {
 | 
			
		||||
      hrd = MEM_callocN(sizeof(*hrd), __func__);
 | 
			
		||||
      ar->regiondata = hrd;
 | 
			
		||||
      region->regiondata = hrd;
 | 
			
		||||
    }
 | 
			
		||||
    if (ar_op) {
 | 
			
		||||
      hrd->regionid = ar_op->regiontype;
 | 
			
		||||
@@ -364,37 +364,37 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *sa)
 | 
			
		||||
    ED_area_update_region_sizes(wm, win, sa);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ED_region_floating_initialize(ar);
 | 
			
		||||
  ED_region_tag_redraw(ar);
 | 
			
		||||
  ED_region_floating_initialize(region);
 | 
			
		||||
  ED_region_tag_redraw(region);
 | 
			
		||||
 | 
			
		||||
  /* Reset zoom level (not well supported). */
 | 
			
		||||
  ar->v2d.cur = ar->v2d.tot = (rctf){
 | 
			
		||||
      .xmax = ar->winx,
 | 
			
		||||
      .ymax = ar->winy,
 | 
			
		||||
  region->v2d.cur = region->v2d.tot = (rctf){
 | 
			
		||||
      .xmax = region->winx,
 | 
			
		||||
      .ymax = region->winy,
 | 
			
		||||
  };
 | 
			
		||||
  ar->v2d.minzoom = 1.0f;
 | 
			
		||||
  ar->v2d.maxzoom = 1.0f;
 | 
			
		||||
  region->v2d.minzoom = 1.0f;
 | 
			
		||||
  region->v2d.maxzoom = 1.0f;
 | 
			
		||||
 | 
			
		||||
  ar->visible = !(ar->flag & RGN_FLAG_HIDDEN);
 | 
			
		||||
  region->visible = !(region->flag & RGN_FLAG_HIDDEN);
 | 
			
		||||
 | 
			
		||||
  /* We shouldn't need to do this every time :S */
 | 
			
		||||
  /* XXX, this is evil! - it also makes the menu show on first draw. :( */
 | 
			
		||||
  if (ar->visible) {
 | 
			
		||||
  if (region->visible) {
 | 
			
		||||
    ARegion *ar_prev = CTX_wm_region(C);
 | 
			
		||||
    CTX_wm_region_set((bContext *)C, ar);
 | 
			
		||||
    hud_region_layout(C, ar);
 | 
			
		||||
    CTX_wm_region_set((bContext *)C, region);
 | 
			
		||||
    hud_region_layout(C, region);
 | 
			
		||||
    if (was_hidden) {
 | 
			
		||||
      ar->winx = ar->v2d.winx;
 | 
			
		||||
      ar->winy = ar->v2d.winy;
 | 
			
		||||
      ar->v2d.cur = ar->v2d.tot = (rctf){
 | 
			
		||||
          .xmax = ar->winx,
 | 
			
		||||
          .ymax = ar->winy,
 | 
			
		||||
      region->winx = region->v2d.winx;
 | 
			
		||||
      region->winy = region->v2d.winy;
 | 
			
		||||
      region->v2d.cur = region->v2d.tot = (rctf){
 | 
			
		||||
          .xmax = region->winx,
 | 
			
		||||
          .ymax = region->winy,
 | 
			
		||||
      };
 | 
			
		||||
    }
 | 
			
		||||
    CTX_wm_region_set((bContext *)C, ar_prev);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ar->visible = !((ar->flag & RGN_FLAG_HIDDEN) || (ar->flag & RGN_FLAG_TOO_SMALL));
 | 
			
		||||
  region->visible = !((region->flag & RGN_FLAG_HIDDEN) || (region->flag & RGN_FLAG_TOO_SMALL));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** \} */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user