Commit: 608e2402ef5da8e01a5079e70026347983940008
Author: Dalai Felinto
Date:   Fri Oct 14 01:38:04 2016 +0000
Branches: blender2.8
https://developer.blender.org/rB608e2402ef5da8e01a5079e70026347983940008

viewport: move border drawing code to new file

===================================================================

M       source/blender/editors/space_view3d/view3d_draw.c
M       source/blender/editors/space_view3d/view3d_draw_legacy.c
M       source/blender/editors/space_view3d/view3d_intern.h

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_draw.c 
b/source/blender/editors/space_view3d/view3d_draw.c
index 6fceb70..5ae655f 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -38,6 +38,8 @@
 #include "BKE_scene.h"
 #include "BKE_unit.h"
 
+#include "BLF_api.h"
+
 #include "BLI_math.h"
 #include "BLI_rect.h"
 #include "BLI_threads.h"
@@ -54,6 +56,7 @@
 #include "GPU_immediate.h"
 #include "GPU_viewport.h"
 
+#include "UI_interface.h"
 #include "UI_resources.h"
 
 #include "RE_engine.h"
@@ -263,6 +266,366 @@ static void view3d_stereo3d_setup(Scene *scene, View3D 
*v3d, ARegion *ar)
        }
 }
 
+/* ******************** view border ***************** */
+
+static void view3d_camera_border(
+        const Scene *scene, const ARegion *ar, const View3D *v3d, const 
RegionView3D *rv3d,
+        rctf *r_viewborder, const bool no_shift, const bool no_zoom)
+{
+       CameraParams params;
+       rctf rect_view, rect_camera;
+
+       /* get viewport viewplane */
+       BKE_camera_params_init(&params);
+       BKE_camera_params_from_view3d(&params, v3d, rv3d);
+       if (no_zoom)
+               params.zoom = 1.0f;
+       BKE_camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 
1.0f);
+       rect_view = params.viewplane;
+
+       /* get camera viewplane */
+       BKE_camera_params_init(&params);
+       /* fallback for non camera objects */
+       params.clipsta = v3d->near;
+       params.clipend = v3d->far;
+       BKE_camera_params_from_object(&params, v3d->camera);
+       if (no_shift) {
+               params.shiftx = 0.0f;
+               params.shifty = 0.0f;
+       }
+       BKE_camera_params_compute_viewplane(&params, scene->r.xsch, 
scene->r.ysch, scene->r.xasp, scene->r.yasp);
+       rect_camera = params.viewplane;
+
+       /* get camera border within viewport */
+       r_viewborder->xmin = ((rect_camera.xmin - rect_view.xmin) / 
BLI_rctf_size_x(&rect_view)) * ar->winx;
+       r_viewborder->xmax = ((rect_camera.xmax - rect_view.xmin) / 
BLI_rctf_size_x(&rect_view)) * ar->winx;
+       r_viewborder->ymin = ((rect_camera.ymin - rect_view.ymin) / 
BLI_rctf_size_y(&rect_view)) * ar->winy;
+       r_viewborder->ymax = ((rect_camera.ymax - rect_view.ymin) / 
BLI_rctf_size_y(&rect_view)) * ar->winy;
+}
+
+void ED_view3d_calc_camera_border_size(
+        const Scene *scene, const ARegion *ar, const View3D *v3d, const 
RegionView3D *rv3d,
+        float r_size[2])
+{
+       rctf viewborder;
+
+       view3d_camera_border(scene, ar, v3d, rv3d, &viewborder, true, true);
+       r_size[0] = BLI_rctf_size_x(&viewborder);
+       r_size[1] = BLI_rctf_size_y(&viewborder);
+}
+
+void ED_view3d_calc_camera_border(
+        const Scene *scene, const ARegion *ar, const View3D *v3d, const 
RegionView3D *rv3d,
+        rctf *r_viewborder, const bool no_shift)
+{
+       view3d_camera_border(scene, ar, v3d, rv3d, r_viewborder, no_shift, 
false);
+}
+
+static void drawviewborder_grid3(unsigned pos, float x1, float x2, float y1, 
float y2, float fac)
+{
+       float x3, y3, x4, y4;
+
+       x3 = x1 + fac * (x2 - x1);
+       y3 = y1 + fac * (y2 - y1);
+       x4 = x1 + (1.0f - fac) * (x2 - x1);
+       y4 = y1 + (1.0f - fac) * (y2 - y1);
+
+       immBegin(GL_LINES, 8);
+       immVertex2f(pos, x1, y3);
+       immVertex2f(pos, x2, y3);
+
+       immVertex2f(pos, x1, y4);
+       immVertex2f(pos, x2, y4);
+
+       immVertex2f(pos, x3, y1);
+       immVertex2f(pos, x3, y2);
+
+       immVertex2f(pos, x4, y1);
+       immVertex2f(pos, x4, y2);
+       immEnd();
+}
+
+/* harmonious triangle */
+static void drawviewborder_triangle(unsigned pos, float x1, float x2, float 
y1, float y2, const char golden, const char dir)
+{
+       float ofs;
+       float w = x2 - x1;
+       float h = y2 - y1;
+
+       immBegin(GL_LINES, 6);
+       if (w > h) {
+               if (golden) {
+                       ofs = w * (1.0f - (1.0f / 1.61803399f));
+               }
+               else {
+                       ofs = h * (h / w);
+               }
+               if (dir == 'B') SWAP(float, y1, y2);
+
+               immVertex2f(pos, x1, y1);
+               immVertex2f(pos, x2, y2);
+
+               immVertex2f(pos, x2, y1);
+               immVertex2f(pos, x1 + (w - ofs), y2);
+
+               immVertex2f(pos, x1, y2);
+               immVertex2f(pos, x1 + ofs, y1);
+       }
+       else {
+               if (golden) {
+                       ofs = h * (1.0f - (1.0f / 1.61803399f));
+               }
+               else {
+                       ofs = w * (w / h);
+               }
+               if (dir == 'B') SWAP(float, x1, x2);
+
+               immVertex2f(pos, x1, y1);
+               immVertex2f(pos, x2, y2);
+
+               immVertex2f(pos, x2, y1);
+               immVertex2f(pos, x1, y1 + ofs);
+
+               immVertex2f(pos, x1, y2);
+               immVertex2f(pos, x2, y1 + (h - ofs));
+       }
+       immEnd();
+}
+
+static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
+{
+       float x1, x2, y1, y2;
+       float x1i, x2i, y1i, y2i;
+
+       rctf viewborder;
+       Camera *ca = NULL;
+       RegionView3D *rv3d = ar->regiondata;
+
+       if (v3d->camera == NULL)
+               return;
+       if (v3d->camera->type == OB_CAMERA)
+               ca = v3d->camera->data;
+
+       ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false);
+       /* the offsets */
+       x1 = viewborder.xmin;
+       y1 = viewborder.ymin;
+       x2 = viewborder.xmax;
+       y2 = viewborder.ymax;
+
+       glLineWidth(1.0f);
+
+       /* apply offsets so the real 3D camera shows through */
+
+       /* note: quite un-scientific but without this bit extra
+        * 0.0001 on the lower left the 2D border sometimes
+        * obscures the 3D camera border */
+       /* note: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't 
noticeable
+        * but keep it here in case we need to remove the workaround */
+       x1i = (int)(x1 - 1.0001f);
+       y1i = (int)(y1 - 1.0001f);
+       x2i = (int)(x2 + (1.0f - 0.0001f));
+       y2i = (int)(y2 + (1.0f - 0.0001f));
+
+       /* use the same program for everything */
+       VertexFormat *format = immVertexFormat();
+       unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+       /* passepartout, specified in camera edit buttons */
+       if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 
0.000001f) {
+               const float winx = (ar->winx + 1);
+               const float winy = (ar->winy + 1);
+
+               float alpha = 1.0f;
+
+               if (ca->passepartalpha != 1.0f) {
+                       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+                       glEnable(GL_BLEND);
+                       alpha = ca->passepartalpha;
+               }
+
+               immUniformColor4f(0.0f, 0.0f, 0.0f, alpha);
+
+               if (x1i > 0.0f)
+                       immRectf(pos, 0.0f, winy, x1i, 0.0f);
+               if (x2i < winx)
+                       immRectf(pos, x2i, winy, winx, 0.0f);
+               if (y2i < winy)
+                       immRectf(pos, x1i, winy, x2i, y2i);
+               if (y2i > 0.0f)
+                       immRectf(pos, x1i, y1i, x2i, 0.0f);
+
+               glDisable(GL_BLEND);
+       }
+
+       setlinestyle(0);
+
+       immUniformThemeColor(TH_BACK);
+       imm_draw_line_box(pos, x1i, y1i, x2i, y2i);
+
+#ifdef VIEW3D_CAMERA_BORDER_HACK
+       if (view3d_camera_border_hack_test == true) {
+               immUniformColor3ubv(view3d_camera_border_hack_col);
+               imm_draw_line_box(pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1);
+               view3d_camera_border_hack_test = false;
+       }
+#endif
+
+       setlinestyle(3);
+
+       /* outer line not to confuse with object selecton */
+       if (v3d->flag2 & V3D_LOCK_CAMERA) {
+               immUniformThemeColor(TH_REDALERT);
+               imm_draw_line_box(pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1);
+       }
+
+       immUniformThemeColor(TH_VIEW_OVERLAY);
+       imm_draw_line_box(pos, x1i, y1i, x2i, y2i);
+
+       /* border */
+       if (scene->r.mode & R_BORDER) {
+               float x3, y3, x4, y4;
+
+               x3 = floorf(x1 + (scene->r.border.xmin * (x2 - x1))) - 1;
+               y3 = floorf(y1 + (scene->r.border.ymin * (y2 - y1))) - 1;
+               x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + 
(U.pixelsize - 1);
+               y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + 
(U.pixelsize - 1);
+
+               imm_cpack(0x4040FF);
+               imm_draw_line_box(pos, x3, y3, x4, y4);
+       }
+
+       /* safety border */
+       if (ca) {
+               if (ca->dtx & CAM_DTX_CENTER) {
+                       float x3, y3;
+
+                       x3 = x1 + 0.5f * (x2 - x1);
+                       y3 = y1 + 0.5f * (y2 - y1);
+
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       immBegin(GL_LINES, 4);
+
+                       immVertex2f(pos, x1, y3);
+                       immVertex2f(pos, x2, y3);
+
+                       immVertex2f(pos, x3, y1);
+                       immVertex2f(pos, x3, y2);
+
+                       immEnd();
+               }
+
+               if (ca->dtx & CAM_DTX_CENTER_DIAG) {
+
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       immBegin(GL_LINES, 4);
+
+                       immVertex2f(pos, x1, y1);
+                       immVertex2f(pos, x2, y2);
+
+                       immVertex2f(pos, x1, y2);
+                       immVertex2f(pos, x2, y1);
+
+                       immEnd();
+               }
+
+               if (ca->dtx & CAM_DTX_THIRDS) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_grid3(pos, x1, x2, y1, y2, 1.0f / 3.0f);
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_grid3(pos, x1, x2, y1, y2, 1.0f - (1.0f 
/ 1.61803399f));
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN_TRI_A) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_triangle(pos, x1, x2, y1, y2, 0, 'A');
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN_TRI_B) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_triangle(pos, x1, x2, y1, y2, 0, 'B');
+               }
+
+               if (ca->dtx & CAM_DTX_HARMONY_TRI_A) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_triangle(pos, x1, x2, y1, y2, 1, 'A');
+               }
+
+               if (ca->dtx & CAM_DTX_HARMONY_TRI_B) {
+                       immUniformThemeColorBlendShade(TH_VIEW_OVERLAY, 
TH_BACK, 0.25f, 0);
+                       drawviewborder_triangle(pos, x1, x2, y1, y2, 1, 'B');
+               }
+
+               if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
+                       UI_draw_safe_areas(
+                               pos, x1, x2, y1, y2,
+                               scene->safe_areas.title,
+                               scene->safe_areas.action);
+
+                       if (ca->flag & CAM_SHOW_SAFE_CENTER) {
+                               UI_draw_safe_areas(
+                                       pos, x1, x2, y1, y2,
+                                       scene->safe_areas.title_center,
+                                       scene->safe_areas.action_center);
+                       }
+               }
+
+               if (ca->flag & CAM_SHOWSENSOR) {
+                       /* determine sensor fit, and get sensor x/y, for auto 
fit we
+                        * assume and square sensor and only use sensor_x */
+                       float sizex = scene->r.xsch * scene->r.xasp;
+                       float sizey = scene->r.ysch * scene->r.yasp;
+                       int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, 
sizex, sizey);
+                       float sensor_x = ca->sensor_x;
+                       float sensor_y = (ca->sensor_fit == 
CAMERA_SENSOR_FIT_AUTO) ? ca->sensor_x : ca->sensor_y;
+
+                       /* determine sensor plane */
+                       rctf rect;
+
+                       if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
+                               float sensor_scale = (x2i - x1i) / sensor_x;
+                               float sensor_height = sensor_scale * sensor_y;
+
+                               rect.xmin = x1i;
+                               rect.xmax = x2i;
+                               rect.ymin = (y1i + y2i) * 0.5f - sensor_height 
* 0

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to