Code cleanup: remove WM subwindows.

These no longer made much sense after regions were added, they just
duplicated state that was already in the regions.
This commit is contained in:
Brecht Van Lommel 2018-02-16 22:41:46 +01:00
parent cbd0e09898
commit 5d3f679013
Notes: blender-bot 2023-02-14 10:11:49 +01:00
Referenced by issue #54322, Partial redraw broken origin.
25 changed files with 187 additions and 544 deletions

View File

@ -182,7 +182,7 @@ ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
BLI_listbase_clear(&newar->panels_category);
BLI_listbase_clear(&newar->panels_category_active);
BLI_listbase_clear(&newar->ui_lists);
newar->swinid = 0;
newar->visible = 0;
newar->manipulator_map = NULL;
newar->regiontimer = NULL;
newar->headerstr = NULL;

View File

@ -6505,7 +6505,6 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
BLI_listbase_clear(&win->queue);
BLI_listbase_clear(&win->handlers);
BLI_listbase_clear(&win->modalhandlers);
BLI_listbase_clear(&win->subwindows);
BLI_listbase_clear(&win->gesture);
BLI_listbase_clear(&win->drawdata);
@ -7307,7 +7306,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
BLI_listbase_clear(&ar->handlers);
BLI_listbase_clear(&ar->uiblocks);
ar->headerstr = NULL;
ar->swinid = 0;
ar->visible = 0;
ar->type = NULL;
ar->swap = 0;
ar->do_draw = 0;
@ -7354,8 +7353,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
link_list(fd, &(sc->areabase));
sc->regionbase.first = sc->regionbase.last= NULL;
sc->context = NULL;
sc->mainwin = sc->subwinactive= 0; /* indices */
sc->active_region = NULL;
sc->swap = 0;
sc->preview = direct_link_preview_image(fd, sc->preview);

View File

@ -134,7 +134,7 @@ void ED_screen_update_after_scene_change(
const struct bScreen *screen,
struct Scene *scene_new,
struct ViewLayer *view_layer);
void ED_screen_set_subwinactive(struct bContext *C, const struct wmEvent *event);
void ED_screen_set_active_region(struct bContext *C, const struct wmEvent *event);
void ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
void ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable);
void ED_screen_animation_timer_update(struct bScreen *screen, int redraws, int refresh);

View File

@ -69,7 +69,6 @@
#include "WM_api.h"
#include "WM_types.h"
#include "wm_subwindow.h"
#include "WM_message.h"
#include "RNA_access.h"
@ -2853,7 +2852,6 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh
uiBlock *block;
wmWindow *window;
Scene *scn;
int getsizex, getsizey;
window = CTX_wm_window(C);
scn = CTX_data_scene(C);
@ -2884,22 +2882,22 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh
UI_block_region_set(block, region);
/* window matrix and aspect */
if (region && region->swinid) {
wm_subwindow_matrix_get(window, region->swinid, block->winmat);
wm_subwindow_size_get(window, region->swinid, &getsizex, &getsizey);
if (region && region->visible) {
gpuGetProjectionMatrix(block->winmat);
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
block->aspect = 2.0f / fabsf(region->winx * block->winmat[0][0]);
}
else {
const bScreen *screen = WM_window_get_active_screen(window);
/* no subwindow created yet, for menus for example, so we
* use the main window instead, since buttons are created
* there anyway */
wm_subwindow_matrix_get(window, screen->mainwin, block->winmat);
wm_subwindow_size_get(window, screen->mainwin, &getsizex, &getsizey);
int width = WM_window_pixels_x(window);
int height = WM_window_pixels_y(window);
rcti winrct = {0, width -1, 0, height - 1};
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
wmGetProjectionMatrix(block->winmat, &winrct);
block->aspect = 2.0f / fabsf(width * block->winmat[0][0]);
block->auto_open = true;
block->flag |= UI_BLOCK_LOOP; /* tag as menu */
}

View File

@ -48,7 +48,6 @@
#include "WM_api.h"
#include "WM_types.h"
#include "wm_subwindow.h"
#include "UI_interface.h"
@ -589,9 +588,7 @@ uiBlock *ui_popup_block_refresh(
ED_region_init(C, ar);
/* get winmat now that we actually have the subwindow */
wmSubWindowSet(window, ar->swinid);
wm_subwindow_matrix_get(window, ar->swinid, block->winmat);
wmGetProjectionMatrix(block->winmat, &ar->winrct);
/* notify change and redraw */
ED_region_tag_redraw(ar);

View File

@ -52,7 +52,6 @@
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
#include "wm_subwindow.h"
#include "ED_screen.h"
#include "ED_screen_types.h"
@ -529,27 +528,15 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
wmWindow *win = CTX_wm_window(C);
ScrArea *sa = CTX_wm_area(C);
ARegionType *at = ar->type;
bool scissor_pad;
/* see BKE_spacedata_draw_locks() */
if (at->do_lock)
return;
/* if no partial draw rect set, full rect */
if (ar->drawrct.xmin == ar->drawrct.xmax) {
ar->drawrct = ar->winrct;
scissor_pad = true;
}
else {
/* extra clip for safety */
BLI_rcti_isect(&ar->winrct, &ar->drawrct, &ar->drawrct);
scissor_pad = false;
}
ar->do_draw |= RGN_DRAWING;
/* note; this sets state, so we can use wmOrtho and friends */
wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, scissor_pad);
/* Set viewport, scissor, ortho and ar->drawrct. */
wmPartialViewport(&ar->drawrct, &ar->winrct, &ar->drawrct);
wmOrtho2_region_pixelspace(ar);
@ -1436,24 +1423,14 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
/* used for area initialize below */
static void region_subwindow(wmWindow *win, ARegion *ar, bool activate)
static void region_subwindow(ARegion *ar)
{
bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev)
hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
if (hidden) {
if (ar->swinid)
wm_subwindow_close(win, ar->swinid);
ar->swinid = 0;
}
else if (ar->swinid == 0) {
ar->swinid = wm_subwindow_open(win, &ar->winrct, activate);
}
else {
wm_subwindow_position(win, ar->swinid, &ar->winrct, activate);
}
ar->visible = !hidden;
}
static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
@ -1560,9 +1537,9 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
/* region windows, default and own handlers */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
region_subwindow(win, ar, false);
region_subwindow(ar);
if (ar->swinid) {
if (ar->visible) {
/* default region handlers */
ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
/* own handlers */
@ -1589,22 +1566,16 @@ static void region_update_rect(ARegion *ar)
/**
* Call to move a popup window (keep OpenGL context free!)
*/
void ED_region_update_rect(bContext *C, ARegion *ar)
void ED_region_update_rect(bContext *UNUSED(C), ARegion *ar)
{
wmWindow *win = CTX_wm_window(C);
wm_subwindow_rect_set(win, ar->swinid, &ar->winrct);
region_update_rect(ar);
}
/* externally called for floating regions like menus */
void ED_region_init(bContext *C, ARegion *ar)
void ED_region_init(bContext *UNUSED(C), ARegion *ar)
{
// ARegionType *at = ar->type;
/* refresh can be called before window opened */
region_subwindow(CTX_wm_window(C), ar, false);
region_subwindow(ar);
region_update_rect(ar);
}

View File

@ -298,7 +298,7 @@ void ED_screen_draw_edges(wmWindow *win)
ScrArea *sa;
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);

View File

@ -68,9 +68,6 @@
#include "WM_message.h"
/* XXX actually should be not here... solve later */
#include "wm_subwindow.h"
#include "screen_intern.h" /* own module include */
@ -848,14 +845,14 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
/* ****************** EXPORTED API TO OTHER MODULES *************************** */
/* screen sets cursor based on swinid */
static void region_cursor_set(wmWindow *win, int swinid, int swin_changed)
/* screen sets cursor based on active region */
static void region_cursor_set(wmWindow *win, bool swin_changed)
{
bScreen *screen = WM_window_get_active_screen(win);
for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid == swinid) {
if (ar == screen->active_region) {
if (swin_changed || (ar->type && ar->type->event_cursor)) {
if (ar->manipulator_map != NULL) {
if (WM_manipulatormap_cursor_set(ar->manipulator_map, win)) {
@ -890,7 +887,7 @@ void ED_screen_do_listen(bContext *C, wmNotifier *note)
break;
case NC_SCENE:
if (note->data == ND_MODE)
region_cursor_set(win, note->swinid, true);
region_cursor_set(win, true);
break;
}
}
@ -918,12 +915,6 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
ScrArea *sa;
rcti winrct;
winrct.xmin = 0;
winrct.xmax = winsize_x - 1;
winrct.ymin = 0;
winrct.ymax = winsize_y - 1;
/* header size depends on DPI, let's verify */
WM_window_set_dpi(win);
@ -931,13 +922,6 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
screen_test_scale(screen, winsize_x, winsize_y);
if (screen->mainwin == 0) {
screen->mainwin = wm_subwindow_open(win, &winrct, false);
}
else {
wm_subwindow_position(win, screen->mainwin, &winrct, false);
}
for (sa = screen->areabase.first; sa; sa = sa->next) {
/* set spacetype and region callbacks, calls init() */
/* sets subwindows for regions, adds handlers */
@ -989,10 +973,7 @@ void ED_region_exit(bContext *C, ARegion *ar)
WM_event_remove_handlers(C, &ar->handlers);
WM_event_modal_handler_region_replace(win, ar, NULL);
if (ar->swinid) {
wm_subwindow_close(win, ar->swinid);
ar->swinid = 0;
}
ar->visible = 0;
if (ar->headerstr) {
MEM_freeN(ar->headerstr);
@ -1044,10 +1025,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
screen->animtimer = NULL;
screen->scrubbing = false;
if (screen->mainwin)
wm_subwindow_close(window, screen->mainwin);
screen->mainwin = 0;
screen->subwinactive = 0;
screen->active_region = NULL;
for (ar = screen->regionbase.first; ar; ar = ar->next)
ED_region_exit(C, ar);
@ -1112,7 +1090,7 @@ static void screen_cursor_set(wmWindow *win, const wmEvent *event)
/* called in wm_event_system.c. sets state vars in screen, cursors */
/* event type is mouse move */
void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
void ED_screen_set_active_region(bContext *C, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
bScreen *scr = WM_window_get_active_screen(win);
@ -1120,7 +1098,7 @@ void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
if (scr) {
ScrArea *sa;
ARegion *ar;
int oldswin = scr->subwinactive;
ARegion *old_ar = scr->active_region;
for (sa = scr->areabase.first; sa; sa = sa->next) {
if (event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
@ -1132,22 +1110,22 @@ void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
/* make overlap active when mouse over */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
scr->subwinactive = ar->swinid;
scr->active_region = ar;
break;
}
}
}
else
scr->subwinactive = scr->mainwin;
scr->active_region = NULL;
/* check for redraw headers */
if (oldswin != scr->subwinactive) {
if (old_ar != scr->active_region) {
for (sa = scr->areabase.first; sa; sa = sa->next) {
bool do_draw = false;
for (ar = sa->regionbase.first; ar; ar = ar->next)
if (ar->swinid == oldswin || ar->swinid == scr->subwinactive)
if (ar == old_ar || ar == scr->active_region)
do_draw = true;
if (do_draw) {
@ -1159,13 +1137,13 @@ void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
}
/* cursors, for time being set always on edges, otherwise aregion doesnt switch */
if (scr->subwinactive == scr->mainwin) {
if (scr->active_region == NULL) {
screen_cursor_set(win, event);
}
else {
/* notifier invokes freeing the buttons... causing a bit too much redraws */
if (oldswin != scr->subwinactive) {
region_cursor_set(win, scr->subwinactive, true);
if (old_ar != scr->active_region) {
region_cursor_set(win, true);
/* this used to be a notifier, but needs to be done immediate
* because it can undo setting the right button as active due
@ -1173,7 +1151,7 @@ void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
UI_screen_free_active_but(C, scr);
}
else
region_cursor_set(win, scr->subwinactive, false);
region_cursor_set(win, false);
}
}
}
@ -1192,7 +1170,7 @@ int ED_screen_area_active(const bContext *C)
return 1;
for (ar = sa->regionbase.first; ar; ar = ar->next)
if (ar->swinid == sc->subwinactive)
if (ar == sc->active_region)
return 1;
}
return 0;

View File

@ -138,7 +138,7 @@ int ED_operator_screen_mainwinactive(bContext *C)
if (CTX_wm_window(C) == NULL) return 0;
screen = CTX_wm_screen(C);
if (screen == NULL) return 0;
if (screen->subwinactive != screen->mainwin) return 0;
if (screen->active_region != NULL) return 0;
return 1;
}

View File

@ -133,9 +133,6 @@ static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent
ReportList *reports = CTX_wm_reports(C);
Report *report;
/* uses opengl */
wmSubWindowSet(CTX_wm_window(C), ar->swinid);
report = info_text_pick(sinfo, ar, reports, event->mval[1]);
RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));

View File

@ -161,7 +161,7 @@ void view3d_operator_needs_opengl(const bContext *C)
view3d_region_operator_needs_opengl(win, ar);
}
void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar)
void view3d_region_operator_needs_opengl(wmWindow *UNUSED(win), ARegion *ar)
{
/* for debugging purpose, context should always be OK */
if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) {
@ -170,7 +170,7 @@ void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar)
else {
RegionView3D *rv3d = ar->regiondata;
wmSubWindowSet(win, ar->swinid);
wmViewport(&ar->winrct); // TODO: bad
gpuLoadProjectionMatrix(rv3d->winmat);
gpuLoadMatrix(rv3d->viewmat);
}

View File

@ -71,10 +71,9 @@ typedef struct bScreen {
char swap; /* indicator to survive swap-exchange systems */
char skip_handling; /* set to delay screen handling after switching back from maximized area */
char scrubbing; /* set when scrubbing to avoid some costly updates */
char pad[6];
char pad[2];
short mainwin; /* screensize subwindow, for screenedges and global menus */
short subwinactive; /* active subwindow */
struct ARegion *active_region; /* active region that has mouse focus */
struct wmTimer *animtimer; /* if set, screen has timer handler added in window */
void *context; /* context callback */
@ -254,7 +253,7 @@ typedef struct ARegion {
rcti drawrct; /* runtime for partial redraw, same or smaller than winrct */
short winx, winy; /* size */
short swinid;
short visible; /* region is currently visible on screen */
short regiontype; /* window, header, etc. identifier for drawing */
short alignment; /* how it should split */
short flag; /* hide, ... */

View File

@ -220,7 +220,6 @@ typedef struct wmWindow {
ListBase handlers; /* window+screen handlers, handled last */
ListBase modalhandlers; /* priority handlers, handled first */
ListBase subwindows; /* opengl stuff for sub windows, see notes in wm_subwindow.c */
ListBase gesture; /* gesture stuff */
struct Stereo3dFormat *stereo3d_format; /* properties for stereoscopic displays */

View File

@ -333,11 +333,6 @@ static void rna_def_region(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Region", "Region in a subdivided screen area");
RNA_def_struct_sdna(srna, "ARegion");
prop = RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "swinid");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Region ID", "Unique ID for this region");
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "regiontype");
RNA_def_property_enum_items(prop, rna_enum_region_type_items);

View File

@ -93,7 +93,6 @@ set(SRC
wm_event_system.h
wm_event_types.h
wm_files.h
wm_subwindow.h
wm_window.h
manipulators/WM_manipulator_api.h
manipulators/WM_manipulator_types.h

View File

@ -457,15 +457,17 @@ struct wmDropBox *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(s
void (*copy)(struct wmDrag *, struct wmDropBox *));
ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
/* Set a subwindow active in pixelspace view, with optional scissor subset */
void wmSubWindowSet (struct wmWindow *win, int swinid);
void wmSubWindowScissorSet (struct wmWindow *win, int swinid, const struct rcti *srct, bool srct_pad);
/* Set OpenGL viewport and scissor */
void wmViewport(const struct rcti *rect);
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct);
void wmWindowViewport(struct wmWindow *win);
/* OpenGL utilities with safety check */
void wmOrtho2 (float x1, float x2, float y1, float y2);
/* use for conventions (avoid hard-coded offsets all over) */
void wmOrtho2_region_pixelspace(const struct ARegion *ar);
void wmOrtho2_pixelspace(const float x, const float y);
void wmGetProjectionMatrix(float mat[4][4], const struct rcti *winrct);
/* threaded Jobs Manager */
enum {

View File

@ -115,6 +115,7 @@ struct ImBuf;
#include "RNA_types.h"
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
#include "BLI_compiler_attrs.h"
/* exported types for WM */
@ -214,7 +215,6 @@ typedef struct wmNotifier {
struct wmWindowManager *wm;
struct wmWindow *window;
int swinid; /* can't rely on this, notifiers can be added without context, swinid of 0 */
unsigned int category, data, subtype, action;
void *reference;
@ -422,7 +422,7 @@ typedef struct wmGesture {
struct wmGesture *next, *prev;
int event_type; /* event->type */
int type; /* gesture type define */
int swinid; /* initial subwindow id where it started */
rcti winrct; /* bounds of region to draw gesture within */
int points; /* optional, amount of points stored */
int points_alloc; /* optional, maximum amount of points stored */
int modal_state;

View File

@ -95,7 +95,7 @@ static void wm_paintcursor_draw(bContext *C, ARegion *ar)
bScreen *screen = WM_window_get_active_screen(win);
wmPaintCursor *pc;
if (ar->swinid && screen->subwinactive == ar->swinid) {
if (ar->visible && ar == screen->active_region) {
for (pc = wm->paintcursors.first; pc; pc = pc->next) {
if (pc->poll == NULL || pc->poll(C)) {
ARegion *ar_other = CTX_wm_region(C);
@ -216,7 +216,7 @@ static void wm_method_draw_full(bContext *C, wmWindow *win)
CTX_wm_area_set(C, sa);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid) {
if (ar->visible) {
CTX_wm_region_set(C, ar);
ED_region_do_draw(C, ar);
ar->do_draw = false;
@ -235,7 +235,7 @@ static void wm_method_draw_full(bContext *C, wmWindow *win)
/* draw overlapping regions */
for (ar = screen->regionbase.first; ar; ar = ar->next) {
if (ar->swinid) {
if (ar->visible) {
CTX_wm_menu_set(C, ar);
ED_region_do_draw(C, ar);
ar->do_draw = false;
@ -295,7 +295,7 @@ static void wm_method_draw_overlap_all(bContext *C, wmWindow *win, int exchange)
/* after backbuffer selection draw, we need to redraw */
for (sa = screen->areabase.first; sa; sa = sa->next)
for (ar = sa->regionbase.first; ar; ar = ar->next)
if (ar->swinid && !wm_area_test_invalid_backbuf(sa))
if (ar->visible && !wm_area_test_invalid_backbuf(sa))
ED_region_tag_redraw(ar);
/* flush overlapping regions */
@ -303,17 +303,17 @@ static void wm_method_draw_overlap_all(bContext *C, wmWindow *win, int exchange)
/* flush redraws of area regions up to overlapping regions */
for (sa = screen->areabase.first; sa; sa = sa->next)
for (ar = sa->regionbase.first; ar; ar = ar->next)
if (ar->swinid && ar->do_draw)
if (ar->visible && ar->do_draw)
wm_flush_regions_up(screen, &ar->winrct);
/* flush between overlapping regions */
for (ar = screen->regionbase.last; ar; ar = ar->prev)
if (ar->swinid && ar->do_draw)
if (ar->visible && ar->do_draw)
wm_flush_regions_up(screen, &ar->winrct);
/* flush redraws of overlapping regions down to area regions */
for (ar = screen->regionbase.last; ar; ar = ar->prev)
if (ar->swinid && ar->do_draw)
if (ar->visible && ar->do_draw)
wm_flush_regions_down(screen, &ar->winrct);
}
@ -332,7 +332,7 @@ static void wm_method_draw_overlap_all(bContext *C, wmWindow *win, int exchange)
CTX_wm_area_set(C, sa);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid) {
if (ar->visible) {
if (ar->do_draw) {
CTX_wm_region_set(C, ar);
ED_region_do_draw(C, ar);
@ -389,7 +389,7 @@ static void wm_method_draw_overlap_all(bContext *C, wmWindow *win, int exchange)
/* draw marked overlapping regions */
for (ar = screen->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->do_draw) {
if (ar->visible && ar->do_draw) {
CTX_wm_menu_set(C, ar);
ED_region_do_draw(C, ar);
ar->do_draw = false;
@ -526,9 +526,7 @@ static void wm_draw_region_blend(wmWindow *win, ARegion *ar, wmDrawTriple *tripl
/* region blend always is 1, except when blend timer is running */
if (fac < 1.0f) {
bScreen *screen = WM_window_get_active_screen(win);
wmSubWindowScissorSet(win, screen->mainwin, &ar->winrct, true);
wmViewport(&ar->winrct);
glEnable(GL_BLEND);
wm_triple_draw_textures(win, triple, 1.0f - fac);
@ -551,7 +549,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
wm_triple_draw_textures(win, drawdata->triple, 1.0f);
}
@ -587,7 +585,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
CTX_wm_area_set(C, sa);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->do_draw) {
if (ar->visible && ar->do_draw) {
if (ar->overlap == false) {
CTX_wm_region_set(C, ar);
ED_region_do_draw(C, ar);
@ -603,7 +601,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
}
if (copytex) {
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
wm_triple_copy_textures(win, triple);
}
@ -611,12 +609,12 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
if (wm->paintcursors.first) {
for (sa = screen->areabase.first; sa; sa = sa->next) {
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->swinid == screen->subwinactive) {
if (ar->visible && ar == screen->active_region) {
CTX_wm_area_set(C, sa);
CTX_wm_region_set(C, ar);
/* make region ready for draw, scissor, pixelspace */
wmSubWindowScissorSet(win, ar->swinid, &ar->winrct, true);
wmViewport(&ar->winrct);
wm_paintcursor_draw(C, ar);
CTX_wm_region_set(C, NULL);
@ -625,7 +623,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
}
}
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
}
/* draw overlapping area regions (always like popups) */
@ -633,7 +631,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
CTX_wm_area_set(C, sa);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->overlap) {
if (ar->visible && ar->overlap) {
CTX_wm_region_set(C, ar);
ED_region_do_draw(C, ar);
ar->do_draw = false;
@ -653,7 +651,7 @@ static void wm_method_draw_triple(bContext *C, wmWindow *win)
/* draw floating regions (menus) */
for (ar = screen->regionbase.first; ar; ar = ar->next) {
if (ar->swinid) {
if (ar->visible) {
CTX_wm_menu_set(C, ar);
ED_region_do_draw(C, ar);
ar->do_draw = false;
@ -693,7 +691,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
wm_triple_draw_textures(win, drawdata->triple, 1.0f);
}
@ -758,7 +756,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
/* draw marked area regions */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->do_draw) {
if (ar->visible && ar->do_draw) {
if (ar->overlap == false) {
CTX_wm_region_set(C, ar);
@ -778,7 +776,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
}
if (copytex) {
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
wm_triple_copy_textures(win, triple_data);
}
@ -786,12 +784,12 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
if (wm->paintcursors.first) {
for (sa = screen->areabase.first; sa; sa = sa->next) {
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->swinid == screen->subwinactive) {
if (ar->visible && ar == screen->active_region) {
CTX_wm_area_set(C, sa);
CTX_wm_region_set(C, ar);
/* make region ready for draw, scissor, pixelspace */
wmSubWindowScissorSet(win, ar->swinid, &ar->winrct, true);
wmViewport(&ar->winrct);
wm_paintcursor_draw(C, ar);
CTX_wm_region_set(C, NULL);
@ -800,7 +798,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
}
}
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
}
/* draw overlapping area regions (always like popups) */
@ -808,7 +806,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
CTX_wm_area_set(C, sa);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->swinid && ar->overlap) {
if (ar->visible && ar->overlap) {
CTX_wm_region_set(C, ar);
ED_region_do_draw(C, ar);
if (sview == STEREO_RIGHT_ID)
@ -831,7 +829,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
/* draw floating regions (menus) */
for (ar = screen->regionbase.first; ar; ar = ar->next) {
if (ar->swinid) {
if (ar->visible) {
CTX_wm_menu_set(C, ar);
ED_region_do_draw(C, ar);
if (sview == STEREO_RIGHT_ID)
@ -850,7 +848,7 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
}
/* copy the ui + overlays */
wmSubWindowSet(win, screen->mainwin);
wmWindowViewport(win);
wm_triple_copy_textures(win, triple_all);
}
@ -873,7 +871,7 @@ static bool wm_draw_update_test_window(wmWindow *win)
wm_tag_redraw_overlay(win, ar);
ar->do_draw_overlay = false;
}
if (ar->swinid && ar->do_draw)
if (ar->visible && ar->do_draw)
do_draw = true;
}
@ -881,7 +879,7 @@ static bool wm_draw_update_test_window(wmWindow *win)
for (ar = sa->regionbase.first; ar; ar = ar->next) {
wm_region_test_render_do_draw(scene, depsgraph, sa, ar);
if (ar->swinid && ar->do_draw)
if (ar->visible && ar->do_draw)
do_draw = true;
}
}

View File

@ -182,7 +182,6 @@ static bool wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, v
/* XXX: in future, which notifiers to send to other windows? */
void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference)
{
ARegion *ar;
wmWindowManager *wm = CTX_wm_manager(C);
wmNotifier *note;
@ -196,10 +195,6 @@ void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference
note->window = CTX_wm_window(C);
ar = CTX_wm_region(C);
if (ar)
note->swinid = ar->swinid;
note->category = type & NOTE_CATEGORY;
note->data = type & NOTE_DATA;
note->subtype = type & NOTE_SUBTYPE;
@ -1209,8 +1204,8 @@ static int wm_operator_invoke(
}
if ((G.debug & G_DEBUG_HANDLERS) && ((event == NULL) || (event->type != MOUSEMOVE))) {
printf("%s: handle evt %d win %d op %s\n",
__func__, event ? event->type : 0, CTX_wm_screen(C)->subwinactive, ot->idname);
printf("%s: handle evt %d region %p op %s\n",
__func__, event ? event->type : 0, CTX_wm_screen(C)->active_region, ot->idname);
}
if (op->type->invoke && event) {
@ -2769,7 +2764,7 @@ void wm_event_do_handlers(bContext *C)
/* Note: setting subwin active should be done here, after modal handlers have been done */
if (event->type == MOUSEMOVE) {
/* state variables in screen, cursors. Also used in wm_draw.c, fails for modal handlers though */
ED_screen_set_subwinactive(C, event);
ED_screen_set_active_region(C, event);
/* for regions having custom cursors */
wm_paintcursor_test(C, event);
}

View File

@ -49,7 +49,6 @@
#include "WM_types.h"
#include "wm.h"
#include "wm_subwindow.h"
#include "wm_draw.h"
#include "GPU_immediate.h"
@ -64,40 +63,37 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type)
wmGesture *gesture = MEM_callocN(sizeof(wmGesture), "new gesture");
wmWindow *window = CTX_wm_window(C);
ARegion *ar = CTX_wm_region(C);
int sx, sy;
BLI_addtail(&window->gesture, gesture);
gesture->type = type;
gesture->event_type = event->type;
gesture->swinid = ar->swinid; /* means only in area-region context! */
gesture->winrct = ar->winrct;
gesture->userdata_free = true; /* Free if userdata is set. */
gesture->modal_state = GESTURE_MODAL_NOP;
wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
if (ELEM(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, WM_GESTURE_TWEAK,
WM_GESTURE_CIRCLE, WM_GESTURE_STRAIGHTLINE))
{
rcti *rect = MEM_callocN(sizeof(rcti), "gesture rect new");
gesture->customdata = rect;
rect->xmin = event->x - sx;
rect->ymin = event->y - sy;
rect->xmin = event->x - gesture->winrct.xmin;
rect->ymin = event->y - gesture->winrct.ymin;
if (type == WM_GESTURE_CIRCLE) {
/* caller is responsible for initializing 'xmax' to radius. */
}
else {
rect->xmax = event->x - sx;
rect->ymax = event->y - sy;
rect->xmax = event->x - gesture->winrct.xmin;
rect->ymax = event->y - gesture->winrct.ymin;
}
}
else if (ELEM(type, WM_GESTURE_LINES, WM_GESTURE_LASSO)) {
short *lasso;
gesture->points_alloc = 1024;
gesture->customdata = lasso = MEM_mallocN(sizeof(short[2]) * gesture->points_alloc, "lasso points");
lasso[0] = event->x - sx;
lasso[1] = event->y - sy;
lasso[0] = event->x - gesture->winrct.xmin;
lasso[1] = event->y - gesture->winrct.ymin;
gesture->points = 1;
}
@ -273,14 +269,13 @@ static void draw_filled_lasso_px_cb(int x, int x_end, int y, void *user_data)
memset(col, 0x10, x_end - x);
}
static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
static void draw_filled_lasso(wmGesture *gt)
{
const short *lasso = (short *)gt->customdata;
const int tot = gt->points;
int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__);
int i;
rcti rect;
rcti rect_win;
float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
for (i = 0; i < tot; i++, lasso += 2) {
@ -290,10 +285,9 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
wm_subwindow_rect_get(win, gt->swinid, &rect_win);
BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
BLI_rcti_isect(&rect_win, &rect, &rect);
BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
BLI_rcti_translate(&rect, gt->winrct.xmin, gt->winrct.ymin);
BLI_rcti_isect(&gt->winrct, &rect, &rect);
BLI_rcti_translate(&rect, -gt->winrct.xmin, -gt->winrct.ymin);
/* highly unlikely this will fail, but could crash if (tot == 0) */
if (BLI_rcti_is_empty(&rect) == false) {
@ -335,13 +329,13 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
}
static void wm_gesture_draw_lasso(wmWindow *win, wmGesture *gt, bool filled)
static void wm_gesture_draw_lasso(wmGesture *gt, bool filled)
{
const short *lasso = (short *)gt->customdata;
int i;
if (filled) {
draw_filled_lasso(win, gt);
draw_filled_lasso(gt);
}
const int numverts = gt->points;
@ -425,7 +419,7 @@ void wm_gesture_draw(wmWindow *win)
glLineWidth(1.0f);
for (; gt; gt = gt->next) {
/* all in subwindow space */
wmSubWindowSet(win, gt->swinid);
wmViewport(&gt->winrct);
if (gt->type == WM_GESTURE_RECT)
wm_gesture_draw_rect(gt);
@ -442,9 +436,9 @@ void wm_gesture_draw(wmWindow *win)
}
}
else if (gt->type == WM_GESTURE_LINES)
wm_gesture_draw_lasso(win, gt, false);
wm_gesture_draw_lasso(gt, false);
else if (gt->type == WM_GESTURE_LASSO)
wm_gesture_draw_lasso(win, gt, true);
wm_gesture_draw_lasso(gt, true);
else if (gt->type == WM_GESTURE_STRAIGHTLINE)
wm_gesture_draw_line(gt);
}

View File

@ -47,7 +47,6 @@
#include "wm.h"
#include "wm_event_types.h"
#include "wm_event_system.h"
#include "wm_subwindow.h"
#include "ED_screen.h"
@ -198,18 +197,15 @@ int WM_gesture_border_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
int sx, sy;
if (event->type == MOUSEMOVE) {
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) {
rect->xmin = rect->xmax = event->x - sx;
rect->ymin = rect->ymax = event->y - sy;
rect->xmin = rect->xmax = event->x - gesture->winrct.xmin;
rect->ymin = rect->ymax = event->y - gesture->winrct.ymin;
}
else {
rect->xmax = event->x - sx;
rect->ymax = event->y - sy;
rect->xmax = event->x - gesture->winrct.xmin;
rect->ymax = event->y - gesture->winrct.ymin;
}
gesture_border_apply_rect(op);
@ -333,13 +329,11 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
int sx, sy;
if (event->type == MOUSEMOVE) {
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
rect->xmin = event->x - sx;
rect->ymin = event->y - sy;
rect->xmin = event->x - gesture->winrct.xmin;
rect->ymin = event->y - gesture->winrct.ymin;
wm_gesture_tag_redraw(C);
@ -464,24 +458,22 @@ static void gesture_tweak_modal(bContext *C, const wmEvent *event)
wmWindow *window = CTX_wm_window(C);
wmGesture *gesture = window->tweak;
rcti *rect = gesture->customdata;
int sx, sy, val;
int val;
switch (event->type) {
case MOUSEMOVE:
case INBETWEEN_MOUSEMOVE:
wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
rect->xmax = event->x - sx;
rect->ymax = event->y - sy;
rect->xmax = event->x - gesture->winrct.xmin;
rect->ymax = event->y - gesture->winrct.ymin;
if ((val = wm_gesture_evaluate(gesture))) {
wmEvent tevent;
wm_event_init_from_window(window, &tevent);
/* We want to get coord from start of drag, not from point where it becomes a tweak event, see T40549 */
tevent.x = rect->xmin + sx;
tevent.y = rect->ymin + sy;
tevent.x = rect->xmin + gesture->winrct.xmin;
tevent.y = rect->ymin + gesture->winrct.ymin;
if (gesture->event_type == LEFTMOUSE)
tevent.type = EVT_TWEAK_L;
else if (gesture->event_type == RIGHTMOUSE)
@ -617,7 +609,6 @@ static void gesture_lasso_apply(bContext *C, wmOperator *op)
int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
int sx, sy;
switch (event->type) {
case MOUSEMOVE:
@ -625,8 +616,6 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
wm_gesture_tag_redraw(C);
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
if (gesture->points == gesture->points_alloc) {
gesture->points_alloc *= 2;
gesture->customdata = MEM_reallocN(gesture->customdata, sizeof(short[2]) * gesture->points_alloc);
@ -637,15 +626,15 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
short *lasso = gesture->customdata;
lasso += (2 * gesture->points - 2);
x = (event->x - sx - lasso[0]);
y = (event->y - sy - lasso[1]);
x = (event->x - gesture->winrct.xmin - lasso[0]);
y = (event->y - gesture->winrct.ymin - lasso[1]);
/* make a simple distance check to get a smoother lasso
* add only when at least 2 pixels between this and previous location */
if ((x * x + y * y) > 4) {
lasso += 2;
lasso[0] = event->x - sx;
lasso[1] = event->y - sy;
lasso[0] = event->x - gesture->winrct.xmin;
lasso[1] = event->y - gesture->winrct.ymin;
gesture->points++;
}
}
@ -813,18 +802,15 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
int sx, sy;
if (event->type == MOUSEMOVE) {
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
if (gesture->is_active == false) {
rect->xmin = rect->xmax = event->x - sx;
rect->ymin = rect->ymax = event->y - sy;
rect->xmin = rect->xmax = event->x - gesture->winrct.xmin;
rect->ymin = rect->ymax = event->y - gesture->winrct.ymin;
}
else {
rect->xmax = event->x - sx;
rect->ymax = event->y - sy;
rect->xmax = event->x - gesture->winrct.xmin;
rect->ymax = event->y - gesture->winrct.ymin;
gesture_straightline_apply(C, op);
}

View File

@ -3310,7 +3310,7 @@ static void redraw_timer_step(
CTX_wm_area_set(C, sa_iter);
for (ar_iter = sa_iter->regionbase.first; ar_iter; ar_iter = ar_iter->next) {
if (ar_iter->swinid) {
if (ar_iter->visible) {
CTX_wm_region_set(C, ar_iter);
ED_region_do_draw(C, ar_iter);
ar_iter->do_draw = false;

View File

@ -21,299 +21,87 @@
* Contributor(s): 2007 Blender Foundation (refactor)
*
* ***** END GPL LICENSE BLOCK *****
*
*
* Subwindow opengl handling.
* BTW: subwindows open/close in X11 are way too slow, tried it, and choose for my own system... (ton)
*
*/
/** \file blender/windowmanager/intern/wm_subwindow.c
* \ingroup wm
*
* Internal subwindows used for OpenGL state, used for regions and screens.
* OpenGL utilities for setting up 2D viewport for window and regions.
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_windowmanager_types.h"
#include "DNA_screen_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_rect.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
#include "BIF_gl.h"
#include "GPU_matrix.h"
#include "WM_api.h"
#include "wm_subwindow.h"
/**
* \note #wmSubWindow stored in #wmWindow but not exposed outside this C file,
* it seems a bit redundant (area regions can store it too, but we keep it
* because we can store all kind of future opengl fanciness here.
*
* We use indices and array because:
* - index has safety, no pointers from this C file hanging around
* - fast lookups of indices with array, list would give overhead
* - old code used it this way...
* - keep option open to have 2 screens using same window
*/
typedef struct wmSubWindow {
struct wmSubWindow *next, *prev;
rcti winrct;
int swinid;
} wmSubWindow;
/* ******************* open, free, set, get data ******************** */
/* not subwindow itself */
static void wm_subwindow_free(wmSubWindow *UNUSED(swin))
void wmViewport(const rcti *winrct)
{
/* future fancy stuff */
}
int width = BLI_rcti_size_x(winrct) + 1;
int height = BLI_rcti_size_y(winrct) + 1;
void wm_subwindows_free(wmWindow *win)
{
wmSubWindow *swin;
for (swin = win->subwindows.first; swin; swin = swin->next)
wm_subwindow_free(swin);
BLI_freelistN(&win->subwindows);
}
glViewport(winrct->xmin, winrct->ymin, width, height);
glScissor(winrct->xmin, winrct->ymin, width, height);
static wmSubWindow *swin_from_swinid(wmWindow *win, int swinid)
{
wmSubWindow *swin;
for (swin = win->subwindows.first; swin; swin = swin->next)
if (swin->swinid == swinid)
break;
return swin;
}
static void wm_swin_size_get(wmSubWindow *swin, int *x, int *y)
{
*x = BLI_rcti_size_x(&swin->winrct) + 1;
*y = BLI_rcti_size_y(&swin->winrct) + 1;
}
void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_swin_size_get(swin, x, y);
}
}
static void wm_swin_origin_get(wmSubWindow *swin, int *x, int *y)
{
*x = swin->winrct.xmin;
*y = swin->winrct.ymin;
}
void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_swin_origin_get(swin, x, y);
}
}
static void wm_swin_matrix_get(wmWindow *win, wmSubWindow *swin, float mat[4][4])
{
const bScreen *screen = WM_window_get_active_screen(win);
/* used by UI, should find a better way to get the matrix there */
if (swin->swinid == screen->mainwin) {
int width, height;
wm_swin_size_get(swin, &width, &height);
orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100);
}
else {
gpuGetProjectionMatrix(mat);
}
}
void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4])
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_swin_matrix_get(win, swin, mat);
}
}
static void wm_swin_rect_get(wmSubWindow *swin, rcti *r_rect)
{
*r_rect = swin->winrct;
}
void wm_subwindow_rect_get(wmWindow *win, int swinid, rcti *r_rect)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_swin_rect_get(swin, r_rect);
}
}
static void wm_swin_rect_set(wmSubWindow *swin, const rcti *rect)
{
swin->winrct = *rect;
}
void wm_subwindow_rect_set(wmWindow *win, int swinid, const rcti *rect)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_swin_rect_set(swin, rect);
}
}
/* always sets pixel-precise 2D window/view matrices */
/* coords is in whole pixels. xmin = 15, xmax = 16: means window is 2 pix big */
int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate)
{
wmSubWindow *swin;
int width, height;
int freewinid = 1;
for (swin = win->subwindows.first; swin; swin = swin->next)
if (freewinid <= swin->swinid)
freewinid = swin->swinid + 1;
swin = MEM_callocN(sizeof(wmSubWindow), "swinopen");
BLI_addtail(&win->subwindows, swin);
swin->swinid = freewinid;
swin->winrct = *winrct;
if (activate) {
/* and we appy it all right away */
wmSubWindowSet(win, swin->swinid);
/* extra service */
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
gpuLoadIdentity();
}
return swin->swinid;
}
void wm_subwindow_close(wmWindow *win, int swinid)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
wm_subwindow_free(swin);
BLI_remlink(&win->subwindows, swin);
MEM_freeN(swin);
}
else {
printf("%s: Internal error, bad winid: %d\n", __func__, swinid);
}
}
/* pixels go from 0-99 for a 100 pixel window */
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate)
{
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin) {
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
int width, height;
swin->winrct = *winrct;
/* CRITICAL, this clamping ensures that
* the viewport never goes outside the screen
* edges (assuming the x, y coords aren't
* outside). This caused a hardware lock
* on Matrox cards if it happens.
*
* Really Blender should never _ever_ try
* to do such a thing, but just to be safe
* clamp it anyway (or fix the bScreen
* scaling routine, and be damn sure you
* fixed it). - zr (2001!)
*/
if (swin->winrct.xmax > winsize_x)
swin->winrct.xmax = winsize_x;
if (swin->winrct.ymax > winsize_y)
swin->winrct.ymax = winsize_y;
if (activate) {
/* extra service */
wmSubWindowSet(win, swinid);
wm_swin_size_get(swin, &width, &height);
wmOrtho2_pixelspace(width, height);
}
}
else {
printf("%s: Internal error, bad winid: %d\n", __func__, swinid);
}
}
/* ---------------- WM versions of OpenGL style API calls ------------------------ */
/* ----------------- exported in WM_api.h ------------------------------------------------------ */
void wmSubWindowScissorSet(wmWindow *win, int swinid, const rcti *srct, bool srct_pad)
{
int width, height;
wmSubWindow *swin = swin_from_swinid(win, swinid);
if (swin == NULL) {
printf("%s %d: doesn't exist\n", __func__, swinid);
return;
}
width = BLI_rcti_size_x(&swin->winrct) + 1;
height = BLI_rcti_size_y(&swin->winrct) + 1;
glViewport(swin->winrct.xmin, swin->winrct.ymin, width, height);
if (srct) {
int scissor_width = BLI_rcti_size_x(srct);
int scissor_height = BLI_rcti_size_y(srct);
/* typically a single pixel doesn't matter,
* but one pixel offset is noticeable with viewport border render */
if (srct_pad) {
scissor_width += 1;
scissor_height += 1;
}
glScissor(srct->xmin, srct->ymin, scissor_width, scissor_height);
}
else
glScissor(swin->winrct.xmin, swin->winrct.ymin, width, height);
wmOrtho2_pixelspace(width, height);
gpuLoadIdentity();
}
/* enable the WM versions of opengl calls */
void wmSubWindowSet(wmWindow *win, int swinid)
void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct)
{
wmSubWindowScissorSet(win, swinid, NULL, true);
/* Setup part of the viewport for partial redraw. */
bool scissor_pad;
if (partialrct->xmin == partialrct->xmax) {
/* Full region. */
*drawrct = *winrct;
scissor_pad = true;
}
else {
/* Partial redraw, clipped to region. */
BLI_rcti_isect(winrct, partialrct, drawrct);
scissor_pad = false;
}
int x = drawrct->xmin;
int y = drawrct->ymin;
int width = BLI_rcti_size_x(winrct) + 1;
int height = BLI_rcti_size_y(winrct) + 1;
int scissor_width = BLI_rcti_size_x(drawrct);
int scissor_height = BLI_rcti_size_y(drawrct);
/* Partial redraw rect uses different convention than region rect,
* so compensate for that here. One pixel offset is noticeable with
* viewport border render. */
if (scissor_pad) {
scissor_width += 1;
scissor_height += 1;
}
glViewport(x, y, width, height);
glScissor(x, y, scissor_width, scissor_height);
wmOrtho2_pixelspace(width, height);
gpuLoadIdentity();
}
void wmWindowViewport(wmWindow *win)
{
int width = WM_window_pixels_x(win);
int height = WM_window_pixels_y(win);
glViewport(0, 0, width, height);
glScissor(0, 0, width, height);
wmOrtho2_pixelspace(width, height);
gpuLoadIdentity();
}
void wmOrtho2(float x1, float x2, float y1, float y2)
@ -330,9 +118,7 @@ static void wmOrtho2_offset(const float x, const float y, const float ofs)
wmOrtho2(ofs, x + ofs, ofs, y + ofs);
}
/**
* default pixel alignment.
*/
/* Default pixel alignment for regions. */
void wmOrtho2_region_pixelspace(const ARegion *ar)
{
wmOrtho2_offset(ar->winx, ar->winy, -0.01f);
@ -343,5 +129,9 @@ void wmOrtho2_pixelspace(const float x, const float y)
wmOrtho2_offset(x, y, -GLA_PIXEL_OFS);
}
/* ********** END MY WINDOW ************** */
void wmGetProjectionMatrix(float mat[4][4], const rcti *winrct)
{
int width = BLI_rcti_size_x(winrct) + 1;
int height = BLI_rcti_size_y(winrct) + 1;
orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100);
}

View File

@ -68,7 +68,6 @@
#include "wm.h"
#include "wm_draw.h"
#include "wm_window.h"
#include "wm_subwindow.h"
#include "wm_event_system.h"
#include "ED_scene.h"
@ -215,7 +214,6 @@ void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
if (win->eventstate) MEM_freeN(win->eventstate);
wm_event_free_all(win);
wm_subwindows_free(win);
wm_draw_data_free(win);

View File

@ -1,51 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2007 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/windowmanager/wm_subwindow.h
* \ingroup wm
*/
#ifndef __WM_SUBWINDOW_H__
#define __WM_SUBWINDOW_H__
/* *************** internal api ************** */
void wm_subwindows_free(wmWindow *win);
int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate);
void wm_subwindow_close(wmWindow *win, int swinid);
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate);
void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y);
void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y);
void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4]);
void wm_subwindow_rect_get(wmWindow *win, int swinid, struct rcti *r_rect);
void wm_subwindow_rect_set(wmWindow *win, int swinid, const rcti *rect);
#endif /* __WM_SUBWINDOW_H__ */