doxygen: blender/editors tagged.
[blender.git] / source / blender / editors / gpencil / gpencil_buttons.c
index e93788bc495c0822aa2d19cdd363ecb92f4cc197..47a9c007951128bd9d981de79d87886e8146eff4 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008, Blender Foundation, Joshua Leung
  * This is a new part of Blender
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+
+/** \file blender/editors/gpencil/gpencil_buttons.c
+ *  \ingroup edgpencil
+ */
+
  
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stddef.h>
 
-#include "MEM_guardedalloc.h"
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
 
 #include "DNA_gpencil_types.h"
-#include "DNA_listBase.h"
-#include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_windowmanager_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_gpencil.h"
-#include "BKE_utildefines.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "RNA_access.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
 
 #include "ED_gpencil.h"
-#include "ED_sequencer.h"
-#include "ED_util.h"
 
 #include "UI_interface.h"
 #include "UI_resources.h"
-#include "UI_view2d.h"
 
 #include "gpencil_intern.h"
 
@@ -77,7 +71,7 @@
 /* These are just 'dummy wrappers' around gpencil api calls */
 
 /* make layer active one after being clicked on */
-void gp_ui_activelayer_cb (bContext *C, void *gpd, void *gpl)
+static void gp_ui_activelayer_cb (bContext *C, void *gpd, void *gpl)
 {
        gpencil_layer_setactive(gpd, gpl);
        
@@ -85,7 +79,7 @@ void gp_ui_activelayer_cb (bContext *C, void *gpd, void *gpl)
 }
 
 /* delete 'active' layer */
-void gp_ui_dellayer_cb (bContext *C, void *gpd, void *gpl)
+static void gp_ui_dellayer_cb (bContext *C, void *gpd, void *gpl)
 {
        /* make sure the layer we want to remove is the active one */
        gpencil_layer_setactive(gpd, gpl); 
@@ -119,21 +113,21 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
        box= uiLayoutBox(layout);
        
        row= uiLayoutRow(box, 0);
+       uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
        block= uiLayoutGetBlock(row); // err...
        
        uiBlockSetEmboss(block, UI_EMBOSSN);
        
        /* left-align ............................... */
-       subrow= uiLayoutRow(row, 1);
-       uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
+       subrow= uiLayoutRow(row, 0);
        
        /* active */
        icon= (gpl->flag & GP_LAYER_ACTIVE) ? ICON_RADIOBUT_ON : ICON_RADIOBUT_OFF;
-       uiItemR(subrow, "", icon, &ptr, "active", 0);
+       uiItemR(subrow, &ptr, "active", 0, "", icon);
        
        /* locked */
        icon= (gpl->flag & GP_LAYER_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
-       uiItemR(subrow, "", icon, &ptr, "locked", 0);
+       uiItemR(subrow, &ptr, "lock", 0, "", icon);
        
        /* when layer is locked or hidden, only draw header */
        if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_HIDE)) {
@@ -141,7 +135,7 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
                
                /* visibility button (only if hidden but not locked!) */
                if ((gpl->flag & GP_LAYER_HIDE) && !(gpl->flag & GP_LAYER_LOCKED))
-                       uiItemR(subrow, "", ICON_RESTRICT_VIEW_ON, &ptr, "hide", 0); 
+                       uiItemR(subrow, &ptr, "hide", 0, "", ICON_RESTRICT_VIEW_ON); 
                        
                
                /* name */
@@ -149,10 +143,10 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
                        sprintf(name, "%s (Hidden)", gpl->info);
                else
                        sprintf(name, "%s (Locked)", gpl->info);
-               uiItemL(subrow, name, 0);
+               uiItemL(subrow, name, ICON_NONE);
                        
                /* delete button (only if hidden but not locked!) */
-               if ((gpl->flag & GP_LAYER_HIDE) & !(gpl->flag & GP_LAYER_LOCKED)) {
+               if ((gpl->flag & GP_LAYER_HIDE) && !(gpl->flag & GP_LAYER_LOCKED)) {
                        /* right-align ............................... */
                        subrow= uiLayoutRow(row, 1);
                        uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
@@ -166,12 +160,17 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
        else {
                /* draw rest of header -------------------------------- */
                /* visibility button */
-               uiItemR(subrow, "", ICON_RESTRICT_VIEW_OFF, &ptr, "hide", 0); 
+               uiItemR(subrow, &ptr, "hide", 0, "", ICON_RESTRICT_VIEW_OFF); 
+               
+               /* frame locking */
+               // TODO: this needs its own icons...
+               icon= (gpl->flag & GP_LAYER_FRAMELOCK) ? ICON_RENDER_STILL : ICON_RENDER_ANIMATION;
+               uiItemR(subrow, &ptr, "lock_frame", 0, "", icon); 
                
                uiBlockSetEmboss(block, UI_EMBOSS);
                
                /* name */
-               uiItemR(subrow, "", 0, &ptr, "info", 0);
+               uiItemR(subrow, &ptr, "info", 0, "", ICON_NONE);
                
                /* delete 'button' */
                uiBlockSetEmboss(block, UI_EMBOSSN);
@@ -189,24 +188,23 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
                box= uiLayoutBox(layout);
                split= uiLayoutSplit(box, 0.5f, 0);
                
-               
                /* draw settings ---------------------------------- */
                /* left column ..................... */
                col= uiLayoutColumn(split, 0);
                
                /* color */
                subcol= uiLayoutColumn(col, 1);
-                       uiItemR(subcol, "", 0, &ptr, "color", 0);
-                       uiItemR(subcol, NULL, 0, &ptr, "opacity", UI_ITEM_R_SLIDER);
+                       uiItemR(subcol, &ptr, "color", 0, "", ICON_NONE);
+                       uiItemR(subcol, &ptr, "alpha", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
                        
                /* stroke thickness */
                subcol= uiLayoutColumn(col, 1);
-                       uiItemR(subcol, NULL, 0, &ptr, "line_thickness", UI_ITEM_R_SLIDER);
+                       uiItemR(subcol, &ptr, "line_width", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
                
                /* debugging options */
                if (G.f & G_DEBUG) {
                        subcol= uiLayoutColumn(col, 1);
-                               uiItemR(subcol, NULL, 0, &ptr, "show_points", 0);
+                               uiItemR(subcol, &ptr, "show_points", 0, NULL, ICON_NONE);
                }
                
                /* right column ................... */
@@ -214,22 +212,26 @@ static void gp_drawui_layer (uiLayout *layout, bGPdata *gpd, bGPDlayer *gpl)
                
                /* onion-skinning */
                subcol= uiLayoutColumn(col, 1);
-                       uiItemR(subcol, "Onion Skinning", 0, &ptr, "use_onion_skinning", 0);
-                       uiItemR(subcol, "Frames", 0, &ptr, "max_ghost_range", 0); // XXX shorter name here? (i.e. GStep)
+                       uiItemR(subcol, &ptr, "use_onion_skinning", 0, "Onion Skinning", ICON_NONE);
+                       uiItemR(subcol, &ptr, "ghost_range_max", 0, "Frames", ICON_NONE); // XXX shorter name here? i.e. GStep
                
-               /* additional options... */
-               subcol= uiLayoutColumn(col, 1);
-                       uiItemO(subcol, "Delete Frame", 0, "GPENCIL_OT_active_frame_delete");
-                       uiItemO(subcol, "Convert...", 0, "GPENCIL_OT_convert");
        }
 } 
 
+/* stroke drawing options available */
+typedef enum eGP_Stroke_Ops {
+       STROKE_OPTS_NORMAL = 0, 
+       STROKE_OPTS_V3D_OFF, 
+       STROKE_OPTS_V3D_ON,
+} eGP_Stroke_Ops;
+
 /* Draw the contents for a grease-pencil panel*/
 static void draw_gpencil_panel (bContext *C, uiLayout *layout, bGPdata *gpd, PointerRNA *ctx_ptr)
 {
        PointerRNA gpd_ptr;
        bGPDlayer *gpl;
        uiLayout *col, *row;
+       short v3d_stroke_opts = STROKE_OPTS_NORMAL;
        
        /* make new PointerRNA for Grease Pencil block */
        RNA_id_pointer_create((ID *)gpd, &gpd_ptr);
@@ -241,8 +243,11 @@ static void draw_gpencil_panel (bContext *C, uiLayout *layout, bGPdata *gpd, Poi
                uiTemplateID(col, C, ctx_ptr, "grease_pencil", "GPENCIL_OT_data_add", NULL, "GPENCIL_OT_data_unlink"); 
                
                /* add new layer button - can be used even when no data, since it can add a new block too */
-               uiItemO(col, NULL, 0, "GPENCIL_OT_layer_add");
-       
+               uiItemO(col, "New Layer", ICON_NONE, "GPENCIL_OT_layer_add");
+               row= uiLayoutRow(col, 1);
+               uiItemO(row, "Delete Frame", ICON_NONE, "GPENCIL_OT_active_frame_delete");
+               uiItemO(row, "Convert", ICON_NONE, "GPENCIL_OT_convert");
+               
        /* sanity checks... */
        if (gpd == NULL)
                return;
@@ -256,20 +261,28 @@ static void draw_gpencil_panel (bContext *C, uiLayout *layout, bGPdata *gpd, Poi
        /* draw gpd drawing settings first ------------------------------------- */
        col= uiLayoutColumn(layout, 1);
                /* label */
-               uiItemL(col, "Drawing Settings:", 0);
+               uiItemL(col, "Drawing Settings:", ICON_NONE);
                
-               /* 'stick to view' option */
-               //uiItemR(col, NULL, 0, &gpd_ptr, "draw_mode", 0);
+               /* check whether advanced 3D-View drawing space options can be used */
+               if (CTX_wm_view3d(C)) {
+                       if (gpd->flag & (GP_DATA_DEPTH_STROKE|GP_DATA_DEPTH_VIEW))
+                               v3d_stroke_opts = STROKE_OPTS_V3D_ON;
+                       else
+                               v3d_stroke_opts = STROKE_OPTS_V3D_OFF;
+               }
+               
+               /* drawing space options */
                row= uiLayoutRow(col, 1);
-               uiItemEnumR_string(row, NULL, 0, &gpd_ptr, "draw_mode", "VIEW");
-               uiItemEnumR_string(row, NULL, 0, &gpd_ptr, "draw_mode", "CURSOR");
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "VIEW", NULL, ICON_NONE);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "CURSOR", NULL, ICON_NONE);
                row= uiLayoutRow(col, 1);
-               uiItemEnumR_string(row, NULL, 0, &gpd_ptr, "draw_mode", "SURFACE");
-               uiItemEnumR_string(row, NULL, 0, &gpd_ptr, "draw_mode", "STROKE");
-
+                       uiLayoutSetActive(row, v3d_stroke_opts);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "SURFACE", NULL, ICON_NONE);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "STROKE", NULL, ICON_NONE);
+               
                row= uiLayoutRow(col, 0);
-               uiLayoutSetActive(row, (gpd->flag & GP_DATA_DEPTH_STROKE) ? 1:0);
-               uiItemR(row, NULL, 0, &gpd_ptr, "use_stroke_endpoints", 0);
+                       uiLayoutSetActive(row, v3d_stroke_opts==STROKE_OPTS_V3D_ON);
+                       uiItemR(row, &gpd_ptr, "use_stroke_endpoints", 0, NULL, ICON_NONE);
 }