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@gmail.com>2018-04-29 13:24:08 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-04-29 23:11:12 +0300
commit7a9f64e6657a231289f56b0a8c9949c8f7a23c59 (patch)
treeefee3c4ac1988ad96d743f1d82e7a677096ca0c3 /source/blender/editors/screen
parent0c512a6f951e36e29d2f6865cc975f7e40c4d31d (diff)
UI: better support for dynamically sized regions in topbar.
Dynamically sized regions in the topbar were flickering due to only updating their size after redraws. Now there is an optional layout() callback for all regions in an area to do UI layout first, then refresh the region layout, and then do the actual drawing for each region. Task T54753
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r--source/blender/editors/screen/area.c107
-rw-r--r--source/blender/editors/screen/screen_edit.c33
2 files changed, 77 insertions, 63 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 6e45b184478..5e68ad1218d 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -501,6 +501,27 @@ void ED_area_do_msg_notify_tag_refresh(
}
/* only exported for WM */
+void ED_region_do_layout(bContext *C, ARegion *ar)
+{
+ /* This is optional, only needed for dynamically sized regions. */
+ ScrArea *sa = CTX_wm_area(C);
+ ARegionType *at = ar->type;
+
+ if (!at->layout) {
+ return;
+ }
+
+ if (at->do_lock) {
+ return;
+ }
+
+ ar->do_draw |= RGN_DRAWING;
+
+ UI_SetTheme(sa ? sa->spacetype : 0, at->regionid);
+ at->layout(C, ar);
+}
+
+/* only exported for WM */
void ED_region_do_draw(bContext *C, ARegion *ar)
{
wmWindow *win = CTX_wm_window(C);
@@ -1187,9 +1208,8 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
alignment = RGN_ALIGN_NONE;
- /* prefsize, for header we stick to exception (prevent dpi rounding error) */
- const float sizex_dpi_fac = (ar->flag & RGN_SIZEX_DPI_APPLIED) ? 1.0f : UI_DPI_FAC;
- prefsizex = sizex_dpi_fac * ((ar->sizex > 1) ? ar->sizex + 0.5f : ar->type->prefsizex);
+ /* prefsize, taking into account DPI */
+ prefsizex = UI_DPI_FAC * ((ar->sizex > 1) ? ar->sizex + 0.5f : ar->type->prefsizex);
if (ar->regiontype == RGN_TYPE_HEADER) {
prefsizey = ED_area_headersize();
@@ -1514,8 +1534,12 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
}
}
-void screen_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
+void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
{
+ if (!(area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
+ return;
+ }
+
const int size_x = WM_window_pixels_x(win);
const int size_y = WM_window_pixels_y(win);
rcti rect;
@@ -1898,6 +1922,23 @@ static ThemeColorID region_background_color_id(const bContext *C, const ARegion
}
}
+static void region_clear_color(const bContext *C, const ARegion *ar, ThemeColorID colorid)
+{
+ if (ar->overlap) {
+ /* view should be in pixelspace */
+ UI_view2d_view_restore(C);
+
+ float back[4];
+ UI_GetThemeColor4fv(colorid, back);
+ glClearColor(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+ else {
+ UI_ThemeClearColor(colorid);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+}
+
void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int contextnr, const bool vertical)
{
const WorkSpace *workspace = CTX_wm_workspace(C);
@@ -2124,20 +2165,7 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
}
}
- /* clear */
- if (ar->overlap) {
- /* view should be in pixelspace */
- UI_view2d_view_restore(C);
-
- float back[4];
- UI_GetThemeColor4fv((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK, back);
- glClearColor(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
- glClear(GL_COLOR_BUFFER_BIT);
- }
- else {
- UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
- glClear(GL_COLOR_BUFFER_BIT);
- }
+ region_clear_color(C, ar, (ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
/* reset line width for drawing tabs */
glLineWidth(1.0f);
@@ -2171,7 +2199,7 @@ void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
WM_event_add_keymap_handler(&ar->handlers, keymap);
}
-void ED_region_header(const bContext *C, ARegion *ar)
+void ED_region_header_layout(const bContext *C, ARegion *ar)
{
uiStyle *style = UI_style_get_dpi();
uiBlock *block;
@@ -2183,10 +2211,6 @@ void ED_region_header(const bContext *C, ARegion *ar)
const int start_ofs = 0.4f * UI_UNIT_X;
bool region_layout_based = ar->flag & RGN_FLAG_DYNAMIC_SIZE;
- /* clear */
- UI_ThemeClearColor(region_background_color_id(C, ar));
- glClear(GL_COLOR_BUFFER_BIT);
-
/* set view2d view matrix for scrolling (without scrollers) */
UI_view2d_view_ortho(&ar->v2d);
@@ -2221,27 +2245,50 @@ void ED_region_header(const bContext *C, ARegion *ar)
if (xco > maxco)
maxco = xco;
- if (region_layout_based && (ar->sizex != (maxco + start_ofs))) {
+ int new_sizex = (maxco + start_ofs) / UI_DPI_FAC;
+
+ if (region_layout_based && (ar->sizex != new_sizex)) {
/* region size is layout based and needs to be updated */
ScrArea *sa = CTX_wm_area(C);
- ar->sizex = maxco + start_ofs;
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->sizex, ar->winy);
-
+ ar->sizex = new_sizex;
sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
- ar->flag |= RGN_SIZEX_DPI_APPLIED;
}
+
UI_block_end(C, block);
- UI_block_draw(C, block);
}
/* always as last */
UI_view2d_totRect_set(&ar->v2d, maxco + (region_layout_based ? 0 : UI_UNIT_X + 80), headery);
- /* restore view matrix? */
+ /* restore view matrix */
+ UI_view2d_view_restore(C);
+}
+
+void ED_region_header_draw(const bContext *C, ARegion *ar)
+{
+ UI_view2d_view_ortho(&ar->v2d);
+
+ /* clear */
+ region_clear_color(C, ar, region_background_color_id(C, ar));
+
+ /* View2D matrix might have changed due to dynamic sized regions. */
+ UI_blocklist_update_window_matrix(C, &ar->uiblocks);
+
+ /* draw blocks */
+ UI_blocklist_draw(C, &ar->uiblocks);
+
+ /* restore view matrix */
UI_view2d_view_restore(C);
}
+void ED_region_header(const bContext *C, ARegion *ar)
+{
+ /* TODO: remove? */
+ ED_region_header_layout(C, ar);
+ ED_region_header_draw(C, ar);
+}
+
void ED_region_header_init(ARegion *ar)
{
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index c7d1605cbbf..1cadefadd5c 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -835,36 +835,6 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
screen->context = ed_screen_context;
}
-static bool screen_regions_need_size_refresh(
- const wmWindow *win, const bScreen *screen)
-{
- ED_screen_areas_iter(win, screen, area) {
- if (area->flag & AREA_FLAG_REGION_SIZE_UPDATE) {
- return true;
- }
- }
-
- return false;
-}
-
-static void screen_refresh_region_sizes_only(
- wmWindowManager *wm, wmWindow *win,
- bScreen *screen)
-{
- const int window_size_x = WM_window_pixels_x(win);
- const int window_size_y = WM_window_pixels_y(win);
- const int screen_size_x = WM_window_screen_pixels_x(win);
- const int screen_size_y = WM_window_screen_pixels_y(win);
-
- screen_vertices_scale(win, screen, window_size_x, window_size_y, screen_size_x, screen_size_y);
-
- ED_screen_areas_iter(win, screen, area) {
- screen_area_update_region_sizes(wm, win, area);
- /* XXX hack to force drawing */
- ED_area_tag_redraw(area);
- }
-}
-
/* file read, set all screens, ... */
void ED_screens_initialize(wmWindowManager *wm)
{
@@ -887,9 +857,6 @@ void ED_screen_ensure_updated(wmWindowManager *wm, wmWindow *win, bScreen *scree
if (screen->do_refresh) {
ED_screen_refresh(wm, win);
}
- else if (screen_regions_need_size_refresh(win, screen)) {
- screen_refresh_region_sizes_only(wm, win, screen);
- }
}