4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
23 * Contributor(s): Blender Foundation, Joshua Leung
25 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_view2d_types.h"
39 #include "BLI_blenlib.h"
41 #include "BKE_context.h"
42 #include "BKE_global.h"
43 #include "BKE_utildefines.h"
48 #include "BIF_glutil.h"
52 #include "ED_screen.h"
54 #include "UI_interface.h"
55 #include "UI_resources.h"
56 #include "UI_view2d.h"
58 #include "interface_intern.h"
60 /* *********************************************************************** */
62 /* helper to allow scrollbars to dynamically hide */
63 static int view2d_scroll_mapped(int scroll)
65 if(scroll & V2D_SCROLL_HORIZONTAL_HIDE)
66 scroll &= ~(V2D_SCROLL_HORIZONTAL);
67 if(scroll & V2D_SCROLL_VERTICAL_HIDE)
68 scroll &= ~(V2D_SCROLL_VERTICAL);
72 /* called each time cur changes, to dynamically update masks */
73 static void view2d_masks(View2D *v2d)
77 /* mask - view frame */
78 v2d->mask.xmin= v2d->mask.ymin= 0;
79 v2d->mask.xmax= v2d->winx - 1; /* -1 yes! masks are pixels */
80 v2d->mask.ymax= v2d->winy - 1;
83 v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
85 if (v2d->scroll & V2D_SCROLL_HORIZONTAL)
86 if(!(v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL))
87 if (v2d->tot.xmax-v2d->tot.xmin <= v2d->cur.xmax-v2d->cur.xmin)
88 v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
89 if (v2d->scroll & V2D_SCROLL_VERTICAL)
90 if(!(v2d->scroll & V2D_SCROLL_SCALE_VERTICAL))
91 if (v2d->tot.ymax-v2d->tot.ymin <= v2d->cur.ymax-v2d->cur.ymin)
92 v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
94 scroll= view2d_scroll_mapped(v2d->scroll);
96 /* scrollers shrink mask area, but should be based off regionsize
97 * - they can only be on one to two edges of the region they define
98 * - if they overlap, they must not occupy the corners (which are reserved for other widgets)
101 /* vertical scroller */
102 if (scroll & V2D_SCROLL_LEFT) {
103 /* on left-hand edge of region */
104 v2d->vert= v2d->mask;
105 v2d->vert.xmax= V2D_SCROLL_WIDTH;
106 v2d->mask.xmin= v2d->vert.xmax + 1;
108 else if (scroll & V2D_SCROLL_RIGHT) {
109 /* on right-hand edge of region */
110 v2d->vert= v2d->mask;
111 v2d->vert.xmax++; /* one pixel extra... was leaving a minor gap... */
112 v2d->vert.xmin= v2d->vert.xmax - V2D_SCROLL_WIDTH;
113 v2d->mask.xmax= v2d->vert.xmin - 1;
116 /* horizontal scroller */
117 if (scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O)) {
118 /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */
120 v2d->hor.ymax= V2D_SCROLL_HEIGHT;
121 v2d->mask.ymin= v2d->hor.ymax + 1;
123 else if (scroll & V2D_SCROLL_TOP) {
124 /* on upper edge of region */
126 v2d->hor.ymin= v2d->hor.ymax - V2D_SCROLL_HEIGHT;
127 v2d->mask.ymax= v2d->hor.ymin - 1;
130 /* adjust vertical scroller if there's a horizontal scroller, to leave corner free */
131 if (scroll & V2D_SCROLL_VERTICAL) {
132 /* just set y min/max for vertical scroller to y min/max of mask as appropriate */
133 if (scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O)) {
134 /* on bottom edge of region (V2D_SCROLL_BOTTOM_O is outliner, the other is for standard) */
135 v2d->vert.ymin= v2d->mask.ymin;
137 else if (scroll & V2D_SCROLL_TOP) {
138 /* on upper edge of region */
139 v2d->vert.ymax= v2d->mask.ymax;
146 /* Refresh and Validation */
148 /* Initialise all relevant View2D data (including view rects if first time) and/or refresh mask sizes after view resize
149 * - for some of these presets, it is expected that the region will have defined some
150 * additional settings necessary for the customisation of the 2D viewport to its requirements
151 * - this function should only be called from region init() callbacks, where it is expected that
152 * this is called before UI_view2d_size_update(), as this one checks that the rects are properly initialised.
154 void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
156 short tot_changed= 0;
158 /* initialise data if there is a need for such */
159 if ((v2d->flag & V2D_IS_INITIALISED) == 0) {
160 /* set initialised flag so that View2D doesn't get reinitialised next time again */
161 v2d->flag |= V2D_IS_INITIALISED;
163 /* see eView2D_CommonViewTypes in UI_view2d.h for available view presets */
165 /* 'standard view' - optimum setup for 'standard' view behaviour, that should be used new views as basis for their
166 * own unique View2D settings, which should be used instead of this in most cases...
168 case V2D_COMMONVIEW_STANDARD:
170 /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
171 v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM);
173 v2d->maxzoom= 1000.0f;
175 /* tot rect and cur should be same size, and aligned using 'standard' OpenGL coordinates for now
176 * - region can resize 'tot' later to fit other data
177 * - keeptot is only within bounds, as strict locking is not that critical
178 * - view is aligned for (0,0) -> (winx-1, winy-1) setup
180 v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
181 v2d->keeptot= V2D_KEEPTOT_BOUNDS;
183 v2d->tot.xmin= v2d->tot.ymin= 0.0f;
184 v2d->tot.xmax= (float)(winx - 1);
185 v2d->tot.ymax= (float)(winy - 1);
189 /* scrollers - should we have these by default? */
190 // XXX for now, we don't override this, or set it either!
194 /* 'list/channel view' - zoom, aspect ratio, and alignment restrictions are set here */
195 case V2D_COMMONVIEW_LIST:
197 /* zoom + aspect ratio are locked */
198 v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
199 v2d->minzoom= v2d->maxzoom= 1.0f;
201 /* tot rect has strictly regulated placement, and must only occur in +/- quadrant */
202 v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
203 v2d->keeptot = V2D_KEEPTOT_STRICT;
206 /* scroller settings are currently not set here... that is left for regions... */
210 /* 'header' regions - zoom, aspect ratio, alignment, and panning restrictions are set here */
211 case V2D_COMMONVIEW_HEADER:
213 /* zoom + aspect ratio are locked */
214 v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
215 v2d->minzoom= v2d->maxzoom= 1.0f;
216 v2d->min[0]= v2d->max[0]= (float)(winx-1);
217 v2d->min[1]= v2d->max[1]= (float)(winy-1);
219 /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
220 v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
221 v2d->keeptot = V2D_KEEPTOT_STRICT;
224 /* panning in y-axis is prohibited */
225 v2d->keepofs= V2D_LOCKOFS_Y;
227 /* absolutely no scrollers allowed */
230 /* pixel offsets need to be applied for smooth UI controls */
231 v2d->flag |= (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
235 /* panels view, with horizontal/vertical align */
236 case V2D_COMMONVIEW_PANELS_UI:
238 /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
239 v2d->keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM);
243 v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
244 v2d->keeptot= V2D_KEEPTOT_BOUNDS;
250 v2d->tot.ymin= -winy;
256 /* other view types are completely defined using their own settings already */
258 /* we don't do anything here, as settings should be fine, but just make sure that rect */
263 /* store view size */
270 /* set 'tot' rect before setting cur? */
272 UI_view2d_totRect_set(v2d, winx, winy);
274 UI_view2d_curRect_validate(v2d);
278 /* Ensure View2D rects remain in a viable configuration
279 * - cur is not allowed to be: larger than max, smaller than min, or outside of tot
281 // XXX pre2.5 -> this used to be called test_view2d()
282 void UI_view2d_curRect_validate(View2D *v2d)
284 float totwidth, totheight, curwidth, curheight, width, height;
288 /* use mask as size of region that View2D resides in, as it takes into account scrollbars already */
289 winx= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
290 winy= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
292 /* get pointers to rcts for less typing */
296 /* we must satisfy the following constraints (in decreasing order of importance):
297 * - alignment restrictions are respected
298 * - cur must not fall outside of tot
299 * - axis locks (zoom and offset) must be maintained
300 * - zoom must not be excessive (check either sizes or zoom values)
301 * - aspect ratio should be respected (NOTE: this is quite closely realted to zoom too)
304 /* Step 1: if keepzoom, adjust the sizes of the rects only
305 * - firstly, we calculate the sizes of the rects
306 * - curwidth and curheight are saved as reference... modify width and height values here
308 totwidth= tot->xmax - tot->xmin;
309 totheight= tot->ymax - tot->ymin;
310 curwidth= width= cur->xmax - cur->xmin;
311 curheight= height= cur->ymax - cur->ymin;
313 /* if zoom is locked, size on the appropriate axis is reset to mask size */
314 if (v2d->keepzoom & V2D_LOCKZOOM_X)
316 if (v2d->keepzoom & V2D_LOCKZOOM_Y)
319 /* keepzoom (V2D_KEEPZOOM set), indicates that zoom level on each axis must not exceed limits
320 * NOTE: in general, it is not expected that the lock-zoom will be used in conjunction with this
322 if (v2d->keepzoom & V2D_KEEPZOOM) {
325 /* check if excessive zoom on x-axis */
326 if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
328 if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
329 fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
334 /* check if excessive zoom on y-axis */
335 if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0) {
337 if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
338 fac= (zoom < v2d->minzoom) ? (zoom / v2d->minzoom) : (zoom / v2d->maxzoom);
344 /* make sure sizes don't exceed that of the min/max sizes (even though we're not doing zoom clamping) */
345 CLAMP(width, v2d->min[0], v2d->max[0]);
346 CLAMP(height, v2d->min[1], v2d->max[1]);
349 /* check if we should restore aspect ratio (if view size changed) */
350 if (v2d->keepzoom & V2D_KEEPASPECT) {
351 short do_x=0, do_y=0, do_cur, do_win;
352 float curRatio, winRatio;
354 /* when a window edge changes, the aspect ratio can't be used to
355 * find which is the best new 'cur' rect. thats why it stores 'old'
357 if (winx != v2d->oldwinx) do_x= 1;
358 if (winy != v2d->oldwiny) do_y= 1;
360 curRatio= height / width;
361 winRatio= winy / winx;
363 /* both sizes change (area/region maximised) */
366 /* here is 1,1 case, so all others must be 0,0 */
367 if (ABS(winx - v2d->oldwinx) > ABS(winy - v2d->oldwiny)) do_y= 0;
370 else if (winRatio > 1.0f) do_x= 0;
377 if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winx != v2d->oldwinx)) {
378 /* special exception for Outliner (and later channel-lists):
379 * - The view may be moved left to avoid contents being pushed out of view when view shrinks.
380 * - The keeptot code will make sure cur->xmin will not be less than tot->xmin (which cannot be allowed)
381 * - width is not adjusted for changed ratios here...
383 if (winx < v2d->oldwinx) {
384 float temp = v2d->oldwinx - winx;
389 /* width does not get modified, as keepaspect here is just set to make
390 * sure visible area adjusts to changing view shape!
395 /* portrait window: correct for x */
396 width= height / winRatio;
400 if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winy != v2d->oldwiny)) {
401 /* special exception for Outliner (and later channel-lists):
402 * - Currently, no actions need to be taken here...
405 if (winy < v2d->oldwiny) {
406 float temp = v2d->oldwiny - winy;
414 /* landscape window: correct for y */
415 height = width * winRatio;
419 /* store region size for next time */
420 v2d->oldwinx= (short)winx;
421 v2d->oldwiny= (short)winy;
424 /* Step 2: apply new sizes to cur rect, but need to take into account alignment settings here... */
425 if ((width != curwidth) || (height != curheight)) {
428 /* resize from centerpoint */
429 if (width != curwidth) {
430 if (v2d->keepofs & V2D_LOCKOFS_X) {
431 cur->xmax += width - (cur->xmax - cur->xmin);
434 temp= (cur->xmax + cur->xmin) * 0.5f;
437 cur->xmin = temp - dh;
438 cur->xmax = temp + dh;
441 if (height != curheight) {
442 if (v2d->keepofs & V2D_LOCKOFS_Y) {
443 cur->ymax += height - (cur->ymax - cur->ymin);
446 temp= (cur->ymax + cur->ymin) * 0.5f;
449 cur->ymin = temp - dh;
450 cur->ymax = temp + dh;
455 /* Step 3: adjust so that it doesn't fall outside of bounds of 'tot' */
459 /* recalculate extents of cur */
460 curwidth= cur->xmax - cur->xmin;
461 curheight= cur->ymax - cur->ymin;
464 if ( (curwidth > totwidth) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_X)) ) {
465 /* if zoom doesn't have to be maintained, just clamp edges */
466 if (cur->xmin < tot->xmin) cur->xmin= tot->xmin;
467 if (cur->xmax > tot->xmax) cur->xmax= tot->xmax;
469 else if (v2d->keeptot == V2D_KEEPTOT_STRICT) {
470 /* This is an exception for the outliner (and later channel-lists, headers)
471 * - must clamp within tot rect (absolutely no excuses)
472 * --> therefore, cur->xmin must not be less than tot->xmin
474 if (cur->xmin < tot->xmin) {
475 /* move cur across so that it sits at minimum of tot */
476 temp= tot->xmin - cur->xmin;
481 else if (cur->xmax > tot->xmax) {
482 /* - only offset by difference of cur-xmax and tot-xmax if that would not move
483 * cur-xmin to lie past tot-xmin
484 * - otherwise, simply shift to tot-xmin???
486 temp= cur->xmax - tot->xmax;
488 if ((cur->xmin - temp) < tot->xmin) {
489 /* only offset by difference from cur-min and tot-min */
490 temp= cur->xmin - tot->xmin;
502 /* This here occurs when:
503 * - width too big, but maintaining zoom (i.e. widths cannot be changed)
504 * - width is OK, but need to check if outside of boundaries
506 * So, resolution is to just shift view by the gap between the extremities.
507 * We favour moving the 'minimum' across, as that's origin for most things
508 * (XXX - in the past, max was favoured... if there are bugs, swap!)
510 if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
511 /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
512 temp= (tot->ymax + tot->ymin) * 0.5f;
513 diff= curheight * 0.5f;
515 cur->ymin= temp - diff;
516 cur->ymax= temp + diff;
518 else if (cur->xmin < tot->xmin) {
519 /* move cur across so that it sits at minimum of tot */
520 temp= tot->xmin - cur->xmin;
525 else if (cur->xmax > tot->xmax) {
526 /* - only offset by difference of cur-xmax and tot-xmax if that would not move
527 * cur-xmin to lie past tot-xmin
528 * - otherwise, simply shift to tot-xmin???
530 temp= cur->xmax - tot->xmax;
532 if ((cur->xmin - temp) < tot->xmin) {
533 /* only offset by difference from cur-min and tot-min */
534 temp= cur->xmin - tot->xmin;
547 if ( (curheight > totheight) && !(v2d->keepzoom & (V2D_KEEPZOOM|V2D_LOCKZOOM_Y)) ) {
548 /* if zoom doesn't have to be maintained, just clamp edges */
549 if (cur->ymin < tot->ymin) cur->ymin= tot->ymin;
550 if (cur->ymax > tot->ymax) cur->ymax= tot->ymax;
553 /* This here occurs when:
554 * - height too big, but maintaining zoom (i.e. heights cannot be changed)
555 * - height is OK, but need to check if outside of boundaries
557 * So, resolution is to just shift view by the gap between the extremities.
558 * We favour moving the 'minimum' across, as that's origin for most things
560 if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
561 /* outside boundaries on both sides, so take middle-point of tot, and place in balanced way */
562 temp= (tot->ymax + tot->ymin) * 0.5f;
563 diff= curheight * 0.5f;
565 cur->ymin= temp - diff;
566 cur->ymax= temp + diff;
568 else if (cur->ymin < tot->ymin) {
569 /* there's still space remaining, so shift up */
570 temp= tot->ymin - cur->ymin;
575 else if (cur->ymax > tot->ymax) {
576 /* there's still space remaining, so shift down */
577 temp= cur->ymax - tot->ymax;
585 /* Step 4: Make sure alignment restrictions are respected */
587 /* If alignment flags are set (but keeptot is not), they must still be respected, as although
588 * they don't specify any particular bounds to stay within, they do define ranges which are
591 * Here, we only check to make sure that on each axis, the 'cur' rect doesn't stray into these
592 * invalid zones, otherwise we offset.
595 /* handle width - posx and negx flags are mutually exclusive, so watch out */
596 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
597 /* width is in negative-x half */
598 if (v2d->cur.xmax > 0) {
599 v2d->cur.xmin -= v2d->cur.xmax;
603 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
604 /* width is in positive-x half */
605 if (v2d->cur.xmin < 0) {
606 v2d->cur.xmax -= v2d->cur.xmin;
607 v2d->cur.xmin = 0.0f;
611 /* handle height - posx and negx flags are mutually exclusive, so watch out */
612 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
613 /* height is in negative-y half */
614 if (v2d->cur.ymax > 0) {
615 v2d->cur.ymin -= v2d->cur.ymax;
616 v2d->cur.ymax = 0.0f;
619 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
620 /* height is in positive-y half */
621 if (v2d->cur.ymin < 0) {
622 v2d->cur.ymax -= v2d->cur.ymin;
623 v2d->cur.ymin = 0.0f;
632 /* ------------------ */
634 /* Called by menus to activate it, or by view2d operators to make sure 'related' views stay in synchrony */
635 void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
640 /* don't continue if no view syncing to be done */
641 if ((v2dcur->flag & (V2D_VIEWSYNC_SCREEN_TIME|V2D_VIEWSYNC_AREA_VERTICAL)) == 0)
644 /* check if doing within area syncing (i.e. channels/vertical) */
645 if ((v2dcur->flag & V2D_VIEWSYNC_AREA_VERTICAL) && (area)) {
646 for (ar= area->regionbase.first; ar; ar= ar->next) {
647 /* don't operate on self */
648 if (v2dcur != &ar->v2d) {
649 /* only if view has vertical locks enabled */
650 if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) {
651 if (flag == V2D_LOCK_COPY) {
652 /* other views with locks on must copy active */
653 ar->v2d.cur.ymin= v2dcur->cur.ymin;
654 ar->v2d.cur.ymax= v2dcur->cur.ymax;
656 else { /* V2D_LOCK_SET */
657 /* active must copy others */
658 v2dcur->cur.ymin= ar->v2d.cur.ymin;
659 v2dcur->cur.ymax= ar->v2d.cur.ymax;
662 /* region possibly changed, so refresh */
663 ED_region_tag_redraw(ar);
669 /* check if doing whole screen syncing (i.e. time/horizontal) */
670 if ((v2dcur->flag & V2D_VIEWSYNC_SCREEN_TIME) && (screen)) {
671 for (sa= screen->areabase.first; sa; sa= sa->next) {
672 for (ar= sa->regionbase.first; ar; ar= ar->next) {
673 /* don't operate on self */
674 if (v2dcur != &ar->v2d) {
675 /* only if view has horizontal locks enabled */
676 if (ar->v2d.flag & V2D_VIEWSYNC_SCREEN_TIME) {
677 if (flag == V2D_LOCK_COPY) {
678 /* other views with locks on must copy active */
679 ar->v2d.cur.xmin= v2dcur->cur.xmin;
680 ar->v2d.cur.xmax= v2dcur->cur.xmax;
682 else { /* V2D_LOCK_SET */
683 /* active must copy others */
684 v2dcur->cur.xmin= ar->v2d.cur.xmin;
685 v2dcur->cur.xmax= ar->v2d.cur.xmax;
688 /* region possibly changed, so refresh */
689 ED_region_tag_redraw(ar);
698 /* Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot)
699 * This does not take into account if zooming the view on an axis will improve the view (if allowed)
701 void UI_view2d_curRect_reset (View2D *v2d)
705 /* assume width and height of 'cur' rect by default, should be same size as mask */
706 width= (float)(v2d->mask.xmax - v2d->mask.xmin + 1);
707 height= (float)(v2d->mask.ymax - v2d->mask.ymin + 1);
709 /* handle width - posx and negx flags are mutually exclusive, so watch out */
710 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
711 /* width is in negative-x half */
712 v2d->cur.xmin= (float)-width;
715 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
716 /* width is in positive-x half */
718 v2d->cur.xmax= (float)width;
721 /* width is centered around x==0 */
722 const float dx= (float)width / 2.0f;
728 /* handle height - posx and negx flags are mutually exclusive, so watch out */
729 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
730 /* height is in negative-y half */
731 v2d->cur.ymin= (float)-height;
734 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
735 /* height is in positive-y half */
737 v2d->cur.ymax= (float)height;
740 /* height is centered around y==0 */
741 const float dy= (float)height / 2.0f;
748 /* ------------------ */
750 /* Change the size of the maximum viewable area (i.e. 'tot' rect) */
751 void UI_view2d_totRect_set (View2D *v2d, int width, int height)
753 int scroll= view2d_scroll_mapped(v2d->scroll);
755 /* don't do anything if either value is 0 */
760 if(scroll & V2D_SCROLL_HORIZONTAL)
761 width -= V2D_SCROLL_WIDTH;
762 if(scroll & V2D_SCROLL_VERTICAL)
763 height -= V2D_SCROLL_HEIGHT;
765 if (ELEM3(0, v2d, width, height)) {
766 printf("Error: View2D totRect set exiting: v2d=%p width=%d height=%d \n", v2d, width, height); // XXX temp debug info
770 /* handle width - posx and negx flags are mutually exclusive, so watch out */
771 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
772 /* width is in negative-x half */
773 v2d->tot.xmin= (float)-width;
776 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
777 /* width is in positive-x half */
779 v2d->tot.xmax= (float)width;
782 /* width is centered around x==0 */
783 const float dx= (float)width / 2.0f;
789 /* handle height - posx and negx flags are mutually exclusive, so watch out */
790 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
791 /* height is in negative-y half */
792 v2d->tot.ymin= (float)-height;
795 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
796 /* height is in positive-y half */
798 v2d->tot.ymax= (float)height;
801 /* height is centered around y==0 */
802 const float dy= (float)height / 2.0f;
808 /* make sure that 'cur' rect is in a valid state as a result of these changes */
809 UI_view2d_curRect_validate(v2d);
812 /* *********************************************************************** */
813 /* View Matrix Setup */
815 /* mapping function to ensure 'cur' draws extended over the area where sliders are */
816 static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
818 *curmasked= v2d->cur;
820 if (view2d_scroll_mapped(v2d->scroll)) {
821 float dx= (v2d->cur.xmax-v2d->cur.xmin)/((float)(v2d->mask.xmax-v2d->mask.xmin+1));
822 float dy= (v2d->cur.ymax-v2d->cur.ymin)/((float)(v2d->mask.ymax-v2d->mask.ymin+1));
824 if (v2d->mask.xmin != 0)
825 curmasked->xmin -= dx*(float)v2d->mask.xmin;
826 if (v2d->mask.xmax+1 != v2d->winx)
827 curmasked->xmax += dx*(float)(v2d->winx - v2d->mask.xmax-1);
829 if (v2d->mask.ymin != 0)
830 curmasked->ymin -= dy*(float)v2d->mask.ymin;
831 if (v2d->mask.ymax+1 != v2d->winy)
832 curmasked->ymax += dy*(float)(v2d->winy - v2d->mask.ymax-1);
837 /* Set view matrices to use 'cur' rect as viewing frame for View2D drawing */
838 void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
843 /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing,
844 * but only applied where requsted
846 /* XXX ton: fix this! */
847 xofs= 0.0; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
848 yofs= 0.0; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
850 /* XXX brecht: instead of zero at least use a tiny offset, otherwise
851 * pixel rounding is effectively random due to float inaccuracy */
855 /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
856 view2d_map_cur_using_mask(v2d, &curmasked);
858 /* set matrix on all appropriate axes */
859 wmOrtho2(curmasked.xmin-xofs, curmasked.xmax-xofs, curmasked.ymin-yofs, curmasked.ymax-yofs);
861 /* XXX is this necessary? */
865 /* Set view matrices to only use one axis of 'cur' only
866 * - xaxis = if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x)
868 void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
870 ARegion *ar= CTX_wm_region(C);
874 /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing,
875 * but only applied where requsted
878 xofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
879 yofs= 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
881 /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
882 view2d_map_cur_using_mask(v2d, &curmasked);
884 /* only set matrix with 'cur' coordinates on relevant axes */
886 wmOrtho2(curmasked.xmin-xofs, curmasked.xmax-xofs, -yofs, ar->winy-yofs);
888 wmOrtho2(-xofs, ar->winx-xofs, curmasked.ymin-yofs, curmasked.ymax-yofs);
890 /* XXX is this necessary? */
895 /* Restore view matrices after drawing */
896 void UI_view2d_view_restore(const bContext *C)
898 ED_region_pixelspace(CTX_wm_region(C));
901 /* *********************************************************************** */
904 /* minimum pixels per gridstep */
905 #define MINGRIDSTEP 35
907 /* View2DGrid is typedef'd in UI_view2d.h */
909 float dx, dy; /* stepsize (in pixels) between gridlines */
910 float startx, starty; /* initial coordinates to start drawing grid from */
911 int powerx, powery; /* step as power of 10 */
914 /* --------------- */
916 /* try to write step as a power of 10 */
917 static void step_to_grid(float *step, int *power, int unit)
919 const float loga= (float)log10(*step);
924 rem= loga - (*power);
925 rem= (float)pow(10.0, rem);
928 if (rem < 0.2f) rem= 0.2f;
929 else if(rem < 0.5f) rem= 0.5f;
932 *step= rem * (float)pow(10.0, (*power));
934 /* for frames, we want 1.0 frame intervals only */
935 if (unit == V2D_UNIT_FRAMES) {
940 /* prevents printing 1.0 2.0 3.0 etc */
941 if (rem == 1.0f) (*power)++;
944 if (rem < 2.0f) rem= 2.0f;
945 else if(rem < 5.0f) rem= 5.0f;
948 *step= rem * (float)pow(10.0, (*power));
951 /* prevents printing 1.0, 2.0, 3.0, etc. */
952 if (rem == 10.0f) (*power)++;
956 /* Intialise settings necessary for drawing gridlines in a 2d-view
957 * - Currently, will return pointer to View2DGrid struct that needs to
958 * be freed with UI_view2d_grid_free()
959 * - Is used for scrollbar drawing too (for units drawing)
960 * - Units + clamping args will be checked, to make sure they are valid values that can be used
961 * so it is very possible that we won't return grid at all!
963 * - xunits,yunits = V2D_UNIT_* grid steps in seconds or frames
964 * - xclamp,yclamp = V2D_CLAMP_* only show whole-number intervals
965 * - winx = width of region we're drawing to
966 * - winy = height of region we're drawing into
968 View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy)
970 Scene *scene= CTX_data_scene(C);
972 float space, pixels, seconddiv;
975 /* check that there are at least some workable args */
976 if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) && ELEM(V2D_ARG_DUMMY, yunits, yclamp))
979 /* grid here is allocated... */
980 grid= MEM_callocN(sizeof(View2DGrid), "View2DGrid");
982 /* rule: gridstep is minimal GRIDSTEP pixels */
983 if (xunits == V2D_UNIT_SECONDS) {
985 seconddiv= (float)(0.01 * FPS);
992 /* calculate x-axis grid scale (only if both args are valid) */
993 if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
994 space= v2d->cur.xmax - v2d->cur.xmin;
995 pixels= (float)(v2d->mask.xmax - v2d->mask.xmin);
997 grid->dx= (MINGRIDSTEP * space) / (seconddiv * pixels);
998 step_to_grid(&grid->dx, &grid->powerx, xunits);
999 grid->dx *= seconddiv;
1001 if (xclamp == V2D_GRID_CLAMP) {
1002 if (grid->dx < 0.1f) grid->dx= 0.1f;
1004 if (grid->powerx < -2) grid->powerx= -2;
1008 /* calculate y-axis grid scale (only if both args are valid) */
1009 if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
1010 space= v2d->cur.ymax - v2d->cur.ymin;
1011 pixels= (float)winy;
1013 grid->dy= MINGRIDSTEP * space / pixels;
1014 step_to_grid(&grid->dy, &grid->powery, yunits);
1016 if (yclamp == V2D_GRID_CLAMP) {
1017 if (grid->dy < 1.0f) grid->dy= 1.0f;
1018 if (grid->powery < 1) grid->powery= 1;
1022 /* calculate start position */
1023 if (ELEM(V2D_ARG_DUMMY, xunits, xclamp) == 0) {
1024 grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - (float)fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
1025 if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
1028 grid->startx= v2d->cur.xmin;
1030 if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
1031 grid->starty= (v2d->cur.ymin - (float)fmod(v2d->cur.ymin, grid->dy));
1032 if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
1035 grid->starty= v2d->cur.ymin;
1040 /* Draw gridlines in the given 2d-region */
1041 void UI_view2d_grid_draw(const bContext *C, View2D *v2d, View2DGrid *grid, int flag)
1043 float vec1[2], vec2[2];
1046 /* check for grid first, as it may not exist */
1050 /* vertical lines */
1051 if (flag & V2D_VERTICAL_LINES) {
1052 /* initialise initial settings */
1053 vec1[0]= vec2[0]= grid->startx;
1054 vec1[1]= grid->starty;
1055 vec2[1]= v2d->cur.ymax;
1057 /* minor gridlines */
1058 step= (v2d->mask.xmax - v2d->mask.xmin + 1) / MINGRIDSTEP;
1059 UI_ThemeColor(TH_GRID);
1061 for (a=0; a<step; a++) {
1062 glBegin(GL_LINE_STRIP);
1067 vec2[0]= vec1[0]+= grid->dx;
1070 /* major gridlines */
1071 vec2[0]= vec1[0]-= 0.5f*grid->dx;
1072 UI_ThemeColorShade(TH_GRID, 16);
1075 for (a=0; a<=step; a++) {
1076 glBegin(GL_LINE_STRIP);
1081 vec2[0]= vec1[0]-= grid->dx;
1085 /* horizontal lines */
1086 if (flag & V2D_HORIZONTAL_LINES) {
1087 /* only major gridlines */
1088 vec1[1]= vec2[1]= grid->starty;
1089 vec1[0]= grid->startx;
1090 vec2[0]= v2d->cur.xmax;
1092 step= (v2d->mask.ymax - v2d->mask.ymin + 1) / MINGRIDSTEP;
1094 UI_ThemeColor(TH_GRID);
1095 for (a=0; a<=step; a++) {
1096 glBegin(GL_LINE_STRIP);
1101 vec2[1]= vec1[1]+= grid->dy;
1104 /* fine grid lines */
1105 vec2[1]= vec1[1]-= 0.5f*grid->dy;
1108 if (flag & V2D_HORIZONTAL_FINELINES) {
1109 UI_ThemeColorShade(TH_GRID, 16);
1110 for (a=0; a<step; a++) {
1111 glBegin(GL_LINE_STRIP);
1116 vec2[1]= vec1[1]-= grid->dy;
1121 /* Axes are drawn as darker lines */
1122 UI_ThemeColorShade(TH_GRID, -50);
1124 /* horizontal axis */
1125 if (flag & V2D_HORIZONTAL_AXIS) {
1126 vec1[0]= v2d->cur.xmin;
1127 vec2[0]= v2d->cur.xmax;
1128 vec1[1]= vec2[1]= 0.0f;
1130 glBegin(GL_LINE_STRIP);
1137 if (flag & V2D_VERTICAL_AXIS) {
1138 vec1[1]= v2d->cur.ymin;
1139 vec2[1]= v2d->cur.ymax;
1140 vec1[0]= vec2[0]= 0.0f;
1142 glBegin(GL_LINE_STRIP);
1149 /* Draw a constant grid in given 2d-region */
1150 void UI_view2d_constant_grid_draw(const bContext *C, View2D *v2d)
1152 float start, step= 25.0f;
1154 UI_ThemeColorShade(TH_BACK, -10);
1156 start= v2d->cur.xmin - (float)fmod(v2d->cur.xmin, step);
1159 for(; start<v2d->cur.xmax; start+=step) {
1160 glVertex2f(start, v2d->cur.ymin);
1161 glVertex2f(start, v2d->cur.ymax);
1164 start= v2d->cur.ymin - (float)fmod(v2d->cur.ymin, step);
1165 for(; start<v2d->cur.ymax; start+=step) {
1166 glVertex2f(v2d->cur.xmin, start);
1167 glVertex2f(v2d->cur.xmax, start);
1171 UI_ThemeColorShade(TH_BACK, -18);
1172 glVertex2f(0.0f, v2d->cur.ymin);
1173 glVertex2f(0.0f, v2d->cur.ymax);
1174 glVertex2f(v2d->cur.xmin, 0.0f);
1175 glVertex2f(v2d->cur.xmax, 0.0f);
1180 /* free temporary memory used for drawing grid */
1181 void UI_view2d_grid_free(View2DGrid *grid)
1183 /* only free if there's a grid */
1188 /* *********************************************************************** */
1191 /* View2DScrollers is typedef'd in UI_view2d.h
1192 * WARNING: the start of this struct must not change, as view2d_ops.c uses this too.
1193 * For now, we don't need to have a separate (internal) header for structs like this...
1195 struct View2DScrollers {
1197 int vert_min, vert_max; /* vertical scrollbar */
1198 int hor_min, hor_max; /* horizontal scrollbar */
1201 View2DGrid *grid; /* grid for coordinate drawing */
1202 short xunits, xclamp; /* units and clamping options for x-axis */
1203 short yunits, yclamp; /* units and clamping options for y-axis */
1206 /* Calculate relevant scroller properties */
1207 View2DScrollers *UI_view2d_scrollers_calc(const bContext *C, View2D *v2d, short xunits, short xclamp, short yunits, short yclamp)
1209 View2DScrollers *scrollers;
1211 float fac, totsize, scrollsize;
1212 int scroll= view2d_scroll_mapped(v2d->scroll);
1217 /* scrollers is allocated here... */
1218 scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
1220 /* scroller 'buttons':
1221 * - These should always remain within the visible region of the scrollbar
1222 * - They represent the region of 'tot' that is visible in 'cur'
1225 /* horizontal scrollers */
1226 if (scroll & V2D_SCROLL_HORIZONTAL) {
1227 /* scroller 'button' extents */
1228 totsize= v2d->tot.xmax - v2d->tot.xmin;
1229 scrollsize= (float)(hor.xmax - hor.xmin);
1231 fac= (v2d->cur.xmin - v2d->tot.xmin) / totsize;
1232 scrollers->hor_min= (int)(hor.xmin + (fac * scrollsize));
1234 fac= (v2d->cur.xmax - v2d->tot.xmin) / totsize;
1235 scrollers->hor_max= (int)(hor.xmin + (fac * scrollsize));
1237 if (scrollers->hor_min > scrollers->hor_max)
1238 scrollers->hor_min= scrollers->hor_max;
1241 /* vertical scrollers */
1242 if (scroll & V2D_SCROLL_VERTICAL) {
1243 /* scroller 'button' extents */
1244 totsize= v2d->tot.ymax - v2d->tot.ymin;
1245 scrollsize= (float)(vert.ymax - vert.ymin);
1247 fac= (v2d->cur.ymin- v2d->tot.ymin) / totsize;
1248 scrollers->vert_min= (int)(vert.ymin + (fac * scrollsize));
1250 fac= (v2d->cur.ymax - v2d->tot.ymin) / totsize;
1251 scrollers->vert_max= (int)(vert.ymin + (fac * scrollsize));
1253 if (scrollers->vert_min > scrollers->vert_max)
1254 scrollers->vert_min= scrollers->vert_max;
1257 /* grid markings on scrollbars */
1258 if (scroll & (V2D_SCROLL_SCALE_HORIZONTAL|V2D_SCROLL_SCALE_VERTICAL)) {
1259 /* store clamping */
1260 scrollers->xclamp= xclamp;
1261 scrollers->xunits= xunits;
1262 scrollers->yclamp= yclamp;
1263 scrollers->yunits= yunits;
1265 scrollers->grid= UI_view2d_grid_calc(C, v2d, xunits, xclamp, yunits, yclamp, (hor.xmax - hor.xmin), (vert.ymax - vert.ymin));
1268 /* return scrollers */
1272 /* Print scale marking along a time scrollbar */
1273 static void scroll_printstr(View2DScrollers *scrollers, Scene *scene, float x, float y, float val, int power, short unit, char dir)
1278 /* adjust the scale unit to work ok */
1280 /* here we bump up the power by factor of 10, as
1281 * rotation values (hence 'degrees') are divided by 10 to
1282 * be able to show the curves at the same time
1284 if ELEM(unit, V2D_UNIT_DEGREES, V2D_UNIT_TIME) {
1290 /* get string to print */
1291 if (unit == V2D_UNIT_SECONDS) {
1292 /* SMPTE timecode style:
1293 * - In general, minutes and seconds should be shown, as most clips will be
1294 * within this length. Hours will only be included if relevant.
1295 * - Only show frames when zoomed in enough for them to be relevant
1296 * (using separator convention of ';' for frames, ala QuickTime).
1297 * When showing frames, use slightly different display to avoid confusion with mm:ss format
1299 int hours=0, minutes=0, seconds=0, frames=0;
1304 /* correction for negative values */
1310 /* XXX should we only display a single digit for hours since clips are
1311 * VERY UNLIKELY to be more than 1-2 hours max? However, that would
1312 * go against conventions...
1314 hours= (int)val / 3600;
1315 val= (float)fmod(val, 3600);
1319 minutes= (int)val / 60;
1320 val= (float)fmod(val, 60);
1324 * Frames are derived from 'fraction' of second. We need to perform some additional rounding
1325 * to cope with 'half' frames, etc., which should be fine in most cases
1328 frames= (int)floor( ((val - seconds) * FPS) + 0.5f );
1331 /* seconds (with pixel offset) */
1332 seconds= (int)floor(val + 0.375f);
1335 /* print timecode to temp string buffer */
1337 /* include "frames" in display */
1338 if (hours) sprintf(str, "%s%02d:%02d:%02d;%02d", neg, hours, minutes, seconds, frames);
1339 else if (minutes) sprintf(str, "%s%02d:%02d;%02d", neg, minutes, seconds, frames);
1340 else sprintf(str, "%s%d;%02d", neg, seconds, frames);
1343 /* don't include 'frames' in display */
1344 if (hours) sprintf(str, "%s%02d:%02d:%02d", neg, hours, minutes, seconds);
1345 else sprintf(str, "%s%02d:%02d", neg, minutes, seconds);
1349 /* round to whole numbers if power is >= 1 (i.e. scale is coarse) */
1350 if (power <= 0) sprintf(str, "%.*f", 1-power, val);
1351 else sprintf(str, "%d", (int)floor(val + 0.375f));
1354 /* get length of string, and adjust printing location to fit it into the horizontal scrollbar */
1357 /* seconds/timecode display has slightly longer strings... */
1358 if (unit == V2D_UNIT_SECONDS)
1364 /* Add degree sympbol to end of string for vertical scrollbar? */
1365 if ((dir == 'v') && (unit == V2D_UNIT_DEGREES)) {
1371 BLF_draw_default(x, y, 0.0f, str);
1374 /* local defines for scrollers drawing */
1375 /* radius of scroller 'button' caps */
1376 #define V2D_SCROLLCAP_RAD 5
1377 /* shading factor for scroller 'bar' */
1378 #define V2D_SCROLLBAR_SHADE 0.1f
1379 /* shading factor for scroller 'button' caps */
1380 #define V2D_SCROLLCAP_SHADE 0.2f
1382 /* Draw scrollbars in the given 2d-region */
1383 void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *vs)
1385 Scene *scene= CTX_data_scene(C);
1386 const short darker= -50, dark= -10, light= 20, lighter= 50;
1387 rcti vert, hor, corner;
1388 int scroll= view2d_scroll_mapped(v2d->scroll);
1390 /* make copies of rects for less typing */
1394 /* horizontal scrollbar */
1395 if (scroll & V2D_SCROLL_HORIZONTAL) {
1396 /* scroller backdrop */
1397 UI_ThemeColorShade(TH_SHADE1, light);
1398 glRecti(hor.xmin, hor.ymin, hor.xmax, hor.ymax);
1400 /* scroller 'button'
1401 * - if view is zoomable in x, draw handles too
1402 * - handles are drawn darker
1403 * - no slider when view is > total for non-zoomable views
1404 * (otherwise, zoomable ones tend to flicker)
1406 if ( (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) ||
1407 ((v2d->tot.xmax - v2d->tot.xmin) > (v2d->cur.xmax - v2d->cur.xmin)) )
1409 if (v2d->keepzoom & V2D_LOCKZOOM_X) {
1410 /* draw base bar as rounded shape */
1411 UI_ThemeColorShade(TH_SHADE1, dark);
1414 /* check that box is large enough for round drawing */
1415 if ((vs->hor_max - vs->hor_min) < (V2D_SCROLLCAP_RAD * 2)) {
1416 /* Rounded box still gets drawn at the minimum size limit
1417 * This doesn't represent extreme scaling well, but looks nicer...
1419 float mid= 0.5f * (vs->hor_max + vs->hor_min);
1421 gl_round_box_shade(GL_POLYGON,
1422 mid-V2D_SCROLLCAP_RAD, (float)hor.ymin+2,
1423 mid+V2D_SCROLLCAP_RAD, (float)hor.ymax-2,
1424 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1427 /* draw rounded box as per normal */
1428 gl_round_box_shade(GL_POLYGON,
1429 (float)vs->hor_min, (float)hor.ymin+2,
1430 (float)vs->hor_max, (float)hor.ymax-2,
1431 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1435 /* base bar drawn as shaded rect */
1436 UI_ThemeColorShade(TH_SHADE1, dark);
1438 gl_round_box_shade(GL_POLYGON,
1439 (float)vs->hor_min, (float)hor.ymin+2,
1440 (float)vs->hor_max, (float)hor.ymax-2,
1441 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1443 /* 'minimum' handle */
1445 UI_ThemeColorShade(TH_SHADE1, darker);
1447 gl_round_box_shade(GL_POLYGON,
1448 (float)vs->hor_min-V2D_SCROLLER_HANDLE_SIZE, (float)hor.ymin+2,
1449 (float)vs->hor_min+V2D_SCROLLER_HANDLE_SIZE, (float)hor.ymax-2,
1450 V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
1452 /* maximum handle */
1454 UI_ThemeColorShade(TH_SHADE1, darker);
1456 gl_round_box_shade(GL_POLYGON,
1457 (float)vs->hor_max-V2D_SCROLLER_HANDLE_SIZE, (float)hor.ymin+2,
1458 (float)vs->hor_max+V2D_SCROLLER_HANDLE_SIZE, (float)hor.ymax-2,
1459 V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
1463 /* scale indicators */
1464 // XXX will need to update the font drawing when the new stuff comes in
1465 if ((scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) {
1466 View2DGrid *grid= vs->grid;
1467 float fac, dfac, fac2, val;
1469 /* the numbers: convert grid->startx and -dx to scroll coordinates
1470 * - fac is x-coordinate to draw to
1471 * - dfac is gap between scale markings
1473 fac= (grid->startx - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
1474 fac= (float)hor.xmin + fac*(hor.xmax - hor.xmin);
1476 dfac= (grid->dx) / (v2d->cur.xmax - v2d->cur.xmin);
1477 dfac= dfac * (hor.xmax - hor.xmin);
1479 /* set starting value, and text color */
1480 UI_ThemeColor(TH_TEXT);
1483 /* if we're clamping to whole numbers only, make sure entries won't be repeated */
1484 if (vs->xclamp == V2D_GRID_CLAMP) {
1485 while (grid->dx < 0.9999f) {
1490 if (vs->xunits == V2D_UNIT_FRAMES)
1493 /* draw numbers in the appropriate range */
1495 for (; fac < hor.xmax; fac+=dfac, val+=grid->dx) {
1496 switch (vs->xunits) {
1497 case V2D_UNIT_FRAMES: /* frames (as whole numbers)*/
1498 scroll_printstr(vs, scene, fac, 3.0f+(float)(hor.ymin), val, grid->powerx, V2D_UNIT_FRAMES, 'h');
1501 case V2D_UNIT_FRAMESCALE: /* frames (not always as whole numbers) */
1502 scroll_printstr(vs, scene, fac, 3.0f+(float)(hor.ymin), val, grid->powerx, V2D_UNIT_FRAMESCALE, 'h');
1505 case V2D_UNIT_SECONDS: /* seconds */
1506 fac2= val/(float)FPS;
1507 scroll_printstr(vs, scene, fac, 3.0f+(float)(hor.ymin), fac2, grid->powerx, V2D_UNIT_SECONDS, 'h');
1510 case V2D_UNIT_SECONDSSEQ: /* seconds with special calculations (only used for sequencer only) */
1514 fac2= val/(float)FPS;
1515 time= (float)floor(fac2);
1518 scroll_printstr(vs, scene, fac, 3.0f+(float)(hor.ymin), time+(float)FPS*fac2/100.0f, grid->powerx, V2D_UNIT_SECONDSSEQ, 'h');
1522 case V2D_UNIT_DEGREES: /* Graph Editor for rotation Drivers */
1523 /* HACK: although we're drawing horizontal, we make this draw as 'vertical', just to get degree signs */
1524 scroll_printstr(vs, scene, fac, 3.0f+(float)(hor.ymin), val, grid->powerx, V2D_UNIT_DEGREES, 'v');
1531 /* decoration outer bevel line */
1532 UI_ThemeColorShade(TH_SHADE1, lighter);
1533 if (scroll & (V2D_SCROLL_BOTTOM|V2D_SCROLL_BOTTOM_O))
1534 sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
1535 else if (scroll & V2D_SCROLL_TOP)
1536 sdrawline(hor.xmin, hor.ymin, hor.xmax, hor.ymin);
1539 /* vertical scrollbar */
1540 if (scroll & V2D_SCROLL_VERTICAL) {
1541 /* scroller backdrop */
1542 UI_ThemeColorShade(TH_SHADE1, light);
1543 glRecti(vert.xmin, vert.ymin, vert.xmax, vert.ymax);
1545 /* scroller 'button'
1546 * - if view is zoomable in y, draw handles too
1547 * - handles are drawn darker
1548 * - no slider when view is > total for non-zoomable views
1549 * (otherwise, zoomable ones tend to flicker)
1551 if ( (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) ||
1552 ((v2d->tot.ymax - v2d->tot.ymin) > (v2d->cur.ymax - v2d->cur.ymin)) )
1554 if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
1555 /* draw base bar as rounded shape */
1556 UI_ThemeColorShade(TH_SHADE1, dark);
1559 /* check that box is large enough for round drawing */
1560 if ((vs->vert_max - vs->vert_min) < (V2D_SCROLLCAP_RAD * 2)) {
1561 /* Rounded box still gets drawn at the minimum size limit
1562 * This doesn't represent extreme scaling well, but looks nicer...
1564 float mid= 0.5f * (vs->vert_max + vs->vert_min);
1566 gl_round_box_vertical_shade(GL_POLYGON,
1567 (float)vert.xmin+2, mid-V2D_SCROLLCAP_RAD,
1568 (float)vert.xmax-2, mid+V2D_SCROLLCAP_RAD,
1569 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1572 /* draw rounded box as per normal */
1573 gl_round_box_vertical_shade(GL_POLYGON,
1574 (float)vert.xmin+2, (float)vs->vert_min,
1575 (float)vert.xmax-2, (float)vs->vert_max,
1576 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1580 /* base bar drawn as shaded rect */
1581 UI_ThemeColorShade(TH_SHADE1, dark);
1583 gl_round_box_vertical_shade(GL_POLYGON,
1584 (float)vert.xmin+2, (float)vs->vert_min,
1585 (float)vert.xmax-2, (float)vs->vert_max,
1586 V2D_SCROLLCAP_RAD, V2D_SCROLLBAR_SHADE, -V2D_SCROLLBAR_SHADE);
1588 /* 'minimum' handle */
1589 UI_ThemeColorShade(TH_SHADE1, darker);
1592 gl_round_box_vertical_shade(GL_POLYGON,
1593 (float)vert.xmin+2, (float)vs->vert_min-V2D_SCROLLER_HANDLE_SIZE,
1594 (float)vert.xmax-2, (float)vs->vert_min+V2D_SCROLLER_HANDLE_SIZE,
1595 V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
1597 /* maximum handle */
1598 UI_ThemeColorShade(TH_SHADE1, darker);
1601 gl_round_box_vertical_shade(GL_POLYGON,
1602 (float)vert.xmin+2, (float)vs->vert_max-V2D_SCROLLER_HANDLE_SIZE,
1603 (float)vert.xmax-2, (float)vs->vert_max+V2D_SCROLLER_HANDLE_SIZE,
1604 V2D_SCROLLCAP_RAD, V2D_SCROLLCAP_SHADE, -V2D_SCROLLCAP_SHADE);
1608 /* scale indiators */
1609 // XXX will need to update the font drawing when the new stuff comes in
1610 if ((scroll & V2D_SCROLL_SCALE_VERTICAL) && (vs->grid)) {
1611 View2DGrid *grid= vs->grid;
1612 float fac, dfac, val;
1614 /* the numbers: convert grid->starty and dy to scroll coordinates
1615 * - fac is y-coordinate to draw to
1616 * - dfac is gap between scale markings
1617 * - these involve a correction for horizontal scrollbar
1618 * NOTE: it's assumed that that scrollbar is there if this is involved!
1620 fac= (grid->starty- v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
1621 fac= (vert.ymin + V2D_SCROLL_HEIGHT) + fac*(vert.ymax - vert.ymin - V2D_SCROLL_HEIGHT);
1623 dfac= (grid->dy) / (v2d->cur.ymax - v2d->cur.ymin);
1624 dfac= dfac * (vert.ymax - vert.ymin - V2D_SCROLL_HEIGHT);
1626 /* set starting value, and text color */
1627 UI_ThemeColor(TH_TEXT);
1630 /* if vertical clamping (to whole numbers) is used (i.e. in Sequencer), apply correction */
1631 // XXX only relevant to Sequencer, so need to review this when we port that code
1632 if (vs->yclamp == V2D_GRID_CLAMP)
1635 /* draw vertical steps */
1637 for (; fac < vert.ymax; fac+= dfac, val += grid->dy) {
1638 scroll_printstr(vs, scene, (float)(vert.xmax)-14.0f, fac, val, grid->powery, vs->yunits, 'v');
1643 /* decoration outer bevel line */
1644 UI_ThemeColorShade(TH_SHADE1, lighter);
1645 if (scroll & V2D_SCROLL_RIGHT)
1646 sdrawline(vert.xmin, vert.ymin, vert.xmin, vert.ymax);
1647 else if (scroll & V2D_SCROLL_LEFT)
1648 sdrawline(vert.xmax, vert.ymin, vert.xmax, vert.ymax);
1651 /* draw a 'sunken square' to cover up any overlapping corners resulting from intersection of overflowing scroller data */
1652 if ((scroll & V2D_SCROLL_VERTICAL) && (scroll & V2D_SCROLL_HORIZONTAL)) {
1653 /* set bounds (these should be right) */
1654 corner.xmin= vert.xmin;
1655 corner.xmax= vert.xmax;
1656 corner.ymin= hor.ymin;
1657 corner.ymax= hor.ymax;
1659 /* firstly, draw using background color to cover up any overlapping junk */
1660 UI_ThemeColor(TH_SHADE1);
1661 glRecti(corner.xmin, corner.ymin, corner.xmax, corner.ymax);
1663 /* now, draw suggestive highlighting... */
1664 /* first, dark lines on top to suggest scrollers overlap box */
1665 UI_ThemeColorShade(TH_SHADE1, darker);
1666 sdrawline(corner.xmin, corner.ymin, corner.xmin, corner.ymax);
1667 sdrawline(corner.xmin, corner.ymax, corner.xmax, corner.ymax);
1668 /* now, light lines on bottom to show box is sunken in */
1669 UI_ThemeColorShade(TH_SHADE1, lighter);
1670 sdrawline(corner.xmax, corner.ymin, corner.xmax, corner.ymax);
1671 sdrawline(corner.xmin, corner.ymin, corner.xmax, corner.ymin);
1675 /* free temporary memory used for drawing scrollers */
1676 void UI_view2d_scrollers_free(View2DScrollers *scrollers)
1678 /* need to free grid as well... */
1679 if (scrollers->grid) MEM_freeN(scrollers->grid);
1680 MEM_freeN(scrollers);
1683 /* *********************************************************************** */
1684 /* List View Utilities */
1686 /* Get the view-coordinates of the nominated cell
1687 * - columnwidth, rowheight = size of each 'cell'
1688 * - startx, starty = coordinates (in 'tot' rect space) that the list starts from
1689 * This should be (0,0) for most views. However, for those where the starting row was offsetted
1690 * (like for Animation Editor channel lists, to make the first entry more visible), these will be
1691 * the min-coordinates of the first item.
1692 * - column, row = the 2d-corodinates (in 2D-view / 'tot' rect space) the cell exists at
1693 * - rect = coordinates of the cell (passed as single var instead of 4 separate, as it's more useful this way)
1695 void UI_view2d_listview_cell_to_view(View2D *v2d, short columnwidth, short rowheight, float startx, float starty, int column, int row, rctf *rect)
1698 if ELEM(NULL, v2d, rect)
1700 if ((columnwidth <= 0) && (rowheight <= 0)) {
1701 rect->xmin= rect->xmax= 0.0f;
1702 rect->ymin= rect->ymax= 0.0f;
1707 rect->xmin= startx + (float)(columnwidth * column);
1708 rect->xmax= startx + (float)(columnwidth * (column + 1));
1710 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
1711 /* simply negate the values for the coordinates if in negative half */
1712 rect->xmin = -rect->xmin;
1713 rect->xmax = -rect->xmax;
1717 rect->ymin= starty + (float)(rowheight * row);
1718 rect->ymax= starty + (float)(rowheight * (row + 1));
1720 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1721 /* simply negate the values for the coordinates if in negative half */
1722 rect->ymin = -rect->ymin;
1723 rect->ymax = -rect->ymax;
1727 /* Get the 'cell' (row, column) that the given 2D-view coordinates (i.e. in 'tot' rect space) lie in.
1728 * - columnwidth, rowheight = size of each 'cell'
1729 * - startx, starty = coordinates (in 'tot' rect space) that the list starts from
1730 * This should be (0,0) for most views. However, for those where the starting row was offsetted
1731 * (like for Animation Editor channel lists, to make the first entry more visible), these will be
1732 * the min-coordinates of the first item.
1733 * - viewx, viewy = 2D-coordinates (in 2D-view / 'tot' rect space) to get the cell for
1734 * - column, row = the 'coordinates' of the relevant 'cell'
1736 void UI_view2d_listview_view_to_cell(View2D *v2d, short columnwidth, short rowheight, float startx, float starty,
1737 float viewx, float viewy, int *column, int *row)
1739 /* adjust view coordinates to be all positive ints, corrected for the start offset */
1740 const int x= (int)(floor(fabs(viewx) + 0.5f) - startx);
1741 const int y= (int)(floor(fabs(viewy) + 0.5f) - starty);
1743 /* sizes must not be negative */
1744 if ( (v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0)) ) {
1745 if (column) *column= 0;
1752 if ((column) && (columnwidth > 0))
1753 *column= x / columnwidth;
1758 if ((row) && (rowheight > 0))
1759 *row= y / rowheight;
1764 /* Get the 'extreme' (min/max) column and row indices which are visible within the 'cur' rect
1765 * - columnwidth, rowheight = size of each 'cell'
1766 * - startx, starty = coordinates that the list starts from, which should be (0,0) for most views
1767 * - column/row_min/max = the starting and ending column/row indices
1769 void UI_view2d_listview_visible_cells(View2D *v2d, short columnwidth, short rowheight, float startx, float starty,
1770 int *column_min, int *column_max, int *row_min, int *row_max)
1772 /* using 'cur' rect coordinates, call the cell-getting function to get the cells for this */
1775 UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty,
1776 v2d->cur.xmin, v2d->cur.ymin, column_min, row_min);
1779 UI_view2d_listview_view_to_cell(v2d, columnwidth, rowheight, startx, starty,
1780 v2d->cur.xmax, v2d->cur.ymax, column_max, row_max);
1784 /* *********************************************************************** */
1785 /* Coordinate Conversions */
1787 /* Convert from screen/region space to 2d-View space
1789 * - x,y = coordinates to convert
1790 * - viewx,viewy = resultant coordinates
1792 void UI_view2d_region_to_view(View2D *v2d, int x, int y, float *viewx, float *viewy)
1797 div= (float)(v2d->mask.xmax - v2d->mask.xmin);
1798 ofs= (float)v2d->mask.xmin;
1800 *viewx= v2d->cur.xmin + (v2d->cur.xmax-v2d->cur.xmin) * ((float)x - ofs) / div;
1804 div= (float)(v2d->mask.ymax - v2d->mask.ymin);
1805 ofs= (float)v2d->mask.ymin;
1807 *viewy= v2d->cur.ymin + (v2d->cur.ymax - v2d->cur.ymin) * ((float)y - ofs) / div;
1811 /* Convert from 2d-View space to screen/region space
1812 * - Coordinates are clamped to lie within bounds of region
1814 * - x,y = coordinates to convert
1815 * - regionx,regiony = resultant coordinates
1817 void UI_view2d_view_to_region(View2D *v2d, float x, float y, int *regionx, int *regiony)
1819 /* set initial value in case coordinate lies outside of bounds */
1821 *regionx= V2D_IS_CLIPPED;
1823 *regiony= V2D_IS_CLIPPED;
1825 /* express given coordinates as proportional values */
1826 x= (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
1827 y= (y - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
1829 /* check if values are within bounds */
1830 if ((x>=0.0f) && (x<=1.0f) && (y>=0.0f) && (y<=1.0f)) {
1832 *regionx= (int)(v2d->mask.xmin + x*(v2d->mask.xmax-v2d->mask.xmin));
1834 *regiony= (int)(v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin));
1838 /* Convert from 2d-view space to screen/region space
1839 * - Coordinates are NOT clamped to lie within bounds of region
1841 * - x,y = coordinates to convert
1842 * - regionx,regiony = resultant coordinates
1844 void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, int *regionx, int *regiony)
1846 /* step 1: express given coordinates as proportional values */
1847 x= (x - v2d->cur.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
1848 y= (y - v2d->cur.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
1850 /* step 2: convert proportional distances to screen coordinates */
1851 x= v2d->mask.xmin + x*(v2d->mask.xmax - v2d->mask.xmin);
1852 y= v2d->mask.ymin + y*(v2d->mask.ymax - v2d->mask.ymin);
1854 /* although we don't clamp to lie within region bounds, we must avoid exceeding size of ints */
1856 if (x < INT_MIN) *regionx= INT_MIN;
1857 else if(x > INT_MAX) *regionx= INT_MAX;
1858 else *regionx= (int)x;
1861 if (y < INT_MIN) *regiony= INT_MIN;
1862 else if(y > INT_MAX) *regiony= INT_MAX;
1863 else *regiony= (int)y;
1867 /* *********************************************************************** */
1870 /* View2D data by default resides in region, so get from region stored in context */
1871 View2D *UI_view2d_fromcontext(const bContext *C)
1873 ScrArea *area= CTX_wm_area(C);
1874 ARegion *region= CTX_wm_region(C);
1876 if (area == NULL) return NULL;
1877 if (region == NULL) return NULL;
1878 return &(region->v2d);
1881 /* same as above, but it returns regionwindow. Utility for pulldowns or buttons */
1882 View2D *UI_view2d_fromcontext_rwin(const bContext *C)
1884 ScrArea *area= CTX_wm_area(C);
1885 ARegion *region= CTX_wm_region(C);
1887 if (area == NULL) return NULL;
1888 if (region == NULL) return NULL;
1889 if (region->regiontype!=RGN_TYPE_WINDOW) {
1890 ARegion *ar= area->regionbase.first;
1891 for(; ar; ar= ar->next)
1892 if(ar->regiontype==RGN_TYPE_WINDOW)
1896 return &(region->v2d);
1900 /* Calculate the scale per-axis of the drawing-area
1901 * - Is used to inverse correct drawing of icons, etc. that need to follow view
1902 * but not be affected by scale
1904 * - x,y = scale on each axis
1906 void UI_view2d_getscale(View2D *v2d, float *x, float *y)
1908 if (x) *x = (v2d->mask.xmax - v2d->mask.xmin) / (v2d->cur.xmax - v2d->cur.xmin);
1909 if (y) *y = (v2d->mask.ymax - v2d->mask.ymin) / (v2d->cur.ymax - v2d->cur.ymin);
1912 /* Check if mouse is within scrollers
1913 * - Returns appropriate code for match
1914 * 'h' = in horizontal scroller
1915 * 'v' = in vertical scroller
1916 * 0 = not in scroller
1918 * - x,y = mouse coordinates in screen (not region) space
1920 short UI_view2d_mouse_in_scrollers (const bContext *C, View2D *v2d, int x, int y)
1922 ARegion *ar= CTX_wm_region(C);
1924 int scroll= view2d_scroll_mapped(v2d->scroll);
1926 /* clamp x,y to region-coordinates first */
1927 co[0]= x - ar->winrct.xmin;
1928 co[1]= y - ar->winrct.ymin;
1930 /* check if within scrollbars */
1931 if (scroll & V2D_SCROLL_HORIZONTAL) {
1932 if (IN_2D_HORIZ_SCROLL(v2d, co)) return 'h';
1934 if (scroll & V2D_SCROLL_VERTICAL) {
1935 if (IN_2D_VERT_SCROLL(v2d, co)) return 'v';
1942 /* ******************* view2d text drawing cache ******************** */
1944 /* assumes caches are used correctly, so for time being no local storage in v2d */
1945 static ListBase strings= {NULL, NULL};
1947 typedef struct View2DString {
1948 struct View2DString *next, *prev;
1956 void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str)
1960 UI_view2d_view_to_region(v2d, x, y, mval, mval+1);
1962 if(mval[0]!=V2D_IS_CLIPPED && mval[1]!=V2D_IS_CLIPPED) {
1963 /* use calloc, rect has to be zeroe'd */
1964 View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
1966 BLI_addtail(&strings, v2s);
1967 BLI_strncpy(v2s->str, str, 128);
1968 v2s->mval[0]= mval[0];
1969 v2s->mval[1]= mval[1];
1970 glGetFloatv(GL_CURRENT_COLOR, v2s->col);
1975 void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str)
1977 View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString");
1979 UI_view2d_to_region_no_clip(v2d, rect->xmin, rect->ymin, &v2s->rect.xmin, &v2s->rect.ymin);
1980 UI_view2d_to_region_no_clip(v2d, rect->xmax, rect->ymax, &v2s->rect.xmax, &v2s->rect.ymax);
1982 BLI_addtail(&strings, v2s);
1983 BLI_strncpy(v2s->str, str, 128);
1984 glGetFloatv(GL_CURRENT_COLOR, v2s->col);
1988 void UI_view2d_text_cache_draw(ARegion *ar)
1993 ED_region_pixelspace(ar);
1995 for(v2s= strings.first; v2s; v2s= v2s->next) {
1996 glColor3fv(v2s->col);
1997 if(v2s->rect.xmin==v2s->rect.xmax)
1998 BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str);
2002 yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28")));
2005 BLF_clipping(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4);
2006 BLF_enable(BLF_CLIPPING);
2008 BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str);
2010 BLF_disable(BLF_CLIPPING);
2017 BLI_freelistN(&strings);
2021 /* ******************************************************** */