View2D - Commented and finished off cleaning up code added so far
This commit is contained in:
@@ -21,29 +21,47 @@
|
|||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Contributor(s): Blender Foundation
|
* Contributor(s): Blender Foundation, Joshua Leung
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* Generic 2d view with should allow drawing grids,
|
||||||
|
* panning, zooming, scrolling, ..
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UI_VIEW2D_H
|
#ifndef UI_VIEW2D_H
|
||||||
#define UI_VIEW2D_H
|
#define UI_VIEW2D_H
|
||||||
|
|
||||||
/* start of a generic 2d view with should allow drawing grids,
|
/* ------------------------------------------ */
|
||||||
* panning, zooming, scrolling, .. */
|
/* Settings: */
|
||||||
|
|
||||||
|
/* grid-units (for drawing time) */
|
||||||
#define V2D_UNIT_SECONDS 0
|
#define V2D_UNIT_SECONDS 0
|
||||||
#define V2D_UNIT_FRAMES 1
|
#define V2D_UNIT_FRAMES 1
|
||||||
|
|
||||||
|
/* clamping of grid values to whole numbers */
|
||||||
#define V2D_GRID_CLAMP 0
|
#define V2D_GRID_CLAMP 0
|
||||||
#define V2D_GRID_NOCLAMP 1
|
#define V2D_GRID_NOCLAMP 1
|
||||||
|
|
||||||
|
/* generic value to use when coordinate lies out of view when converting */
|
||||||
#define V2D_IS_CLIPPED 12000
|
#define V2D_IS_CLIPPED 12000
|
||||||
|
|
||||||
#define V2D_HORIZONTAL_LINES 1
|
/* flags for grid-lines to draw */
|
||||||
#define V2D_VERTICAL_LINES 2
|
#define V2D_HORIZONTAL_LINES (1<<0)
|
||||||
#define V2D_HORIZONTAL_AXIS 4
|
#define V2D_VERTICAL_LINES (1<<1)
|
||||||
#define V2D_VERTICAL_AXIS 8
|
#define V2D_HORIZONTAL_AXIS (1<<2)
|
||||||
|
#define V2D_VERTICAL_AXIS (1<<3)
|
||||||
|
|
||||||
|
/* ------------------------------------------ */
|
||||||
|
/* Macros: */
|
||||||
|
|
||||||
|
/* test if mouse in scrollbar */
|
||||||
|
// XXX do we want more elegant method?
|
||||||
|
#define IN_2D_VERT_SCROLL(v2d, co) (BLI_in_rcti(&v2d->vert, co[0], co[1]))
|
||||||
|
#define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_in_rcti(&v2d->hor, co[0], co[1]))
|
||||||
|
|
||||||
|
/* ------------------------------------------ */
|
||||||
|
/* Type definitions: */
|
||||||
|
|
||||||
struct View2D;
|
struct View2D;
|
||||||
struct View2DGrid;
|
struct View2DGrid;
|
||||||
@@ -51,15 +69,21 @@ struct bContext;
|
|||||||
|
|
||||||
typedef struct View2DGrid View2DGrid;
|
typedef struct View2DGrid View2DGrid;
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* Prototypes: */
|
||||||
|
|
||||||
/* setup */
|
/* setup */
|
||||||
void UI_view2d_ortho(const struct bContext *C, struct View2D *v2d);
|
void UI_view2d_ortho(const struct bContext *C, struct View2D *v2d);
|
||||||
void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
|
void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
|
||||||
|
|
||||||
/* grid drawing */
|
/* grid drawing */
|
||||||
View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, int unit, int type, int winx, int winy);
|
View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, short unit, short type, int winx, int winy);
|
||||||
void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
|
void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
|
||||||
void UI_view2d_free_grid(View2DGrid *grid);
|
void UI_view2d_free_grid(View2DGrid *grid);
|
||||||
|
|
||||||
|
/* scrollbar drawing */
|
||||||
|
|
||||||
|
|
||||||
/* coordinate conversion */
|
/* coordinate conversion */
|
||||||
void UI_view2d_region_to_view(struct View2D *v2d, short x, short y, float *viewx, float *viewy);
|
void UI_view2d_region_to_view(struct View2D *v2d, short x, short y, float *viewx, float *viewy);
|
||||||
void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, short *regionx, short *regiony);
|
void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, short *regionx, short *regiony);
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s): Blender Foundation, Joshua Leung
|
||||||
|
*
|
||||||
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -17,68 +43,50 @@
|
|||||||
#include "UI_resources.h"
|
#include "UI_resources.h"
|
||||||
#include "UI_view2d.h"
|
#include "UI_view2d.h"
|
||||||
|
|
||||||
/* minimum pixels per gridstep */
|
/* *********************************************************************** */
|
||||||
#define IPOSTEP 35
|
/* Setup and Refresh Code */
|
||||||
|
|
||||||
struct View2DGrid {
|
|
||||||
float dx, dy, startx, starty;
|
|
||||||
int machtx, machty;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Setup */
|
|
||||||
|
|
||||||
|
/* Set view matrices to ortho for View2D drawing */
|
||||||
void UI_view2d_ortho(const bContext *C, View2D *v2d)
|
void UI_view2d_ortho(const bContext *C, View2D *v2d)
|
||||||
{
|
{
|
||||||
wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
|
wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Adjust mask size in response to view size changes */
|
||||||
|
// XXX pre2.5 -> this used to be called calc_scrollrcts()
|
||||||
void UI_view2d_update_size(View2D *v2d, int winx, int winy)
|
void UI_view2d_update_size(View2D *v2d, int winx, int winy)
|
||||||
{
|
{
|
||||||
|
/* mask - view frame */
|
||||||
v2d->mask.xmin= v2d->mask.ymin= 0;
|
v2d->mask.xmin= v2d->mask.ymin= 0;
|
||||||
v2d->mask.xmax= winx;
|
v2d->mask.xmax= winx;
|
||||||
v2d->mask.ymax= winy;
|
v2d->mask.ymax= winy;
|
||||||
|
|
||||||
#if 0
|
/* scrollbars shrink mask area, but should be based off regionsize */
|
||||||
if(sa->spacetype==SPACE_ACTION) {
|
// XXX scrollbars should become limited to one bottom lower edges of region like everyone else does!
|
||||||
if(sa->winx > ACTWIDTH+50) {
|
|
||||||
v2d->mask.xmin+= ACTWIDTH;
|
|
||||||
v2d->hor.xmin+=ACTWIDTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(sa->spacetype==SPACE_NLA){
|
|
||||||
if(sa->winx > NLAWIDTH+50) {
|
|
||||||
v2d->mask.xmin+= NLAWIDTH;
|
|
||||||
v2d->hor.xmin+=NLAWIDTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(sa->spacetype==SPACE_IPO) {
|
|
||||||
int ipobutx = calc_ipobuttonswidth(sa);
|
|
||||||
|
|
||||||
v2d->mask.xmax-= ipobutx;
|
|
||||||
|
|
||||||
if(v2d->mask.xmax<ipobutx)
|
|
||||||
v2d->mask.xmax= winx;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(v2d->scroll) {
|
if(v2d->scroll) {
|
||||||
if(v2d->scroll & L_SCROLL) {
|
/* vertical scrollbar */
|
||||||
|
if (v2d->scroll & L_SCROLL) {
|
||||||
|
/* on left-hand edge of region */
|
||||||
v2d->vert= v2d->mask;
|
v2d->vert= v2d->mask;
|
||||||
v2d->vert.xmax= SCROLLB;
|
v2d->vert.xmax= SCROLLB;
|
||||||
v2d->mask.xmin= SCROLLB;
|
v2d->mask.xmin= SCROLLB;
|
||||||
}
|
}
|
||||||
else if(v2d->scroll & R_SCROLL) {
|
else if(v2d->scroll & R_SCROLL) {
|
||||||
|
/* on right-hand edge of region */
|
||||||
v2d->vert= v2d->mask;
|
v2d->vert= v2d->mask;
|
||||||
v2d->vert.xmin= v2d->vert.xmax-SCROLLB;
|
v2d->vert.xmin= v2d->vert.xmax-SCROLLB;
|
||||||
v2d->mask.xmax= v2d->vert.xmin;
|
v2d->mask.xmax= v2d->vert.xmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((v2d->scroll & B_SCROLL) || (v2d->scroll & B_SCROLLO)) {
|
/* horizontal scrollbar */
|
||||||
|
if ((v2d->scroll & B_SCROLL) || (v2d->scroll & B_SCROLLO)) {
|
||||||
|
/* on bottom edge of region (B_SCROLLO is outliner, the ohter is for standard) */
|
||||||
v2d->hor= v2d->mask;
|
v2d->hor= v2d->mask;
|
||||||
v2d->hor.ymax= SCROLLH;
|
v2d->hor.ymax= SCROLLH;
|
||||||
v2d->mask.ymin= SCROLLH;
|
v2d->mask.ymin= SCROLLH;
|
||||||
}
|
}
|
||||||
else if(v2d->scroll & T_SCROLL) {
|
else if(v2d->scroll & T_SCROLL) {
|
||||||
|
/* on upper edge of region */
|
||||||
v2d->hor= v2d->mask;
|
v2d->hor= v2d->mask;
|
||||||
v2d->hor.ymin= v2d->hor.ymax-SCROLLH;
|
v2d->hor.ymin= v2d->hor.ymax-SCROLLH;
|
||||||
v2d->mask.ymax= v2d->hor.ymin;
|
v2d->mask.ymax= v2d->hor.ymin;
|
||||||
@@ -86,58 +94,82 @@ void UI_view2d_update_size(View2D *v2d, int winx, int winy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grid */
|
/* *********************************************************************** */
|
||||||
|
/* Gridlines */
|
||||||
|
|
||||||
static void step_to_grid(float *step, int *macht, int unit)
|
/* minimum pixels per gridstep */
|
||||||
|
#define MINGRIDSTEP 35
|
||||||
|
|
||||||
|
/* View2DGrid is typedef'd in UI_view2d.h */
|
||||||
|
struct View2DGrid {
|
||||||
|
float dx, dy; /* stepsize (in pixels) between gridlines */
|
||||||
|
float startx, starty; /* */
|
||||||
|
int powerx, powery; /* step as power of 10 */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* --------------- */
|
||||||
|
|
||||||
|
/* try to write step as a power of 10 */
|
||||||
|
static void step_to_grid(float *step, int *power, int unit)
|
||||||
{
|
{
|
||||||
float loga, rem;
|
const float loga= log10(*step);
|
||||||
|
float rem;
|
||||||
|
|
||||||
/* try to write step as a power of 10 */
|
*power= (int)(loga);
|
||||||
|
|
||||||
loga= log10(*step);
|
rem= loga - (*power);
|
||||||
*macht= (int)(loga);
|
|
||||||
|
|
||||||
rem= loga- *macht;
|
|
||||||
rem= pow(10.0, rem);
|
rem= pow(10.0, rem);
|
||||||
|
|
||||||
if(loga<0.0) {
|
if (loga < 0.0f) {
|
||||||
if(rem < 0.2) rem= 0.2;
|
if (rem < 0.2f) rem= 0.2f;
|
||||||
else if(rem < 0.5) rem= 0.5;
|
else if(rem < 0.5f) rem= 0.5f;
|
||||||
else rem= 1.0;
|
else rem= 1.0f;
|
||||||
|
|
||||||
*step= rem*pow(10.0, (float)*macht);
|
*step= rem * pow(10.0, (double)(*power));
|
||||||
|
|
||||||
if(unit == V2D_UNIT_FRAMES) {
|
/* for frames, we want 1.0 frame intervals only */
|
||||||
rem = 1.0;
|
if (unit == V2D_UNIT_FRAMES) {
|
||||||
*step = 1.0;
|
rem = 1.0f;
|
||||||
|
*step = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rem==1.0) (*macht)++; // prevents printing 1.0 2.0 3.0 etc
|
/* prevents printing 1.0 2.0 3.0 etc */
|
||||||
|
if (rem == 1.0f) (*power)++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(rem < 2.0) rem= 2.0;
|
if (rem < 2.0f) rem= 2.0f;
|
||||||
else if(rem < 5.0) rem= 5.0;
|
else if(rem < 5.0f) rem= 5.0f;
|
||||||
else rem= 10.0;
|
else rem= 10.0f;
|
||||||
|
|
||||||
*step= rem*pow(10.0, (float)*macht);
|
*step= rem * pow(10.0, (double)(*power));
|
||||||
|
|
||||||
(*macht)++;
|
(*power)++;
|
||||||
if(rem==10.0) (*macht)++; // prevents printing 1.0 2.0 3.0 etc
|
/* prevents printing 1.0, 2.0, 3.0, etc. */
|
||||||
|
if (rem == 10.0f) (*power)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
View2DGrid *UI_view2d_calc_grid(const bContext *C, View2D *v2d, int unit, int clamp, int winx, int winy)
|
/* Intialise settings necessary for drawing gridlines in a 2d-view
|
||||||
|
* - Currently, will return pointer to View2DGrid struct that needs to
|
||||||
|
* be freed with UI_view2d_free_grid()
|
||||||
|
* - Is used for scrollbar drawing too (for units drawing) --> (XXX needs review)
|
||||||
|
*
|
||||||
|
* - unit = V2D_UNIT_* grid steps in seconds or frames
|
||||||
|
* - clamp = V2D_CLAMP_* only show whole-number intervals
|
||||||
|
* - winx = width of region we're drawing to
|
||||||
|
* - winy = height of region we're drawing into
|
||||||
|
*/
|
||||||
|
View2DGrid *UI_view2d_calc_grid(const bContext *C, View2D *v2d, short unit, short clamp, int winx, int winy)
|
||||||
{
|
{
|
||||||
View2DGrid *grid;
|
View2DGrid *grid;
|
||||||
float space, pixels, seconddiv;
|
float space, pixels, seconddiv;
|
||||||
int secondgrid;
|
int secondgrid;
|
||||||
|
|
||||||
grid= MEM_callocN(sizeof(View2DGrid), "View2DGrid");
|
|
||||||
|
|
||||||
/* rule: gridstep is minimal IPOSTEP pixels */
|
|
||||||
/* how large is IPOSTEP pixels? */
|
|
||||||
|
|
||||||
if(unit == V2D_UNIT_FRAMES) {
|
/* grid here is allocated... */
|
||||||
|
grid= MEM_callocN(sizeof(View2DGrid), "View2DGrid");
|
||||||
|
|
||||||
|
/* rule: gridstep is minimal GRIDSTEP pixels */
|
||||||
|
if (unit == V2D_UNIT_FRAMES) {
|
||||||
secondgrid= 0;
|
secondgrid= 0;
|
||||||
seconddiv= 0.01f * FPS;
|
seconddiv= 0.01f * FPS;
|
||||||
}
|
}
|
||||||
@@ -145,187 +177,233 @@ View2DGrid *UI_view2d_calc_grid(const bContext *C, View2D *v2d, int unit, int cl
|
|||||||
secondgrid= 1;
|
secondgrid= 1;
|
||||||
seconddiv= 1.0f;
|
seconddiv= 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
space= v2d->cur.xmax - v2d->cur.xmin;
|
space= v2d->cur.xmax - v2d->cur.xmin;
|
||||||
pixels= v2d->mask.xmax - v2d->mask.xmin;
|
pixels= v2d->mask.xmax - v2d->mask.xmin;
|
||||||
|
|
||||||
grid->dx= IPOSTEP*space/(seconddiv*pixels);
|
grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);
|
||||||
step_to_grid(&grid->dx, &grid->machtx, unit);
|
step_to_grid(&grid->dx, &grid->powerx, unit);
|
||||||
grid->dx*= seconddiv;
|
grid->dx *= seconddiv;
|
||||||
|
|
||||||
if(clamp == V2D_GRID_CLAMP) {
|
if (clamp == V2D_GRID_CLAMP) {
|
||||||
if(grid->dx < 0.1) grid->dx= 0.1;
|
if (grid->dx < 0.1f) grid->dx= 0.1f;
|
||||||
grid->machtx-= 2;
|
grid->powerx-= 2;
|
||||||
if(grid->machtx<-2) grid->machtx= -2;
|
if (grid->powerx < -2) grid->powerx= -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
space= (v2d->cur.ymax - v2d->cur.ymin);
|
space= (v2d->cur.ymax - v2d->cur.ymin);
|
||||||
pixels= winy;
|
pixels= winy;
|
||||||
grid->dy= IPOSTEP*space/pixels;
|
grid->dy= MINGRIDSTEP*space/pixels;
|
||||||
step_to_grid(&grid->dy, &grid->machty, unit);
|
step_to_grid(&grid->dy, &grid->powery, unit);
|
||||||
|
|
||||||
if(clamp == V2D_GRID_CLAMP) {
|
if (clamp == V2D_GRID_CLAMP) {
|
||||||
if(grid->dy < 1.0) grid->dy= 1.0;
|
if (grid->dy < 1.0f) grid->dy= 1.0f;
|
||||||
if(grid->machty<1) grid->machty= 1;
|
if (grid->powery < 1) grid->powery= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
|
grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
|
||||||
if(v2d->cur.xmin<0.0) grid->startx-= grid->dx;
|
if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
|
||||||
|
|
||||||
grid->starty= (v2d->cur.ymin-fmod(v2d->cur.ymin, grid->dy));
|
grid->starty= (v2d->cur.ymin-fmod(v2d->cur.ymin, grid->dy));
|
||||||
if(v2d->cur.ymin<0.0) grid->starty-= grid->dy;
|
if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
|
||||||
|
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Draw gridlines in the given 2d-region */
|
||||||
void UI_view2d_draw_grid(const bContext *C, View2D *v2d, View2DGrid *grid, int flag)
|
void UI_view2d_draw_grid(const bContext *C, View2D *v2d, View2DGrid *grid, int flag)
|
||||||
{
|
{
|
||||||
float vec1[2], vec2[2];
|
float vec1[2], vec2[2];
|
||||||
int a, step;
|
int a, step;
|
||||||
|
|
||||||
if(flag & V2D_VERTICAL_LINES) {
|
/* vertical lines */
|
||||||
/* vertical lines */
|
if (flag & V2D_VERTICAL_LINES) {
|
||||||
|
/* initialise initial settings */
|
||||||
vec1[0]= vec2[0]= grid->startx;
|
vec1[0]= vec2[0]= grid->startx;
|
||||||
vec1[1]= grid->starty;
|
vec1[1]= grid->starty;
|
||||||
vec2[1]= v2d->cur.ymax;
|
vec2[1]= v2d->cur.ymax;
|
||||||
|
|
||||||
step= (v2d->mask.xmax - v2d->mask.xmin+1)/IPOSTEP;
|
/* minor gridlines */
|
||||||
|
step= (v2d->mask.xmax - v2d->mask.xmin + 1) / MINGRIDSTEP;
|
||||||
|
|
||||||
UI_ThemeColor(TH_GRID);
|
UI_ThemeColor(TH_GRID);
|
||||||
|
|
||||||
for(a=0; a<step; a++) {
|
for (a=0; a<step; a++) {
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2fv(vec1); glVertex2fv(vec2);
|
glVertex2fv(vec1);
|
||||||
|
glVertex2fv(vec2);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
vec2[0]= vec1[0]+= grid->dx;
|
vec2[0]= vec1[0]+= grid->dx;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2[0]= vec1[0]-= 0.5*grid->dx;
|
/* major gridlines */
|
||||||
|
vec2[0]= vec1[0]-= 0.5f*grid->dx;
|
||||||
|
|
||||||
UI_ThemeColorShade(TH_GRID, 16);
|
UI_ThemeColorShade(TH_GRID, 16);
|
||||||
|
|
||||||
step++;
|
step++;
|
||||||
for(a=0; a<=step; a++) {
|
for (a=0; a<=step; a++) {
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2fv(vec1); glVertex2fv(vec2);
|
glVertex2fv(vec1);
|
||||||
|
glVertex2fv(vec2);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
vec2[0]= vec1[0]-= grid->dx;
|
vec2[0]= vec1[0]-= grid->dx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag & V2D_HORIZONTAL_LINES) {
|
/* horizontal lines */
|
||||||
/* horizontal lines */
|
if (flag & V2D_HORIZONTAL_LINES) {
|
||||||
|
/* only major gridlines */
|
||||||
vec1[0]= grid->startx;
|
vec1[0]= grid->startx;
|
||||||
vec1[1]= vec2[1]= grid->starty;
|
vec1[1]= vec2[1]= grid->starty;
|
||||||
vec2[0]= v2d->cur.xmax;
|
vec2[0]= v2d->cur.xmax;
|
||||||
|
|
||||||
step= (C->area->winy+1)/IPOSTEP;
|
step= (v2d->mask.ymax - v2d->mask.ymax + 1) / MINGRIDSTEP;
|
||||||
|
|
||||||
UI_ThemeColor(TH_GRID);
|
UI_ThemeColor(TH_GRID);
|
||||||
for(a=0; a<=step; a++) {
|
for (a=0; a<=step; a++) {
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2fv(vec1); glVertex2fv(vec2);
|
glVertex2fv(vec1);
|
||||||
|
glVertex2fv(vec2);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
vec2[1]= vec1[1]+= grid->dy;
|
vec2[1]= vec1[1]+= grid->dy;
|
||||||
}
|
}
|
||||||
vec2[1]= vec1[1]-= 0.5*grid->dy;
|
|
||||||
|
vec2[1]= vec1[1]-= 0.5f*grid->dy;
|
||||||
step++;
|
step++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Axes are drawn as darker lines */
|
||||||
UI_ThemeColorShade(TH_GRID, -50);
|
UI_ThemeColorShade(TH_GRID, -50);
|
||||||
|
|
||||||
if(flag & V2D_HORIZONTAL_AXIS) {
|
/* horizontal axis */
|
||||||
/* horizontal axis */
|
if (flag & V2D_HORIZONTAL_AXIS) {
|
||||||
vec1[0]= v2d->cur.xmin;
|
vec1[0]= v2d->cur.xmin;
|
||||||
vec2[0]= v2d->cur.xmax;
|
vec2[0]= v2d->cur.xmax;
|
||||||
vec1[1]= vec2[1]= 0.0;
|
vec1[1]= vec2[1]= 0.0f;
|
||||||
|
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
|
glVertex2fv(vec1);
|
||||||
glVertex2fv(vec1);
|
glVertex2fv(vec2);
|
||||||
glVertex2fv(vec2);
|
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag & V2D_VERTICAL_AXIS) {
|
/* vertical axis */
|
||||||
/* vertical axis */
|
if (flag & V2D_VERTICAL_AXIS) {
|
||||||
vec1[1]= v2d->cur.ymin;
|
vec1[1]= v2d->cur.ymin;
|
||||||
vec2[1]= v2d->cur.ymax;
|
vec2[1]= v2d->cur.ymax;
|
||||||
vec1[0]= vec2[0]= 0.0;
|
vec1[0]= vec2[0]= 0.0f;
|
||||||
|
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2fv(vec1); glVertex2fv(vec2);
|
glVertex2fv(vec1);
|
||||||
|
glVertex2fv(vec2);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* free temporary memory used for drawing grid */
|
||||||
void UI_view2d_free_grid(View2DGrid *grid)
|
void UI_view2d_free_grid(View2DGrid *grid)
|
||||||
{
|
{
|
||||||
MEM_freeN(grid);
|
MEM_freeN(grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Coordinate conversion */
|
/* *********************************************************************** */
|
||||||
|
/* Coordinate Conversions */
|
||||||
|
|
||||||
|
/* Convert from screen/region space to 2d-View space
|
||||||
|
*
|
||||||
|
* - x,y = coordinates to convert
|
||||||
|
* - viewx,viewy = resultant coordinates
|
||||||
|
*/
|
||||||
void UI_view2d_region_to_view(View2D *v2d, short x, short y, float *viewx, float *viewy)
|
void UI_view2d_region_to_view(View2D *v2d, short x, short y, float *viewx, float *viewy)
|
||||||
{
|
{
|
||||||
float div, ofs;
|
float div, ofs;
|
||||||
|
|
||||||
if(viewx) {
|
if (viewx) {
|
||||||
div= v2d->mask.xmax-v2d->mask.xmin;
|
div= v2d->mask.xmax - v2d->mask.xmin;
|
||||||
ofs= v2d->mask.xmin;
|
ofs= v2d->mask.xmin;
|
||||||
|
|
||||||
*viewx= v2d->cur.xmin+ (v2d->cur.xmax-v2d->cur.xmin)*(x-ofs)/div;
|
*viewx= v2d->cur.xmin + (v2d->cur.xmax-v2d->cur.xmin) * (x - ofs) / div;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(viewy) {
|
if (viewy) {
|
||||||
div= v2d->mask.ymax-v2d->mask.ymin;
|
div= v2d->mask.ymax - v2d->mask.ymin;
|
||||||
ofs= v2d->mask.ymin;
|
ofs= v2d->mask.ymin;
|
||||||
|
|
||||||
*viewy= v2d->cur.ymin+ (v2d->cur.ymax-v2d->cur.ymin)*(y-ofs)/div;
|
*viewy= v2d->cur.ymin + (v2d->cur.ymax - v2d->cur.ymin) * (y - ofs) / div;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert from 2d-View space to screen/region space
|
||||||
|
* - Coordinates are clamped to lie within bounds of region
|
||||||
|
*
|
||||||
|
* - x,y = coordinates to convert
|
||||||
|
* - regionx,regiony = resultant coordinates
|
||||||
|
*/
|
||||||
void UI_view2d_view_to_region(View2D *v2d, float x, float y, short *regionx, short *regiony)
|
void UI_view2d_view_to_region(View2D *v2d, float x, float y, short *regionx, short *regiony)
|
||||||
{
|
{
|
||||||
*regionx= V2D_IS_CLIPPED;
|
/* set initial value in case coordinate lies outside of bounds */
|
||||||
*regiony= V2D_IS_CLIPPED;
|
if (regionx)
|
||||||
|
*regionx= V2D_IS_CLIPPED;
|
||||||
x= (x - v2d->cur.xmin)/(v2d->cur.xmax-v2d->cur.xmin);
|
if (regiony)
|
||||||
y= (x - v2d->cur.ymin)/(v2d->cur.ymax-v2d->cur.ymin);
|
*regiony= V2D_IS_CLIPPED;
|
||||||
|
|
||||||
if(x>=0.0 && x<=1.0) {
|
/* express given coordinates as proportional values */
|
||||||
if(y>=0.0 && y<=1.0) {
|
x= (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
|
||||||
if(regionx)
|
y= (x - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
|
||||||
*regionx= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
|
|
||||||
if(regiony)
|
/* check if values are within bounds */
|
||||||
*regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
|
if ((x>=0.0f) && (x<=1.0f) && (y>=0.0f) && (y<=1.0f)) {
|
||||||
}
|
if (regionx)
|
||||||
|
*regionx= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
|
||||||
|
if (regiony)
|
||||||
|
*regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert from 2d-view space to screen/region space
|
||||||
|
* - Coordinates are NOT clamped to lie within bounds of region
|
||||||
|
*
|
||||||
|
* - x,y = coordinates to convert
|
||||||
|
* - regionx,regiony = resultant coordinates
|
||||||
|
*/
|
||||||
void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx, short *regiony)
|
void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx, short *regiony)
|
||||||
{
|
{
|
||||||
x= (x - v2d->cur.xmin)/(v2d->cur.xmax-v2d->cur.xmin);
|
/* step 1: express given coordinates as proportional values */
|
||||||
y= (x - v2d->cur.ymin)/(v2d->cur.ymax-v2d->cur.ymin);
|
x= (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
|
||||||
|
y= (x - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
|
||||||
x= v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin);
|
|
||||||
y= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
|
/* step 2: convert proportional distances to screen coordinates */
|
||||||
|
x= v2d->mask.xmin + x*(v2d->mask.xmax - v2d->mask.xmin);
|
||||||
if(regionx) {
|
y= v2d->mask.ymin + y*(v2d->mask.ymax - v2d->mask.ymin);
|
||||||
if(x<-32760) *regionx= -32760;
|
|
||||||
else if(x>32760) *regionx= 32760;
|
/* although we don't clamp to lie within region bounds, we must avoid exceeding size of shorts */
|
||||||
|
if (regionx) {
|
||||||
|
if (x < -32760) *regionx= -32760;
|
||||||
|
else if(x > 32760) *regionx= 32760;
|
||||||
else *regionx= x;
|
else *regionx= x;
|
||||||
}
|
}
|
||||||
|
if (regiony) {
|
||||||
if(regiony) {
|
if (y < -32760) *regiony= -32760;
|
||||||
if(y<-32760) *regiony= -32760;
|
else if(y > 32760) *regiony= 32760;
|
||||||
else if(y>32760) *regiony= 32760;
|
|
||||||
else *regiony= y;
|
else *regiony= y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* *********************************************************************** */
|
||||||
|
/* Utilities */
|
||||||
|
|
||||||
|
/* Calculate the scale per-axis of the drawing-area
|
||||||
|
* - Is used to inverse correct drawing of icons, etc. that need to follow view
|
||||||
|
* but not be affected by scale
|
||||||
|
*
|
||||||
|
* - x,y = scale on each axis
|
||||||
|
*/
|
||||||
void UI_view2d_getscale(View2D *v2d, float *x, float *y)
|
void UI_view2d_getscale(View2D *v2d, float *x, float *y)
|
||||||
{
|
{
|
||||||
if (x) *x = (v2d->mask.xmax-v2d->mask.xmin)/(v2d->cur.xmax-v2d->cur.xmin);
|
if (x) *x = (v2d->mask.xmax - v2d->mask.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
|
||||||
if (y) *y = (v2d->mask.ymax-v2d->mask.ymin)/(v2d->cur.ymax-v2d->cur.ymin);
|
if (y) *y = (v2d->mask.ymax - v2d->mask.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,14 +178,17 @@ typedef struct ARegion {
|
|||||||
#define WIN_BACK_OK 2
|
#define WIN_BACK_OK 2
|
||||||
#define WIN_EQUAL 3
|
#define WIN_EQUAL 3
|
||||||
|
|
||||||
#define L_SCROLL 1 /* left scrollbar */
|
/* scrollbar flags for View2D */
|
||||||
|
/* left scrollbar */
|
||||||
|
#define L_SCROLL 1
|
||||||
#define R_SCROLL 2
|
#define R_SCROLL 2
|
||||||
#define VERT_SCROLL 3
|
#define VERT_SCROLL 3
|
||||||
#define T_SCROLL 4
|
#define T_SCROLL 4
|
||||||
#define B_SCROLL 8
|
#define B_SCROLL 8
|
||||||
#define HOR_SCROLL 12
|
#define HOR_SCROLL 12
|
||||||
#define B_SCROLLO 16 /* special hack for outliner hscroll - prevent hanging */
|
/* special hack for outliner hscroll - prevent hanging older versions of Blender */
|
||||||
#define HOR_SCROLLO 20 /* in older versions of blender */
|
#define B_SCROLLO 16
|
||||||
|
#define HOR_SCROLLO 20
|
||||||
|
|
||||||
/* Panel->snap - for snapping to screen edges */
|
/* Panel->snap - for snapping to screen edges */
|
||||||
#define PNL_SNAP_NONE 0
|
#define PNL_SNAP_NONE 0
|
||||||
|
|||||||
@@ -471,9 +471,6 @@ typedef struct SpaceImaSel {
|
|||||||
#define MOVIEFILE_ICON 1024 /* movie file that preview can't load */
|
#define MOVIEFILE_ICON 1024 /* movie file that preview can't load */
|
||||||
#define FOLDERFILE 2048 /* represents folders for filtering */
|
#define FOLDERFILE 2048 /* represents folders for filtering */
|
||||||
|
|
||||||
#define SCROLLH 16 /* height scrollbar */
|
|
||||||
#define SCROLLB 16 /* width scrollbar */
|
|
||||||
|
|
||||||
/* SpaceImage->mode */
|
/* SpaceImage->mode */
|
||||||
#define SI_TEXTURE 0
|
#define SI_TEXTURE 0
|
||||||
#define SI_SHOW 1
|
#define SI_SHOW 1
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
*
|
*
|
||||||
* The Original Code is: all of this file.
|
* The Original Code is: all of this file.
|
||||||
*
|
*
|
||||||
* Contributor(s): none yet.
|
* Contributor(s): Joshua Leung
|
||||||
*
|
*
|
||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
@@ -33,32 +33,46 @@
|
|||||||
|
|
||||||
#include "DNA_vec_types.h"
|
#include "DNA_vec_types.h"
|
||||||
|
|
||||||
|
/* ---------------------------------- */
|
||||||
|
|
||||||
|
/* View 2D data - stored per region */
|
||||||
typedef struct View2D {
|
typedef struct View2D {
|
||||||
rctf tot, cur;
|
rctf tot, cur;
|
||||||
rcti vert, hor, mask;
|
rcti vert, hor, mask;
|
||||||
|
|
||||||
float min[2], max[2];
|
float min[2], max[2];
|
||||||
float minzoom, maxzoom;
|
float minzoom, maxzoom;
|
||||||
short scroll, keeptot;
|
|
||||||
|
short scroll, keeptot; /* scroll - scrollbars to display (bitflag); keeptot - 'tot' rect */
|
||||||
short keepaspect, keepzoom;
|
short keepaspect, keepzoom;
|
||||||
short oldwinx, oldwiny;
|
short oldwinx, oldwiny;
|
||||||
int flag;
|
|
||||||
|
|
||||||
float cursor[2]; /* only used in the UV view for now*/
|
int flag; /* settings */
|
||||||
short around;
|
|
||||||
|
float cursor[2]; /* only used in the UV view for now (for 2D-cursor) */
|
||||||
|
short around; /* pivot point for transforms (rotate and scale) */
|
||||||
char pad[6];
|
char pad[6];
|
||||||
} View2D;
|
} View2D;
|
||||||
|
|
||||||
|
/* ---------------------------------- */
|
||||||
|
|
||||||
/* v2d->keepzoom */
|
/* v2d->keepzoom */
|
||||||
#define V2D_KEEPZOOM 0x0001
|
#define V2D_KEEPZOOM 0x0001
|
||||||
#define V2D_LOCKZOOM_X 0x0100
|
#define V2D_LOCKZOOM_X 0x0100
|
||||||
#define V2D_LOCKZOOM_Y 0x0200
|
#define V2D_LOCKZOOM_Y 0x0200
|
||||||
|
|
||||||
/* event codes for locking function */
|
/* event codes for locking function */
|
||||||
#define V2D_LOCK_COPY 1
|
#define V2D_LOCK_COPY 1
|
||||||
#define V2D_LOCK_REDRAW 2
|
#define V2D_LOCK_REDRAW 2
|
||||||
|
|
||||||
/* v2d->flag */
|
/* v2d->flag */
|
||||||
#define V2D_VIEWLOCK 1
|
#define V2D_VIEWLOCK (1<<0)
|
||||||
|
|
||||||
|
/* scrollbar thickness */
|
||||||
|
/* height */
|
||||||
|
#define SCROLLH 16
|
||||||
|
/* width */
|
||||||
|
#define SCROLLB 16
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user