Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-06-11 14:10:31 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-06-11 14:10:31 +0400
commita019f1d3d6a6f8bd17d4683e9a948a84a0ba9925 (patch)
tree30aa6d88bceb23df15c05e287cbc00b39157f746 /source/blender/editors/space_time
parent161d60debf9d9facb0169b677999eb7907346012 (diff)
2.5 Branch
========== * Changed wmOperatorType, removing init/exit callbacks and adding cancel callback, removed default storage in favor of properties. Defined return values for exec/invoke/modal/cancel. * Don't allocate operator on the stack, and removed operator copy for handlers. Now it frees based on return values from callbacks, and just keeps a wmOperator on the heap. Also it now registers after the operator is fully finished, to get the correct final properties. * Changed OP_get_* functions to return 1 if the property is found and 0 otherwise, gives more readable code in my opinion. Added OP_verify_* functions to quickly check if the property is available and set if it's not, that's common for exec/invoke. * Removed WM_operatortypelist_append in favor of WM_operatortype_append which takes a function pointer instead of a list, avoids macro's and duplicating code. * Fix a crash where the handler would still be used while it was freed by the operator. * Spacetypes now have operatortypes() and keymap() callbacks to abstract them a bit more. * Renamed C->curarea to C->area for consistency. Removed View3D/View2D/ SpaceIpo from bContext, seems bad to keep these. * Set context variables like window/screen/area/region to NULL again when leaving that context, instead of leaving the pointers there. * Added if(G.f & G_DEBUG) for many of the prints, makes output a bit cleaner and easier to debug. * Fixed priority of the editors/interface module in scons, would otherwise give link errors. * Added start of generic view2d api. * Added space_time with some basic drawing and a single operator to change the frame.
Diffstat (limited to 'source/blender/editors/space_time')
-rw-r--r--source/blender/editors/space_time/Makefile52
-rw-r--r--source/blender/editors/space_time/SConscript9
-rw-r--r--source/blender/editors/space_time/space_time.c263
-rw-r--r--source/blender/editors/space_time/time_intern.h41
-rw-r--r--source/blender/editors/space_time/time_ops.c185
5 files changed, 550 insertions, 0 deletions
diff --git a/source/blender/editors/space_time/Makefile b/source/blender/editors/space_time/Makefile
new file mode 100644
index 00000000000..72dca174dba
--- /dev/null
+++ b/source/blender/editors/space_time/Makefile
@@ -0,0 +1,52 @@
+#
+# $Id: Makefile 14 2002-10-13 15:57:19Z hans $
+#
+# ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2007 Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): none yet.
+#
+# ***** END GPL LICENSE BLOCK *****
+#
+# Makes module object directory and bounces make to subdirectories.
+
+LIBNAME = ed_time
+DIR = $(OCGDIR)/blender/$(LIBNAME)
+
+include nan_compile.mk
+
+CFLAGS += $(LEVEL_1_C_WARNINGS)
+
+CPPFLAGS += -I$(OPENGL_HEADERS)
+
+# not very neat....
+CPPFLAGS += -I../../windowmanager
+CPPFLAGS += -I../../blenloader
+CPPFLAGS += -I../../blenkernel
+CPPFLAGS += -I../../blenlib
+CPPFLAGS += -I../../makesdna
+CPPFLAGS += -I../../imbuf
+CPPFLAGS += -I../../python
+CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
+
+# own include
+
+CPPFLAGS += -I../include
diff --git a/source/blender/editors/space_time/SConscript b/source/blender/editors/space_time/SConscript
new file mode 100644
index 00000000000..091218e0794
--- /dev/null
+++ b/source/blender/editors/space_time/SConscript
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+Import ('env')
+
+sources = env.Glob('*.c')
+
+incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
+incs += '../../windowmanager #/intern/guardedalloc'
+
+env.BlenderLib ( 'bf_editors_space_time', sources, Split(incs), [], libtype=['core','intern'], priority=[35, 40] )
diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c
new file mode 100644
index 00000000000..f6557c5f14f
--- /dev/null
+++ b/source/blender/editors/space_time/space_time.c
@@ -0,0 +1,263 @@
+/**
+ * $Id$
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+#include <stdio.h>
+
+#include "DNA_object_types.h"
+#include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+#include "BLI_rand.h"
+
+#include "BKE_global.h"
+#include "BKE_screen.h"
+
+#include "ED_area.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+#include "BIF_resources.h"
+#include "BIF_view2d.h"
+
+#include "time_intern.h"
+
+/* ************************ main time area region *********************** */
+
+/* draws a current frame indicator for the TimeLine */
+static void time_draw_cfra_time(const bContext *C, SpaceTime *stime)
+{
+ Scene *scene= C->scene;
+ float vec[2];
+
+ vec[0]= scene->r.cfra;
+ vec[0]*= scene->r.framelen;
+
+ vec[1]= stime->v2d.cur.ymin;
+ BIF_ThemeColor(TH_CFRAME); // no theme, should be global color once...
+ glLineWidth(3.0);
+
+ glBegin(GL_LINES);
+ glVertex2fv(vec);
+ vec[1]= stime->v2d.cur.ymax;
+ glVertex2fv(vec);
+ glEnd();
+
+ glLineWidth(1.0);
+}
+
+static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime)
+{
+ /* draw darkened area outside of active timeline
+ * frame range used is preview range or scene range */
+ BIF_ThemeColorShade(TH_BACK, -25);
+
+ if (PSFRA < PEFRA) {
+ glRectf(stime->v2d.cur.xmin, stime->v2d.cur.ymin, PSFRA, stime->v2d.cur.ymax);
+ glRectf(PEFRA, stime->v2d.cur.ymin, stime->v2d.cur.xmax, stime->v2d.cur.ymax);
+ }
+ else {
+ glRectf(stime->v2d.cur.xmin, stime->v2d.cur.ymin, stime->v2d.cur.xmax, stime->v2d.cur.ymax);
+ }
+
+ BIF_ThemeColorShade(TH_BACK, -60);
+ /* thin lines where the actual frames are */
+ fdrawline(PSFRA, stime->v2d.cur.ymin, PSFRA, stime->v2d.cur.ymax);
+ fdrawline(PEFRA, stime->v2d.cur.ymin, PEFRA, stime->v2d.cur.ymax);
+}
+
+static void time_main_area_init(const bContext *C, ARegion *ar)
+{
+ /* add handlers, stuff you only do once or on area/region changes */
+}
+
+static void time_main_area_refresh(const bContext *C, ARegion *ar)
+{
+ /* refresh to match contextual changes */
+}
+
+static void time_main_area_draw(const bContext *C, ARegion *ar)
+{
+ /* draw entirely, windowsize changes should be handled here */
+ SpaceTime *stime= C->area->spacedata.first;
+ float col[3];
+ int unit, winx, winy;
+
+ winx= ar->winrct.xmax-ar->winrct.xmin;
+ winy= ar->winrct.ymax-ar->winrct.ymin;
+
+ /* clear and setup matrix */
+ BIF_GetThemeColor3fv(TH_BACK, col);
+ col[0]= 1.0f;
+ col[1]= 0.8f;
+ col[2]= 0.0f;
+ glClearColor(col[0], col[1], col[2], 0.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ BIF_view2d_ortho(C, &stime->v2d);
+
+ /* start and end frame */
+ time_draw_sfra_efra(C, stime);
+
+ /* grid */
+ unit= (stime->flag & TIME_DRAWFRAMES)? V2D_UNIT_FRAMES: V2D_UNIT_SECONDS;
+ BIF_view2d_calc_grid(C, &stime->v2d, unit, V2D_GRID_CLAMP, winx, winy);
+ BIF_view2d_draw_grid(C, &stime->v2d, V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS);
+
+ /* current frame */
+ time_draw_cfra_time(C, stime);
+}
+
+static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
+{
+ /* draw entirely, windowsize changes should be handled here */
+}
+
+/* ******************** default callbacks for time space ***************** */
+
+static SpaceLink *time_new(void)
+{
+ SpaceTime *stime;
+
+ stime= MEM_callocN(sizeof(SpaceTime), "inittime");
+
+ stime->spacetype= SPACE_TIME;
+ stime->blockscale= 0.7;
+ stime->redraws= TIME_ALL_3D_WIN|TIME_ALL_ANIM_WIN;
+
+ stime->v2d.tot.xmin= -4.0;
+ stime->v2d.tot.ymin= 0.0;
+ stime->v2d.tot.xmax= (float)EFRA + 4.0;
+ //stime->v2d.tot.ymax= (float)stime->winy;
+
+ stime->v2d.cur= stime->v2d.tot;
+
+ stime->v2d.min[0]= 1.0;
+ //stime->v2d.min[1]= (float)stime->winy;
+
+ stime->v2d.max[0]= 32000.0;
+ //stime->v2d.max[1]= (float)stime->winy;
+
+ stime->v2d.minzoom= 0.1f;
+ stime->v2d.maxzoom= 10.0;
+
+ stime->v2d.scroll= 0;
+ stime->v2d.keepaspect= 0;
+ stime->v2d.keepzoom= 0;
+ stime->v2d.keeptot= 0;
+
+ stime->flag |= TIME_DRAWFRAMES;
+
+ return (SpaceLink*)stime;
+}
+
+/* not spacelink itself */
+static void time_free(SpaceLink *sl)
+{
+}
+
+/* spacetype; init callback */
+static void time_init(wmWindowManager *wm, ScrArea *sa)
+{
+ ARegion *ar;
+
+ /* link area to SpaceXXX struct */
+
+ /* add handlers to area */
+ /* define how many regions, the order and types */
+
+ /* add types to regions */
+ for(ar= sa->regionbase.first; ar; ar= ar->next) {
+ if(ar->regiontype == RGN_TYPE_WINDOW) {
+ static ARegionType mainart={NULL, NULL, NULL, NULL};
+
+ mainart.init= time_main_area_init;
+ mainart.refresh= time_main_area_refresh;
+ mainart.draw= time_main_area_draw;
+ mainart.listener= time_main_area_listener;
+
+ ar->type= &mainart;
+
+ /* XXX the windowmanager may not be th best place to keep these
+ * keymaps, and this function callback may not be the best one
+ * to add the keymap handler, also will need to take care of
+ * area type changes, etc, basically space callbacks need to
+ * be looked at further */
+ WM_event_remove_keymap_handler(&wm->timekeymap, &ar->handlers);
+ WM_event_add_keymap_handler(&wm->timekeymap, &ar->handlers);
+ }
+ else {
+ static ARegionType art={NULL, NULL, NULL, NULL};
+
+ /* for time being; register 1 type */
+ ar->type= &art;
+ }
+ }
+}
+
+/* spacetype; context changed */
+static void time_refresh(bContext *C, ScrArea *sa)
+{
+
+}
+
+static SpaceLink *time_duplicate(SpaceLink *sl)
+{
+ SpaceTime *stime= (SpaceTime *)sl;
+ SpaceTime *stimen= MEM_dupallocN(stime);
+
+ return (SpaceLink *)stimen;
+}
+
+/* only called once, from screen/spacetypes.c */
+void ED_spacetype_time(void)
+{
+ static SpaceType st;
+
+ st.spaceid= SPACE_TIME;
+
+ st.new= time_new;
+ st.free= time_free;
+ st.init= time_init;
+ st.refresh= time_refresh;
+ st.duplicate= time_duplicate;
+ st.operatortypes= time_operatortypes;
+ st.keymap= time_keymap;
+
+ BKE_spacetype_register(&st);
+}
+
diff --git a/source/blender/editors/space_time/time_intern.h b/source/blender/editors/space_time/time_intern.h
new file mode 100644
index 00000000000..e7fb9af7906
--- /dev/null
+++ b/source/blender/editors/space_time/time_intern.h
@@ -0,0 +1,41 @@
+/**
+ * $Id:
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef ED_TIME_INTERN_H
+#define ED_TIME_INTERN_H
+
+/* internal exports only */
+
+struct wmWindowManager;
+
+/* time_ops.c */
+void time_operatortypes(void);
+void time_keymap(struct wmWindowManager *wm);
+
+#endif /* ED_TIME_INTERN_H */
+
diff --git a/source/blender/editors/space_time/time_ops.c b/source/blender/editors/space_time/time_ops.c
new file mode 100644
index 00000000000..a02c5eb6844
--- /dev/null
+++ b/source/blender/editors/space_time/time_ops.c
@@ -0,0 +1,185 @@
+/**
+ * $Id:
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_global.h"
+
+#include "BIF_view2d.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* ********************** frame change operator ***************************/
+
+static int change_frame_init(bContext *C, wmOperator *op)
+{
+ SpaceTime *stime= C->area->spacedata.first;
+ int cfra;
+
+ if(!OP_get_int(op, "frame", &cfra))
+ return 0;
+
+ stime->flag |= TIME_CFRA_NUM;
+
+ return 1;
+}
+
+static void change_frame_apply(bContext *C, wmOperator *op)
+{
+ int cfra;
+
+ OP_get_int(op, "frame", &cfra);
+
+ if(cfra < MINFRAME)
+ cfra= MINFRAME;
+
+#if 0
+ if( cfra!=CFRA || first )
+ {
+ first= 0;
+ CFRA= cfra;
+ update_for_newframe_nodraw(0); // 1= nosound
+ timeline_force_draw(stime->redraws);
+ }
+ else PIL_sleep_ms(30);
+#endif
+
+ if(cfra!=CFRA)
+ CFRA= cfra;
+
+ WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
+ /* XXX: add WM_NOTE_TIME_CHANGED? */
+}
+
+static void change_frame_exit(bContext *C, wmOperator *op)
+{
+ SpaceTime *stime= C->area->spacedata.first;
+
+ stime->flag &= ~TIME_CFRA_NUM;
+}
+
+static int change_frame_exec(bContext *C, wmOperator *op)
+{
+ if(!change_frame_init(C, op))
+ return OPERATOR_CANCELLED;
+
+ change_frame_apply(C, op);
+ change_frame_exit(C, op);
+ return OPERATOR_FINISHED;
+}
+
+static int frame_from_event(bContext *C, wmEvent *event)
+{
+ SpaceTime *stime= C->area->spacedata.first;
+ ARegion *region= C->region;
+ int x, y;
+ float viewx;
+
+ /* XXX region->winrect isn't updated on window changes */
+ x= event->x - region->winrct.xmin;
+ y= event->y - region->winrct.ymin;
+ BIF_view2d_region_to_view(&stime->v2d, x, y, &viewx, NULL);
+
+ return (int)(viewx+0.5f);
+}
+
+static int change_frame_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ OP_verify_int(op, "frame", frame_from_event(C, event), NULL);
+ change_frame_init(C, op);
+ change_frame_apply(C, op);
+
+ /* add temp handler */
+ WM_event_add_modal_handler(&C->region->handlers, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int change_frame_cancel(bContext *C, wmOperator *op)
+{
+ change_frame_exit(C, op);
+ return OPERATOR_CANCELLED;
+}
+
+static int change_frame_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ /* execute the events */
+ switch(event->type) {
+ case MOUSEMOVE:
+ OP_set_int(op, "frame", frame_from_event(C, event));
+ change_frame_apply(C, op);
+ break;
+
+ case LEFTMOUSE:
+ if(event->val==0) {
+ change_frame_exit(C, op);
+ WM_event_remove_modal_handler(&C->region->handlers, op);
+ return OPERATOR_FINISHED;
+ }
+ break;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+/* Operator for joining two areas (space types) */
+void ED_TIME_OT_change_frame(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Change frame";
+ ot->idname= "ED_TIME_OT_change_frame";
+
+ /* api callbacks */
+ ot->exec= change_frame_exec;
+ ot->invoke= change_frame_invoke;
+ ot->cancel= change_frame_cancel;
+ ot->modal= change_frame_modal;
+}
+
+/* ************************** registration **********************************/
+
+void time_operatortypes(void)
+{
+ WM_operatortype_append(ED_TIME_OT_change_frame);
+}
+
+void time_keymap(wmWindowManager *wm)
+{
+ WM_keymap_verify_item(&wm->timekeymap, "ED_TIME_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
+}
+