Blender 2.5 project: added first more complex handler + operator
authorTon Roosendaal <ton@blender.org>
Thu, 10 Jan 2008 17:38:17 +0000 (17:38 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 10 Jan 2008 17:38:17 +0000 (17:38 +0000)
- on mouse-over edge, you can drag area borders around.
- note it's a handerized system now, so it updates UI while you
  move mouse.

Feedback needed:

- read bottom part of the screen_edit.c file. It's the proposed
  method for adding tools and handlers. I think it's close, but
  might need some tweaks.

18 files changed:
source/blender/blenloader/intern/readfile.c
source/blender/editors/include/ED_screen.h
source/blender/editors/screen/area.c
source/blender/editors/screen/ed_screen.c [deleted file]
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_intern.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/screen/spacetypes.c
source/blender/makesdna/DNA_screen_types.h
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/screen_edit.c [deleted file]
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_keymap.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c

index 7bc60be4fd9641ee74d3ae91008e06208a12f0c7..2fbfa974360c874cacc98f0f6c0265a77d2a78fe 100644 (file)
@@ -4576,7 +4576,6 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
                if(sa->headertype) {
                        ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                        BLI_addtail(&sa->regionbase, ar);
-                       ar->winrct= sa->headrct;
                        ar->regiontype= RGN_TYPE_HEADER;
                        ar->minsize= HEADERY;   // DNA_screen_types.h
                        if(sa->headertype==1)
@@ -4587,7 +4586,7 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
                
                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                BLI_addtail(&sa->regionbase, ar);
-               ar->winrct= sa->winrct;
+               ar->winrct= sa->totrct;
                ar->regiontype= RGN_TYPE_WINDOW;
        }
 }
index 991e1177e2790478833e2c1dd15da91892c89390..369bfb80169e4176a44735b8c0be4533c497ef4c 100644 (file)
@@ -54,8 +54,14 @@ void ED_screen_draw(struct wmWindow *win);
 void   ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
 void   ED_screen_do_listen(bScreen *screen, struct wmNotifier *note);
 bScreen *ED_screen_duplicate(struct wmWindow *win, bScreen *sc);
+void   ED_screen_set_subwinactive(struct wmWindow *win);
 
 void   ed_screen_keymap(struct wmWindowManager *wm);
 
+/* operators; context poll callbacks */
+int            ED_operator_screenactive(bContext *C);
+int            ED_operator_screen_mainwinactive(bContext *C);
+
+
 #endif /* ED_SCREEN_H */
 
index 5acc3091364abc16e3b1fae5ae81e7bda9822610..e12bd82c627fc67db06dbb5f04c1e279de4468d7 100644 (file)
@@ -88,15 +88,19 @@ static void region_draw_emboss(ARegion *ar)
 
 void ED_region_do_listen(ARegion *ar, wmNotifier *note)
 {
-       if(ar->type->listener)
-               ar->type->listener(ar, note);
-       
-       /* generic notes */
-       if(note->type==WM_NOTE_REDRAW)
-               ar->do_draw= 1;
-       if(note->type==WM_NOTE_REFRESH)
-               ar->do_refresh= 1;
        
+       /* generic notes first */
+       switch(note->type) {
+               case WM_NOTE_WINDOW_REDRAW:
+                       ar->do_draw= 1;
+                       break;
+               case WM_NOTE_SCREEN_CHANGED:
+                       ar->do_draw= ar->do_refresh= 1;
+                       break;
+               default:
+                       if(ar->type->listener)
+                               ar->type->listener(ar, note);
+       }
 }
 
 void ED_region_do_draw(bContext *C, ARegion *ar)
diff --git a/source/blender/editors/screen/ed_screen.c b/source/blender/editors/screen/ed_screen.c
deleted file mode 100644 (file)
index 5da6516..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * $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) 2007 Blender Foundation.
- * All rights reserved.
- *
- * 
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "WM_api.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "ED_area.h"
-#include "ED_screen.h"
-
-
-static void del_area(ScrArea *sa)
-{
-       
-       freespacelist(sa);
-       
-//     uiFreeBlocks(&sa->uiblocks);
-//     uiFreePanels(&sa->panels);
-       
-//     BPY_free_scriptlink(&sa->scriptlink);
-       
-}
-
-
-/* bad level to blenkernel, solve */
-void unlink_screen(bScreen *sc) 
-{
-       ScrArea *sa;
-       
-       for (sa= sc->areabase.first; sa; sa= sa->next)  
-               del_area(sa);
-}
\ No newline at end of file
index e73a4e8e77b2d121e718fd81f8ba5a61b815c2e3..cbb0e82b185411525b2c5e703cedf1cfb6c4c328 100644 (file)
@@ -237,7 +237,7 @@ static int scredge_is_horizontal(ScrEdge *se)
        return (se->v1->vec.y == se->v2->vec.y);
 }
 
-static ScrEdge *screen_find_active_scredge(bScreen *sc, short *mval)
+static ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my)
 {
        ScrEdge *se;
        
@@ -247,7 +247,7 @@ static ScrEdge *screen_find_active_scredge(bScreen *sc, short *mval)
                        min= MIN2(se->v1->vec.x, se->v2->vec.x);
                        max= MAX2(se->v1->vec.x, se->v2->vec.x);
                        
-                       if (abs(mval[1]-se->v1->vec.y)<=2 && mval[0] >= min && mval[0]<=max)
+                       if (abs(my-se->v1->vec.y)<=2 && mx>=min && mx<=max)
                                return se;
                } 
                else {
@@ -255,7 +255,7 @@ static ScrEdge *screen_find_active_scredge(bScreen *sc, short *mval)
                        min= MIN2(se->v1->vec.y, se->v2->vec.y);
                        max= MAX2(se->v1->vec.y, se->v2->vec.y);
                        
-                       if (abs(mval[0]-se->v1->vec.x)<=2 && mval[1] >= min && mval[1]<=max)
+                       if (abs(mx-se->v1->vec.x)<=2 && my>=min && my<=max)
                                return se;
                }
        }
@@ -263,6 +263,7 @@ static ScrEdge *screen_find_active_scredge(bScreen *sc, short *mval)
        return NULL;
 }
 
+/* danger: is used while areamove! */
 static void select_connected_scredge(bScreen *sc, ScrEdge *edge)
 {
        ScrEdge *se;
@@ -278,7 +279,7 @@ static void select_connected_scredge(bScreen *sc, ScrEdge *edge)
        
        sv= sc->vertbase.first;
        while(sv) {
-               sv->flag= 0;
+               sv->flag = 0;
                sv= sv->next;
        }
        
@@ -410,13 +411,11 @@ bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
 /* *************************************************************** */
 
 /* test if screen vertices should be scaled */
-/* also check offset */
 void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
 {
        ScrVert *sv=NULL;
-       ScrEdge *se;
        ScrArea *sa, *san;
-       int sizex, sizey, yval;
+       int sizex, sizey;
        float facx, facy, tempf, min[2], max[2];
        
        /* calculate size */
@@ -472,29 +471,6 @@ void screen_test_scale(bScreen *sc, int winsizex, int winsizey)
                        MEM_freeN(sa);
                }
        }
-       
-       /* make each window at least HEADERY high */
-       for(sa= sc->areabase.first; sa; sa= sa->next) {
-               
-               if(sa->v1->vec.y+HEADERY > sa->v2->vec.y) {
-                       /* lower edge */
-                       se= screen_findedge(sc, sa->v4, sa->v1);
-                       if(se && sa->v1!=sa->v2 ) {
-                               select_connected_scredge(sc, se);
-                               
-                               /* all selected vertices get the right offset */
-                               yval= sa->v2->vec.y-HEADERY;
-                               sv= sc->vertbase.first;
-                               while(sv) {
-                                       /* if is a collapsed area */
-                                       if(sv!=sa->v2 && sv!=sa->v3) {
-                                               if(sv->flag) sv->vec.y= yval;
-                                       }
-                                       sv= sv->next;
-                               }
-                       }
-               }
-       }
 }
 
 
@@ -529,12 +505,14 @@ void ED_screen_do_listen(bScreen *screen, wmNotifier *note)
 {
        
        /* generic notes */
-       if(note->type==WM_NOTE_REDRAW)
-               screen->do_draw= 1;
-       if(note->type==WM_NOTE_REFRESH)
-               if(note->swinid==0)
-                       screen->do_refresh= screen->do_draw= 1;
-       
+       switch(note->type) {
+               case WM_NOTE_WINDOW_REDRAW:
+                       screen->do_draw= 1;
+                       break;
+               case WM_NOTE_SCREEN_CHANGED:
+                       screen->do_draw= screen->do_refresh= 1;
+                       break;
+       }
 }
 
 
@@ -552,7 +530,7 @@ void ED_screen_draw(wmWindow *win)
 }
 
 /* make this screen usable */
-/* for file read and first use, for scaling window */
+/* for file read and first use, for scaling window, area moves */
 void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
 {
        ScrArea *sa;
@@ -592,28 +570,48 @@ void ED_screens_initialize(wmWindowManager *wm)
 
 void placeholder()
 {
-       removedouble_scrverts(NULL);
        removenotused_scrverts(NULL);
-       removedouble_scredges(NULL);
        removenotused_scredges(NULL);
 }
 
-/* *************************************************** */
+/* called in wm_event_system.c. sets state var in screen */
+void ED_screen_set_subwinactive(wmWindow *win)
+{
+       if(win->screen) {
+               wmEvent *event= win->eventstate;
+               ScrArea *sa;
+               
+               for(sa= win->screen->areabase.first; sa; sa= sa->next) {
+                       if(event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
+                               if(event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
+                                       break;
+               }
+               if(sa) {
+                       ARegion *ar;
+                       for(ar= sa->regionbase.first; ar; ar= ar->next) {
+                               if(BLI_in_rcti(&ar->winrct, event->x, event->y))
+                                       win->screen->subwinactive= ar->swinid;
+                       }
+               }
+               else
+                       win->screen->subwinactive= win->screen->mainwin;
+               
+       }
+}
+
+/* ****************** cursor near edge operator ********************************* */
 
 /* operator cb */
 int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event)
 {
-       short mval[2]= {event->x, event->y};
-       ScrEdge *actedge= screen_find_active_scredge(C->screen, mval);
-       
-       if (actedge) {
-               if (scredge_is_horizontal(actedge)) {
+       if (C->screen->subwinactive==C->screen->mainwin) {
+               ScrEdge *actedge= screen_find_active_scredge(C->screen, event->x, event->y);
+               
+               if (actedge && scredge_is_horizontal(actedge)) {
                        WM_set_cursor(C, CURSOR_Y_MOVE);
                } else {
                        WM_set_cursor(C, CURSOR_X_MOVE);
                }
-               // this does global hotkeys too
-//             screen_edge_edit_event(g_activearea, actedge, event, val);
        } else {
                WM_set_cursor(C, CURSOR_STD);
        }
@@ -622,3 +620,190 @@ int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event)
 }
 
 
+
+/* ************** move area edge operator ********************************************** */
+
+/* operator state vars used:  
+           op->veci   mouse coord near edge
+           op->delta  movement of edge
+
+   callbacks:
+
+   init()   find edge based on op->veci, test if the edge can be moved, select edges,
+            clear delta, calculate min and max movement
+
+   exec()      apply op->delta on selection
+   
+   invoke() handler gets called on a mouse click near edge
+            call init()
+            add handler
+
+   modal()     accept modal events while doing it
+                       call exec() with delta motion
+            call exit() and remove handler
+
+   exit()      cleanup, send notifier
+
+*/
+
+/* "global" variables for all functions inside this operator */
+/*  we could do it with properties? */
+static int     bigger, smaller, dir, origval;
+       
+/* validate selection inside screen, set variables OK */
+/* return 0: init failed */
+static int move_areas_init (bContext *C, wmOperator *op)
+{
+       ScrEdge *actedge= screen_find_active_scredge(C->screen, op->veci.x, op->veci.y);
+       ScrArea *sa;
+       
+       if(actedge==NULL) return 0;
+       
+       dir= scredge_is_horizontal(actedge)?'h':'v';
+       if(dir=='h') origval= actedge->v1->vec.y;
+       else origval= actedge->v1->vec.x;
+       
+       select_connected_scredge(C->screen, actedge);
+
+       /* now all verices with 'flag==1' are the ones that can be moved. */
+       /* we check all areas and test for free space with MINSIZE */
+       bigger= smaller= 10000;
+       for(sa= C->screen->areabase.first; sa; sa= sa->next) {
+               if(dir=='h') {  /* if top or down edge selected, test height */
+                  
+                  if(sa->v1->flag && sa->v4->flag) {
+                          int y1= sa->v2->vec.y - sa->v1->vec.y-AREAMINY;
+                          bigger= MIN2(bigger, y1);
+                  }
+                  else if(sa->v2->flag && sa->v3->flag) {
+                          int y1= sa->v2->vec.y - sa->v1->vec.y-AREAMINY;
+                          smaller= MIN2(smaller, y1);
+                  }
+               }
+               else {  /* if left or right edge selected, test width */
+                       if(sa->v1->flag && sa->v2->flag) {
+                               int x1= sa->v4->vec.x - sa->v1->vec.x-AREAMINX;
+                               bigger= MIN2(bigger, x1);
+                       }
+                       else if(sa->v3->flag && sa->v4->flag) {
+                               int x1= sa->v4->vec.x - sa->v1->vec.x-AREAMINX;
+                               smaller= MIN2(smaller, x1);
+                       }
+               }
+       }
+       
+       return 1;
+}
+
+/* moves selected screen edge amount of delta */
+/* needs init call to work */
+static int move_areas_exec(bContext *C, wmOperator *op)
+{
+       ScrVert *v1;
+       
+       op->delta= CLAMPIS(op->delta, -smaller, bigger);
+       
+       for (v1= C->screen->vertbase.first; v1; v1= v1->next) {
+               if (v1->flag) {
+                       /* that way a nice AREAGRID  */
+                       if((dir=='v') && v1->vec.x>0 && v1->vec.x<C->window->sizex-1) {
+                               v1->vec.x= origval + op->delta;
+                               if(op->delta != bigger && op->delta != -smaller) v1->vec.x-= (v1->vec.x % AREAGRID);
+                       }
+                       if((dir=='h') && v1->vec.y>0 && v1->vec.y<C->window->sizey-1) {
+                               v1->vec.y= origval + op->delta;
+
+                               v1->vec.y+= AREAGRID-1;
+                               v1->vec.y-= (v1->vec.y % AREAGRID);
+                               
+                               /* prevent too small top header */
+                               if(v1->vec.y > C->window->sizey-HEADERY)
+                                       v1->vec.y= C->window->sizey-HEADERY;
+                       }
+               }
+       }
+       return 1;
+}
+
+static int move_areas_exit(bContext *C, wmOperator *op)
+{
+       
+       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0);
+
+       /* this makes sure aligned edges will result in aligned grabbing */
+       removedouble_scrverts(C->screen);
+       removedouble_scredges(C->screen);
+       
+       return 1;
+}
+
+/* interaction callback */
+/* return 0 = stop evaluating for next handlers */
+static int move_areas_invoke (bContext *C, wmOperator *op, wmEvent *event)
+{
+       
+       /* operator arguments and storage */
+       op->delta= 0;
+       op->veci.x= event->x;
+       op->veci.y= event->y;
+       
+       if(0==move_areas_init(C, op)) 
+               return 1;
+       
+       /* add temp handler */
+       WM_event_add_modal_handler(&C->window->handlers, op);
+       
+       return 0;
+}
+
+/* modal callback for while moving edges */
+/* return 0 = stop evaluating for next handlers */
+static int move_areas_modal (bContext *C, wmOperator *op, wmEvent *event)
+{
+       /* execute the events */
+       switch(event->type) {
+               case MOUSEMOVE:
+                       
+                       if(dir=='v')
+                               op->delta= event->x - op->veci.x;
+                       else
+                               op->delta= event->y - op->veci.y;
+                       
+                       move_areas_exec(C, op);
+                       WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0);
+                       break;
+                       
+               case LEFTMOUSE:
+                       if(event->val==0) {
+                               WM_event_remove_modal_handler(&C->window->handlers, op);
+                               move_areas_exit(C, op);
+                       }
+                       break;
+                       
+               case ESCKEY:
+                       op->delta= 0;
+                       move_areas_exec(C, op);
+                       
+                       WM_event_remove_modal_handler(&C->window->handlers, op);
+                       move_areas_exit(C, op);
+                       break;
+       }
+       
+       return 1;
+}
+
+void ED_SCR_OT_move_areas(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "Move area edges";
+       ot->idname= "ED_SCR_OT_move_areas";
+
+       ot->init= move_areas_init;
+       ot->invoke= move_areas_invoke;
+       ot->modal= move_areas_modal;
+       ot->exec= move_areas_exec;
+       ot->exit= move_areas_exit;
+
+       ot->poll= ED_operator_screen_mainwinactive;
+}
index 01c9c08ac51b8c80eb9b22fa1ccd2b74aae4d53e..680404cc41b2accc3496a62c240c6d31aeea977e 100644 (file)
@@ -36,7 +36,9 @@ struct wmEvent;
 void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space);
 
 /* screen_edit.c */
-int screen_cursor_test(bContext *C, struct wmOperator *op, struct wmEvent *event);
+int screen_cursor_test(bContext *C, wmOperator *op, wmEvent *event);
+
+void ED_SCR_OT_move_areas(wmOperatorType *ot);
 
 
 #endif /* ED_SCREEN_INTERN_H */
index b88438ecdfc8acd848d32aa5c6bdba9bc78a3ce7..c6d44017db7d85b3969044f5927c0086380e0d35 100644 (file)
@@ -44,6 +44,8 @@
 
 static ListBase local_ops;
 
+/* ************** Poll tests ********************** */
+
 int ED_operator_screenactive(bContext *C)
 {
        if(C->window==NULL) return 0;
@@ -51,24 +53,22 @@ int ED_operator_screenactive(bContext *C)
        return 1;
 }
 
-
-
-static void ED_SCR_OT_move_areas(wmOperatorType *ot)
+int ED_operator_screen_mainwinactive(bContext *C)
 {
-    ot->name= "Move area edges";
-    ot->idname= "ED_SCR_OT_move_areas";
-       
-    ot->interactive= NULL;
-    ot->exec= NULL;
-    ot->poll= ED_operator_screenactive;
+       if(C->window==NULL) return 0;
+       if(C->screen==NULL) return 0;
+       if (C->screen->subwinactive!=C->screen->mainwin) return 0;
+       return 1;
 }
 
+/* ******************************* */
+
 static void ED_SCR_OT_cursor_type(wmOperatorType *ot)
 {
     ot->name= "Cursor type";
     ot->idname= "ED_SCR_OT_cursor_type";
        
-    ot->interactive= screen_cursor_test;
+    ot->invoke= screen_cursor_test;
     ot->exec= NULL;
     ot->poll= ED_operator_screenactive;
 }
@@ -88,8 +88,6 @@ void ED_operatortypes_screen(void)
        ADD_OPTYPE( ED_SCR_OT_move_areas );
        ADD_OPTYPE( ED_SCR_OT_cursor_type );
        
-       
-       
        WM_operatortypelist_append(&local_ops);
 }
 
@@ -97,6 +95,7 @@ void ED_operatortypes_screen(void)
 void ed_screen_keymap(wmWindowManager *wm)
 {
        WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_cursor_type", MOUSEMOVE, 0, 0, 0);
+       WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_move_areas", LEFTMOUSE, KM_PRESS, 0, 0);
 
 }
 
index eec6da90e1a128f68bf0537ec53f9cb9f7c48dbe..88ac8de1f882d3a3e4de9f33fd95aaad80377bb7 100644 (file)
@@ -33,6 +33,7 @@
 #include "BIF_gl.h"
 
 #include "WM_api.h"
+#include "WM_types.h"
 
 #include "ED_screen.h"
 #include "ED_area.h"
index 953877953d9446c05eed6a8817bf6190ccdc6de9..61f8bab83fd352dd49740af52c5812b61095ce22 100644 (file)
@@ -108,7 +108,6 @@ typedef struct ScrArea {
        bScreen *full;                  /* if area==full, this is the parent */
 
        rcti totrct;                    /* rect bound by v1 v2 v3 v4 */
-       rcti headrct, winrct;   /* OLD! gets converted to region */
 
        char spacetype, butspacetype;   /* SPACE_..., butspacetype is button arg  */
        short winx, winy;                               /* size */
@@ -156,7 +155,6 @@ typedef struct ARegion {
 
 /* If you change EDGEWIDTH, also do the global arrat edcol[]  */
 #define EDGEWIDTH      1
-#define EDGEWIDTH2     0
 #define AREAGRID       4
 #define AREAMINX       32
 #define HEADERY                26
index 193f2020463e81c951a3667c1bae4743b495a756..d85642eecbffc3b1e89cc6ddc53533a247076aa7 100644 (file)
@@ -108,12 +108,14 @@ typedef struct wmOperatorType {
        char *name;             /* text for ui, undo */
        char *idname;   /* unique identifier */
        
-       /* this callback alters UI, adds handlers, uses cb's below */
-       int (*interactive)(struct bContext *, struct wmOperator *, struct wmEvent *event);
+       /* this callback alters UI, adds handlers, or uses cb's below */
+       int (*invoke)(struct bContext *, struct wmOperator *, struct wmEvent *event);
+       /* this callback is for modal temporary ops, initialize was called */
+       int (*modal)(struct bContext *, struct wmOperator *, struct wmEvent *event);
        
-       void (*init)(struct bContext *, struct wmOperator *);
+       int (*init)(struct bContext *, struct wmOperator *);
        int (*exec)(struct bContext *, struct wmOperator *);
-       void (*exit)(struct bContext *, struct wmOperator *);
+       int (*exit)(struct bContext *, struct wmOperator *);
        
        int (*poll)(struct bContext *);
        
@@ -153,16 +155,19 @@ typedef struct wmOperator {
        
        /* default storage (lazy?) */
        void *argv1, *argv2;
-       float argf1, argf2;
-       int arg1, arg2;
-       
+       vec3f   vecf;
+       vec3i   veci;
+       float fac, deltaf;
+       int value, delta;
+
        /* custom storage, dna pointer */
-       void *customdata; /* XXX dynamic properties! */
+       void *customdata; 
+       /* or IDproperty list */
+       void *properties;
 
        
 } wmOperator;
 
 
-
 #endif /* DNA_WINDOWMANAGER_TYPES_H */
 
index 6f94bfac456a9877aa055c1a15dcdcd869fda40c..915c55f4cf77b995aaf2eecbf0ab0b101dba16b2 100644 (file)
@@ -61,10 +61,14 @@ void                WM_keymap_set_item      (ListBase *lb, char *idname, short type,
                                                                 short val, int modifier, short keymodifier);
 void           WM_keymap_verify_item(ListBase *lb, char *idname, short type, 
                                                                 short val, int modifier, short keymodifier);
+void           WM_keymap_add_item      (ListBase *lb, char *idname, short type, 
+                                                                short val, int modifier, short keymodifier);
 struct wmEventHandler *WM_event_add_keymap_handler(ListBase *keymap, ListBase *handlers);
-struct wmEventHandler *WM_event_add_modal_keymap_handler(ListBase *keymap, ListBase *handlers, wmOperator *op);
+struct wmEventHandler *WM_event_add_modal_handler(ListBase *handlers, wmOperator *op);
+void           WM_event_remove_modal_handler(ListBase *handlers, wmOperator *op);
 
-void           WM_event_add_notifier(wmWindowManager *wm, wmWindow *window, int swinid, int type, int value);
+void           WM_event_add_notifier(wmWindowManager *wm, wmWindow *window, int swinid, int type, 
+                                                                 int value);
 
 
                        /* operator api, default callbacks */
index 9c670aff71e4e98a57f8c167586e242826074c47..c232815fd49c1b8895323489321262b7ea659dff 100644 (file)
@@ -99,8 +99,9 @@ typedef struct wmNotifier {
 
 
 enum {
-       WM_NOTE_REDRAW,
-       WM_NOTE_REFRESH,
+       WM_NOTE_WINDOW_REDRAW,
+       WM_NOTE_SCREEN_CHANGED,
+       WM_NOTE_OBJECT_CHANGED,
        
        WM_NOTE_LAST
 };
diff --git a/source/blender/windowmanager/intern/screen_edit.c b/source/blender/windowmanager/intern/screen_edit.c
deleted file mode 100644 (file)
index e69de29..0000000
index 37efc1a1367c19accac6859e671ecf44d088c177..ebf94bfc5c3fd03e19be7b5f9e27fa649a17be06 100644 (file)
@@ -205,14 +205,20 @@ void wm_draw_update(bContext *C)
 
 /* ********************* handlers *************** */
 
+/* not handler itself */
+static void wm_event_free_handler(wmEventHandler *handler)
+{
+       if(handler->op)
+               MEM_freeN(handler->op);
+}
+
 void wm_event_free_handlers(ListBase *lb)
 {
        wmEventHandler *handler;
        
-       for(handler= lb->first; handler; handler= handler->next) {
-               if(handler->op)
-                       MEM_freeN(handler->op);
-       }
+       for(handler= lb->first; handler; handler= handler->next)
+               wm_event_free_handler(handler);
+       
        BLI_freelistN(lb);
 }
 
@@ -227,7 +233,8 @@ static int wm_eventmatch(wmEvent *winevent, wmKeymapItem *km)
        if(winevent->ctrl!=km->ctrl) return 0;
        if(winevent->alt!=km->alt) return 0;
        if(winevent->oskey!=km->oskey) return 0;
-       if(winevent->keymodifier!=km->keymodifier) return 0;
+       if(km->keymodifier)
+               if(winevent->keymodifier!=km->keymodifier) return 0;
        
        /* optional boundbox */
        
@@ -240,25 +247,23 @@ static int wm_handler_operator_call(bContext *C, wmEventHandler *handler, wmEven
        
        /* derived, modal or blocking operator */
        if(handler->op) {
-               if( handler->op->type->poll(C)) {
-                       if(handler->op->type->interactive)
-                               retval= handler->op->type->interactive(C, handler->op, event);
-                       else
-                               printf("wm_handler_operator_call error\n");
-               }
+               if(handler->op->type->modal)
+                       retval= handler->op->type->modal(C, handler->op, event);
+               else
+                       printf("wm_handler_operator_call error\n");
        }
        else {
                wmOperatorType *ot= WM_operatortype_find(event->keymap_idname);
                if(ot) {
-                       if(ot->poll(C)) {
+                       if(ot->poll==NULL || ot->poll(C)) {
                                /* operator on stack, register or new modal handle malloc-copies */
                                wmOperator op;
                                
                                memset(&op, 0, sizeof(wmOperator));
                                op.type= ot;
 
-                               if(op.type->interactive)
-                                       retval= op.type->interactive(C, &op, event);
+                               if(op.type->invoke)
+                                       retval= (*op.type->invoke)(C, &op, event);
                                else if(&op.type->exec)
                                        retval= op.type->exec(C, &op);
                                
@@ -298,6 +303,11 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
                        if(action==WM_HANDLER_BREAK)
                                break;
                }
+               else {
+                       /* modal, swallows all */
+                       action= wm_handler_operator_call(C, handler, event);
+               }
+               
                /* modal+blocking handler */
                if(handler->flag & WM_HANDLER_BLOCKING)
                        action= WM_HANDLER_BREAK;
@@ -336,7 +346,7 @@ void wm_event_do_handlers(bContext *C)
                                ScrArea *sa= win->screen->areabase.first;
                                
                                for(; sa; sa= sa->next) {
-                                       if(wm_event_inside_i(event, &sa->winrct)) {
+                                       if(wm_event_inside_i(event, &sa->totrct)) {
                                                
                                                C->curarea= sa;
                                                action= wm_handlers_do(C, event, &sa->handlers);
@@ -368,7 +378,7 @@ void WM_event_set_handler_flag(wmEventHandler *handler, int flag)
        handler->flag= flag;
 }
 
-wmEventHandler *WM_event_add_modal_keymap_handler(ListBase *keymap, ListBase *handlers, wmOperator *op)
+wmEventHandler *WM_event_add_modal_handler(ListBase *handlers, wmOperator *op)
 {
        /* debug test; operator not in registry */
        if(op->type->flag & OPTYPE_REGISTER) {
@@ -378,8 +388,7 @@ wmEventHandler *WM_event_add_modal_keymap_handler(ListBase *keymap, ListBase *ha
                wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
                wmOperator *opc= MEM_mallocN(sizeof(wmOperator), "operator modal");
                
-               BLI_addtail(handlers, handler);
-               handler->keymap= keymap;
+               BLI_addhead(handlers, handler);
                *opc= *op;
                handler->op= opc;
                
@@ -388,6 +397,20 @@ wmEventHandler *WM_event_add_modal_keymap_handler(ListBase *keymap, ListBase *ha
        return NULL;
 }
 
+void WM_event_remove_modal_handler(ListBase *handlers, wmOperator *op)
+{
+       wmEventHandler *handler;
+       
+       for(handler= handlers->first; handler; handler= handler->next) {
+               if(handler->op==op) {
+                       BLI_remlink(handlers, handler);
+                       wm_event_free_handler(handler);
+                       MEM_freeN(handler);
+                       break;
+               }
+       }
+}
+
 wmEventHandler *WM_event_add_keymap_handler(ListBase *keymap, ListBase *handlers)
 {
        wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
@@ -398,6 +421,7 @@ wmEventHandler *WM_event_add_keymap_handler(ListBase *keymap, ListBase *handlers
        return handler;
 }
 
+
 /* ********************* ghost stuff *************** */
 
 static int convert_key(GHOST_TKey key) 
@@ -517,6 +541,8 @@ void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata)
                                event.x= evt->x= cx;
                                event.y= evt->y= (win->sizey-1) - cy;
                                
+                               ED_screen_set_subwinactive(win);        /* state variables in screen */
+                               
                                update_tablet_data(win, &event);
                                wm_event_add(win, &event);
                        }
@@ -535,6 +561,11 @@ void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata)
                        else
                                event.type= MIDDLEMOUSE;
                        
+                       if(event.val)
+                               event.keymodifier= evt->keymodifier= event.type;
+                       else
+                               event.keymodifier= evt->keymodifier= 0;
+                       
                        update_tablet_data(win, &event);
                        wm_event_add(win, &event);
                        
index da81c0edff2d66a3b3ddaf91245ff6afa6472cc3..8dbe235d256c40eb6dacec306cfba38e3101886c 100644 (file)
@@ -557,7 +557,9 @@ int WM_read_homefile(bContext *C, int from_memory)
        if (!from_memory && BLI_exists(tstr)) {
                success = BKE_read_file(C, tstr, NULL);
        } else {
-               //XXX success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL);
+               extern int datatoc_B_blend_size;
+               extern char datatoc_B_blend[];
+               success = BKE_read_file_from_memory(C, datatoc_B_blend, datatoc_B_blend_size, NULL);
                /* outliner patch for 2.42 .b.blend */
                outliner_242_patch();
        }
index da340e35d7924a58c86ac7d8bcb94144e42fc7b1..7a5ec0e4d47e5b17996fb6bfe488778a0cd783b5 100644 (file)
@@ -108,5 +108,16 @@ void WM_keymap_set_item(ListBase *lb, char *idname, short type, short val, int m
        keymap_set(km, type, val, modifier, keymodifier);
 }
 
+/* always add item */
+void WM_keymap_add_item(ListBase *lb, char *idname, short type, short val, int modifier, short keymodifier)
+{
+       wmKeymapItem *km= MEM_callocN(sizeof(wmKeymapItem), "keymap entry");
+       
+       BLI_addtail(lb, km);
+       BLI_strncpy(km->idname, idname, OP_MAX_TYPENAME);
+
+       keymap_set(km, type, val, modifier, keymodifier);
+}
+
 
 
index 49989000c6fcc0ce5d11b3a438f900449aaef487..27f8b48451a27708441a0d69e36eed6f28120277 100644 (file)
@@ -87,7 +87,7 @@ static void WM_OT_window_duplicate(wmOperatorType *ot)
        ot->name= "Duplicate Window";
        ot->idname= "WM_OT_window_duplicate";
        
-       ot->interactive= NULL; //WM_operator_confirm;
+       ot->invoke= NULL; //WM_operator_confirm;
        ot->exec= wm_window_duplicate_op;
        ot->poll= WM_operator_winactive;
 }
@@ -97,7 +97,7 @@ static void WM_OT_save_homefile(wmOperatorType *ot)
        ot->name= "Save User Settings";
        ot->idname= "WM_OT_save_homefile";
        
-       ot->interactive= NULL; //WM_operator_confirm;
+       ot->invoke= NULL; //WM_operator_confirm;
        ot->exec= WM_write_homefile;
        ot->poll= WM_operator_winactive;
        
@@ -109,7 +109,7 @@ static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
     ot->name= "Toggle Fullscreen";
     ot->idname= "WM_OT_window_fullscreen_toggle";
 
-    ot->interactive= NULL;
+    ot->invoke= NULL;
     ot->exec= wm_window_fullscreen_toggle_op;
     ot->poll= WM_operator_winactive;
 }
index a802efffb96a3172fa3687c86448d425dd1b319f..21c456fd51c8d4ee26d5b0deb296ba64b0f2640d 100644 (file)
@@ -381,6 +381,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
                                win->eventstate->x= cx;
                                win->eventstate->y= (win->sizey-1) - cy;
                                
+                               ED_screen_set_subwinactive(win);        /* active subwindow in screen */
+                               
                                wm_window_make_drawable(C, win);
                                break;
                        }
@@ -392,7 +394,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
                                printf("ghost redraw\n");
                                
                                wm_window_make_drawable(C, win);
-                               WM_event_add_notifier(C->wm, win, 0, WM_NOTE_REDRAW, 0);
+                               WM_event_add_notifier(C->wm, win, 0, WM_NOTE_WINDOW_REDRAW, 0);
 
                                break;
                        }
@@ -432,14 +434,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
                                }
                                
                                wm_window_make_drawable(C, win);
-                               WM_event_add_notifier(C->wm, win, 0, WM_NOTE_REFRESH, 0);
-                               WM_event_add_notifier(C->wm, win, 0, WM_NOTE_REDRAW, 0);
+                               WM_event_add_notifier(C->wm, win, 0, WM_NOTE_SCREEN_CHANGED, 0);
                                
                                break;
                        }
                        default:
-                               if(type==GHOST_kEventKeyDown)
-                                       WM_event_add_notifier(C->wm, win, 0, WM_NOTE_REDRAW, 0);
+                               if(type==GHOST_kEventKeyDown) // XXX debug
+                                       WM_event_add_notifier(C->wm, win, 0, WM_NOTE_WINDOW_REDRAW, 0);
                                wm_event_add_ghostevent(win, type, data);
                                break;
                }