Code cleanup: avoid redundant lookups for subwindows
This commit is contained in:
@@ -2430,8 +2430,8 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor
|
|||||||
|
|
||||||
/* window matrix and aspect */
|
/* window matrix and aspect */
|
||||||
if (region && region->swinid) {
|
if (region && region->swinid) {
|
||||||
wm_subwindow_getmatrix(window, region->swinid, block->winmat);
|
wm_subwindow_matrix_get(window, region->swinid, block->winmat);
|
||||||
wm_subwindow_getsize(window, region->swinid, &getsizex, &getsizey);
|
wm_subwindow_size_get(window, region->swinid, &getsizex, &getsizey);
|
||||||
|
|
||||||
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
|
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
|
||||||
}
|
}
|
||||||
@@ -2439,8 +2439,8 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor
|
|||||||
/* no subwindow created yet, for menus for example, so we
|
/* no subwindow created yet, for menus for example, so we
|
||||||
* use the main window instead, since buttons are created
|
* use the main window instead, since buttons are created
|
||||||
* there anyway */
|
* there anyway */
|
||||||
wm_subwindow_getmatrix(window, window->screen->mainwin, block->winmat);
|
wm_subwindow_matrix_get(window, window->screen->mainwin, block->winmat);
|
||||||
wm_subwindow_getsize(window, window->screen->mainwin, &getsizex, &getsizey);
|
wm_subwindow_size_get(window, window->screen->mainwin, &getsizex, &getsizey);
|
||||||
|
|
||||||
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
|
block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
|
||||||
block->auto_open = true;
|
block->auto_open = true;
|
||||||
|
@@ -1606,7 +1606,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, ARegion *butregion, uiBut
|
|||||||
/* get winmat now that we actually have the subwindow */
|
/* get winmat now that we actually have the subwindow */
|
||||||
wmSubWindowSet(window, ar->swinid);
|
wmSubWindowSet(window, ar->swinid);
|
||||||
|
|
||||||
wm_subwindow_getmatrix(window, ar->swinid, block->winmat);
|
wm_subwindow_matrix_get(window, ar->swinid, block->winmat);
|
||||||
|
|
||||||
/* notify change and redraw */
|
/* notify change and redraw */
|
||||||
ED_region_tag_redraw(ar);
|
ED_region_tag_redraw(ar);
|
||||||
|
@@ -72,7 +72,7 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type)
|
|||||||
gesture->event_type = event->type;
|
gesture->event_type = event->type;
|
||||||
gesture->swinid = ar->swinid; /* means only in area-region context! */
|
gesture->swinid = ar->swinid; /* means only in area-region context! */
|
||||||
|
|
||||||
wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
if (ELEM5(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, WM_GESTURE_TWEAK,
|
if (ELEM5(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, WM_GESTURE_TWEAK,
|
||||||
WM_GESTURE_CIRCLE, WM_GESTURE_STRAIGHTLINE))
|
WM_GESTURE_CIRCLE, WM_GESTURE_STRAIGHTLINE))
|
||||||
@@ -261,7 +261,7 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
|
|||||||
|
|
||||||
BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
|
BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
|
||||||
|
|
||||||
wm_subwindow_getrect(win, gt->swinid, &rect_win);
|
wm_subwindow_rect_get(win, gt->swinid, &rect_win);
|
||||||
BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
|
BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
|
||||||
BLI_rcti_isect(&rect_win, &rect, &rect);
|
BLI_rcti_isect(&rect_win, &rect, &rect);
|
||||||
BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
|
BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
|
||||||
|
@@ -3036,7 +3036,7 @@ int WM_border_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
int sx, sy;
|
int sx, sy;
|
||||||
|
|
||||||
if (event->type == MOUSEMOVE) {
|
if (event->type == MOUSEMOVE) {
|
||||||
wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->mode == 0) {
|
if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->mode == 0) {
|
||||||
rect->xmin = rect->xmax = event->x - sx;
|
rect->xmin = rect->xmax = event->x - sx;
|
||||||
@@ -3137,7 +3137,7 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
int sx, sy;
|
int sx, sy;
|
||||||
|
|
||||||
if (event->type == MOUSEMOVE) {
|
if (event->type == MOUSEMOVE) {
|
||||||
wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
rect->xmin = event->x - sx;
|
rect->xmin = event->x - sx;
|
||||||
rect->ymin = event->y - sy;
|
rect->ymin = event->y - sy;
|
||||||
@@ -3236,7 +3236,7 @@ static void tweak_gesture_modal(bContext *C, const wmEvent *event)
|
|||||||
case MOUSEMOVE:
|
case MOUSEMOVE:
|
||||||
case INBETWEEN_MOUSEMOVE:
|
case INBETWEEN_MOUSEMOVE:
|
||||||
|
|
||||||
wm_subwindow_getorigin(window, gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
rect->xmax = event->x - sx;
|
rect->xmax = event->x - sx;
|
||||||
rect->ymax = event->y - sy;
|
rect->ymax = event->y - sy;
|
||||||
@@ -3376,7 +3376,7 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
|||||||
|
|
||||||
wm_gesture_tag_redraw(C);
|
wm_gesture_tag_redraw(C);
|
||||||
|
|
||||||
wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
if (gesture->points == gesture->size) {
|
if (gesture->points == gesture->size) {
|
||||||
short *old_lasso = gesture->customdata;
|
short *old_lasso = gesture->customdata;
|
||||||
@@ -3559,7 +3559,7 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev
|
|||||||
int sx, sy;
|
int sx, sy;
|
||||||
|
|
||||||
if (event->type == MOUSEMOVE) {
|
if (event->type == MOUSEMOVE) {
|
||||||
wm_subwindow_getorigin(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
|
||||||
|
|
||||||
if (gesture->mode == 0) {
|
if (gesture->mode == 0) {
|
||||||
rect->xmin = rect->xmax = event->x - sx;
|
rect->xmin = rect->xmax = event->x - sx;
|
||||||
|
@@ -95,7 +95,7 @@ void wm_subwindows_free(wmWindow *win)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wm_subwindow_get(wmWindow *win)
|
int wm_subwindow_get_id(wmWindow *win)
|
||||||
{
|
{
|
||||||
if (win->curswin)
|
if (win->curswin)
|
||||||
return win->curswin->swinid;
|
return win->curswin->swinid;
|
||||||
@@ -112,55 +112,77 @@ static wmSubWindow *swin_from_swinid(wmWindow *win, int swinid)
|
|||||||
return swin;
|
return swin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_subwindow_getsize(wmWindow *win, int swinid, int *x, int *y)
|
|
||||||
|
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);
|
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
||||||
|
|
||||||
if (swin) {
|
if (swin) {
|
||||||
*x = BLI_rcti_size_x(&swin->winrct) + 1;
|
wm_swin_size_get(swin, x, y);
|
||||||
*y = BLI_rcti_size_y(&swin->winrct) + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_subwindow_getorigin(wmWindow *win, int swinid, int *x, int *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);
|
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
||||||
|
|
||||||
if (swin) {
|
if (swin) {
|
||||||
*x = swin->winrct.xmin;
|
wm_swin_origin_get(swin, x, y);
|
||||||
*y = swin->winrct.ymin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_subwindow_getmatrix(wmWindow *win, int swinid, float mat[4][4])
|
|
||||||
|
static void wm_swin_matrix_get(wmWindow *win, wmSubWindow *swin, float mat[4][4])
|
||||||
|
{
|
||||||
|
/* used by UI, should find a better way to get the matrix there */
|
||||||
|
if (swin->swinid == win->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 {
|
||||||
|
glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4])
|
||||||
{
|
{
|
||||||
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
||||||
|
|
||||||
if (swin) {
|
if (swin) {
|
||||||
/* used by UI, should find a better way to get the matrix there */
|
wm_swin_matrix_get(win, swin, mat);
|
||||||
if (swinid == win->screen->mainwin) {
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
wm_subwindow_getsize(win, swin->swinid, &width, &height);
|
|
||||||
orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_subwindow_getrect(wmWindow *win, int swinid, rcti *r_rect)
|
|
||||||
|
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);
|
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
||||||
|
|
||||||
if (swin) {
|
if (swin) {
|
||||||
*r_rect = swin->winrct;
|
wm_swin_rect_get(swin, r_rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* always sets pixel-precise 2D window/view matrices */
|
/* always sets pixel-precise 2D window/view matrices */
|
||||||
/* coords is in whole pixels. xmin = 15, xmax = 16: means window is 2 pix big */
|
/* coords is in whole pixels. xmin = 15, xmax = 16: means window is 2 pix big */
|
||||||
int wm_subwindow_open(wmWindow *win, rcti *winrct)
|
int wm_subwindow_open(wmWindow *win, const rcti *winrct)
|
||||||
{
|
{
|
||||||
wmSubWindow *swin;
|
wmSubWindow *swin;
|
||||||
int width, height;
|
int width, height;
|
||||||
@@ -180,7 +202,7 @@ int wm_subwindow_open(wmWindow *win, rcti *winrct)
|
|||||||
wmSubWindowSet(win, swin->swinid);
|
wmSubWindowSet(win, swin->swinid);
|
||||||
|
|
||||||
/* extra service */
|
/* extra service */
|
||||||
wm_subwindow_getsize(win, swin->swinid, &width, &height);
|
wm_swin_size_get(swin, &width, &height);
|
||||||
wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
|
wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
@@ -205,7 +227,7 @@ void wm_subwindow_close(wmWindow *win, int swinid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pixels go from 0-99 for a 100 pixel window */
|
/* pixels go from 0-99 for a 100 pixel window */
|
||||||
void wm_subwindow_position(wmWindow *win, int swinid, rcti *winrct)
|
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct)
|
||||||
{
|
{
|
||||||
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
wmSubWindow *swin = swin_from_swinid(win, swinid);
|
||||||
|
|
||||||
@@ -237,7 +259,7 @@ void wm_subwindow_position(wmWindow *win, int swinid, rcti *winrct)
|
|||||||
|
|
||||||
/* extra service */
|
/* extra service */
|
||||||
wmSubWindowSet(win, swinid);
|
wmSubWindowSet(win, swinid);
|
||||||
wm_subwindow_getsize(win, swinid, &width, &height);
|
wm_swin_size_get(swin, &width, &height);
|
||||||
wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
|
wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -36,16 +36,16 @@
|
|||||||
/* *************** internal api ************** */
|
/* *************** internal api ************** */
|
||||||
void wm_subwindows_free(wmWindow *win);
|
void wm_subwindows_free(wmWindow *win);
|
||||||
|
|
||||||
int wm_subwindow_open(wmWindow *win, rcti *winrct);
|
int wm_subwindow_open(wmWindow *win, const rcti *winrct);
|
||||||
void wm_subwindow_close(wmWindow *win, int swinid);
|
void wm_subwindow_close(wmWindow *win, int swinid);
|
||||||
int wm_subwindow_get(wmWindow *win); /* returns id */
|
int wm_subwindow_get_id(wmWindow *win); /* returns id */
|
||||||
|
|
||||||
void wm_subwindow_position(wmWindow *win, int swinid, rcti *winrct);
|
void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct);
|
||||||
|
|
||||||
void wm_subwindow_getsize(wmWindow *win, int swinid, int *x, int *y);
|
void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y);
|
||||||
void wm_subwindow_getorigin(wmWindow *win, int swinid, int *x, int *y);
|
void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y);
|
||||||
void wm_subwindow_getmatrix(wmWindow *win, int swinid, float mat[4][4]);
|
void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4]);
|
||||||
void wm_subwindow_getrect(wmWindow *win, int swinid, struct rcti *r_rect);
|
void wm_subwindow_rect_get(wmWindow *win, int swinid, struct rcti *r_rect);
|
||||||
|
|
||||||
unsigned int index_to_framebuffer(int index);
|
unsigned int index_to_framebuffer(int index);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user