Blender V4.5
view2d.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cfloat>
11#include <climits>
12#include <cmath>
13#include <cstring>
14
15#include "MEM_guardedalloc.h"
16
17#include "DNA_userdef_types.h"
18
19#include "BLI_link_utils.h"
20#include "BLI_listbase.h"
21#include "BLI_math_matrix.h"
22#include "BLI_memarena.h"
23#include "BLI_rect.h"
24#include "BLI_utildefines.h"
25
26#include "BKE_context.hh"
27#include "BKE_global.hh"
28#include "BKE_screen.hh"
29
30#include "GPU_immediate.hh"
31#include "GPU_matrix.hh"
32#include "GPU_state.hh"
33
34#include "WM_api.hh"
35
36#include "BLF_api.hh"
37
38#include "ED_screen.hh"
39
40#include "UI_interface.hh"
41#include "UI_view2d.hh"
42
43#include "view2d_intern.hh"
44
45static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize);
46
47/* -------------------------------------------------------------------- */
50
52{
53 const float min = float(INT_MIN);
54 const float max = float(INT_MAX);
55
56 if (UNLIKELY(f < min)) {
57 return min;
58 }
59 if (UNLIKELY(f > max)) {
60 return int(max);
61 }
62 return int(f);
63}
64
69BLI_INLINE void clamp_rctf_to_rcti(rcti *dst, const rctf *src)
70{
71 dst->xmin = clamp_float_to_int(src->xmin);
72 dst->xmax = clamp_float_to_int(src->xmax);
73 dst->ymin = clamp_float_to_int(src->ymin);
74 dst->ymax = clamp_float_to_int(src->ymax);
75}
76
77float view2d_page_size_y(const View2D &v2d)
78{
79 return v2d.page_size_y ? v2d.page_size_y : BLI_rcti_size_y(&v2d.mask);
80}
81
82/* XXX still unresolved: scrolls hide/unhide vs region mask handling */
83/* XXX there's V2D_SCROLL_HORIZONTAL_HIDE and V2D_SCROLL_HORIZONTAL_FULLR ... */
84
86
87/* -------------------------------------------------------------------- */
90
98static int view2d_scroll_mapped(int scroll)
99{
100 if (scroll & V2D_SCROLL_HORIZONTAL_FULLR) {
101 scroll &= ~V2D_SCROLL_HORIZONTAL;
102 }
103 if (scroll & V2D_SCROLL_VERTICAL_FULLR) {
104 scroll &= ~V2D_SCROLL_VERTICAL;
105 }
106 return scroll;
107}
108
109void UI_view2d_mask_from_win(const View2D *v2d, rcti *r_mask)
110{
111 r_mask->xmin = 0;
112 r_mask->ymin = 0;
113 r_mask->xmax = v2d->winx - 1; /* -1 yes! masks are pixels */
114 r_mask->ymax = v2d->winy - 1;
115}
116
122static void view2d_masks(View2D *v2d, const rcti *mask_scroll)
123{
124 int scroll;
125
126 /* mask - view frame */
127 UI_view2d_mask_from_win(v2d, &v2d->mask);
128 if (mask_scroll == nullptr) {
129 mask_scroll = &v2d->mask;
130 }
131
132 /* check size if hiding flag is set: */
135 if (BLI_rctf_size_x(&v2d->tot) > BLI_rctf_size_x(&v2d->cur)) {
137 }
138 else {
140 }
141 }
142 }
143 if (v2d->scroll & V2D_SCROLL_VERTICAL_HIDE) {
144 if (!(v2d->scroll & V2D_SCROLL_VERTICAL_HANDLES)) {
145 if (BLI_rctf_size_y(&v2d->tot) + 0.01f > BLI_rctf_size_y(&v2d->cur)) {
147 }
148 else {
150 }
151 }
152 }
153
154 /* Do not use mapped scroll here because we want to update scroller rects
155 * even if they are not displayed. For initialization purposes. See #75003. */
156 scroll = v2d->scroll;
157
158 /* Scrollers are based off region-size:
159 * - they can only be on one to two edges of the region they define
160 * - if they overlap, they must not occupy the corners (which are reserved for other widgets)
161 */
162 if (scroll) {
163 float scroll_width, scroll_height;
164
165 UI_view2d_scroller_size_get(v2d, false, &scroll_width, &scroll_height);
166
167 /* vertical scroller */
168 if (scroll & V2D_SCROLL_LEFT) {
169 /* on left-hand edge of region */
170 v2d->vert = *mask_scroll;
171 v2d->vert.xmax = scroll_width;
172 }
173 else if (scroll & V2D_SCROLL_RIGHT) {
174 /* on right-hand edge of region */
175 v2d->vert = *mask_scroll;
176 v2d->vert.xmax++; /* one pixel extra... was leaving a minor gap... */
177 v2d->vert.xmin = v2d->vert.xmax - scroll_width;
178 }
179
180 /* horizontal scroller */
181 if (scroll & V2D_SCROLL_BOTTOM) {
182 /* on bottom edge of region */
183 v2d->hor = *mask_scroll;
184 v2d->hor.ymax = scroll_height;
185 }
186 else if (scroll & V2D_SCROLL_TOP) {
187 /* on upper edge of region */
188 v2d->hor = *mask_scroll;
189 v2d->hor.ymin = v2d->hor.ymax - scroll_height;
190 }
191
192 /* Adjust horizontal scroller to avoid interfering with splitter areas. */
193 if (scroll & V2D_SCROLL_HORIZONTAL) {
194 v2d->hor.xmin += UI_AZONESPOTW;
195 v2d->hor.xmax -= UI_AZONESPOTW;
196 }
197
198 /* Adjust vertical scroller to avoid horizontal scrollers and splitter areas. */
199 if (scroll & V2D_SCROLL_VERTICAL) {
200 /* Note that top splitter areas are in the header,
201 * outside of `mask_scroll`, so we can ignore them. */
202 v2d->vert.ymin += UI_AZONESPOTH;
203 if (scroll & V2D_SCROLL_BOTTOM) {
204 /* on bottom edge of region */
205 v2d->vert.ymin = max_ii(v2d->hor.ymax, v2d->vert.ymin);
206 }
207 else if (scroll & V2D_SCROLL_TOP) {
208 /* on upper edge of region */
209 v2d->vert.ymax = v2d->hor.ymin;
210 }
211 }
212 }
213}
214
216
217/* -------------------------------------------------------------------- */
220
221void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
222{
223 bool tot_changed = false, do_init;
224 const uiStyle *style = UI_style_get();
225
226 do_init = (v2d->flag & V2D_IS_INIT) == 0;
227
228 /* see eView2D_CommonViewTypes in UI_view2d.hh for available view presets */
229 switch (type) {
230 /* 'standard view' - optimum setup for 'standard' view behavior,
231 * that should be used new views as basis for their
232 * own unique View2D settings, which should be used instead of this in most cases...
233 */
235 /* for now, aspect ratio should be maintained,
236 * and zoom is clamped within sane default limits */
238 v2d->minzoom = 0.01f;
239 v2d->maxzoom = 1000.0f;
240
241 /* View2D tot rect and cur should be same size,
242 * and aligned using 'standard' OpenGL coordinates for now:
243 * - region can resize 'tot' later to fit other data
244 * - keeptot is only within bounds, as strict locking is not that critical
245 * - view is aligned for (0,0) -> (winx-1, winy-1) setup
246 */
249 if (do_init) {
250 v2d->tot.xmin = v2d->tot.ymin = 0.0f;
251 v2d->tot.xmax = float(winx - 1);
252 v2d->tot.ymax = float(winy - 1);
253
254 v2d->cur = v2d->tot;
255 }
256 /* scrollers - should we have these by default? */
257 /* XXX for now, we don't override this, or set it either! */
258 break;
259 }
260 /* 'list/channel view' - zoom, aspect ratio, and alignment restrictions are set here */
261 case V2D_COMMONVIEW_LIST: {
262 /* zoom + aspect ratio are locked */
264 v2d->minzoom = v2d->maxzoom = 1.0f;
265
266 /* tot rect has strictly regulated placement, and must only occur in +/- quadrant */
269 tot_changed = do_init;
270
271 /* scroller settings are currently not set here... that is left for regions... */
272 break;
273 }
274 /* 'stack view' - practically the same as list/channel view,
275 * except is located in the pos y half instead.
276 * Zoom, aspect ratio, and alignment restrictions are set here. */
278 /* zoom + aspect ratio are locked */
280 v2d->minzoom = v2d->maxzoom = 1.0f;
281
282 /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
285 tot_changed = do_init;
286
287 /* scroller settings are currently not set here... that is left for regions... */
288 break;
289 }
290 /* 'header' regions - zoom, aspect ratio,
291 * alignment, and panning restrictions are set here */
293 /* zoom + aspect ratio are locked */
295 v2d->minzoom = v2d->maxzoom = 1.0f;
296
297 if (do_init) {
298 v2d->tot.xmin = 0.0f;
299 v2d->tot.xmax = winx;
300 v2d->tot.ymin = 0.0f;
301 v2d->tot.ymax = winy;
302 v2d->cur = v2d->tot;
303
304 v2d->min[0] = v2d->max[0] = float(winx - 1);
305 v2d->min[1] = v2d->max[1] = float(winy - 1);
306 }
307 /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
310 tot_changed = do_init;
311
312 /* panning in y-axis is prohibited */
313 v2d->keepofs = V2D_LOCKOFS_Y;
314
315 /* absolutely no scrollers allowed */
316 v2d->scroll = 0;
317 break;
318 }
319 /* panels view, with horizontal/vertical align */
321
322 /* for now, aspect ratio should be maintained,
323 * and zoom is clamped within sane default limits */
325 v2d->minzoom = 0.5f;
326 v2d->maxzoom = 2.0f;
327
330
331 /* NOTE: scroll is being flipped in #ED_region_panels() drawing. */
333
334 if (do_init) {
335 const float panelzoom = (style) ? style->panelzoom : 1.0f;
336
337 v2d->tot.xmin = 0.0f;
338 v2d->tot.xmax = winx;
339
340 v2d->tot.ymax = 0.0f;
341 v2d->tot.ymin = -winy;
342
343 v2d->cur.xmin = 0.0f;
344 v2d->cur.xmax = (winx)*panelzoom;
345
346 v2d->cur.ymax = 0.0f;
347 v2d->cur.ymin = (-winy) * panelzoom;
348 }
349 break;
350 }
351 /* other view types are completely defined using their own settings already */
352 default:
353 /* we don't do anything here,
354 * as settings should be fine, but just make sure that rect */
355 break;
356 }
357
358 /* set initialized flag so that View2D doesn't get reinitialized next time again */
359 v2d->flag |= V2D_IS_INIT;
360
361 /* store view size */
362 v2d->winx = winx;
363 v2d->winy = winy;
364
365 view2d_masks(v2d, nullptr);
366
367 if (do_init) {
368 /* Visible by default. */
369 v2d->alpha_hor = v2d->alpha_vert = 255;
370 }
371
372 /* set 'tot' rect before setting cur? */
373 /* XXX confusing stuff here still */
374 if (tot_changed) {
375 view2d_totRect_set_resize(v2d, winx, winy, !do_init);
376 }
377 else {
379 }
380}
381
386static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize)
387{
388 /* NOTE: #calculateZfac uses this logic, keep in sync. */
389 float totwidth, totheight, curwidth, curheight, width, height;
390 float winx, winy;
391 rctf *cur, *tot;
392
393 /* use mask as size of region that View2D resides in, as it takes into account
394 * scroll-bars already - keep in sync with `zoomx/zoomy` in #view_zoomstep_apply_ex! */
395 winx = float(BLI_rcti_size_x(&v2d->mask) + 1);
396 winy = float(BLI_rcti_size_y(&v2d->mask) + 1);
397
398 /* get pointers to rcts for less typing */
399 cur = &v2d->cur;
400 tot = &v2d->tot;
401
402 /* we must satisfy the following constraints (in decreasing order of importance):
403 * - alignment restrictions are respected
404 * - cur must not fall outside of tot
405 * - axis locks (zoom and offset) must be maintained
406 * - zoom must not be excessive (check either sizes or zoom values)
407 * - aspect ratio should be respected (NOTE: this is quite closely related to zoom too)
408 */
409
410 /* Step 1: if keepzoom, adjust the sizes of the rects only
411 * - firstly, we calculate the sizes of the rects
412 * - curwidth and curheight are saved as reference... modify width and height values here
413 */
414 totwidth = BLI_rctf_size_x(tot);
415 totheight = BLI_rctf_size_y(tot);
416 /* Keep in sync with `zoomx/zoomy` in #view_zoomstep_apply_ex! */
417 curwidth = width = BLI_rctf_size_x(cur);
418 curheight = height = BLI_rctf_size_y(cur);
419
420 /* if zoom is locked, size on the appropriate axis is reset to mask size */
421 if (v2d->keepzoom & V2D_LOCKZOOM_X) {
422 width = winx;
423 }
424 if (v2d->keepzoom & V2D_LOCKZOOM_Y) {
425 height = winy;
426 }
427
428 /* values used to divide, so make it safe
429 * NOTE: width and height must use FLT_MIN instead of 1, otherwise it is impossible to
430 * get enough resolution in Graph Editor for editing some curves
431 */
432 if (width < FLT_MIN) {
433 width = 1;
434 }
435 if (height < FLT_MIN) {
436 height = 1;
437 }
438 winx = std::max<float>(winx, 1);
439 winy = std::max<float>(winy, 1);
440 if (v2d->oldwinx == 0) {
441 v2d->oldwinx = winx;
442 }
443 if (v2d->oldwiny == 0) {
444 v2d->oldwiny = winy;
445 }
446
447 /* V2D_KEEPZOOM indicates that zoom level should be preserved when the window size changes. */
448 if (resize && (v2d->keepzoom & V2D_KEEPZOOM)) {
449 float zoom, oldzoom;
450
451 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
452 zoom = winx / width;
453 oldzoom = v2d->oldwinx / curwidth;
454
455 if (oldzoom != zoom) {
456 width *= zoom / oldzoom;
457 }
458 }
459
460 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
461 zoom = winy / height;
462 oldzoom = v2d->oldwiny / curheight;
463
464 if (oldzoom != zoom) {
465 height *= zoom / oldzoom;
466 }
467 }
468 }
469 /* keepzoom (V2D_LIMITZOOM set), indicates that zoom level on each axis must not exceed limits
470 * NOTE: in general, it is not expected that the lock-zoom will be used in conjunction with this
471 */
472 else if (v2d->keepzoom & V2D_LIMITZOOM) {
473
474 /* check if excessive zoom on x-axis */
475 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
476 const float zoom = winx / width;
477 if (zoom < v2d->minzoom) {
478 width = winx / v2d->minzoom;
479 }
480 else if (zoom > v2d->maxzoom) {
481 width = winx / v2d->maxzoom;
482 }
483 }
484
485 /* check if excessive zoom on y-axis */
486 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
487 const float zoom = winy / height;
488 if (zoom < v2d->minzoom) {
489 height = winy / v2d->minzoom;
490 }
491 else if (zoom > v2d->maxzoom) {
492 height = winy / v2d->maxzoom;
493 }
494 }
495 }
496 else {
497 /* make sure sizes don't exceed that of the min/max sizes
498 * (even though we're not doing zoom clamping) */
499 CLAMP(width, v2d->min[0], v2d->max[0]);
500 CLAMP(height, v2d->min[1], v2d->max[1]);
501 }
502
503 /* check if we should restore aspect ratio (if view size changed) */
504 if (v2d->keepzoom & V2D_KEEPASPECT) {
505 bool do_x = false, do_y = false, do_cur;
506 float curRatio, winRatio;
507
508 /* when a window edge changes, the aspect ratio can't be used to
509 * find which is the best new 'cur' rect. that's why it stores 'old'
510 */
511 if (winx != v2d->oldwinx) {
512 do_x = true;
513 }
514 if (winy != v2d->oldwiny) {
515 do_y = true;
516 }
517
518 curRatio = height / width;
519 winRatio = winy / winx;
520
521 /* Both sizes change (area/region maximized). */
522 if (do_x == do_y) {
523 if (do_x && do_y) {
524 /* here is 1,1 case, so all others must be 0,0 */
525 if (fabsf(winx - v2d->oldwinx) > fabsf(winy - v2d->oldwiny)) {
526 do_y = false;
527 }
528 else {
529 do_x = false;
530 }
531 }
532 else if (winRatio > curRatio) {
533 do_x = false;
534 }
535 else {
536 do_x = true;
537 }
538 }
539 do_cur = do_x;
540 // do_win = do_y; /* UNUSED. */
541
542 if (do_cur) {
543 if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winx != v2d->oldwinx)) {
544 /* Special exception for Outliner (and later channel-lists):
545 * - The view may be moved left to avoid contents
546 * being pushed out of view when view shrinks.
547 * - The keeptot code will make sure cur->xmin will not be less than tot->xmin
548 * (which cannot be allowed).
549 * - width is not adjusted for changed ratios here.
550 */
551 if (winx < v2d->oldwinx) {
552 const float temp = v2d->oldwinx - winx;
553
554 cur->xmin -= temp;
555 cur->xmax -= temp;
556
557 /* Width does not get modified, as keep-aspect here is just set to make
558 * sure visible area adjusts to changing view shape! */
559 }
560 }
561 else {
562 /* portrait window: correct for x */
563 width = height / winRatio;
564 }
565 }
566 else {
567 if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winy != v2d->oldwiny)) {
568 /* special exception for Outliner (and later channel-lists):
569 * - Currently, no actions need to be taken here...
570 */
571
572 if (winy < v2d->oldwiny) {
573 const float temp = v2d->oldwiny - winy;
574
575 if (v2d->align & V2D_ALIGN_NO_NEG_Y) {
576 cur->ymin -= temp;
577 cur->ymax -= temp;
578 }
579 else { /* Assume V2D_ALIGN_NO_POS_Y or combination */
580 cur->ymin += temp;
581 cur->ymax += temp;
582 }
583 }
584 }
585 else {
586 /* landscape window: correct for y */
587 height = width * winRatio;
588 }
589 }
590 }
591
592 /* Store region size for next time. */
593 v2d->oldwinx = short(winx);
594 v2d->oldwiny = short(winy);
595
596 /* Step 2: apply new sizes to cur rect,
597 * but need to take into account alignment settings here... */
598 const bool do_keepofs = resize || !(v2d->flag & V2D_ZOOM_IGNORE_KEEPOFS);
599 if ((width != curwidth) || (height != curheight)) {
600 float temp, dh;
601
602 /* Resize from center-point, unless otherwise specified. */
603 if (width != curwidth) {
604 if (v2d->keepofs & V2D_LOCKOFS_X) {
605 cur->xmax += width - BLI_rctf_size_x(cur);
606 }
607 else if ((v2d->keepofs & V2D_KEEPOFS_X) && do_keepofs) {
608 if (v2d->align & V2D_ALIGN_NO_POS_X) {
609 cur->xmin -= width - BLI_rctf_size_x(cur);
610 }
611 else {
612 cur->xmax += width - BLI_rctf_size_x(cur);
613 }
614 }
615 else {
616 temp = BLI_rctf_cent_x(cur);
617 dh = width * 0.5f;
618
619 cur->xmin = temp - dh;
620 cur->xmax = temp + dh;
621 }
622 }
623 if (height != curheight) {
624 if (v2d->keepofs & V2D_LOCKOFS_Y) {
625 cur->ymax += height - BLI_rctf_size_y(cur);
626 }
627 else if ((v2d->keepofs & V2D_KEEPOFS_Y) && do_keepofs) {
628 if (v2d->align & V2D_ALIGN_NO_POS_Y) {
629 cur->ymin -= height - BLI_rctf_size_y(cur);
630 }
631 else {
632 cur->ymax += height - BLI_rctf_size_y(cur);
633 }
634 }
635 else {
636 temp = BLI_rctf_cent_y(cur);
637 dh = height * 0.5f;
638
639 cur->ymin = temp - dh;
640 cur->ymax = temp + dh;
641 }
642 }
643 }
644
645 /* Step 3: adjust so that it doesn't fall outside of bounds of 'tot' */
646 if (v2d->keeptot) {
647 float temp, diff;
648
649 /* recalculate extents of cur */
650 curwidth = BLI_rctf_size_x(cur);
651 curheight = BLI_rctf_size_y(cur);
652
653 /* width */
654 if ((curwidth > totwidth) &&
656 {
657 /* if zoom doesn't have to be maintained, just clamp edges */
658 cur->xmin = std::max(cur->xmin, tot->xmin);
659 cur->xmax = std::min(cur->xmax, tot->xmax);
660 }
661 else if (v2d->keeptot == V2D_KEEPTOT_STRICT) {
662 /* This is an exception for the outliner (and later channel-lists, headers)
663 * - must clamp within tot rect (absolutely no excuses)
664 * --> therefore, cur->xmin must not be less than tot->xmin
665 */
666 if (cur->xmin < tot->xmin) {
667 /* move cur across so that it sits at minimum of tot */
668 temp = tot->xmin - cur->xmin;
669
670 cur->xmin += temp;
671 cur->xmax += temp;
672 }
673 else if (cur->xmax > tot->xmax) {
674 /* - only offset by difference of cur-xmax and tot-xmax if that would not move
675 * cur-xmin to lie past tot-xmin
676 * - otherwise, simply shift to tot-xmin???
677 */
678 temp = cur->xmax - tot->xmax;
679
680 if ((cur->xmin - temp) < tot->xmin) {
681 /* only offset by difference from cur-min and tot-min */
682 temp = cur->xmin - tot->xmin;
683
684 cur->xmin -= temp;
685 cur->xmax -= temp;
686 }
687 else {
688 cur->xmin -= temp;
689 cur->xmax -= temp;
690 }
691 }
692 }
693 else {
694 /* This here occurs when:
695 * - width too big, but maintaining zoom (i.e. widths cannot be changed)
696 * - width is OK, but need to check if outside of boundaries
697 *
698 * So, resolution is to just shift view by the gap between the extremities.
699 * We favor moving the 'minimum' across, as that's origin for most things.
700 * (XXX: in the past, max was favored... if there are bugs, swap!)
701 */
702 if ((cur->xmin < tot->xmin) && (cur->xmax > tot->xmax)) {
703 /* outside boundaries on both sides,
704 * so take middle-point of tot, and place in balanced way */
705 temp = BLI_rctf_cent_x(tot);
706 diff = curwidth * 0.5f;
707
708 cur->xmin = temp - diff;
709 cur->xmax = temp + diff;
710 }
711 else if (cur->xmin < tot->xmin) {
712 /* move cur across so that it sits at minimum of tot */
713 temp = tot->xmin - cur->xmin;
714
715 cur->xmin += temp;
716 cur->xmax += temp;
717 }
718 else if (cur->xmax > tot->xmax) {
719 /* - only offset by difference of cur-xmax and tot-xmax if that would not move
720 * cur-xmin to lie past tot-xmin
721 * - otherwise, simply shift to tot-xmin???
722 */
723 temp = cur->xmax - tot->xmax;
724
725 if ((cur->xmin - temp) < tot->xmin) {
726 /* only offset by difference from cur-min and tot-min */
727 temp = cur->xmin - tot->xmin;
728
729 cur->xmin -= temp;
730 cur->xmax -= temp;
731 }
732 else {
733 cur->xmin -= temp;
734 cur->xmax -= temp;
735 }
736 }
737 }
738
739 /* height */
740 if ((curheight > totheight) &&
742 {
743 /* if zoom doesn't have to be maintained, just clamp edges */
744 cur->ymin = std::max(cur->ymin, tot->ymin);
745 cur->ymax = std::min(cur->ymax, tot->ymax);
746 }
747 else {
748 /* This here occurs when:
749 * - height too big, but maintaining zoom (i.e. heights cannot be changed)
750 * - height is OK, but need to check if outside of boundaries
751 *
752 * So, resolution is to just shift view by the gap between the extremities.
753 * We favor moving the 'minimum' across, as that's origin for most things.
754 */
755 if ((cur->ymin < tot->ymin) && (cur->ymax > tot->ymax)) {
756 /* outside boundaries on both sides,
757 * so take middle-point of tot, and place in balanced way */
758 temp = BLI_rctf_cent_y(tot);
759 diff = curheight * 0.5f;
760
761 cur->ymin = temp - diff;
762 cur->ymax = temp + diff;
763 }
764 else if (cur->ymin < tot->ymin) {
765 /* there's still space remaining, so shift up */
766 temp = tot->ymin - cur->ymin;
767
768 cur->ymin += temp;
769 cur->ymax += temp;
770 }
771 else if (cur->ymax > tot->ymax) {
772 /* there's still space remaining, so shift down */
773 temp = cur->ymax - tot->ymax;
774
775 cur->ymin -= temp;
776 cur->ymax -= temp;
777 }
778 }
779 }
780
781 /* Step 4: Make sure alignment restrictions are respected */
782 if (v2d->align) {
783 /* If alignment flags are set (but keeptot is not), they must still be respected, as although
784 * they don't specify any particular bounds to stay within, they do define ranges which are
785 * invalid.
786 *
787 * Here, we only check to make sure that on each axis, the 'cur' rect doesn't stray into these
788 * invalid zones, otherwise we offset.
789 */
790
791 /* handle width - posx and negx flags are mutually exclusive, so watch out */
792 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
793 /* width is in negative-x half */
794 if (v2d->cur.xmax > 0) {
795 v2d->cur.xmin -= v2d->cur.xmax;
796 v2d->cur.xmax = 0.0f;
797 }
798 }
799 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
800 /* width is in positive-x half */
801 if (v2d->cur.xmin < 0) {
802 v2d->cur.xmax -= v2d->cur.xmin;
803 v2d->cur.xmin = 0.0f;
804 }
805 }
806
807 /* handle height - posx and negx flags are mutually exclusive, so watch out */
808 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
809 /* height is in negative-y half */
810 if (v2d->cur.ymax > 0) {
811 v2d->cur.ymin -= v2d->cur.ymax;
812 v2d->cur.ymax = 0.0f;
813 }
814 }
815 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
816 /* height is in positive-y half */
817 if (v2d->cur.ymin < 0) {
818 v2d->cur.ymax -= v2d->cur.ymin;
819 v2d->cur.ymin = 0.0f;
820 }
821 }
822 }
823
824 /* set masks */
825 view2d_masks(v2d, nullptr);
826}
827
832
834{
836
837 ARegion *region = CTX_wm_region(C);
838
839 if (region->runtime->type->on_view2d_changed != nullptr) {
840 region->runtime->type->on_view2d_changed(C, region);
841 }
842}
843
845{
846 const float cur_height_y = BLI_rctf_size_y(&v2d->cur);
847
848 if (BLI_rctf_size_y(&v2d->cur) > BLI_rctf_size_y(&v2d->tot)) {
849 v2d->cur.ymin = -cur_height_y;
850 v2d->cur.ymax = 0;
851 }
852 else if (v2d->cur.ymin < v2d->tot.ymin) {
853 v2d->cur.ymin = v2d->tot.ymin;
854 v2d->cur.ymax = v2d->cur.ymin + cur_height_y;
855 }
856}
857
858/* ------------------ */
859
864
865void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
866{
867 /* don't continue if no view syncing to be done */
869 return;
870 }
871
872 /* check if doing within area syncing (i.e. channels/vertical) */
873 if ((v2dcur->flag & V2D_VIEWSYNC_AREA_VERTICAL) && (area)) {
874 LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
875 /* don't operate on self */
876 if (v2dcur != &region->v2d) {
877 /* only if view has vertical locks enabled */
878 if (region->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) {
879 if (flag == V2D_LOCK_COPY) {
880 /* other views with locks on must copy active */
881 region->v2d.cur.ymin = v2dcur->cur.ymin;
882 region->v2d.cur.ymax = v2dcur->cur.ymax;
883 }
884 else { /* V2D_LOCK_SET */
885 /* active must copy others */
886 v2dcur->cur.ymin = region->v2d.cur.ymin;
887 v2dcur->cur.ymax = region->v2d.cur.ymax;
888 }
889
890 /* region possibly changed, so refresh */
892 }
893 }
894 }
895 }
896
897 /* check if doing whole screen syncing (i.e. time/horizontal) */
898 if ((v2dcur->flag & V2D_VIEWSYNC_SCREEN_TIME) && (screen)) {
899 LISTBASE_FOREACH (ScrArea *, area_iter, &screen->areabase) {
900 if (!UI_view2d_area_supports_sync(area_iter)) {
901 continue;
902 }
903 LISTBASE_FOREACH (ARegion *, region, &area_iter->regionbase) {
904 /* don't operate on self */
905 if (v2dcur != &region->v2d) {
906 /* only if view has horizontal locks enabled */
907 if (region->v2d.flag & V2D_VIEWSYNC_SCREEN_TIME) {
908 if (flag == V2D_LOCK_COPY) {
909 /* other views with locks on must copy active */
910 region->v2d.cur.xmin = v2dcur->cur.xmin;
911 region->v2d.cur.xmax = v2dcur->cur.xmax;
912 }
913 else { /* V2D_LOCK_SET */
914 /* active must copy others */
915 v2dcur->cur.xmin = region->v2d.cur.xmin;
916 v2dcur->cur.xmax = region->v2d.cur.xmax;
917 }
918
919 /* region possibly changed, so refresh */
921 }
922 }
923 }
924 }
925 }
926}
927
929{
930 float width, height;
931
932 /* assume width and height of 'cur' rect by default, should be same size as mask */
933 width = float(BLI_rcti_size_x(&v2d->mask) + 1);
934 height = float(BLI_rcti_size_y(&v2d->mask) + 1);
935
936 /* handle width - posx and negx flags are mutually exclusive, so watch out */
937 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
938 /* width is in negative-x half */
939 v2d->cur.xmin = -width;
940 v2d->cur.xmax = 0.0f;
941 }
942 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
943 /* width is in positive-x half */
944 v2d->cur.xmin = 0.0f;
945 v2d->cur.xmax = width;
946 }
947 else {
948 /* width is centered around (x == 0) */
949 const float dx = width / 2.0f;
950
951 v2d->cur.xmin = -dx;
952 v2d->cur.xmax = dx;
953 }
954
955 /* handle height - posx and negx flags are mutually exclusive, so watch out */
956 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
957 /* height is in negative-y half */
958 v2d->cur.ymin = -height;
959 v2d->cur.ymax = 0.0f;
960 }
961 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
962 /* height is in positive-y half */
963 v2d->cur.ymin = 0.0f;
964 v2d->cur.ymax = height;
965 }
966 else {
967 /* height is centered around (y == 0) */
968 const float dy = height / 2.0f;
969
970 v2d->cur.ymin = -dy;
971 v2d->cur.ymax = dy;
972 }
973}
974
975/* ------------------ */
976
977void view2d_totRect_set_resize(View2D *v2d, int width, int height, bool resize)
978{
979 /* don't do anything if either value is 0 */
980 width = abs(width);
981 height = abs(height);
982
983 if (ELEM(0, width, height)) {
984 if (G.debug & G_DEBUG) {
985 /* XXX: temp debug info. */
986 printf("Error: View2D totRect set exiting: v2d=%p width=%d height=%d\n",
987 (void *)v2d,
988 width,
989 height);
990 }
991 return;
992 }
993
994 /* handle width - posx and negx flags are mutually exclusive, so watch out */
995 if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
996 /* width is in negative-x half */
997 v2d->tot.xmin = float(-width);
998 v2d->tot.xmax = 0.0f;
999 }
1000 else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
1001 /* width is in positive-x half */
1002 v2d->tot.xmin = 0.0f;
1003 v2d->tot.xmax = float(width);
1004 }
1005 else {
1006 /* width is centered around (x == 0) */
1007 const float dx = float(width) / 2.0f;
1008
1009 v2d->tot.xmin = -dx;
1010 v2d->tot.xmax = dx;
1011 }
1012
1013 /* handle height - posx and negx flags are mutually exclusive, so watch out */
1014 if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
1015 /* height is in negative-y half */
1016 v2d->tot.ymin = float(-height);
1017 v2d->tot.ymax = 0.0f;
1018 }
1019 else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
1020 /* height is in positive-y half */
1021 v2d->tot.ymin = 0.0f;
1022 v2d->tot.ymax = float(height);
1023 }
1024 else {
1025 /* height is centered around (y == 0) */
1026 const float dy = float(height) / 2.0f;
1027
1028 v2d->tot.ymin = -dy;
1029 v2d->tot.ymax = dy;
1030 }
1031
1032 /* make sure that 'cur' rect is in a valid state as a result of these changes */
1034}
1035
1036void UI_view2d_totRect_set(View2D *v2d, int width, int height)
1037{
1038 view2d_totRect_set_resize(v2d, width, height, false);
1039}
1040
1042{
1043 /* TODO(sergey): This way we avoid threading conflict with sequencer rendering
1044 * text strip. But ideally we want to make glyph cache to be fully safe
1045 * for threading.
1046 */
1047 if (G.is_rendering) {
1048 return;
1049 }
1050 /* While scaling we can accumulate fonts at many sizes (~20 or so).
1051 * Not an issue with embedded font, but can use over 500Mb with i18n ones! See #38244. */
1052
1053 /* NOTE: only some views draw text, we could check for this case to avoid cleaning cache. */
1055}
1056
1058
1059/* -------------------------------------------------------------------- */
1062
1063/* mapping function to ensure 'cur' draws extended over the area where sliders are */
1064static void view2d_map_cur_using_mask(const View2D *v2d, rctf *r_curmasked)
1065{
1066 *r_curmasked = v2d->cur;
1067
1068 if (view2d_scroll_mapped(v2d->scroll)) {
1069 const float sizex = BLI_rcti_size_x(&v2d->mask);
1070 const float sizey = BLI_rcti_size_y(&v2d->mask);
1071
1072 /* prevent tiny or narrow regions to get
1073 * invalid coordinates - mask can get negative even... */
1074 if (sizex > 0.0f && sizey > 0.0f) {
1075 const float dx = BLI_rctf_size_x(&v2d->cur) / (sizex + 1);
1076 const float dy = BLI_rctf_size_y(&v2d->cur) / (sizey + 1);
1077
1078 if (v2d->mask.xmin != 0) {
1079 r_curmasked->xmin -= dx * float(v2d->mask.xmin);
1080 }
1081 if (v2d->mask.xmax + 1 != v2d->winx) {
1082 r_curmasked->xmax += dx * float(v2d->winx - v2d->mask.xmax - 1);
1083 }
1084
1085 if (v2d->mask.ymin != 0) {
1086 r_curmasked->ymin -= dy * float(v2d->mask.ymin);
1087 }
1088 if (v2d->mask.ymax + 1 != v2d->winy) {
1089 r_curmasked->ymax += dy * float(v2d->winy - v2d->mask.ymax - 1);
1090 }
1091 }
1092 }
1093}
1094
1096{
1097 rctf curmasked;
1098 const int sizex = BLI_rcti_size_x(&v2d->mask);
1099 const int sizey = BLI_rcti_size_y(&v2d->mask);
1100 const float eps = 0.001f;
1101 float xofs = 0.0f, yofs = 0.0f;
1102
1103 /* Pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1
1104 * correspondence with pixels for smooth UI drawing,
1105 * but only applied where requested.
1106 */
1107 /* XXX(@brecht): instead of zero at least use a tiny offset, otherwise
1108 * pixel rounding is effectively random due to float inaccuracy */
1109 if (sizex > 0) {
1110 xofs = eps * BLI_rctf_size_x(&v2d->cur) / sizex;
1111 }
1112 if (sizey > 0) {
1113 yofs = eps * BLI_rctf_size_y(&v2d->cur) / sizey;
1114 }
1115
1116 /* apply mask-based adjustments to cur rect (due to scrollers),
1117 * to eliminate scaling artifacts */
1118 view2d_map_cur_using_mask(v2d, &curmasked);
1119
1120 BLI_rctf_translate(&curmasked, -xofs, -yofs);
1121
1122 /* XXX ton: this flag set by outliner, for icons */
1123 if (v2d->flag & V2D_PIXELOFS_X) {
1124 curmasked.xmin = floorf(curmasked.xmin) - (eps + xofs);
1125 curmasked.xmax = floorf(curmasked.xmax) - (eps + xofs);
1126 }
1127 if (v2d->flag & V2D_PIXELOFS_Y) {
1128 curmasked.ymin = floorf(curmasked.ymin) - (eps + yofs);
1129 curmasked.ymax = floorf(curmasked.ymax) - (eps + yofs);
1130 }
1131
1132 /* set matrix on all appropriate axes */
1133 wmOrtho2(curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
1134}
1135
1136void UI_view2d_view_orthoSpecial(ARegion *region, View2D *v2d, const bool xaxis)
1137{
1138 rctf curmasked;
1139 float xofs, yofs;
1140
1141 /* Pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1
1142 * correspondence with pixels for smooth UI drawing,
1143 * but only applied where requested.
1144 */
1145 /* XXX(ton): temp. */
1146 xofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? GLA_PIXEL_OFS : 0.0f;
1147 yofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? GLA_PIXEL_OFS : 0.0f;
1148
1149 /* apply mask-based adjustments to cur rect (due to scrollers),
1150 * to eliminate scaling artifacts */
1151 view2d_map_cur_using_mask(v2d, &curmasked);
1152
1153 /* only set matrix with 'cur' coordinates on relevant axes */
1154 if (xaxis) {
1155 wmOrtho2(curmasked.xmin - xofs, curmasked.xmax - xofs, -yofs, region->winy - yofs);
1156 }
1157 else {
1158 wmOrtho2(-xofs, region->winx - xofs, curmasked.ymin - yofs, curmasked.ymax - yofs);
1159 }
1160}
1161
1163{
1164 ARegion *region = CTX_wm_region(C);
1165 const int width = BLI_rcti_size_x(&region->winrct) + 1;
1166 const int height = BLI_rcti_size_y(&region->winrct) + 1;
1167
1168 wmOrtho2(0.0f, float(width), 0.0f, float(height));
1170
1171 // ED_region_pixelspace(CTX_wm_region(C));
1172}
1173
1175
1176/* -------------------------------------------------------------------- */
1179
1181 const View2D *v2d, int colorid, float step, int level_size, int totlevels)
1182{
1183 /* Exit if there is nothing to draw */
1184 if (totlevels == 0) {
1185 return;
1186 }
1187
1188 int offset = -10;
1189 float lstep = step;
1190 uchar grid_line_color[3];
1191
1192 /* Make an estimate of at least how many vertices will be needed */
1193 uint vertex_count = 4;
1194 vertex_count += 2 * (int((v2d->cur.xmax - v2d->cur.xmin) / lstep) + 1);
1195 vertex_count += 2 * (int((v2d->cur.ymax - v2d->cur.ymin) / lstep) + 1);
1196
1201
1202 GPU_line_width(1.0f);
1203
1205 immBeginAtMost(GPU_PRIM_LINES, vertex_count);
1206
1207 for (int level = 0; level < totlevels; level++) {
1208 /* Blend the background color (colorid) with the grid color, to avoid either too low contrast
1209 * or high contrast grid lines. This only has an effect if colorid != TH_GRID. */
1210 UI_GetThemeColorBlendShade3ubv(colorid, TH_GRID, 0.25f, offset, grid_line_color);
1211
1212 int i = int(v2d->cur.xmin / lstep);
1213 if (v2d->cur.xmin > 0.0f) {
1214 i++;
1215 }
1216 float start = i * lstep;
1217
1218 for (; start < v2d->cur.xmax; start += lstep, i++) {
1219 if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) {
1220 continue;
1221 }
1222
1223 immAttrSkip(color);
1224 immVertex2f(pos, start, v2d->cur.ymin);
1225 immAttr4ub(color, UNPACK3(grid_line_color), 255);
1226 immVertex2f(pos, start, v2d->cur.ymax);
1227 }
1228
1229 i = int(v2d->cur.ymin / lstep);
1230 if (v2d->cur.ymin > 0.0f) {
1231 i++;
1232 }
1233 start = i * lstep;
1234
1235 for (; start < v2d->cur.ymax; start += lstep, i++) {
1236 if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) {
1237 continue;
1238 }
1239
1240 immAttrSkip(color);
1241 immVertex2f(pos, v2d->cur.xmin, start);
1242 immAttr4ub(color, UNPACK3(grid_line_color), 255);
1243 immVertex2f(pos, v2d->cur.xmax, start);
1244 }
1245
1246 lstep *= level_size;
1247 offset -= 6;
1248 }
1249
1250 /* X and Y axis */
1252 colorid, TH_GRID, 0.5f, -18 + ((totlevels - 1) * -6), grid_line_color);
1253
1254 immAttrSkip(color);
1255 immVertex2f(pos, 0.0f, v2d->cur.ymin);
1256 immAttr4ub(color, UNPACK3(grid_line_color), 255);
1257 immVertex2f(pos, 0.0f, v2d->cur.ymax);
1258
1259 immAttrSkip(color);
1260 immVertex2f(pos, v2d->cur.xmin, 0.0f);
1261 immAttr4ub(color, UNPACK3(grid_line_color), 255);
1262 immVertex2f(pos, v2d->cur.xmax, 0.0f);
1263
1264 immEnd();
1266}
1267
1269 const float step, const float min, const float max, float *r_start, int *r_count)
1270{
1271 *r_start = min;
1272 if (*r_start < 0.0f) {
1273 *r_start += -fmod(min, step);
1274 }
1275 else {
1276 *r_start += step - fabs(fmod(min, step));
1277 }
1278
1279 if (*r_start > max) {
1280 *r_count = 0;
1281 }
1282 else {
1283 *r_count = (max - *r_start) / step + 1;
1284 }
1285}
1286
1288 const int grid_color_id,
1289 const float min_step,
1290 const int grid_subdivisions)
1291{
1292 BLI_assert(grid_subdivisions >= 0 && grid_subdivisions < 4);
1293 if (grid_subdivisions == 0) {
1294 return;
1295 }
1296
1297 const float zoom_x = float(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur);
1298
1303
1304 /* Scaling the dots fully with the zoom looks too busy, but a bit of size variation is nice. */
1305 const float min_point_size = 2.0f * U.pixelsize;
1306 const float point_size_factor = 1.5f;
1307 const float max_point_size = point_size_factor * min_point_size;
1308
1309 /* Each consecutive grid level is five times larger than the previous. */
1310 const int subdivision_scale = 5;
1311
1312 const float view_level = logf(min_step / zoom_x) / logf(subdivision_scale);
1313 const int largest_visible_level = int(view_level);
1314
1315 for (int level_offset = 0; level_offset <= grid_subdivisions; level_offset++) {
1316 const int level = largest_visible_level - level_offset;
1317
1318 if (level < 0) {
1319 break;
1320 }
1321
1322 const float level_scale = powf(subdivision_scale, level);
1323 const float point_size_precise = min_point_size * level_scale * zoom_x;
1324 const float point_size_draw = ceilf(
1325 clamp_f(point_size_precise, min_point_size, max_point_size));
1326
1327 /* Offset point by this amount to better align centers as size changes. */
1328 const float point_size_offset = (point_size_draw / 2.0f) - U.pixelsize;
1329
1330 /* To compensate the for the clamped point_size we adjust the alpha to make the overall
1331 * brightness of the grid background more consistent. */
1332 const float alpha = pow2f(point_size_precise / point_size_draw);
1333
1334 /* Make sure we don't draw points once the alpha gets too low. */
1335 const float alpha_cutoff = 0.01f;
1336 if (alpha < alpha_cutoff) {
1337 break;
1338 }
1339 const float alpha_clamped = clamp_f((1.0f + alpha_cutoff) * alpha - alpha_cutoff, 0.0f, 1.0f);
1340
1341 /* If we have don't draw enough subdivision levels so they fade out naturally, we apply an
1342 * additional fade to the last level to avoid pop in. */
1343 const bool last_level = level_offset == grid_subdivisions;
1344 const float subdivision_fade = last_level ? (1.0f - fractf(view_level)) : 1.0f;
1345
1346 float color[4];
1347 UI_GetThemeColor3fv(grid_color_id, color);
1348 color[3] = alpha_clamped * subdivision_fade;
1349
1350 const float step = min_step * level_scale;
1351 int count_x;
1352 float start_x;
1353
1354 /* Count points that fit in viewport. */
1355 grid_axis_start_and_count(step, v2d->cur.xmin, v2d->cur.xmax, &start_x, &count_x);
1356 int count_y;
1357 float start_y;
1358 grid_axis_start_and_count(step, v2d->cur.ymin, v2d->cur.ymax, &start_y, &count_y);
1359 if (count_x == 0 || count_y == 0) {
1360 continue;
1361 }
1362
1363 immUniform1f("size", point_size_draw);
1364 immUniform4fv("color", color);
1365 immBegin(GPU_PRIM_POINTS, count_x * count_y);
1366
1367 /* Theoretically drawing on top of lower grid levels could be avoided, but it would also
1368 * increase the complexity of this loop, which isn't worth the time at the moment. */
1369 for (int i_y = 0; i_y < count_y; i_y++) {
1370 const float y = start_y + step * i_y;
1371 for (int i_x = 0; i_x < count_x; i_x++) {
1372 const float x = start_x + step * i_x;
1373 immVertex2f(pos, x + point_size_offset, y + point_size_offset);
1374 }
1375 }
1376
1377 immEnd();
1378 }
1379
1382}
1383
1385
1386/* -------------------------------------------------------------------- */
1389
1390void view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom, View2DScrollers *r_scrollers)
1391{
1392 rcti vert, hor;
1393 float fac1, fac2, totsize, scrollsize;
1394 const int scroll = view2d_scroll_mapped(v2d->scroll);
1395
1396 /* Always update before drawing (for dynamically sized scrollers). */
1397 view2d_masks(v2d, mask_custom);
1398
1399 vert = v2d->vert;
1400 hor = v2d->hor;
1401
1402 /* Pad scroll-bar drawing away from region edges. */
1403 const int edge_pad = int(0.1f * U.widget_unit);
1404 if (scroll & V2D_SCROLL_BOTTOM) {
1405 hor.ymin += edge_pad;
1406 }
1407 else {
1408 hor.ymax -= edge_pad;
1409 }
1410
1411 if (scroll & V2D_SCROLL_LEFT) {
1412 vert.xmin += edge_pad;
1413 }
1414 else {
1415 vert.xmax -= edge_pad;
1416 }
1417
1420
1421 /* store in scrollers, used for drawing */
1422 r_scrollers->vert = vert;
1423 r_scrollers->hor = hor;
1424
1425 /* scroller 'buttons':
1426 * - These should always remain within the visible region of the scroll-bar
1427 * - They represent the region of 'tot' that is visible in 'cur'
1428 */
1429
1430 /* horizontal scrollers */
1431 if (scroll & V2D_SCROLL_HORIZONTAL) {
1432 /* scroller 'button' extents */
1433 totsize = BLI_rctf_size_x(&v2d->tot);
1434 scrollsize = float(BLI_rcti_size_x(&hor));
1435 if (totsize == 0.0f) {
1436 totsize = 1.0f; /* avoid divide by zero */
1437 }
1438
1439 fac1 = (v2d->cur.xmin - v2d->tot.xmin) / totsize;
1440 if (fac1 <= 0.0f) {
1441 r_scrollers->hor_min = hor.xmin;
1442 }
1443 else {
1444 r_scrollers->hor_min = int(hor.xmin + (fac1 * scrollsize));
1445 }
1446
1447 fac2 = (v2d->cur.xmax - v2d->tot.xmin) / totsize;
1448 if (fac2 >= 1.0f) {
1449 r_scrollers->hor_max = hor.xmax;
1450 }
1451 else {
1452 r_scrollers->hor_max = int(hor.xmin + (fac2 * scrollsize));
1453 }
1454
1455 /* prevent inverted sliders */
1456 r_scrollers->hor_min = std::min(r_scrollers->hor_min, r_scrollers->hor_max);
1457 /* prevent sliders from being too small to grab */
1458 if ((r_scrollers->hor_max - r_scrollers->hor_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
1459 r_scrollers->hor_max = r_scrollers->hor_min + V2D_SCROLL_THUMB_SIZE_MIN;
1460
1461 CLAMP(r_scrollers->hor_max, hor.xmin + V2D_SCROLL_THUMB_SIZE_MIN, hor.xmax);
1462 CLAMP(r_scrollers->hor_min, hor.xmin, hor.xmax - V2D_SCROLL_THUMB_SIZE_MIN);
1463 }
1464 }
1465
1466 /* vertical scrollers */
1467 if (scroll & V2D_SCROLL_VERTICAL) {
1468 /* scroller 'button' extents */
1469 totsize = BLI_rctf_size_y(&v2d->tot);
1470 scrollsize = float(BLI_rcti_size_y(&vert));
1471 if (totsize == 0.0f) {
1472 totsize = 1.0f; /* avoid divide by zero */
1473 }
1474
1475 fac1 = (v2d->cur.ymin - v2d->tot.ymin) / totsize;
1476 if (fac1 <= 0.0f) {
1477 r_scrollers->vert_min = vert.ymin;
1478 }
1479 else {
1480 r_scrollers->vert_min = int(vert.ymin + (fac1 * scrollsize));
1481 }
1482
1483 fac2 = (v2d->cur.ymax - v2d->tot.ymin) / totsize;
1484 if (fac2 >= 1.0f) {
1485 r_scrollers->vert_max = vert.ymax;
1486 }
1487 else {
1488 r_scrollers->vert_max = int(vert.ymin + (fac2 * scrollsize));
1489 }
1490
1491 /* prevent inverted sliders */
1492 r_scrollers->vert_min = std::min(r_scrollers->vert_min, r_scrollers->vert_max);
1493 /* prevent sliders from being too small to grab */
1494 if ((r_scrollers->vert_max - r_scrollers->vert_min) < V2D_SCROLL_THUMB_SIZE_MIN) {
1495 r_scrollers->vert_max = r_scrollers->vert_min + V2D_SCROLL_THUMB_SIZE_MIN;
1496
1497 CLAMP(r_scrollers->vert_max, vert.ymin + V2D_SCROLL_THUMB_SIZE_MIN, vert.ymax);
1498 CLAMP(r_scrollers->vert_min, vert.ymin, vert.ymax - V2D_SCROLL_THUMB_SIZE_MIN);
1499 }
1500 }
1501}
1502
1503void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
1504{
1505 View2DScrollers scrollers;
1506 view2d_scrollers_calc(v2d, mask_custom, &scrollers);
1507 bTheme *btheme = UI_GetTheme();
1508 rcti vert, hor;
1509 const int scroll = view2d_scroll_mapped(v2d->scroll);
1510 const char emboss_alpha = btheme->tui.widget_emboss[3];
1511 const float alpha_min = V2D_SCROLL_MIN_ALPHA;
1512
1513 uchar scrollers_back_color[4];
1514
1515 /* Color for scroll-bar backs. */
1516 UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color);
1517
1518 /* make copies of rects for less typing */
1519 vert = scrollers.vert;
1520 hor = scrollers.hor;
1521
1522 /* Horizontal scroll-bar. */
1523 if (scroll & V2D_SCROLL_HORIZONTAL) {
1524 uiWidgetColors wcol = btheme->tui.wcol_scroll;
1525 /* 0..255 -> min...1 */
1526 const float alpha_fac = ((v2d->alpha_hor / 255.0f) * (1.0f - alpha_min)) + alpha_min;
1527 rcti slider;
1528 int state;
1529
1530 slider.xmin = scrollers.hor_min;
1531 slider.xmax = scrollers.hor_max;
1532 slider.ymin = hor.ymin;
1533 slider.ymax = hor.ymax;
1534
1536
1537 /* In the case that scroll-bar track is invisible, range from 0 ->`final_alpha` instead to
1538 * avoid errors with users trying to click into the underlying view. */
1539 if (wcol.inner[3] == 0) {
1540 const float final_alpha = 0.25f;
1541 wcol.inner[3] = final_alpha * v2d->alpha_hor;
1542 }
1543 else {
1544 wcol.inner[3] *= alpha_fac;
1545 }
1546 wcol.item[3] *= alpha_fac;
1547 wcol.outline[3] = 0;
1548 btheme->tui.widget_emboss[3] = 0; /* will be reset later */
1549
1550 /* show zoom handles if:
1551 * - zooming on x-axis is allowed (no scroll otherwise)
1552 * - slider bubble is large enough (no overdraw confusion)
1553 * - scale is shown on the scroller
1554 * (workaround to make sure that button windows don't show these,
1555 * and only the time-grids with their zoom-ability can do so).
1556 */
1557 if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->scroll & V2D_SCROLL_HORIZONTAL_HANDLES) &&
1559 {
1561 }
1562
1563 UI_draw_widget_scroll(&wcol, &hor, &slider, state);
1564 }
1565
1566 /* Vertical scroll-bar. */
1567 if (scroll & V2D_SCROLL_VERTICAL) {
1568 uiWidgetColors wcol = btheme->tui.wcol_scroll;
1569 rcti slider;
1570 /* 0..255 -> min...1 */
1571 const float alpha_fac = ((v2d->alpha_vert / 255.0f) * (1.0f - alpha_min)) + alpha_min;
1572 int state;
1573
1574 slider.xmin = vert.xmin;
1575 slider.xmax = vert.xmax;
1576 slider.ymin = scrollers.vert_min;
1577 slider.ymax = scrollers.vert_max;
1578
1580
1581 /* In the case that scroll-bar track is invisible, range from 0 ->`final_alpha` instead to
1582 * avoid errors with users trying to click into the underlying view. */
1583 if (wcol.inner[3] == 0) {
1584 const float final_alpha = 0.25f;
1585 wcol.inner[3] = final_alpha * v2d->alpha_vert;
1586 }
1587 else {
1588 wcol.inner[3] *= alpha_fac;
1589 }
1590 wcol.item[3] *= alpha_fac;
1591 wcol.outline[3] = 0;
1592 btheme->tui.widget_emboss[3] = 0; /* will be reset later */
1593
1594 /* show zoom handles if:
1595 * - zooming on y-axis is allowed (no scroll otherwise)
1596 * - slider bubble is large enough (no overdraw confusion)
1597 * - scale is shown on the scroller
1598 * (workaround to make sure that button windows don't show these,
1599 * and only the time-grids with their zoomability can do so)
1600 */
1601 if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && (v2d->scroll & V2D_SCROLL_VERTICAL_HANDLES) &&
1603 {
1605 }
1606
1607 UI_draw_widget_scroll(&wcol, &vert, &slider, state);
1608 }
1609
1610 /* Was changed above, so reset. */
1611 btheme->tui.widget_emboss[3] = emboss_alpha;
1612}
1613
1615
1616/* -------------------------------------------------------------------- */
1619
1620void UI_view2d_listview_view_to_cell(float columnwidth,
1621 float rowheight,
1622 float startx,
1623 float starty,
1624 float viewx,
1625 float viewy,
1626 int *r_column,
1627 int *r_row)
1628{
1629 if (r_column) {
1630 if (columnwidth > 0) {
1631 /* Columns go from left to right (x increases). */
1632 *r_column = floorf((viewx - startx) / columnwidth);
1633 }
1634 else {
1635 *r_column = 0;
1636 }
1637 }
1638
1639 if (r_row) {
1640 if (rowheight > 0) {
1641 /* Rows got from top to bottom (y decreases). */
1642 *r_row = floorf((starty - viewy) / rowheight);
1643 }
1644 else {
1645 *r_row = 0;
1646 }
1647 }
1648}
1649
1651
1652/* -------------------------------------------------------------------- */
1655
1656float UI_view2d_region_to_view_x(const View2D *v2d, float x)
1657{
1658 return (v2d->cur.xmin +
1659 (BLI_rctf_size_x(&v2d->cur) * (x - v2d->mask.xmin) / BLI_rcti_size_x(&v2d->mask)));
1660}
1661float UI_view2d_region_to_view_y(const View2D *v2d, float y)
1662{
1663 return (v2d->cur.ymin +
1664 (BLI_rctf_size_y(&v2d->cur) * (y - v2d->mask.ymin) / BLI_rcti_size_y(&v2d->mask)));
1665}
1666
1668 const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y)
1669{
1670 *r_view_x = UI_view2d_region_to_view_x(v2d, x);
1671 *r_view_y = UI_view2d_region_to_view_y(v2d, y);
1672}
1673
1674void UI_view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst)
1675{
1676 const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)};
1677 const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)),
1678 float(BLI_rcti_size_y(&v2d->mask))};
1679
1680 rect_dst->xmin = (v2d->cur.xmin +
1681 (cur_size[0] * (rect_src->xmin - v2d->mask.xmin) / mask_size[0]));
1682 rect_dst->xmax = (v2d->cur.xmin +
1683 (cur_size[0] * (rect_src->xmax - v2d->mask.xmin) / mask_size[0]));
1684 rect_dst->ymin = (v2d->cur.ymin +
1685 (cur_size[1] * (rect_src->ymin - v2d->mask.ymin) / mask_size[1]));
1686 rect_dst->ymax = (v2d->cur.ymin +
1687 (cur_size[1] * (rect_src->ymax - v2d->mask.ymin) / mask_size[1]));
1688}
1689
1690float UI_view2d_view_to_region_x(const View2D *v2d, float x)
1691{
1692 return (v2d->mask.xmin +
1693 (((x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur)) * BLI_rcti_size_x(&v2d->mask)));
1694}
1695float UI_view2d_view_to_region_y(const View2D *v2d, float y)
1696{
1697 return (v2d->mask.ymin +
1698 (((y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur)) * BLI_rcti_size_y(&v2d->mask)));
1699}
1700
1702 const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
1703{
1704 /* express given coordinates as proportional values */
1705 x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
1706 y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
1707
1708 /* check if values are within bounds */
1709 if ((x >= 0.0f) && (x <= 1.0f) && (y >= 0.0f) && (y <= 1.0f)) {
1710 *r_region_x = int(v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask)));
1711 *r_region_y = int(v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask)));
1712
1713 return true;
1714 }
1715
1716 /* set initial value in case coordinate lies outside of bounds */
1717 *r_region_x = *r_region_y = V2D_IS_CLIPPED;
1718
1719 return false;
1720}
1721
1723 const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
1724{
1725 /* Step 1: express given coordinates as proportional values. */
1726 x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
1727 y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
1728
1729 /* Step 2: convert proportional distances to screen coordinates. */
1730 x = v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask));
1731 y = v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask));
1732
1733 /* Although we don't clamp to lie within region bounds, we must avoid exceeding size of ints. */
1734 *r_region_x = clamp_float_to_int(x);
1735 *r_region_y = clamp_float_to_int(y);
1736}
1737
1739 const View2D *v2d, float x, float y, float *r_region_x, float *r_region_y)
1740{
1741 /* express given coordinates as proportional values */
1742 x = (x - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur);
1743 y = (y - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur);
1744
1745 /* convert proportional distances to screen coordinates */
1746 *r_region_x = v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask));
1747 *r_region_y = v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask));
1748}
1749
1751 const float xy_a[2],
1752 const float xy_b[2],
1753 int r_region_a[2],
1754 int r_region_b[2])
1755{
1756 rctf rect_unit;
1757 rect_unit.xmin = rect_unit.ymin = 0.0f;
1758 rect_unit.xmax = rect_unit.ymax = 1.0f;
1759
1760 /* Express given coordinates as proportional values. */
1761 const float s_a[2] = {
1762 (xy_a[0] - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur),
1763 (xy_a[1] - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur),
1764 };
1765 const float s_b[2] = {
1766 (xy_b[0] - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur),
1767 (xy_b[1] - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur),
1768 };
1769
1770 /* Set initial value in case coordinates lie outside bounds. */
1771 r_region_a[0] = r_region_b[0] = r_region_a[1] = r_region_b[1] = V2D_IS_CLIPPED;
1772
1773 if (BLI_rctf_isect_segment(&rect_unit, s_a, s_b)) {
1774 r_region_a[0] = int(v2d->mask.xmin + (s_a[0] * BLI_rcti_size_x(&v2d->mask)));
1775 r_region_a[1] = int(v2d->mask.ymin + (s_a[1] * BLI_rcti_size_y(&v2d->mask)));
1776 r_region_b[0] = int(v2d->mask.xmin + (s_b[0] * BLI_rcti_size_x(&v2d->mask)));
1777 r_region_b[1] = int(v2d->mask.ymin + (s_b[1] * BLI_rcti_size_y(&v2d->mask)));
1778
1779 return true;
1780 }
1781
1782 return false;
1783}
1784
1785void UI_view2d_view_to_region_rcti(const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
1786{
1787 const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)};
1788 const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)),
1789 float(BLI_rcti_size_y(&v2d->mask))};
1790 rctf rect_tmp;
1791
1792 /* Step 1: express given coordinates as proportional values. */
1793 rect_tmp.xmin = (rect_src->xmin - v2d->cur.xmin) / cur_size[0];
1794 rect_tmp.xmax = (rect_src->xmax - v2d->cur.xmin) / cur_size[0];
1795 rect_tmp.ymin = (rect_src->ymin - v2d->cur.ymin) / cur_size[1];
1796 rect_tmp.ymax = (rect_src->ymax - v2d->cur.ymin) / cur_size[1];
1797
1798 /* Step 2: convert proportional distances to screen coordinates. */
1799 rect_tmp.xmin = v2d->mask.xmin + (rect_tmp.xmin * mask_size[0]);
1800 rect_tmp.xmax = v2d->mask.xmin + (rect_tmp.xmax * mask_size[0]);
1801 rect_tmp.ymin = v2d->mask.ymin + (rect_tmp.ymin * mask_size[1]);
1802 rect_tmp.ymax = v2d->mask.ymin + (rect_tmp.ymax * mask_size[1]);
1803
1804 clamp_rctf_to_rcti(rect_dst, &rect_tmp);
1805}
1806
1807void UI_view2d_view_to_region_m4(const View2D *v2d, float matrix[4][4])
1808{
1809 rctf mask;
1810 unit_m4(matrix);
1811 BLI_rctf_rcti_copy(&mask, &v2d->mask);
1813}
1814
1815bool UI_view2d_view_to_region_rcti_clip(const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
1816{
1817 const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)};
1818 const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)),
1819 float(BLI_rcti_size_y(&v2d->mask))};
1820 rctf rect_tmp;
1821
1822 BLI_assert(rect_src->xmin <= rect_src->xmax && rect_src->ymin <= rect_src->ymax);
1823
1824 /* Step 1: express given coordinates as proportional values. */
1825 rect_tmp.xmin = (rect_src->xmin - v2d->cur.xmin) / cur_size[0];
1826 rect_tmp.xmax = (rect_src->xmax - v2d->cur.xmin) / cur_size[0];
1827 rect_tmp.ymin = (rect_src->ymin - v2d->cur.ymin) / cur_size[1];
1828 rect_tmp.ymax = (rect_src->ymax - v2d->cur.ymin) / cur_size[1];
1829
1830 if (((rect_tmp.xmax < 0.0f) || (rect_tmp.xmin > 1.0f) || (rect_tmp.ymax < 0.0f) ||
1831 (rect_tmp.ymin > 1.0f)) == 0)
1832 {
1833 /* Step 2: convert proportional distances to screen coordinates. */
1834 rect_tmp.xmin = v2d->mask.xmin + (rect_tmp.xmin * mask_size[0]);
1835 rect_tmp.xmax = v2d->mask.ymin + (rect_tmp.xmax * mask_size[0]);
1836 rect_tmp.ymin = v2d->mask.ymin + (rect_tmp.ymin * mask_size[1]);
1837 rect_tmp.ymax = v2d->mask.ymin + (rect_tmp.ymax * mask_size[1]);
1838
1839 clamp_rctf_to_rcti(rect_dst, &rect_tmp);
1840
1841 return true;
1842 }
1843
1844 rect_dst->xmin = rect_dst->xmax = rect_dst->ymin = rect_dst->ymax = V2D_IS_CLIPPED;
1845 return false;
1846}
1847
1849
1850/* -------------------------------------------------------------------- */
1853
1855{
1856 ScrArea *area = CTX_wm_area(C);
1857 ARegion *region = CTX_wm_region(C);
1858
1859 if (area == nullptr) {
1860 return nullptr;
1861 }
1862 if (region == nullptr) {
1863 return nullptr;
1864 }
1865 return &(region->v2d);
1866}
1867
1869{
1870 ScrArea *area = CTX_wm_area(C);
1871 ARegion *region = CTX_wm_region(C);
1872
1873 if (area == nullptr) {
1874 return nullptr;
1875 }
1876 if (region == nullptr) {
1877 return nullptr;
1878 }
1879 if (region->regiontype != RGN_TYPE_WINDOW) {
1881 return region_win ? &(region_win->v2d) : nullptr;
1882 }
1883 return &(region->v2d);
1884}
1885
1886void UI_view2d_scroller_size_get(const View2D *v2d, bool mapped, float *r_x, float *r_y)
1887{
1888 const int scroll = (mapped) ? view2d_scroll_mapped(v2d->scroll) : v2d->scroll;
1889
1890 if (r_x) {
1891 if (scroll & V2D_SCROLL_VERTICAL) {
1893 *r_x = ((*r_x - V2D_SCROLL_MIN_WIDTH) * (v2d->alpha_vert / 255.0f)) + V2D_SCROLL_MIN_WIDTH;
1894 }
1895 else {
1896 *r_x = 0;
1897 }
1898 }
1899 if (r_y) {
1900 if (scroll & V2D_SCROLL_HORIZONTAL) {
1903 *r_y = ((*r_y - V2D_SCROLL_MIN_WIDTH) * (v2d->alpha_hor / 255.0f)) + V2D_SCROLL_MIN_WIDTH;
1904 }
1905 else {
1906 *r_y = 0;
1907 }
1908 }
1909}
1910
1911void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
1912{
1913 if (r_x) {
1914 *r_x = UI_view2d_scale_get_x(v2d);
1915 }
1916 if (r_y) {
1917 *r_y = UI_view2d_scale_get_y(v2d);
1918 }
1919}
1921{
1922 return BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur);
1923}
1925{
1926 return BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur);
1927}
1928void UI_view2d_scale_get_inverse(const View2D *v2d, float *r_x, float *r_y)
1929{
1930 if (r_x) {
1931 *r_x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
1932 }
1933 if (r_y) {
1934 *r_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask);
1935 }
1936}
1937
1938void UI_view2d_center_get(const View2D *v2d, float *r_x, float *r_y)
1939{
1940 /* get center */
1941 if (r_x) {
1942 *r_x = BLI_rctf_cent_x(&v2d->cur);
1943 }
1944 if (r_y) {
1945 *r_y = BLI_rctf_cent_y(&v2d->cur);
1946 }
1947}
1948void UI_view2d_center_set(View2D *v2d, float x, float y)
1949{
1950 BLI_rctf_recenter(&v2d->cur, x, y);
1951
1952 /* make sure that 'cur' rect is in a valid state as a result of these changes */
1954}
1955
1956void UI_view2d_offset(View2D *v2d, float xfac, float yfac)
1957{
1958 if (xfac != -1.0f) {
1959 const float xsize = BLI_rctf_size_x(&v2d->cur);
1960 const float xmin = v2d->tot.xmin;
1961 const float xmax = v2d->tot.xmax - xsize;
1962
1963 v2d->cur.xmin = (xmin * (1.0f - xfac)) + (xmax * xfac);
1964 v2d->cur.xmax = v2d->cur.xmin + xsize;
1965 }
1966
1967 if (yfac != -1.0f) {
1968 const float ysize = BLI_rctf_size_y(&v2d->cur);
1969 const float ymin = v2d->tot.ymin;
1970 const float ymax = v2d->tot.ymax - ysize;
1971
1972 v2d->cur.ymin = (ymin * (1.0f - yfac)) + (ymax * yfac);
1973 v2d->cur.ymax = v2d->cur.ymin + ysize;
1974 }
1975
1977}
1978
1980{
1981 const float cur_size_y = BLI_rctf_size_y(&v2d->cur);
1982 const float page_size_y = view2d_page_size_y(*v2d);
1983
1984 v2d->cur.ymax = roundf(v2d->cur.ymax / page_size_y) * page_size_y;
1985 v2d->cur.ymin = v2d->cur.ymax - cur_size_y;
1986
1988}
1989
1991 const View2D *v2d,
1992 const int xy[2],
1993 int *r_scroll)
1994{
1995 const int scroll = view2d_scroll_mapped(v2d->scroll);
1996 *r_scroll = scroll;
1997
1998 if (scroll) {
1999 /* Move to region-coordinates. */
2000 const int co[2] = {
2001 xy[0] - region->winrct.xmin,
2002 xy[1] - region->winrct.ymin,
2003 };
2004 if (scroll & V2D_SCROLL_HORIZONTAL) {
2005 if (IN_2D_HORIZ_SCROLL(v2d, co)) {
2006 return 'h';
2007 }
2008 }
2009 if (scroll & V2D_SCROLL_VERTICAL) {
2010 if (IN_2D_VERT_SCROLL(v2d, co)) {
2011 return 'v';
2012 }
2013 }
2014 }
2015
2016 return 0;
2017}
2018
2020 const View2D *v2d,
2021 const rcti *rect,
2022 int *r_scroll)
2023{
2024 const int scroll = view2d_scroll_mapped(v2d->scroll);
2025 *r_scroll = scroll;
2026
2027 if (scroll) {
2028 /* Move to region-coordinates. */
2029 rcti rect_region = *rect;
2030 BLI_rcti_translate(&rect_region, -region->winrct.xmin, region->winrct.ymin);
2031 if (scroll & V2D_SCROLL_HORIZONTAL) {
2032 if (IN_2D_HORIZ_SCROLL_RECT(v2d, &rect_region)) {
2033 return 'h';
2034 }
2035 }
2036 if (scroll & V2D_SCROLL_VERTICAL) {
2037 if (IN_2D_VERT_SCROLL_RECT(v2d, &rect_region)) {
2038 return 'v';
2039 }
2040 }
2041 }
2042
2043 return 0;
2044}
2045
2046char UI_view2d_mouse_in_scrollers(const ARegion *region, const View2D *v2d, const int xy[2])
2047{
2048 int scroll_dummy = 0;
2049 return UI_view2d_mouse_in_scrollers_ex(region, v2d, xy, &scroll_dummy);
2050}
2051
2052char UI_view2d_rect_in_scrollers(const ARegion *region, const View2D *v2d, const rcti *rect)
2053{
2054 int scroll_dummy = 0;
2055 return UI_view2d_rect_in_scrollers_ex(region, v2d, rect, &scroll_dummy);
2056}
2057
2059
2060/* -------------------------------------------------------------------- */
2063
2066 union {
2068 int pack;
2071 int mval[2];
2072
2073 /* str is allocated past the end */
2074 char str[0];
2075};
2076
2077/* assumes caches are used correctly, so for time being no local storage in v2d */
2079static View2DString *g_v2d_strings = nullptr;
2080
2082 View2D *v2d, float x, float y, const char *str, size_t str_len, const uchar col[4])
2083{
2084 int mval[2];
2085
2086 BLI_assert(str_len == strlen(str));
2087
2088 if (UI_view2d_view_to_region_clip(v2d, x, y, &mval[0], &mval[1])) {
2089 const int alloc_len = str_len + 1;
2090
2091 if (g_v2d_strings_arena == nullptr) {
2093 }
2094
2095 View2DString *v2s = static_cast<View2DString *>(
2097
2099
2100 v2s->col.pack = *((const int *)col);
2101
2102 v2s->rect = rcti{};
2103
2104 v2s->mval[0] = mval[0];
2105 v2s->mval[1] = mval[1];
2106
2107 memcpy(v2s->str, str, alloc_len);
2108 }
2109}
2110
2112 View2D *v2d, const rctf *rect_view, const char *str, size_t str_len, const uchar col[4])
2113{
2114 rcti rect;
2115
2116 BLI_assert(str_len == strlen(str));
2117
2118 if (UI_view2d_view_to_region_rcti_clip(v2d, rect_view, &rect)) {
2119 const int alloc_len = str_len + 1;
2120
2121 if (g_v2d_strings_arena == nullptr) {
2123 }
2124
2125 View2DString *v2s = static_cast<View2DString *>(
2127
2129
2130 v2s->col.pack = *((const int *)col);
2131
2132 v2s->rect = rect;
2133
2134 v2s->mval[0] = v2s->rect.xmin;
2135 v2s->mval[1] = v2s->rect.ymin;
2136
2137 memcpy(v2s->str, str, alloc_len);
2138 }
2139}
2140
2142{
2143 View2DString *v2s;
2144 int col_pack_prev = 0;
2145
2146 /* investigate using BLF_ascender() */
2147 const int font_id = BLF_default();
2148
2150 const float default_height = g_v2d_strings ? BLF_height(font_id, "28", 3) : 0.0f;
2151
2153
2154 for (v2s = g_v2d_strings; v2s; v2s = v2s->next) {
2155 int xofs = 0, yofs;
2156
2157 yofs = ceil(0.5f * (BLI_rcti_size_y(&v2s->rect) - default_height));
2158 yofs = std::max(yofs, 1);
2159
2160 if (col_pack_prev != v2s->col.pack) {
2161 BLF_color4ubv(font_id, v2s->col.ub);
2162 col_pack_prev = v2s->col.pack;
2163 }
2164
2165 /* Don't use clipping if `v2s->rect` is not set. */
2166 if (BLI_rcti_size_x(&v2s->rect) == 0 && BLI_rcti_size_y(&v2s->rect) == 0) {
2167 BLF_draw_default(float(v2s->mval[0] + xofs),
2168 float(v2s->mval[1] + yofs),
2169 0.0,
2170 v2s->str,
2172 }
2173 else {
2174 BLF_enable(font_id, BLF_CLIPPING);
2176 font_id, v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4);
2178 v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f, v2s->str, BLF_DRAW_STR_DUMMY_MAX);
2179 BLF_disable(font_id, BLF_CLIPPING);
2180 }
2181 }
2182 g_v2d_strings = nullptr;
2183
2184 if (g_v2d_strings_arena) {
2186 g_v2d_strings_arena = nullptr;
2187 }
2188}
2189
ScrArea * CTX_wm_area(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
@ G_DEBUG
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
int BLF_set_default()
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:840
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
Definition blf.cc:906
@ BLF_CLIPPING
Definition BLF_api.hh:434
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:468
void BLF_disable(int fontid, int option)
Definition blf.cc:329
int BLF_default()
void BLF_cache_clear()
Definition blf.cc:98
void BLF_enable(int fontid, int option)
Definition blf.cc:320
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:449
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_INLINE
#define LISTBASE_FOREACH(type, var, list)
MINLINE float pow2f(float x)
MINLINE float clamp_f(float value, float min, float max)
MINLINE int max_ii(int a, int b)
void unit_m4(float m[4][4])
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void BLI_rctf_translate(struct rctf *rect, float x, float y)
Definition rct.cc:573
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:198
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.h:189
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.h:185
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:566
void BLI_rctf_transform_calc_m4_pivot_min(const rctf *dst, const rctf *src, float matrix[4][4])
Definition rct.cc:551
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
void BLI_rctf_recenter(struct rctf *rect, float x, float y)
Definition rct.cc:602
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:194
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:202
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:206
unsigned char uchar
unsigned int uint
#define CLAMP(a, b, c)
#define CLAMP_MAX(a, c)
#define UNPACK3(a)
#define UNLIKELY(x)
#define ELEM(...)
@ RGN_TYPE_WINDOW
@ SPACE_CLIP
@ SPACE_ACTION
@ SPACE_NLA
@ SPACE_SEQ
@ SPACE_GRAPH
@ V2D_SCROLL_V_ACTIVE
@ V2D_SCROLL_H_ACTIVE
@ V2D_SCROLL_LEFT
@ V2D_SCROLL_HORIZONTAL_FULLR
@ V2D_SCROLL_HORIZONTAL_HIDE
@ V2D_SCROLL_VERTICAL_FULLR
@ V2D_SCROLL_VERTICAL_HIDE
@ V2D_SCROLL_HORIZONTAL
@ V2D_SCROLL_TOP
@ V2D_SCROLL_VERTICAL_HANDLES
@ V2D_SCROLL_RIGHT
@ V2D_SCROLL_BOTTOM
@ V2D_SCROLL_HORIZONTAL_HANDLES
@ V2D_SCROLL_VERTICAL
@ V2D_VIEWSYNC_SCREEN_TIME
@ V2D_PIXELOFS_X
@ V2D_IS_INIT
@ V2D_ZOOM_IGNORE_KEEPOFS
@ V2D_PIXELOFS_Y
@ V2D_VIEWSYNC_AREA_VERTICAL
@ V2D_LOCKOFS_X
@ V2D_LOCKOFS_Y
@ V2D_KEEPOFS_Y
@ V2D_KEEPOFS_X
@ V2D_ALIGN_NO_NEG_X
@ V2D_ALIGN_NO_NEG_Y
@ V2D_ALIGN_NO_POS_Y
@ V2D_ALIGN_NO_POS_X
@ V2D_LIMITZOOM
@ V2D_LOCKZOOM_X
@ V2D_KEEPZOOM
@ V2D_KEEPASPECT
@ V2D_LOCKZOOM_Y
@ V2D_KEEPTOT_BOUNDS
@ V2D_KEEPTOT_STRICT
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:659
void immEnd()
void immUnbindProgram()
void immAttr4ub(uint attr_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void immAttrSkip(uint attr_id)
void immVertex2f(uint attr_id, float x, float y)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat()
void immUniform4fv(const char *name, const float data[4])
void immBegin(GPUPrimType, uint vertex_len)
void GPU_matrix_identity_set()
@ GPU_PRIM_LINES
@ GPU_PRIM_POINTS
@ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_FLAT_COLOR
void GPU_program_point_size(bool enable)
Definition gpu_state.cc:180
void GPU_line_width(float width)
Definition gpu_state.cc:166
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_U8
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define UI_AZONESPOTW
const uiStyle * UI_style_get()
@ UI_SCROLL_PRESSED
@ UI_SCROLL_ARROWS
void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
#define UI_AZONESPOTH
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_GRID
@ TH_BACK
void UI_GetThemeColorBlendShade3ubv(int colorid1, int colorid2, float fac, int offset, unsigned char col[3])
bTheme * UI_GetTheme()
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
#define V2D_SCROLL_HEIGHT
Definition UI_view2d.hh:53
#define V2D_LOCK_COPY
Definition UI_view2d.hh:85
#define V2D_SCROLL_MIN_ALPHA
Definition UI_view2d.hh:57
#define V2D_SCROLL_HANDLE_HEIGHT
Definition UI_view2d.hh:67
#define V2D_SCROLL_THUMB_SIZE_MIN
Definition UI_view2d.hh:74
#define IN_2D_HORIZ_SCROLL(v2d, co)
Definition UI_view2d.hh:95
#define V2D_SCROLL_WIDTH
Definition UI_view2d.hh:54
#define V2D_SCROLL_HANDLE_WIDTH
Definition UI_view2d.hh:68
#define IN_2D_VERT_SCROLL(v2d, co)
Definition UI_view2d.hh:94
#define IN_2D_VERT_SCROLL_RECT(v2d, rct)
Definition UI_view2d.hh:97
#define V2D_SCROLL_HANDLE_SIZE_HOTSPOT
Definition UI_view2d.hh:71
#define V2D_SCROLL_MIN_WIDTH
Definition UI_view2d.hh:60
@ V2D_COMMONVIEW_LIST
Definition UI_view2d.hh:35
@ V2D_COMMONVIEW_STACK
Definition UI_view2d.hh:37
@ V2D_COMMONVIEW_HEADER
Definition UI_view2d.hh:39
@ V2D_COMMONVIEW_STANDARD
Definition UI_view2d.hh:33
@ V2D_COMMONVIEW_PANELS_UI
Definition UI_view2d.hh:41
#define V2D_IS_CLIPPED
Definition UI_view2d.hh:21
#define IN_2D_HORIZ_SCROLL_RECT(v2d, rct)
Definition UI_view2d.hh:98
#define U
#define logf(x)
#define powf(x, y)
#define ceilf(x)
#define floorf(x)
#define fabsf(x)
#define str(s)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
Definition frames.inl:1166
uint pos
uint col
#define abs
#define ceil
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define printf(...)
#define MEM_SIZE_OPTIMAL(size)
format
MINLINE float fractf(float a)
ccl_device_inline float2 fmod(const float2 a, const float b)
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static ulong state[N]
#define G(x, y, z)
const btScalar eps
Definition poly34.cpp:11
#define min(a, b)
Definition sort.cc:36
ARegionRuntimeHandle * runtime
ListBase regionbase
uiWidgetColors wcol_scroll
unsigned char widget_emboss[4]
char str[0]
Definition view2d.cc:2074
int mval[2]
Definition view2d.cc:2071
View2DString * next
Definition view2d.cc:2065
uchar ub[4]
Definition view2d.cc:2067
union View2DString::@313236031256172071232005263243243110222355104011 col
char alpha_vert
float minzoom
short keeptot
short scroll_ui
short oldwiny
float max[2]
short keepzoom
short keepofs
float min[2]
short oldwinx
float maxzoom
float page_size_y
ListBase areabase
ThemeUI tui
float xmax
float xmin
float ymax
float ymin
int ymin
int ymax
int xmin
int xmax
float panelzoom
unsigned char inner[4]
unsigned char outline[4]
unsigned char item[4]
i
Definition text_draw.cc:230
max
Definition text_draw.cc:251
char UI_view2d_rect_in_scrollers(const ARegion *region, const View2D *v2d, const rcti *rect)
Definition view2d.cc:2052
void UI_view2d_curRect_validate(View2D *v2d)
Definition view2d.cc:828
void view2d_totRect_set_resize(View2D *v2d, int width, int height, bool resize)
Definition view2d.cc:977
void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag)
Definition view2d.cc:865
static void grid_axis_start_and_count(const float step, const float min, const float max, float *r_start, int *r_count)
Definition view2d.cc:1268
View2D * UI_view2d_fromcontext_rwin(const bContext *C)
Definition view2d.cc:1868
void UI_view2d_scale_get_inverse(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1928
void UI_view2d_curRect_reset(View2D *v2d)
Definition view2d.cc:928
static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize)
Definition view2d.cc:386
bool UI_view2d_view_to_region_segment_clip(const View2D *v2d, const float xy_a[2], const float xy_b[2], int r_region_a[2], int r_region_b[2])
Definition view2d.cc:1750
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y)
Definition view2d.cc:1667
void UI_view2d_view_orthoSpecial(ARegion *region, View2D *v2d, const bool xaxis)
Definition view2d.cc:1136
char UI_view2d_mouse_in_scrollers(const ARegion *region, const View2D *v2d, const int xy[2])
Definition view2d.cc:2046
void UI_view2d_multi_grid_draw(const View2D *v2d, int colorid, float step, int level_size, int totlevels)
Definition view2d.cc:1180
static View2DString * g_v2d_strings
Definition view2d.cc:2079
float view2d_page_size_y(const View2D &v2d)
Definition view2d.cc:77
void UI_view2d_view_to_region_rcti(const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
Definition view2d.cc:1785
bool UI_view2d_view_to_region_clip(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
Definition view2d.cc:1701
bool UI_view2d_view_to_region_rcti_clip(const View2D *v2d, const rctf *rect_src, rcti *rect_dst)
Definition view2d.cc:1815
char UI_view2d_mouse_in_scrollers_ex(const ARegion *region, const View2D *v2d, const int xy[2], int *r_scroll)
Definition view2d.cc:1990
void UI_view2d_curRect_clamp_y(View2D *v2d)
Definition view2d.cc:844
void UI_view2d_dot_grid_draw(const View2D *v2d, const int grid_color_id, const float min_step, const int grid_subdivisions)
Definition view2d.cc:1287
void UI_view2d_scrollers_draw(View2D *v2d, const rcti *mask_custom)
Definition view2d.cc:1503
BLI_INLINE void clamp_rctf_to_rcti(rcti *dst, const rctf *src)
Definition view2d.cc:69
void UI_view2d_view_restore(const bContext *C)
Definition view2d.cc:1162
void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
Definition view2d.cc:221
void UI_view2d_curRect_changed(const bContext *C, View2D *v2d)
Definition view2d.cc:833
void UI_view2d_text_cache_draw(ARegion *region)
Definition view2d.cc:2141
float UI_view2d_region_to_view_y(const View2D *v2d, float y)
Definition view2d.cc:1661
void UI_view2d_totRect_set(View2D *v2d, int width, int height)
Definition view2d.cc:1036
void UI_view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst)
Definition view2d.cc:1674
static int view2d_scroll_mapped(int scroll)
Definition view2d.cc:98
float UI_view2d_view_to_region_y(const View2D *v2d, float y)
Definition view2d.cc:1695
void UI_view2d_listview_view_to_cell(float columnwidth, float rowheight, float startx, float starty, float viewx, float viewy, int *r_column, int *r_row)
Definition view2d.cc:1620
void UI_view2d_center_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1938
void UI_view2d_view_ortho(const View2D *v2d)
Definition view2d.cc:1095
static MemArena * g_v2d_strings_arena
Definition view2d.cc:2078
void UI_view2d_view_to_region(const View2D *v2d, float x, float y, int *r_region_x, int *r_region_y)
Definition view2d.cc:1722
View2D * UI_view2d_fromcontext(const bContext *C)
Definition view2d.cc:1854
float UI_view2d_scale_get_y(const View2D *v2d)
Definition view2d.cc:1924
void UI_view2d_scroller_size_get(const View2D *v2d, bool mapped, float *r_x, float *r_y)
Definition view2d.cc:1886
void UI_view2d_offset(View2D *v2d, float xfac, float yfac)
Definition view2d.cc:1956
void UI_view2d_scale_get(const View2D *v2d, float *r_x, float *r_y)
Definition view2d.cc:1911
bool UI_view2d_area_supports_sync(ScrArea *area)
Definition view2d.cc:860
void UI_view2d_mask_from_win(const View2D *v2d, rcti *r_mask)
Definition view2d.cc:109
char UI_view2d_rect_in_scrollers_ex(const ARegion *region, const View2D *v2d, const rcti *rect, int *r_scroll)
Definition view2d.cc:2019
void UI_view2d_view_to_region_m4(const View2D *v2d, float matrix[4][4])
Definition view2d.cc:1807
void UI_view2d_view_to_region_fl(const View2D *v2d, float x, float y, float *r_region_x, float *r_region_y)
Definition view2d.cc:1738
void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, size_t str_len, const uchar col[4])
Definition view2d.cc:2081
void UI_view2d_offset_y_snap_to_closest_page(View2D *v2d)
Definition view2d.cc:1979
void UI_view2d_center_set(View2D *v2d, float x, float y)
Definition view2d.cc:1948
float UI_view2d_region_to_view_x(const View2D *v2d, float x)
Definition view2d.cc:1656
float UI_view2d_view_to_region_x(const View2D *v2d, float x)
Definition view2d.cc:1690
void UI_view2d_zoom_cache_reset()
Definition view2d.cc:1041
void view2d_scrollers_calc(View2D *v2d, const rcti *mask_custom, View2DScrollers *r_scrollers)
Definition view2d.cc:1390
static void view2d_map_cur_using_mask(const View2D *v2d, rctf *r_curmasked)
Definition view2d.cc:1064
BLI_INLINE int clamp_float_to_int(const float f)
Definition view2d.cc:51
static void view2d_masks(View2D *v2d, const rcti *mask_scroll)
Definition view2d.cc:122
void UI_view2d_text_cache_add_rectf(View2D *v2d, const rctf *rect_view, const char *str, size_t str_len, const uchar col[4])
Definition view2d.cc:2111
float UI_view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1920
int xy[2]
Definition wm_draw.cc:174
void wmOrtho2(float x1, float x2, float y1, float y2)
void wmOrtho2_region_pixelspace(const ARegion *region)
uint8_t flag
Definition wm_window.cc:139