[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17481] branches/blender2.5/blender/source /blender: 2.5 getting-back-into-coding commit :)
Ton Roosendaal
ton at blender.org
Mon Nov 17 19:54:03 CET 2008
Revision: 17481
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17481
Author: ton
Date: 2008-11-17 19:54:03 +0100 (Mon, 17 Nov 2008)
Log Message:
-----------
2.5 getting-back-into-coding commit :)
- cleaned up join and split operations. Most noticable is operator callback
design, which should make a design based on user-less exec() first, then
wrap invoke() and modal() around it. The exec() should be callable with
only Context and properties.
- split now works again; and inversed as previously, if you drag from a
triangle (action zone) inside area it subdivides area as expected.
- dragging from triangle outside area, over an edge, joins areas
- split has been simplified, it had too many options... it could just work
simpler (now)
- 'action zone' now is an operator itself, a widget sending an ACTIONZONE event,
which can be handled by others (so other gestures can be added in action zone
too)
Still evaluating:
- context gets set where?
- code structure confuses... what are proper functions for operators?
- what is WM... should low level screen stuff more there?
- when do you send event, notifier?
- files grow to large, will clean
Oh yeah and docs, docs, docs. Coming! :)
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/include/ED_screen.h
branches/blender2.5/blender/source/blender/editors/include/ED_screen_types.h
branches/blender2.5/blender/source/blender/editors/screen/area.c
branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c
branches/blender2.5/blender/source/blender/editors/screen/screen_intern.h
branches/blender2.5/blender/source/blender/editors/screen/screen_ops.c
branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_event_system.c
branches/blender2.5/blender/source/blender/windowmanager/wm_event_types.h
Modified: branches/blender2.5/blender/source/blender/editors/include/ED_screen.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_screen.h 2008-11-17 18:44:06 UTC (rev 17480)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_screen.h 2008-11-17 18:54:03 UTC (rev 17481)
@@ -69,6 +69,7 @@
/* operators; context poll callbacks */
int ED_operator_screenactive(struct bContext *C);
int ED_operator_screen_mainwinactive(struct bContext *C);
+int ED_operator_areaactive(struct bContext *C);
#endif /* ED_SCREEN_H */
Modified: branches/blender2.5/blender/source/blender/editors/include/ED_screen_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_screen_types.h 2008-11-17 18:44:06 UTC (rev 17480)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_screen_types.h 2008-11-17 18:54:03 UTC (rev 17481)
@@ -33,23 +33,14 @@
struct AZone *next, *prev;
int type;
int flag;
- int action;
int pos;
short x1, y1, x2, y2;
} AZone;
-#define MAX_AZONES 8
-
-
/* actionzone type */
#define AZONE_TRI 1
#define AZONE_QUAD 2
-/* actionzone action */
-#define AZONE_SPLIT 1
-#define AZONE_JOIN 2
-#define AZONE_DRAG 3
-
/* actionzone pos */
#define AZONE_S 1
#define AZONE_SW 2
Modified: branches/blender2.5/blender/source/blender/editors/screen/area.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/screen/area.c 2008-11-17 18:44:06 UTC (rev 17480)
+++ branches/blender2.5/blender/source/blender/editors/screen/area.c 2008-11-17 18:54:03 UTC (rev 17481)
@@ -267,77 +267,21 @@
}
#define AZONESPOT 12
-void area_azone_initialize(ScrArea *sa) {
+void area_azone_initialize(ScrArea *sa)
+{
AZone *az;
if(sa->actionzones.first==NULL) {
/* set action zones - should these actually be ARegions? With these we can easier check area hotzones */
+ /* (ton) for time being just area, ARegion split is not foreseen on user level */
az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
BLI_addtail(&(sa->actionzones), az);
az->type= AZONE_TRI;
- az->x1= sa->v1->vec.x+1;
- az->y1= sa->v1->vec.y+1;
- az->x2= sa->v1->vec.x+AZONESPOT;
- az->y2= sa->v1->vec.y+AZONESPOT;
az->pos= AZONE_SW;
- az->action= AZONE_SPLIT;
az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
BLI_addtail(&(sa->actionzones), az);
az->type= AZONE_TRI;
- az->x1= sa->v3->vec.x-1;
- az->y1= sa->v3->vec.y-1;
- az->x2= sa->v3->vec.x-AZONESPOT;
- az->y2= sa->v3->vec.y-AZONESPOT;
az->pos= AZONE_NE;
- az->action= AZONE_DRAG;
-
- /*az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_TRI;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;
-
- az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_TRI;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;
-
- az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_QUAD;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;
-
- az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_QUAD;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;
-
- az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_QUAD;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;
-
- az= (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&sa->azones, az);
- az->type= AZONE_QUAD;
- az->x1= as->v1->vec.x;
- az->y1= as->v1->vec.y;
- az->x2= as->v1->vec.x+AZONESPOT;
- az->y2= as->v1->vec.y+AZONESPOT;*/
}
for(az= sa->actionzones.first; az; az= az->next) {
@@ -406,7 +350,6 @@
{
Panel *pa1, *pa2, *patab;
ARegion *ar;
- AZone *az;
sa1->headertype= sa2->headertype;
sa1->spacetype= sa2->spacetype;
Modified: branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c 2008-11-17 18:44:06 UTC (rev 17480)
+++ branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c 2008-11-17 18:54:03 UTC (rev 17481)
@@ -24,8 +24,12 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include <string.h>
+
#include "MEM_guardedalloc.h"
+#include "DNA_vec_types.h"
+
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
@@ -115,38 +119,6 @@
return NULL;
}
-static ScrArea *screen_test_edge_area(bScreen* scr, ScrArea *sa, ScrEdge *se)
-{
- /* test if edge is in area, if not,
- then find an area that has it */
-
- ScrEdge *se1=0, *se2=0, *se3=0, *se4=0;
-
- if(sa) {
- se1= screen_findedge(scr, sa->v1, sa->v2);
- se2= screen_findedge(scr, sa->v2, sa->v3);
- se3= screen_findedge(scr, sa->v3, sa->v4);
- se4= screen_findedge(scr, sa->v4, sa->v1);
- }
- if(se1!=se && se2!=se && se3!=se && se4!=se) {
-
- sa= scr->areabase.first;
- while(sa) {
- /* a bit optimise? */
- if(se->v1==sa->v1 || se->v1==sa->v2 || se->v1==sa->v3 || se->v1==sa->v4) {
- se1= screen_findedge(scr, sa->v1, sa->v2);
- se2= screen_findedge(scr, sa->v2, sa->v3);
- se3= screen_findedge(scr, sa->v3, sa->v4);
- se4= screen_findedge(scr, sa->v4, sa->v1);
- if(se1==se || se2==se || se3==se || se4==se) return sa;
- }
- sa= sa->next;
- }
- }
-
- return sa; /* is null when not find */
-}
-
static ScrArea *screen_areahascursor(bScreen *scr, int x, int y)
{
ScrArea *sa= NULL;
@@ -159,6 +131,38 @@
return sa;
}
+/* *************************** action zone operator ************************** */
+
+/* operator state vars used:
+ none
+
+functions:
+
+ apply() set actionzone event
+
+ exit() free customdata
+
+callbacks:
+
+ exec() never used
+
+ invoke() check if in zone
+ add customdata, put mouseco and area in it
+ add modal handler
+
+ modal() accept modal events while doing it
+ call apply() with gesture info, active window, nonactive window
+ call exit() and remove handler when LMB confirm
+
+*/
+
+typedef struct sActionzoneData {
+ ScrArea *sa1, *sa2;
+ AZone *az;
+ int x, y, gesture_dir;
+} sActionzoneData;
+
+
static AZone *is_in_area_actionzone(ScrArea *sa, int x, int y)
{
AZone *az= NULL;
@@ -166,16 +170,118 @@
for(az= sa->actionzones.first, i= 0; az; az= az->next, i++) {
if(az && az->type == AZONE_TRI) {
- if(IsPointInTri2DInts(az->x1, az->y1, az->x2, az->y2, x, y)) break;
+ if(IsPointInTri2DInts(az->x1, az->y1, az->x2, az->y2, x, y))
+ break;
}
if(az->type == AZONE_QUAD) {
- if(az->x1 < x && x < az->x2 && az->y1 < y && y < az->y2) break;
+ if(az->x1 < x && x < az->x2 && az->y1 < y && y < az->y2)
+ break;
}
}
return az;
}
+static int actionzone_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ AZone *az= is_in_area_actionzone(C->area, event->x, event->y);
+ sActionzoneData *sad;
+
+ /* quick escape */
+ if(az==NULL)
+ return OPERATOR_PASS_THROUGH;
+
+ /* ok we do the actionzone */
+ sad= op->customdata= MEM_callocN(sizeof(sActionzoneData), "sActionzoneData");
+ sad->sa1= C->area;
+ sad->az= az;
+ sad->x= event->x; sad->y= event->y;
+
+ /* add modal handler */
+ WM_event_add_modal_handler(&C->window->handlers, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void actionzone_exit(bContext *C, wmOperator *op)
+{
+ if(op->customdata)
+ MEM_freeN(op->customdata);
+ op->customdata= NULL;
+}
+
+/* send EVT_ACTIONZONE event */
+static void actionzone_apply(bContext *C, wmOperator *op)
+{
+ wmEvent event;
+
+ event= *(C->window->eventstate); /* XXX huh huh? make api call */
+ event.type= EVT_ACTIONZONE;
+ event.customdata= op->customdata;
+ event.customdatafree= TRUE;
+ op->customdata= NULL;
+
+ wm_event_add(C->window, &event);
+}
+
+static int actionzone_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ sActionzoneData *sad= op->customdata;
+ int deltax, deltay;
+
+ switch(event->type) {
+ case MOUSEMOVE:
+ /* calculate gesture direction */
+ deltax= (event->x - sad->x);
+ deltay= (event->y - sad->y);
+
+ if(deltay > ABS(deltax))
+ sad->gesture_dir= AZONE_N;
+ else if(deltax > ABS(deltay))
+ sad->gesture_dir= AZONE_E;
+ else if(deltay < -ABS(deltax))
+ sad->gesture_dir= AZONE_S;
+ else
+ sad->gesture_dir= AZONE_W;
+
+ /* gesture is large enough? */
+ if(ABS(deltax) > 12 || ABS(deltay) > 12) {
+
+ /* second area, for join */
+ sad->sa2= screen_areahascursor(C->screen, event->x, event->y);
+ /* apply sends event */
+ actionzone_apply(C, op);
+ actionzone_exit(C, op);
+
+ WM_event_remove_modal_handler(&C->window->handlers, op);
+
+ return OPERATOR_FINISHED;
+ }
+ break;
+ case ESCKEY:
+ case LEFTMOUSE:
+ actionzone_exit(C, op);
+ WM_event_remove_modal_handler(&C->window->handlers, op);
+ return OPERATOR_CANCELLED;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void ED_SCR_OT_actionzone(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Handle area action zones";
+ ot->idname= "ED_SCR_OT_actionzone";
+
+ ot->invoke= actionzone_invoke;
+ ot->modal= actionzone_modal;
+
+ ot->poll= ED_operator_areaactive;
+}
+
+/* ************************************** */
+
static void removedouble_scrverts(bScreen *sc)
{
ScrVert *v1, *verg;
@@ -564,7 +670,7 @@
/* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
/* -1 = not valid check */
-/* used with split operator */
+/* used with join operator */
static int area_getorientation(bScreen *screen, ScrArea *sa, ScrArea *sb)
{
ScrVert *sav1, *sav2, *sav3, *sav4;
@@ -636,7 +742,7 @@
}
}
-static ScrArea* splitarea(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
+static ScrArea *splitarea(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
{
ScrArea *newa=NULL;
ScrVert *sv1, *sv2;
@@ -818,16 +924,11 @@
#define SCR_BACK 0.55
#define SCR_ROUND 12
-/** join areas arrow drawing **/
-typedef struct point{
- float x,y;
-}_point;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list