Action Editor: Initial support for a Properties Region
authorJoshua Leung <aligorith@gmail.com>
Sun, 8 May 2016 02:38:30 +0000 (14:38 +1200)
committerJoshua Leung <aligorith@gmail.com>
Sun, 8 May 2016 12:53:52 +0000 (00:53 +1200)
This commit adds some of the initial support for a properties region in the
Action Editor. There are currently no panels to display, as there is still
a lot of work required to port over the required internal architecture to
support the panels seen in the Graph Editor.

release/scripts/startup/bl_ui/space_dopesheet.py
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/space_action/CMakeLists.txt
source/blender/editors/space_action/action_buttons.c [new file with mode: 0644]
source/blender/editors/space_action/action_intern.h
source/blender/editors/space_action/action_ops.c
source/blender/editors/space_action/space_action.c

index af40f1f070c2059849a46d5e8a196fe664c076d3..0eeba5be369698b667edb66a440278d287f866c2 100644 (file)
@@ -207,6 +207,9 @@ class DOPESHEET_MT_view(Menu):
 
         st = context.space_data
 
+        layout.operator("action.properties", icon='MENU_PANEL')
+        layout.separator()
+
         layout.prop(st, "use_realtime_update")
         layout.prop(st, "show_frame_indicator")
         layout.prop(st, "show_sliders")
index f7d208a6a1bb8ac3da6b9cdc61890e4e972124cb..efd167d49d5bedfb738132dece69bdc10fbaf4e9 100644 (file)
@@ -137,6 +137,30 @@ static void do_version_constraints_stretch_to_limits(ListBase *lb)
        }
 }
 
+static void do_version_action_editor_properties_region(ListBase *regionbase)
+{
+       ARegion *ar;
+       
+       for (ar = regionbase->first; ar; ar = ar->next) {
+               if (ar->regiontype == RGN_TYPE_UI) {
+                       /* already exists */
+                       return;
+               }
+               else if (ar->regiontype == RGN_TYPE_WINDOW) {
+                       /* add new region here */
+                       ARegion *arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
+                       
+                       BLI_insertlinkbefore(regionbase, ar, arnew);
+                       
+                       arnew->regiontype = RGN_TYPE_UI;
+                       arnew->alignment = RGN_ALIGN_RIGHT;
+                       arnew->flag = RGN_FLAG_HIDDEN;
+                       
+                       return;
+               }
+       }
+}
+
 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 {
        if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
@@ -1109,5 +1133,22 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                        SEQ_END
                }
 
+               /* Adding "Properties" region to DopeSheet */
+               for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+                       for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+                               /* handle pushed-back space data first */
+                               for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+                                       if (sl->spacetype == SPACE_ACTION) {
+                                               SpaceAction *saction = (SpaceAction *)sl;
+                                               do_version_action_editor_properties_region(&saction->regionbase);
+                                       }
+                               }
+                               
+                               /* active spacedata info must be handled too... */
+                               if (sa->spacetype == SPACE_ACTION) {
+                                       do_version_action_editor_properties_region(&sa->regionbase);
+                               }
+                       }
+               }
        }
 }
index 839071d1330e31e9797e877b42831f8979d3ee3d..24c3ee9cd3d67fad6a39729b4205810a14005358 100644 (file)
@@ -36,6 +36,7 @@ set(INC_SYS
 )
 
 set(SRC
+       action_buttons.c
        action_data.c
        action_draw.c
        action_edit.c
diff --git a/source/blender/editors/space_action/action_buttons.c b/source/blender/editors/space_action/action_buttons.c
new file mode 100644 (file)
index 0000000..a3112f1
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * 
+ * Contributor(s): Blender Foundation, Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_action/action_buttons.c
+ *  \ingroup spaction
+ */
+
+
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+#include <float.h>
+
+#include "DNA_anim_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_depsgraph.h"
+#include "BKE_fcurve.h"
+#include "BKE_main.h"
+#include "BKE_global.h"
+#include "BKE_screen.h"
+#include "BKE_unit.h"
+
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+
+#include "ED_anim_api.h"
+#include "ED_keyframing.h"
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "action_intern.h"   // own include
+
+/* ******************* action editor space & buttons ************** */
+
+/* ******************* general ******************************** */
+
+void action_buttons_register(ARegionType *art)
+{
+#if 0
+       PanelType *pt;
+       
+       // TODO: AnimData / Actions List
+       
+       pt = MEM_callocN(sizeof(PanelType), "spacetype action panel properties");
+       strcpy(pt->idname, "ACTION_PT_properties");
+       strcpy(pt->label, N_("Active F-Curve"));
+       strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+       pt->draw = action_anim_panel_properties;
+       pt->poll = action_anim_panel_poll;
+       BLI_addtail(&art->paneltypes, pt);
+       
+       pt = MEM_callocN(sizeof(PanelType), "spacetype action panel properties");
+       strcpy(pt->idname, "ACTION_PT_key_properties");
+       strcpy(pt->label, N_("Active Keyframe"));
+       strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+       pt->draw = action_anim_panel_key_properties;
+       pt->poll = action_anim_panel_poll;
+       BLI_addtail(&art->paneltypes, pt);
+       
+       pt = MEM_callocN(sizeof(PanelType), "spacetype action panel modifiers");
+       strcpy(pt->idname, "ACTION_PT_modifiers");
+       strcpy(pt->label, N_("Modifiers"));
+       strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+       pt->draw = action_anim_panel_modifiers;
+       pt->poll = action_anim_panel_poll;
+       BLI_addtail(&art->paneltypes, pt);
+#endif
+}
+
+static int action_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       ScrArea *sa = CTX_wm_area(C);
+       ARegion *ar = action_has_buttons_region(sa);
+       
+       if (ar)
+               ED_region_toggle_hidden(C, ar);
+
+       return OPERATOR_FINISHED;
+}
+
+void ACTION_OT_properties(wmOperatorType *ot)
+{
+       ot->name = "Properties";
+       ot->idname = "ACTION_OT_properties";
+       ot->description = "Toggle display properties panel";
+       
+       ot->exec = action_properties_toggle_exec;
+       ot->poll = ED_operator_action_active;
+
+       /* flags */
+       ot->flag = 0;
+}
index 17f1f404225fe064f9e8528803327314e57817c9..50e10e7e154e88a1e54500cf4c66660452e71098 100644 (file)
 struct bContext;
 struct bAnimContext;
 struct SpaceAction;
+struct ScrArea;
 struct ARegion;
+struct ARegionType;
 struct wmOperatorType;
 
 /* internal exports only */
 
+/* **************************************** */
+/* space_action.c / action_buttons.c */
+
+struct ARegion *action_has_buttons_region(struct ScrArea *sa);
+
+void action_buttons_register(struct ARegionType *art);
+void ACTION_OT_properties(struct wmOperatorType *ot);
+
 /* ***************************************** */
 /* action_draw.c */
 void draw_channel_names(struct bContext *C, struct bAnimContext *ac, struct ARegion *ar); 
index 59b147c6f6ca21af8415a6283f90b1de3267327a..f69f9944f8a320dee6cb638ee0f045175e5bc1e4 100644 (file)
@@ -51,6 +51,9 @@
 
 void action_operatortypes(void)
 {
+       /* view */
+       WM_operatortype_append(ACTION_OT_properties);
+       
        /* keyframes */
        /* selection */
        WM_operatortype_append(ACTION_OT_clickselect);
@@ -257,6 +260,13 @@ void action_keymap(wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap;
        
+       /* keymap for all regions */
+       keymap = WM_keymap_find(keyconf, "Dopesheet Generic", SPACE_ACTION, 0);
+       
+       /* region management... */
+       WM_keymap_add_item(keymap, "ACTION_OT_properties", NKEY, KM_PRESS, 0, 0);
+       
+       
        /* channels */
        /* Channels are not directly handled by the Action Editor module, but are inherited from the Animation module. 
         * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these
index 53c5a008af84f384e6518fe97aead7e9257e4be4..60240109432ff1214c85d3932ed5d78ee26b442a 100644 (file)
 
 #include "action_intern.h"  /* own include */
 
+/* ******************** manage regions ********************* */
+
+ARegion *action_has_buttons_region(ScrArea *sa)
+{
+       ARegion *ar, *arnew;
+       
+       ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
+       if (ar) return ar;
+       
+       /* add subdiv level; after main */
+       ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+       
+       /* is error! */
+       if (ar == NULL) return NULL;
+       
+       arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
+       
+       BLI_insertlinkafter(&sa->regionbase, ar, arnew);
+       arnew->regiontype = RGN_TYPE_UI;
+       arnew->alignment = RGN_ALIGN_RIGHT;
+       
+       arnew->flag = RGN_FLAG_HIDDEN;
+       
+       return arnew;
+}
+
 /* ******************** default callbacks for action space ***************** */
 
 static SpaceLink *action_new(const bContext *C)
@@ -93,6 +119,14 @@ static SpaceLink *action_new(const bContext *C)
        ar->v2d.scroll = V2D_SCROLL_BOTTOM;
        ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
        
+       /* ui buttons */
+       ar = MEM_callocN(sizeof(ARegion), "buttons region for action");
+       
+       BLI_addtail(&saction->regionbase, ar);
+       ar->regiontype = RGN_TYPE_UI;
+       ar->alignment = RGN_ALIGN_RIGHT;
+       ar->flag = RGN_FLAG_HIDDEN;
+       
        /* main region */
        ar = MEM_callocN(sizeof(ARegion), "main region for action");
        
@@ -159,6 +193,8 @@ static void action_main_region_init(wmWindowManager *wm, ARegion *ar)
        /* own keymap */
        keymap = WM_keymap_find(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+       keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
 
 static void action_main_region_draw(const bContext *C, ARegion *ar)
@@ -231,6 +267,9 @@ static void action_channel_region_init(wmWindowManager *wm, ARegion *ar)
        /* own keymap */
        keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+       
+       keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);
 }
 
 static void action_channel_region_draw(const bContext *C, ARegion *ar)
@@ -498,6 +537,54 @@ static void action_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(s
 
 }
 
+/* add handlers, stuff you only do once or on area/region changes */
+static void action_buttons_area_init(wmWindowManager *wm, ARegion *ar)
+{
+       wmKeyMap *keymap;
+       
+       ED_region_panels_init(wm, ar);
+       
+       keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);
+}
+
+static void action_buttons_area_draw(const bContext *C, ARegion *ar)
+{
+       ED_region_panels(C, ar, NULL, -1, true);
+}
+
+static void action_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+{
+       /* context changes */
+       switch (wmn->category) {
+               case NC_ANIMATION:
+                       ED_region_tag_redraw(ar);
+                       break;
+               case NC_SCENE:
+                       switch (wmn->data) {
+                               case ND_OB_ACTIVE:
+                               case ND_FRAME:
+                               case ND_MARKERS:
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                       }
+                       break;
+               case NC_OBJECT:
+                       switch (wmn->data) {
+                               case ND_BONE_ACTIVE:
+                               case ND_BONE_SELECT:
+                               case ND_KEYS:
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                       }
+                       break;
+               default:
+                       if (wmn->data == ND_KEYS)
+                               ED_region_tag_redraw(ar);
+                       break;
+       }
+}
+
 static void action_refresh(const bContext *C, ScrArea *sa)
 {
        SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
@@ -579,6 +666,18 @@ void ED_spacetype_action(void)
        
        BLI_addhead(&st->regiontypes, art);
        
+       /* regions: UI buttons */
+       art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
+       art->regionid = RGN_TYPE_UI;
+       art->prefsizex = 200;
+       art->keymapflag = ED_KEYMAP_UI;
+       art->listener = action_region_listener;
+       art->init = action_buttons_area_init;
+       art->draw = action_buttons_area_draw;
+       
+       BLI_addhead(&st->regiontypes, art);
+       
+       action_buttons_register(art);
        
        BKE_spacetype_register(st);
 }