Index: release/scripts/ui/buttons_data_camera.py =================================================================== --- release/scripts/ui/buttons_data_camera.py (revision 23894) +++ release/scripts/ui/buttons_data_camera.py (working copy) @@ -93,6 +93,13 @@ sub.active = cam.show_passepartout sub.itemR(cam, "passepartout_alpha", text="Alpha", slider=True) + row = layout.row() + row.itemR(cam,"compo_type", text="") + sub = layout.row() + sub.active = cam.compo_type in ["TRIANGLE"] + sub.itemR(cam,"compo_dir", text="") + + bpy.types.register(DATA_PT_context_camera) bpy.types.register(DATA_PT_camera) bpy.types.register(DATA_PT_camera_display) Index: source/blender/makesdna/DNA_camera_types.h =================================================================== --- source/blender/makesdna/DNA_camera_types.h (revision 23894) +++ source/blender/makesdna/DNA_camera_types.h (working copy) @@ -61,6 +61,8 @@ struct Ipo *ipo; // XXX depreceated... old animation system struct Object *dof_ob; + short compo_type, compo_dir; + int padding; } Camera; /* **************** CAMERA ********************* */ @@ -79,6 +81,17 @@ #define CAM_DS_EXPAND 64 #define CAM_PANORAMA 128 +#define CAM_CG_TYPE_NONE 0 +#define CAM_CG_TYPE_THIRDS 1 +#define CAM_CG_TYPE_MEAN 2 +#define CAM_CG_TYPE_TRIANGLE 3 +#define CAM_CG_TYPE_DIAGONAL 4 + +#define CAM_CG_DIR_UP_LEFT 0 +#define CAM_CG_DIR_UP_RIGHT 1 +#define CAM_CG_DIR_DOWN_LEFT 2 +#define CAM_CG_DIR_DOWN_RIGHT 3 + /* yafray: dof sampling switch */ #define CAM_YF_NO_QMC 512 Index: source/blender/makesrna/intern/rna_camera.c =================================================================== --- source/blender/makesrna/intern/rna_camera.c (revision 23894) +++ source/blender/makesrna/intern/rna_camera.c (working copy) @@ -65,6 +65,21 @@ {CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""}, {0, NULL, 0, NULL, NULL}}; + static EnumPropertyItem prop_compo_type_items[]={ + {CAM_CG_TYPE_NONE , "NONE", 0, "No composition guide", ""}, + {CAM_CG_TYPE_THIRDS , "THIRDS", 0, "Rule of thirds", ""}, + {CAM_CG_TYPE_MEAN , "MEAN", 0, "Golden mean", ""}, + {CAM_CG_TYPE_TRIANGLE , "TRIANGLE", 0, "Golden triangle", ""}, + {CAM_CG_TYPE_DIAGONAL , "DIAGONAL", 0, "Diagonals", ""}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem prop_compo_dir_items[]={ + {CAM_CG_DIR_UP_LEFT , "UP_LEFT", 0, "Top left", ""}, + {CAM_CG_DIR_UP_RIGHT , "UP_RIGHT", 0, "Top right", ""}, + {CAM_CG_DIR_DOWN_LEFT , "DOWN_LEFT", 0, "Bottom left", ""}, + {CAM_CG_DIR_DOWN_RIGHT , "DOWN_RIGHT", 0, "Bottom right", ""}, + {0, NULL, 0, NULL, NULL}}; + srna= RNA_def_struct(brna, "Camera", "ID"); RNA_def_struct_ui_text(srna, "Camera", "Camera datablock for storing camera settings."); RNA_def_struct_ui_icon(srna, ICON_CAMERA_DATA); @@ -74,7 +89,17 @@ 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, "compo_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_compo_type_items); + RNA_def_property_ui_text(prop, "Composition rule", "Which guiding lines to show."); + RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); + prop= RNA_def_property(srna, "compo_dir", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, prop_compo_dir_items); + RNA_def_property_ui_text(prop, "Direction", "How to orient the composition guides."); + RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL); + /* Number values */ prop= RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR); Index: source/blender/editors/space_view3d/view3d_draw.c =================================================================== --- source/blender/editors/space_view3d/view3d_draw.c (revision 23894) +++ source/blender/editors/space_view3d/view3d_draw.c (working copy) @@ -990,7 +990,97 @@ glEnd(); } +static void draw_compo_thirds( float x1, float y1, float x2, float y2, float div) +{ + float dx=(x2-x1)/div; + float dy=(y2-y1)/div; + glBegin(GL_LINES); + + glVertex2f( x1, y1+dy); + glVertex2f( x2, y1+dy); + + glVertex2f( x1, y2-dy); + glVertex2f( x2, y2-dy); + + glVertex2f( x1+dx, y1); + glVertex2f( x1+dx, y2); + + glVertex2f( x2-dx, y1); + glVertex2f( x2-dx, y2); + + glEnd(); +} + +#define GOLDEN_SECTION 1.6180339887f + +static void draw_compo_golden_triangle( float x1, float y1, float x2, float y2, short dir) +{ + /* Major line is from (a,c) to (b,d), minor line from major/phi to (a,d) */ + float a,b,c,d; + float dx; + float dy; + + /* Dir is where the minor line ends (a,d)*/ + switch( dir) { + case CAM_CG_DIR_UP_LEFT: + a=x1; + b=x2; + c=y1; + d=y2; + break; + + case CAM_CG_DIR_UP_RIGHT: + a=x2; + b=x1; + c=y1; + d=y2; + break; + + case CAM_CG_DIR_DOWN_LEFT: + a=x1; + b=x2; + c=y2; + d=y1; + break; + + case CAM_CG_DIR_DOWN_RIGHT: + a=x2; + b=x1; + c=y2; + d=y1; + break; + + default: + return; + } + + glBegin(GL_LINES); + + glVertex2f( a, c); + glVertex2f( b, d); + + dx=(b-a)/GOLDEN_SECTION; + dy=(d-c)/GOLDEN_SECTION; + glVertex2f( a+dx, c+dy); + glVertex2f( a, d); + + glEnd(); +} + +static void draw_compo_diagonal( float x1, float y1, float x2, float y2) +{ + glBegin(GL_LINES); + + glVertex2f( x1, y1); + glVertex2f( x2, y2); + + glVertex2f( x2, y1); + glVertex2f( x1, y2); + + glEnd(); +} + static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) { extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad); // interface_panel.c @@ -999,6 +1089,8 @@ float x3, y3, x4, y4; rctf viewborder; Camera *ca= NULL; + short compo_type, compo_dir; + if(v3d->camera==NULL) return; @@ -1042,6 +1134,31 @@ setlinestyle(3); UI_ThemeColor(TH_WIRE); glRectf(x1, y1, x2, y2); + + /* Composition guides */ + if (ca) { + compo_type=ca->compo_type; + compo_dir =ca->compo_dir; + switch (compo_type) { + case CAM_CG_TYPE_THIRDS: + draw_compo_thirds(x1, y1, x2, y2, 3.0f); + break; + case CAM_CG_TYPE_MEAN: + /* phi=1.6180339887f, + * Golden section: long/short=total/long=phi + * total/long=phi + * total/phi=long + * */ + draw_compo_thirds (x1, y1, x2, y2, GOLDEN_SECTION); + break; + case CAM_CG_TYPE_TRIANGLE : + draw_compo_golden_triangle(x1, y1, x2, y2, compo_dir); + break; + case CAM_CG_TYPE_DIAGONAL: + draw_compo_diagonal(x1, y1, x2, y2); + break; + } + } /* camera name - draw in highlighted text color */ if (ca && (ca->flag & CAM_SHOWNAME)) {