[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17504] branches/blender2.5/blender/source /blender: Code shuffle to make a bit more structure.
Ton Roosendaal
ton at blender.org
Wed Nov 19 17:28:11 CET 2008
Revision: 17504
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17504
Author: ton
Date: 2008-11-19 17:28:11 +0100 (Wed, 19 Nov 2008)
Log Message:
-----------
Code shuffle to make a bit more structure.
- operator definitions, callbacks, registry to WM and handlers for it are
now always in a file xxxx_ops.c or xxxx_operators.c, in the bottom you
will find the registry and handler code.
- fixed some confusing naming conventions "rip_area vs area_join" etc. Now
stick to convention to first name subject, then operation (like UI :).
So it's area_rip, screen_add, and so on.
- Nicely put exported calls (outside module) together in bottom: this using
names such as ED_screen_duplicate().
- Moved Operator-Property API to new C file.
Modified Paths:
--------------
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.c
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c
branches/blender2.5/blender/source/blender/windowmanager/wm.h
Added Paths:
-----------
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operator_props.c
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-19 13:16:05 UTC (rev 17503)
+++ branches/blender2.5/blender/source/blender/editors/screen/screen_edit.c 2008-11-19 16:28:11 UTC (rev 17504)
@@ -31,7 +31,6 @@
#include "DNA_vec_types.h"
#include "BLI_blenlib.h"
-#include "BLI_arithb.h"
#include "BKE_global.h"
#include "BKE_library.h"
@@ -90,7 +89,7 @@
}
-static ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
+ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
{
ScrEdge *se;
@@ -102,171 +101,8 @@
return NULL;
}
-static ScrArea *screen_areahascursor(bScreen *scr, int x, int y)
+void removedouble_scrverts(bScreen *sc)
{
- ScrArea *sa= NULL;
- sa= scr->areabase.first;
- while(sa) {
- if(BLI_in_rcti(&sa->totrct, x, y)) break;
- sa= sa->next;
- }
-
- 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;
- int i= 0;
-
- 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(az->type == AZONE_QUAD) {
- 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;
ScrEdge *se;
ScrArea *sa;
@@ -319,7 +155,7 @@
}
-static void removenotused_scrverts(bScreen *sc)
+void removenotused_scrverts(bScreen *sc)
{
ScrVert *sv, *svn;
ScrEdge *se;
@@ -345,7 +181,7 @@
}
}
-static void removedouble_scredges(bScreen *sc)
+void removedouble_scredges(bScreen *sc)
{
ScrEdge *verg, *se, *sn;
@@ -365,7 +201,7 @@
}
}
-static void removenotused_scredges(bScreen *sc)
+void removenotused_scredges(bScreen *sc)
{
ScrEdge *se, *sen;
ScrArea *sa;
@@ -401,80 +237,6 @@
}
}
-static int scredge_is_horizontal(ScrEdge *se)
-{
- return (se->v1->vec.y == se->v2->vec.y);
-}
-
-static ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
-{
- ScrEdge *se;
-
- for (se= sc->edgebase.first; se; se= se->next) {
- if (scredge_is_horizontal(se)) {
- short min, max;
- min= MIN2(se->v1->vec.x, se->v2->vec.x);
- max= MAX2(se->v1->vec.x, se->v2->vec.x);
-
- if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max)
- return se;
- }
- else {
- short min, max;
- min= MIN2(se->v1->vec.y, se->v2->vec.y);
- max= MAX2(se->v1->vec.y, se->v2->vec.y);
-
- if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max)
- return se;
- }
- }
-
- return NULL;
-}
-
-/* danger: is used while areamove! */
-static void select_connected_scredge(bScreen *sc, ScrEdge *edge)
-{
- ScrEdge *se;
- ScrVert *sv;
- int oneselected;
- char dir;
-
- /* select connected, only in the right direction */
- /* 'dir' is the direction of EDGE */
-
- if(edge->v1->vec.x==edge->v2->vec.x) dir= 'v';
- else dir= 'h';
-
- sv= sc->vertbase.first;
- while(sv) {
- sv->flag = 0;
- sv= sv->next;
- }
-
- edge->v1->flag= 1;
- edge->v2->flag= 1;
-
- oneselected= 1;
- while(oneselected) {
- se= sc->edgebase.first;
- oneselected= 0;
- while(se) {
- if(se->v1->flag + se->v2->flag==1) {
- if(dir=='h') if(se->v1->vec.y==se->v2->vec.y) {
- se->v1->flag= se->v2->flag= 1;
- oneselected= 1;
- }
- if(dir=='v') if(se->v1->vec.x==se->v2->vec.x) {
- se->v1->flag= se->v2->flag= 1;
- oneselected= 1;
- }
- }
- se= se->next;
- }
- }
-}
-
/* adds no space data */
static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
{
@@ -499,14 +261,108 @@
MEM_freeN(sa);
}
-/* Helper function to join 2 areas, it has a return value, 0=failed 1=success
- * used by the split, join and rip operators
- */
-int screen_join_areas(bScreen *scr, ScrArea *sa1, ScrArea *sa2);
+/* return 0: no split possible */
+/* else return (integer) screencoordinate split point */
+static short testsplitpoint(wmWindow *win, ScrArea *sa, char dir, float fac)
+{
+ short x, y;
+
+ // area big enough?
+ if(sa->v4->vec.x- sa->v1->vec.x <= 2*AREAMINX) return 0;
+ if(sa->v2->vec.y- sa->v1->vec.y <= 2*AREAMINY) return 0;
+
+ // to be sure
+ if(fac<0.0) fac= 0.0;
+ if(fac>1.0) fac= 1.0;
+
+ if(dir=='h') {
+ y= sa->v1->vec.y+ fac*(sa->v2->vec.y- sa->v1->vec.y);
+
+ if(y- sa->v1->vec.y < AREAMINY)
+ y= sa->v1->vec.y+ AREAMINY;
+ else if(sa->v2->vec.y- y < AREAMINY)
+ y= sa->v2->vec.y- AREAMINY;
+ else y-= (y % AREAGRID);
+
+ return y;
+ }
+ else {
+ x= sa->v1->vec.x+ fac*(sa->v4->vec.x- sa->v1->vec.x);
+
+ if(x- sa->v1->vec.x < AREAMINX)
+ x= sa->v1->vec.x+ AREAMINX;
+ else if(sa->v4->vec.x- x < AREAMINX)
+ x= sa->v4->vec.x- AREAMINX;
+ else x-= (x % AREAGRID);
+
+ return x;
+ }
+}
+ScrArea *area_split(wmWindow *win, bScreen *sc, ScrArea *sa, char dir, float fac)
+{
+ ScrArea *newa=NULL;
+ ScrVert *sv1, *sv2;
+ short split;
+
+ if(sa==0) return NULL;
+
+ split= testsplitpoint(win, sa, dir, fac);
+ if(split==0) return NULL;
+
+ if(dir=='h') {
+ /* new vertices */
+ sv1= screen_addvert(sc, sa->v1->vec.x, split);
+ sv2= screen_addvert(sc, sa->v4->vec.x, split);
+
+ /* new edges */
+ screen_addedge(sc, sa->v1, sv1);
+ screen_addedge(sc, sv1, sa->v2);
+ screen_addedge(sc, sa->v3, sv2);
+ screen_addedge(sc, sv2, sa->v4);
+ screen_addedge(sc, sv1, sv2);
+
+ /* new areas: top */
+ newa= screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
+ area_copy_data(newa, sa, 0);
+
+ /* area below */
+ sa->v2= sv1;
+ sa->v3= sv2;
+
+ }
+ else {
+ /* new vertices */
+ sv1= screen_addvert(sc, split, sa->v1->vec.y);
+ sv2= screen_addvert(sc, split, sa->v2->vec.y);
+
+ /* new edges */
+ screen_addedge(sc, sa->v1, sv1);
+ screen_addedge(sc, sv1, sa->v4);
+ screen_addedge(sc, sa->v2, sv2);
+ screen_addedge(sc, sv2, sa->v3);
+ screen_addedge(sc, sv1, sv2);
+
+ /* new areas: left */
+ newa= screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
+ area_copy_data(newa, sa, 0);
+
+ /* area right */
+ sa->v1= sv1;
+ sa->v2= sv2;
+ }
+
+ /* remove double vertices en edges */
+ removedouble_scrverts(sc);
+ removedouble_scredges(sc);
+ removenotused_scredges(sc);
+
+ return newa;
+}
+
/* empty screen, with 1 dummy area without spacedata */
/* uses window size */
-static bScreen *screen_add(wmWindow *win, char *name)
+bScreen *screen_add(wmWindow *win, char *name)
{
bScreen *sc;
ScrVert *sv1, *sv2, *sv3, *sv4;
@@ -581,100 +437,11 @@
}
-/* *********** Rip area operator ****************** */
-
-/* operator callback */
-/* (ton) removed attempt to merge ripped area with another, don't think this is desired functionality.
- conventions: 'atomic' and 'dont think for user' :) */
-static int screen_area_rip_op(bContext *C, wmOperator *op)
-{
- wmWindow *win;
- bScreen *newsc;
- rcti rect;
-
- /* poll() checks area context, but we don't accept full-area windows */
- if(C->screen->full != SCREENNORMAL)
- return OPERATOR_CANCELLED;
-
- /* adds window to WM */
- rect= C->area->totrct;
- BLI_translate_rcti(&rect, C->window->posx, C->window->posy);
- win= WM_window_open(C, &rect);
-
- /* allocs new screen and adds to newly created window, using window size */
- newsc= screen_add(win, C->screen->id.name+2);
-
- /* copy area to new screen */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list