camera composition guides: center, thirds, golden rule
authorCampbell Barton <ideasman42@gmail.com>
Tue, 10 May 2011 03:03:53 +0000 (03:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 10 May 2011 03:03:53 +0000 (03:03 +0000)
release/scripts/startup/bl_ui/properties_data_camera.py
source/blender/editors/space_view3d/view3d_draw.c
source/blender/makesdna/DNA_camera_types.h
source/blender/makesrna/intern/rna_camera.c

index e5076fd20d5922c8855473fc7120b39ddbc8b55d..80cd5227fca8043d72182e0db9cbc151a5654e8c 100644 (file)
@@ -127,6 +127,7 @@ class DATA_PT_camera_display(CameraButtonsPanel, bpy.types.Panel):
         col.prop(cam, "show_mist", text="Mist")
         col.prop(cam, "show_title_safe", text="Title Safe")
         col.prop(cam, "show_name", text="Name")
+        col.prop_menu_enum(cam, "show_guide")
 
         col = split.column()
         col.prop(cam, "draw_size", text="Size")
index e967e8ed2e7b3f395fe87df636e5bd9ecdd0989f..fe0b0b7c928d2a3fd0c87a438a544e4a55b58c43 100644 (file)
@@ -921,6 +921,60 @@ void view3d_calc_camera_border(Scene *scene, ARegion *ar, RegionView3D *rv3d, Vi
        }
 }
 
+static void drawviewborder_grid3(float x1, float x2, float y1, float y2, float fac, char diagonal)
+{
+       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);
+
+       glBegin(GL_LINES);
+       switch(diagonal) {
+       case '\0':
+               glVertex2f(x1, y3);
+               glVertex2f(x2, y3);
+
+               glVertex2f(x1, y4);
+               glVertex2f(x2, y4);
+
+               glVertex2f(x3, y1);
+               glVertex2f(x3, y2);
+
+               glVertex2f(x4, y1);
+               glVertex2f(x4, y2);
+               break;
+       case 'H': /* hoz */
+               glVertex2f(x1, y1);
+               glVertex2f(x2, y4);
+
+               glVertex2f(x1, y3);
+               glVertex2f(x2, y2);
+
+               glVertex2f(x2, y1);
+               glVertex2f(x1, y4);
+
+               glVertex2f(x2, y3);
+               glVertex2f(x1, y2);
+               break;
+       case 'V': /* vert */
+               glVertex2f(x1, y1);
+               glVertex2f(x4, y2);
+
+               glVertex2f(x3, y1);
+               glVertex2f(x2, y2);
+
+               glVertex2f(x1, y2);
+               glVertex2f(x4, y1);
+
+               glVertex2f(x3, y2);
+               glVertex2f(x2, y1);
+               break;
+       }
+       glEnd();
+}
+
 static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
 {
        float fac, a;
@@ -995,21 +1049,70 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
        }
 
        /* safety border */
-       if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
-               fac= 0.1;
-               
-               a= fac*(x2-x1);
-               x1+= a; 
-               x2-= a;
-               
-               a= fac*(y2-y1);
-               y1+= a;
-               y2-= a;
-               
-               UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
-               
-               uiSetRoundBox(15);
-               uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
+       if(ca) {
+               if (ca->dtx & CAM_DTX_CENTER) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+
+                       x3= x1+ 0.5f*(x2-x1);
+                       y3= y1+ 0.5f*(y2-y1);
+
+                       glBegin(GL_LINES);
+                       glVertex2f(x1, y3);
+                       glVertex2f(x2, y3);
+
+                       glVertex2f(x3, y1);
+                       glVertex2f(x3, y2);
+                       glEnd();
+               }
+
+               if (ca->dtx & CAM_DTX_CENTER_DIAG) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+
+                       glBegin(GL_LINES);
+                       glVertex2f(x1, y1);
+                       glVertex2f(x2, y2);
+
+                       glVertex2f(x1, y2);
+                       glVertex2f(x2, y1);
+                       glEnd();
+               }
+
+               if (ca->dtx & CAM_DTX_THIRDS) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+                       drawviewborder_grid3(x1, x2, y1, y2, 1.0f/3.0f, '\0');
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+                       drawviewborder_grid3(x1, x2, y1, y2, 1.0f-(1.0f/1.61803399), '\0');
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN_DIAG_H) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+                       drawviewborder_grid3(x1, x2, y1, y2, 1.0f-(1.0f/1.61803399), 'H');
+               }
+
+               if (ca->dtx & CAM_DTX_GOLDEN_DIAG_V) {
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+                       drawviewborder_grid3(x1, x2, y1, y2, 1.0f-(1.0f/1.61803399), 'V');
+               }
+
+               if (ca->flag & CAM_SHOWTITLESAFE) {
+                       fac= 0.1;
+
+                       a= fac*(x2-x1);
+                       x1+= a;
+                       x2-= a;
+
+                       a= fac*(y2-y1);
+                       y1+= a;
+                       y2-= a;
+
+                       UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
+
+                       uiSetRoundBox(15);
+                       uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
+               }
        }
 
        setlinestyle(0);
index 4ebd7318ea87c43b0332a1acb5729784c99acb29..d64b72c6f402c0360b701099bb3eb4b2f678a5a9 100644 (file)
@@ -47,7 +47,9 @@ typedef struct Camera {
        ID id;
        struct AnimData *adt;   /* animation data (must be immediately after id for utilities to use it) */ 
        
-       short type, flag;
+       char type; /* CAM_PERSP or CAM_ORTHO */
+       char dtx; /* draw type extra */
+       short flag;
        float passepartalpha;
        float clipsta, clipend;
        float lens, ortho_scale, drawsize;
@@ -69,6 +71,14 @@ typedef struct Camera {
 #define CAM_PERSP              0
 #define CAM_ORTHO              1
 
+/* dtx */
+#define CAM_DTX_CENTER                 1
+#define CAM_DTX_CENTER_DIAG            2
+#define CAM_DTX_THIRDS                 4
+#define CAM_DTX_GOLDEN                 8
+#define CAM_DTX_GOLDEN_DIAG_H  16
+#define CAM_DTX_GOLDEN_DIAG_V  32
+
 /* flag */
 #define CAM_SHOWLIMITS 1
 #define CAM_SHOWMIST   2
index 34b1dc858813e9831026dbd7eab62f19761f7b88..ff25d6d49b0cfae59ce2f0d6626141bb34ce11c3 100644 (file)
@@ -67,6 +67,14 @@ void RNA_def_camera(BlenderRNA *brna)
                {CAM_PERSP, "PERSP", 0, "Perspective", ""},
                {CAM_ORTHO, "ORTHO", 0, "Orthographic", ""},
                {0, NULL, 0, NULL, NULL}};
+       static EnumPropertyItem prop_draw_type_extra_items[] = {
+               {CAM_DTX_CENTER, "CENTER", 0, "Center", ""},
+               {CAM_DTX_CENTER_DIAG, "CENTER_DIAGONAL", 0, "Center Diagonal", ""},
+               {CAM_DTX_THIRDS, "THIRDS", 0, "Thirds", ""},
+               {CAM_DTX_GOLDEN, "GOLDEN", 0, "Golden", ""},
+               {CAM_DTX_GOLDEN_DIAG_H, "GOLDEN_DIAGONAL_H", 0, "Golden Diagonal Hoz", ""},
+               {CAM_DTX_GOLDEN_DIAG_V, "GOLDEN_DIAGONAL_V", 0, "Golden Diagonal Vert", ""},
+               {0, NULL, 0, NULL, NULL}};
        static EnumPropertyItem prop_lens_unit_items[] = {
                {0, "MILLIMETERS", 0, "Millimeters", ""},
                {CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""},
@@ -81,6 +89,13 @@ void RNA_def_camera(BlenderRNA *brna)
        RNA_def_property_enum_items(prop, prop_type_items);
        RNA_def_property_ui_text(prop, "Type", "Camera types");
        RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+
+       prop= RNA_def_property(srna, "show_guide", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "dtx");
+       RNA_def_property_enum_items(prop, prop_draw_type_extra_items);
+       RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+       RNA_def_property_ui_text(prop, "Comosition Guide",  "Draw overlay");
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
        
        /* Number values */