2008-01-07 18:03:41 +00:00
|
|
|
/**
|
|
|
|
* $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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2008-11-19 16:28:11 +00:00
|
|
|
#include "BLI_arithb.h"
|
2008-01-07 18:03:41 +00:00
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
2008-12-17 16:21:14 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2008-11-24 18:59:59 +00:00
|
|
|
#include "ED_markers.h"
|
2008-01-07 18:03:41 +00:00
|
|
|
#include "ED_screen.h"
|
2008-11-19 16:28:11 +00:00
|
|
|
#include "ED_screen_types.h"
|
2008-01-07 18:03:41 +00:00
|
|
|
|
2008-11-21 19:14:38 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
#include "screen_intern.h" /* own module include */
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
/* ************** Exported Poll tests ********************** */
|
2008-01-10 17:38:17 +00:00
|
|
|
|
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! :)
2008-11-17 18:54:03 +00:00
|
|
|
int ED_operator_areaactive(bContext *C)
|
|
|
|
{
|
|
|
|
if(C->window==NULL) return 0;
|
|
|
|
if(C->screen==NULL) return 0;
|
|
|
|
if(C->area==NULL) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
int ED_operator_screenactive(bContext *C)
|
|
|
|
{
|
|
|
|
if(C->window==NULL) return 0;
|
|
|
|
if(C->screen==NULL) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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! :)
2008-11-17 18:54:03 +00:00
|
|
|
/* when mouse is over area-edge */
|
2008-01-10 17:38:17 +00:00
|
|
|
int ED_operator_screen_mainwinactive(bContext *C)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2008-01-10 17:38:17 +00:00
|
|
|
if(C->window==NULL) return 0;
|
|
|
|
if(C->screen==NULL) return 0;
|
|
|
|
if (C->screen->subwinactive!=C->screen->mainwin) return 0;
|
|
|
|
return 1;
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
/* *************************** 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;
|
|
|
|
|
|
|
|
/* used by other operators too */
|
|
|
|
static ScrArea *screen_areahascursor(bScreen *scr, int x, int y)
|
|
|
|
{
|
|
|
|
ScrArea *sa= NULL;
|
|
|
|
sa= scr->areabase.first;
|
|
|
|
while(sa) {
|
|
|
|
if(BLI_in_rcti(&sa->totrct, x, y)) break;
|
|
|
|
sa= sa->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-15 16:54:47 +00:00
|
|
|
AZone *is_in_area_actionzone(ScrArea *sa, int x, int y)
|
2008-11-19 16:28:11 +00:00
|
|
|
{
|
|
|
|
AZone *az= NULL;
|
|
|
|
int i= 0;
|
|
|
|
|
|
|
|
for(az= sa->actionzones.first, i= 0; az; az= az->next, i++) {
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
if(az->type == AZONE_TRI) {
|
2008-11-19 16:28:11 +00:00
|
|
|
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 */
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
WM_event_add_modal_handler(C, &C->window->handlers, op);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESCKEY:
|
|
|
|
case LEFTMOUSE:
|
|
|
|
actionzone_exit(C, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* *********** 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 */
|
|
|
|
area_copy_data((ScrArea *)newsc->areabase.first, C->area, 0);
|
|
|
|
|
|
|
|
/* screen, areas init */
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_area_rip(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name= "Rip Area into New Window";
|
|
|
|
ot->idname= "ED_SCR_OT_area_rip";
|
|
|
|
|
2008-12-17 15:38:40 +00:00
|
|
|
ot->invoke= WM_operator_confirm;
|
2008-11-19 16:28:11 +00:00
|
|
|
ot->exec= screen_area_rip_op;
|
|
|
|
ot->poll= ED_operator_areaactive;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ************** move area edge operator *********************************** */
|
|
|
|
|
|
|
|
/* operator state vars used:
|
|
|
|
x, y mouse coord near edge
|
|
|
|
delta movement of edge
|
|
|
|
|
|
|
|
functions:
|
|
|
|
|
|
|
|
init() set default property values, find edge based on mouse coords, test
|
|
|
|
if the edge can be moved, select edges, calculate min and max movement
|
|
|
|
|
|
|
|
apply() apply delta on selection
|
|
|
|
|
|
|
|
exit() cleanup, send notifier
|
|
|
|
|
|
|
|
cancel() cancel moving
|
|
|
|
|
|
|
|
callbacks:
|
|
|
|
|
|
|
|
exec() execute without any user interaction, based on properties
|
|
|
|
call init(), apply(), exit()
|
|
|
|
|
|
|
|
invoke() gets called on mouse click near edge
|
|
|
|
call init(), add handler
|
|
|
|
|
|
|
|
modal() accept modal events while doing it
|
|
|
|
call apply() with delta motion
|
|
|
|
call exit() and remove handler
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct sAreaMoveData {
|
|
|
|
int bigger, smaller, origval;
|
|
|
|
char dir;
|
|
|
|
} sAreaMoveData;
|
|
|
|
|
|
|
|
/* helper call to move area-edge, sets limits */
|
|
|
|
static void area_move_set_limits(bScreen *sc, int dir, int *bigger, int *smaller)
|
|
|
|
{
|
|
|
|
ScrArea *sa;
|
|
|
|
|
|
|
|
/* we check all areas and test for free space with MINSIZE */
|
|
|
|
*bigger= *smaller= 100000;
|
|
|
|
|
|
|
|
for(sa= sc->areabase.first; sa; sa= sa->next) {
|
|
|
|
if(dir=='h') {
|
|
|
|
int y1= sa->v2->vec.y - sa->v1->vec.y-AREAMINY;
|
|
|
|
|
|
|
|
/* if top or down edge selected, test height */
|
|
|
|
if(sa->v1->flag && sa->v4->flag)
|
|
|
|
*bigger= MIN2(*bigger, y1);
|
|
|
|
else if(sa->v2->flag && sa->v3->flag)
|
|
|
|
*smaller= MIN2(*smaller, y1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int x1= sa->v4->vec.x - sa->v1->vec.x-AREAMINX;
|
|
|
|
|
|
|
|
/* if left or right edge selected, test width */
|
|
|
|
if(sa->v1->flag && sa->v2->flag)
|
|
|
|
*bigger= MIN2(*bigger, x1);
|
|
|
|
else if(sa->v3->flag && sa->v4->flag)
|
|
|
|
*smaller= MIN2(*smaller, x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validate selection inside screen, set variables OK */
|
|
|
|
/* return 0: init failed */
|
|
|
|
static int area_move_init (bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ScrEdge *actedge;
|
|
|
|
sAreaMoveData *md;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* required properties */
|
2008-11-24 15:51:55 +00:00
|
|
|
x= RNA_int_get(op->ptr, "x");
|
|
|
|
y= RNA_int_get(op->ptr, "y");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* setup */
|
|
|
|
actedge= screen_find_active_scredge(C->screen, x, y);
|
|
|
|
if(actedge==NULL) return 0;
|
|
|
|
|
|
|
|
md= MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData");
|
|
|
|
op->customdata= md;
|
|
|
|
|
|
|
|
md->dir= scredge_is_horizontal(actedge)?'h':'v';
|
|
|
|
if(md->dir=='h') md->origval= actedge->v1->vec.y;
|
|
|
|
else md->origval= actedge->v1->vec.x;
|
|
|
|
|
|
|
|
select_connected_scredge(C->screen, actedge);
|
|
|
|
/* now all vertices with 'flag==1' are the ones that can be moved. */
|
|
|
|
|
|
|
|
area_move_set_limits(C->screen, md->dir, &md->bigger, &md->smaller);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* moves selected screen edge amount of delta, used by split & move */
|
|
|
|
static void area_move_apply_do(bContext *C, int origval, int delta, int dir, int bigger, int smaller)
|
|
|
|
{
|
|
|
|
ScrVert *v1;
|
|
|
|
|
|
|
|
delta= CLAMPIS(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 + delta;
|
|
|
|
if(delta != bigger && 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 + 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-AREAMINY)
|
|
|
|
v1->vec.y= C->window->sizey-AREAMINY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void area_move_apply(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sAreaMoveData *md= op->customdata;
|
|
|
|
int delta;
|
|
|
|
|
2008-11-24 15:51:55 +00:00
|
|
|
delta= RNA_int_get(op->ptr, "delta");
|
2008-11-19 16:28:11 +00:00
|
|
|
area_move_apply_do(C, md->origval, delta, md->dir, md->bigger, md->smaller);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void area_move_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if(op->customdata)
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
op->customdata= NULL;
|
|
|
|
|
|
|
|
/* this makes sure aligned edges will result in aligned grabbing */
|
|
|
|
removedouble_scrverts(C->screen);
|
|
|
|
removedouble_scredges(C->screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int area_move_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if(!area_move_init(C, op))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
area_move_apply(C, op);
|
|
|
|
area_move_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interaction callback */
|
|
|
|
static int area_move_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_int_set(op->ptr, "x", event->x);
|
|
|
|
RNA_int_set(op->ptr, "y", event->y);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
if(!area_move_init(C, op))
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* add temp handler */
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
WM_event_add_modal_handler(C, &C->window->handlers, op);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int area_move_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_int_set(op->ptr, "delta", 0);
|
2008-11-19 16:28:11 +00:00
|
|
|
area_move_apply(C, op);
|
|
|
|
area_move_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* modal callback for while moving edges */
|
|
|
|
static int area_move_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
sAreaMoveData *md;
|
|
|
|
int delta, x, y;
|
|
|
|
|
|
|
|
md= op->customdata;
|
|
|
|
|
2008-11-24 15:51:55 +00:00
|
|
|
x= RNA_int_get(op->ptr, "x");
|
|
|
|
y= RNA_int_get(op->ptr, "y");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* execute the events */
|
|
|
|
switch(event->type) {
|
|
|
|
case MOUSEMOVE:
|
|
|
|
delta= (md->dir == 'v')? event->x - x: event->y - y;
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_int_set(op->ptr, "delta", delta);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
area_move_apply(C, op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
if(event->val==0) {
|
|
|
|
area_move_exit(C, op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESCKEY:
|
|
|
|
return area_move_cancel(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_area_move(wmOperatorType *ot)
|
|
|
|
{
|
2008-11-21 19:14:38 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Move area edges";
|
|
|
|
ot->idname= "ED_SCR_OT_area_move";
|
|
|
|
|
|
|
|
ot->exec= area_move_exec;
|
|
|
|
ot->invoke= area_move_invoke;
|
|
|
|
ot->cancel= area_move_cancel;
|
|
|
|
ot->modal= area_move_modal;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_screen_mainwinactive; /* when mouse is over area-edge */
|
2008-11-21 19:14:38 +00:00
|
|
|
|
|
|
|
/* rna */
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "x", PROP_INT, PROP_NONE);
|
|
|
|
prop= RNA_def_property(ot->srna, "y", PROP_INT, PROP_NONE);
|
|
|
|
prop= RNA_def_property(ot->srna, "delta", PROP_INT, PROP_NONE);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************** split area operator *********************************** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
operator state vars:
|
|
|
|
fac spit point
|
|
|
|
dir direction 'v' or 'h'
|
|
|
|
|
|
|
|
operator customdata:
|
|
|
|
area pointer to (active) area
|
|
|
|
x, y last used mouse pos
|
|
|
|
(more, see below)
|
|
|
|
|
|
|
|
functions:
|
|
|
|
|
|
|
|
init() set default property values, find area based on context
|
|
|
|
|
|
|
|
apply() split area based on state vars
|
|
|
|
|
|
|
|
exit() cleanup, send notifier
|
|
|
|
|
|
|
|
cancel() remove duplicated area
|
|
|
|
|
|
|
|
callbacks:
|
|
|
|
|
|
|
|
exec() execute without any user interaction, based on state vars
|
|
|
|
call init(), apply(), exit()
|
|
|
|
|
|
|
|
invoke() gets called on mouse click in action-widget
|
|
|
|
call init(), add modal handler
|
|
|
|
call apply() with initial motion
|
|
|
|
|
|
|
|
modal() accept modal events while doing it
|
|
|
|
call move-areas code with delta motion
|
|
|
|
call exit() or cancel() and remove handler
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SPLIT_STARTED 1
|
|
|
|
#define SPLIT_PROGRESS 2
|
|
|
|
|
|
|
|
typedef struct sAreaSplitData
|
|
|
|
{
|
|
|
|
int x, y; /* last used mouse position */
|
|
|
|
|
|
|
|
int origval; /* for move areas */
|
|
|
|
int bigger, smaller; /* constraints for moving new edge */
|
|
|
|
int delta; /* delta move edge */
|
2008-12-03 19:33:42 +00:00
|
|
|
int origmin, origsize; /* to calculate fac, for property storage */
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
ScrEdge *nedge; /* new edge */
|
|
|
|
ScrArea *sarea; /* start area */
|
|
|
|
ScrArea *narea; /* new area */
|
|
|
|
} sAreaSplitData;
|
|
|
|
|
|
|
|
/* generic init, no UI stuff here */
|
|
|
|
static int area_split_init(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sAreaSplitData *sd;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
/* required context */
|
|
|
|
if(C->area==NULL) return 0;
|
|
|
|
|
|
|
|
/* required properties */
|
2008-11-24 15:51:55 +00:00
|
|
|
dir= RNA_enum_get(op->ptr, "dir");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* minimal size */
|
|
|
|
if(dir=='v' && C->area->winx < 2*AREAMINX) return 0;
|
|
|
|
if(dir=='h' && C->area->winy < 2*AREAMINY) return 0;
|
|
|
|
|
|
|
|
/* custom data */
|
|
|
|
sd= (sAreaSplitData*)MEM_callocN(sizeof (sAreaSplitData), "op_area_split");
|
|
|
|
op->customdata= sd;
|
|
|
|
|
|
|
|
sd->sarea= C->area;
|
2008-12-03 19:33:42 +00:00
|
|
|
sd->origsize= dir=='v' ? C->area->winx:C->area->winy;
|
|
|
|
sd->origmin = dir=='v' ? C->area->totrct.xmin:C->area->totrct.ymin;
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* with sa as center, sb is located at: 0=W, 1=N, 2=E, 3=S */
|
|
|
|
/* used with split operator */
|
|
|
|
static ScrEdge *area_findsharededge(bScreen *screen, ScrArea *sa, ScrArea *sb)
|
|
|
|
{
|
|
|
|
ScrVert *sav1= sa->v1;
|
|
|
|
ScrVert *sav2= sa->v2;
|
|
|
|
ScrVert *sav3= sa->v3;
|
|
|
|
ScrVert *sav4= sa->v4;
|
|
|
|
ScrVert *sbv1= sb->v1;
|
|
|
|
ScrVert *sbv2= sb->v2;
|
|
|
|
ScrVert *sbv3= sb->v3;
|
|
|
|
ScrVert *sbv4= sb->v4;
|
|
|
|
|
|
|
|
if(sav1==sbv4 && sav2==sbv3) { /* sa to right of sb = W */
|
|
|
|
return screen_findedge(screen, sav1, sav2);
|
|
|
|
}
|
|
|
|
else if(sav2==sbv1 && sav3==sbv4) { /* sa to bottom of sb = N */
|
|
|
|
return screen_findedge(screen, sav2, sav3);
|
|
|
|
}
|
|
|
|
else if(sav3==sbv2 && sav4==sbv1) { /* sa to left of sb = E */
|
|
|
|
return screen_findedge(screen, sav3, sav4);
|
|
|
|
}
|
|
|
|
else if(sav1==sbv2 && sav4==sbv3) { /* sa on top of sb = S*/
|
|
|
|
return screen_findedge(screen, sav1, sav4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
/* do the split, return success */
|
|
|
|
static int area_split_apply(bContext *C, wmOperator *op)
|
2008-11-19 16:28:11 +00:00
|
|
|
{
|
|
|
|
sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
|
|
|
|
float fac;
|
|
|
|
int dir;
|
|
|
|
|
2008-11-24 15:51:55 +00:00
|
|
|
fac= RNA_float_get(op->ptr, "fac");
|
|
|
|
dir= RNA_enum_get(op->ptr, "dir");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
sd->narea= area_split(C->window, C->screen, sd->sarea, dir, fac);
|
|
|
|
|
|
|
|
if(sd->narea) {
|
|
|
|
ScrVert *sv;
|
|
|
|
|
|
|
|
sd->nedge= area_findsharededge(C->screen, sd->sarea, sd->narea);
|
|
|
|
|
|
|
|
/* select newly created edge, prepare for moving edge */
|
|
|
|
for(sv= C->screen->vertbase.first; sv; sv= sv->next)
|
|
|
|
sv->flag = 0;
|
|
|
|
|
|
|
|
sd->nedge->v1->flag= 1;
|
|
|
|
sd->nedge->v2->flag= 1;
|
|
|
|
|
|
|
|
if(dir=='h') sd->origval= sd->nedge->v1->vec.y;
|
|
|
|
else sd->origval= sd->nedge->v1->vec.x;
|
|
|
|
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
|
|
|
|
return 1;
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
return 0;
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void area_split_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if (op->customdata) {
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
op->customdata = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* this makes sure aligned edges will result in aligned grabbing */
|
|
|
|
removedouble_scrverts(C->screen);
|
|
|
|
removedouble_scredges(C->screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* UI callback, adds new handler */
|
|
|
|
static int area_split_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
sAreaSplitData *sd;
|
|
|
|
|
|
|
|
if(event->type==EVT_ACTIONZONE) {
|
|
|
|
sActionzoneData *sad= event->customdata;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
/* verify *sad itself */
|
|
|
|
if(sad==NULL || sad->sa1==NULL || sad->az==NULL)
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* is this our *sad? if areas not equal it should be passed on */
|
|
|
|
if(C->area!=sad->sa1 || sad->sa1!=sad->sa2)
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* prepare operator state vars */
|
|
|
|
if(sad->gesture_dir==AZONE_N || sad->gesture_dir==AZONE_S) {
|
|
|
|
dir= 'h';
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_float_set(op->ptr, "fac", ((float)(event->x - sad->sa1->v1->vec.x)) / (float)sad->sa1->winx);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dir= 'v';
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_float_set(op->ptr, "fac", ((float)(event->y - sad->sa1->v1->vec.y)) / (float)sad->sa1->winy);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_enum_set(op->ptr, "dir", dir);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* general init, also non-UI case, adds customdata, sets area and defaults */
|
|
|
|
if(!area_split_init(C, op))
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
sd= (sAreaSplitData *)op->customdata;
|
|
|
|
|
|
|
|
sd->x= event->x;
|
|
|
|
sd->y= event->y;
|
|
|
|
|
|
|
|
/* do the split */
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
if(area_split_apply(C, op)) {
|
|
|
|
area_move_set_limits(C->screen, dir, &sd->bigger, &sd->smaller);
|
|
|
|
|
|
|
|
/* add temp handler for edge move or cancel */
|
|
|
|
WM_event_add_modal_handler(C, &C->window->handlers, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
}
|
2008-11-24 10:45:36 +00:00
|
|
|
else {
|
|
|
|
/* nonmodal for now */
|
|
|
|
return op->type->exec(C, op);
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* function to be called outside UI context, or for redo */
|
|
|
|
static int area_split_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!area_split_init(C, op))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
area_split_apply(C, op);
|
|
|
|
area_split_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int area_split_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
|
|
|
|
|
2008-12-14 17:48:52 +00:00
|
|
|
if (screen_area_join(C, C->screen, sd->sarea, sd->narea)) {
|
2008-11-19 16:28:11 +00:00
|
|
|
if (C->area == sd->narea) {
|
|
|
|
C->area = NULL;
|
|
|
|
}
|
|
|
|
sd->narea = NULL;
|
|
|
|
}
|
|
|
|
area_split_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
|
2008-12-03 19:33:42 +00:00
|
|
|
float fac;
|
2008-11-19 16:28:11 +00:00
|
|
|
int dir;
|
|
|
|
|
|
|
|
/* execute the events */
|
|
|
|
switch(event->type) {
|
|
|
|
case MOUSEMOVE:
|
2008-11-24 15:51:55 +00:00
|
|
|
dir= RNA_enum_get(op->ptr, "dir");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
sd->delta= (dir == 'v')? event->x - sd->origval: event->y - sd->origval;
|
|
|
|
area_move_apply_do(C, sd->origval, sd->delta, dir, sd->bigger, sd->smaller);
|
|
|
|
|
2008-12-03 19:33:42 +00:00
|
|
|
fac= (dir == 'v') ? event->x-sd->origmin : event->y-sd->origmin;
|
|
|
|
RNA_float_set(op->ptr, "fac", fac / (float)sd->origsize);
|
|
|
|
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
if(event->val==0) { /* mouse up */
|
|
|
|
area_split_exit(C, op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RIGHTMOUSE: /* cancel operation */
|
|
|
|
case ESCKEY:
|
|
|
|
return area_split_cancel(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2008-12-09 15:59:43 +00:00
|
|
|
static EnumPropertyItem prop_direction_items[] = {
|
|
|
|
{'h', "HORIZONTAL", "Horizontal", ""},
|
|
|
|
{'v', "VERTICAL", "Vertical", ""},
|
|
|
|
{0, NULL, NULL, NULL}};
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
void ED_SCR_OT_area_split(wmOperatorType *ot)
|
|
|
|
{
|
2008-11-21 19:14:38 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
ot->name = "Split area";
|
|
|
|
ot->idname = "ED_SCR_OT_area_split";
|
|
|
|
|
|
|
|
ot->exec= area_split_exec;
|
|
|
|
ot->invoke= area_split_invoke;
|
|
|
|
ot->modal= area_split_modal;
|
|
|
|
|
2008-11-24 10:45:36 +00:00
|
|
|
ot->poll= ED_operator_areaactive;
|
2008-12-03 19:33:42 +00:00
|
|
|
ot->flag= OPTYPE_REGISTER;
|
|
|
|
|
2008-11-21 19:14:38 +00:00
|
|
|
/* rna */
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "dir", PROP_ENUM, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_enum_items(prop, prop_direction_items);
|
|
|
|
RNA_def_property_enum_default(prop, 'h');
|
|
|
|
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "fac", PROP_FLOAT, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_range(prop, 0.0, 1.0);
|
|
|
|
RNA_def_property_float_default(prop, 0.5f);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 16:21:14 +00:00
|
|
|
/* ************** frame change operator ***************************** */
|
|
|
|
|
|
|
|
|
|
|
|
/* function to be called outside UI context, or for redo */
|
|
|
|
static int frame_offset_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
delta = RNA_int_get(op->ptr, "delta");
|
|
|
|
|
|
|
|
C->scene->r.cfra += delta;
|
|
|
|
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
|
|
|
|
/* XXX: add WM_NOTE_TIME_CHANGED? */
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_frame_offset(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
ot->name = "Frame Offset";
|
|
|
|
ot->idname = "ED_SCR_OT_frame_offset";
|
|
|
|
|
|
|
|
ot->exec= frame_offset_exec;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_screenactive;
|
|
|
|
ot->flag= OPTYPE_REGISTER;
|
|
|
|
|
|
|
|
/* rna */
|
|
|
|
RNA_def_property(ot->srna, "delta", PROP_INT, PROP_NONE);
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
/* ************** join area operator ********************************************** */
|
|
|
|
|
|
|
|
/* operator state vars used:
|
|
|
|
x1, y1 mouse coord in first area, which will disappear
|
|
|
|
x2, y2 mouse coord in 2nd area, which will become joined
|
|
|
|
|
|
|
|
functions:
|
|
|
|
|
|
|
|
init() find edge based on state vars
|
|
|
|
test if the edge divides two areas,
|
|
|
|
store active and nonactive area,
|
|
|
|
|
|
|
|
apply() do the actual join
|
|
|
|
|
|
|
|
exit() cleanup, send notifier
|
|
|
|
|
|
|
|
callbacks:
|
|
|
|
|
|
|
|
exec() calls init, apply, exit
|
|
|
|
|
|
|
|
invoke() sets mouse coords in x,y
|
|
|
|
call init()
|
|
|
|
add modal handler
|
|
|
|
|
|
|
|
modal() accept modal events while doing it
|
|
|
|
call apply() with active window and nonactive window
|
|
|
|
call exit() and remove handler when LMB confirm
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct sAreaJoinData
|
|
|
|
{
|
|
|
|
ScrArea *sa1; /* first area to be considered */
|
|
|
|
ScrArea *sa2; /* second area to be considered */
|
|
|
|
ScrArea *scr; /* designed for removal */
|
|
|
|
|
|
|
|
} sAreaJoinData;
|
|
|
|
|
|
|
|
|
|
|
|
/* validate selection inside screen, set variables OK */
|
|
|
|
/* return 0: init failed */
|
|
|
|
/* XXX todo: find edge based on (x,y) and set other area? */
|
|
|
|
static int area_join_init(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
ScrArea *sa1, *sa2;
|
|
|
|
sAreaJoinData* jd= NULL;
|
|
|
|
int x1, y1;
|
|
|
|
int x2, y2;
|
|
|
|
|
|
|
|
/* required properties, make negative to get return 0 if not set by caller */
|
2008-11-24 15:51:55 +00:00
|
|
|
x1= RNA_int_get(op->ptr, "x1");
|
|
|
|
y1= RNA_int_get(op->ptr, "y1");
|
|
|
|
x2= RNA_int_get(op->ptr, "x2");
|
|
|
|
y2= RNA_int_get(op->ptr, "y2");
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
sa1 = screen_areahascursor(C->screen, x1, y1);
|
|
|
|
sa2 = screen_areahascursor(C->screen, x2, y2);
|
|
|
|
if(sa1==NULL || sa2==NULL || sa1==sa2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
jd = (sAreaJoinData*)MEM_callocN(sizeof (sAreaJoinData), "op_area_join");
|
|
|
|
|
|
|
|
jd->sa1 = sa1;
|
|
|
|
jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
|
|
|
|
jd->sa2 = sa2;
|
|
|
|
jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
|
|
|
|
|
|
|
|
op->customdata= jd;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply the join of the areas (space types) */
|
|
|
|
static int area_join_apply(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
|
|
|
|
if (!jd) return 0;
|
|
|
|
|
2008-12-14 17:48:52 +00:00
|
|
|
if(!screen_area_join(C, C->screen, jd->sa1, jd->sa2)){
|
2008-11-19 16:28:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (C->area == jd->sa2) {
|
|
|
|
C->area = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finish operation */
|
|
|
|
static void area_join_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if (op->customdata) {
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
op->customdata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this makes sure aligned edges will result in aligned grabbing */
|
|
|
|
removedouble_scredges(C->screen);
|
|
|
|
removenotused_scredges(C->screen);
|
|
|
|
removenotused_scrverts(C->screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int area_join_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if(!area_join_init(C, op))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
area_join_apply(C, op);
|
|
|
|
area_join_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* interaction callback */
|
|
|
|
static int area_join_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(event->type==EVT_ACTIONZONE) {
|
|
|
|
sActionzoneData *sad= event->customdata;
|
|
|
|
|
|
|
|
/* verify *sad itself */
|
|
|
|
if(sad==NULL || sad->sa1==NULL || sad->sa2==NULL)
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* is this our *sad? if areas equal it should be passed on */
|
|
|
|
if(sad->sa1==sad->sa2)
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* prepare operator state vars */
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_int_set(op->ptr, "x1", sad->x);
|
|
|
|
RNA_int_set(op->ptr, "y1", sad->y);
|
|
|
|
RNA_int_set(op->ptr, "x2", event->x);
|
|
|
|
RNA_int_set(op->ptr, "y2", event->y);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
if(!area_join_init(C, op))
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
|
|
/* add temp handler */
|
Lots of stuff; couldn't commit in parts because of refactor work.
* Changes in interface/ module
This commit brings back the way how buttons/menus work under control
of WM event system. The previous implementation extended usage of
handlers and operators in an interesting but confusing way. Better to
try it first according the design specs. :)
Most obviously:
- modal-handler operators are not stored anymore in regions/areas/windows.
such modal handlers own their operator, and should remove it themselves.
- removed code to move handlers from one queue to another.
(needs review with brecht!)
- WM fix: the API call to remove a modal handler got removed. This was a
dangerous thing anyway, and you should leave that to the event system.
Now, if a handler modal() call gets a cancel/finish return, it frees
itself in event system. WM_event_remove_modal_handler was a confusing
call anyway!
Todo:
- allow button-activate to refresh after using button
- re-enable arrow keys for menus
(do both after commit)
- review return values of operator callbacks in interface_ops.c
* Fixes in WM system
- Freeing areas/regions/windows, also on quit, now correctly closes
running modal handlers
- On starting a modal handler, the handler now stores previous area
and region context, so they send proper notifiers etc.
* Other fixes
- Area-split operator had bug, wrong minimal size checking. This
solves error when trying to split a very narrow area.
- removed DNA_USHORT_FIX from screen_types.h, gave warning
- operators didn't get ID name copied when activated, needed for
later re-use or saving.
2008-12-02 14:22:52 +00:00
|
|
|
WM_event_add_modal_handler(C, &C->window->handlers, op);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int area_join_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
|
|
|
|
|
|
|
|
if (jd->sa1) {
|
|
|
|
jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
|
|
|
|
jd->sa1->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
}
|
|
|
|
if (jd->sa2) {
|
|
|
|
jd->sa2->flag &= ~AREA_FLAG_DRAWJOINFROM;
|
|
|
|
jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
}
|
|
|
|
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
area_join_exit(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* modal callback while selecting area (space) that will be removed */
|
|
|
|
static int area_join_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
sAreaJoinData *jd = (sAreaJoinData *)op->customdata;
|
|
|
|
|
|
|
|
/* execute the events */
|
|
|
|
switch(event->type) {
|
|
|
|
|
|
|
|
case MOUSEMOVE:
|
|
|
|
{
|
|
|
|
ScrArea *sa = screen_areahascursor(C->screen, event->x, event->y);
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
if (sa) {
|
|
|
|
if (jd->sa1 != sa) {
|
|
|
|
dir = area_getorientation(C->screen, jd->sa1, sa);
|
|
|
|
if (dir >= 0) {
|
|
|
|
if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
jd->sa2 = sa;
|
|
|
|
jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we are not bordering on the previously selected area
|
|
|
|
we check if area has common border with the one marked for removal
|
|
|
|
in this case we can swap areas.
|
|
|
|
*/
|
|
|
|
dir = area_getorientation(C->screen, sa, jd->sa2);
|
|
|
|
if (dir >= 0) {
|
|
|
|
if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
|
|
|
|
if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
jd->sa1 = jd->sa2;
|
|
|
|
jd->sa2 = sa;
|
|
|
|
if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
|
|
|
|
if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
jd->sa2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we are back in the area previously selected for keeping
|
|
|
|
* we swap the areas if possible to allow user to choose */
|
|
|
|
if (jd->sa2 != NULL) {
|
|
|
|
if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM;
|
|
|
|
if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
jd->sa1 = jd->sa2;
|
|
|
|
jd->sa2 = sa;
|
|
|
|
if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM;
|
|
|
|
if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
|
|
|
|
dir = area_getorientation(C->screen, jd->sa1, jd->sa2);
|
|
|
|
if (dir < 0) {
|
|
|
|
printf("oops, didn't expect that!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dir = area_getorientation(C->screen, jd->sa1, sa);
|
|
|
|
if (dir >= 0) {
|
|
|
|
if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO;
|
|
|
|
jd->sa2 = sa;
|
|
|
|
jd->sa2->flag |= AREA_FLAG_DRAWJOINTO;
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LEFTMOUSE:
|
|
|
|
if(event->val==0) {
|
|
|
|
area_join_apply(C, op);
|
2008-12-03 13:44:16 +00:00
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
2008-11-19 16:28:11 +00:00
|
|
|
area_join_exit(C, op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESCKEY:
|
|
|
|
return area_join_cancel(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Operator for joining two areas (space types) */
|
|
|
|
void ED_SCR_OT_area_join(wmOperatorType *ot)
|
|
|
|
{
|
2008-11-21 19:14:38 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Join area";
|
|
|
|
ot->idname= "ED_SCR_OT_area_join";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= area_join_exec;
|
|
|
|
ot->invoke= area_join_invoke;
|
|
|
|
ot->modal= area_join_modal;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_screenactive;
|
2008-11-21 19:14:38 +00:00
|
|
|
|
|
|
|
/* rna */
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "x1", PROP_INT, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_int_default(prop, -100);
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "y1", PROP_INT, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_int_default(prop, -100);
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "x2", PROP_INT, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_int_default(prop, -100);
|
2008-11-24 15:51:55 +00:00
|
|
|
prop= RNA_def_property(ot->srna, "y2", PROP_INT, PROP_NONE);
|
2008-11-21 19:14:38 +00:00
|
|
|
RNA_def_property_int_default(prop, -100);
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-03 19:33:42 +00:00
|
|
|
/* ************** repeat last operator ***************************** */
|
|
|
|
|
|
|
|
static int repeat_last_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
wmOperator *lastop= C->wm->operators.last;
|
|
|
|
|
|
|
|
if(lastop) {
|
2008-12-04 09:37:42 +00:00
|
|
|
printf("repeat %s\n", lastop->type->idname);
|
2008-12-03 19:33:42 +00:00
|
|
|
lastop->type->exec(C, lastop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_repeat_last(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Repeat Last";
|
|
|
|
ot->idname= "ED_SCR_OT_repeat_last";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2008-12-17 15:38:40 +00:00
|
|
|
ot->invoke= WM_operator_confirm;
|
2008-12-03 19:33:42 +00:00
|
|
|
ot->exec= repeat_last_exec;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_screenactive;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-09 15:59:43 +00:00
|
|
|
/* ************** region split operator ***************************** */
|
|
|
|
|
|
|
|
/* insert a region in the area region list */
|
|
|
|
static int region_split_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2008-12-14 17:25:46 +00:00
|
|
|
ARegion *newar= BKE_area_region_copy(C->region);
|
2008-12-09 15:59:43 +00:00
|
|
|
int dir= RNA_enum_get(op->ptr, "dir");
|
|
|
|
|
|
|
|
BLI_insertlinkafter(&C->area->regionbase, C->region, newar);
|
|
|
|
|
|
|
|
newar->alignment= C->region->alignment;
|
|
|
|
|
|
|
|
if(dir=='h')
|
|
|
|
C->region->alignment= RGN_ALIGN_HSPLIT;
|
|
|
|
else
|
|
|
|
C->region->alignment= RGN_ALIGN_VSPLIT;
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_region_split(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Split Region";
|
|
|
|
ot->idname= "ED_SCR_OT_region_split";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2008-12-17 15:38:40 +00:00
|
|
|
ot->invoke= WM_operator_confirm;
|
2008-12-09 15:59:43 +00:00
|
|
|
ot->exec= region_split_exec;
|
|
|
|
ot->poll= ED_operator_areaactive;
|
|
|
|
|
|
|
|
prop= RNA_def_property(ot->srna, "dir", PROP_ENUM, PROP_NONE);
|
|
|
|
RNA_def_property_enum_items(prop, prop_direction_items);
|
|
|
|
RNA_def_property_enum_default(prop, 'h');
|
|
|
|
}
|
|
|
|
|
2008-12-15 11:59:42 +00:00
|
|
|
/* ************** region flip operator ***************************** */
|
|
|
|
|
|
|
|
/* flip a region alignment */
|
|
|
|
static int region_flip_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
if(C->region->alignment==RGN_ALIGN_TOP)
|
|
|
|
C->region->alignment= RGN_ALIGN_BOTTOM;
|
|
|
|
else if(C->region->alignment==RGN_ALIGN_BOTTOM)
|
|
|
|
C->region->alignment= RGN_ALIGN_TOP;
|
|
|
|
else if(C->region->alignment==RGN_ALIGN_LEFT)
|
|
|
|
C->region->alignment= RGN_ALIGN_RIGHT;
|
|
|
|
else if(C->region->alignment==RGN_ALIGN_RIGHT)
|
|
|
|
C->region->alignment= RGN_ALIGN_LEFT;
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_region_flip(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Flip Region";
|
|
|
|
ot->idname= "ED_SCR_OT_region_flip";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2008-12-17 15:38:40 +00:00
|
|
|
ot->invoke= WM_operator_confirm;
|
2008-12-15 11:59:42 +00:00
|
|
|
ot->exec= region_flip_exec;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_areaactive;
|
|
|
|
}
|
|
|
|
|
2008-12-09 15:59:43 +00:00
|
|
|
|
2.5: work on bringing back SpaceTime options
- RMB select, also with SHIFT
- RMB tweak for translate
- SHIFT+D dupli
- BKEY border select/deselect
- AKEY (de)select all
- XKEY delete
- GKEY grab
Added some XXX comments for future todos, especially for when other
spaces come back with time markers.
Also added ED_util for putting in all to-be-cleaned cruft
Context conflict: input methods for Markers can conflict with other
spacetypes. It was solved in pre-2.5 with manually tweaking it all over,
but I would prefer one keymap for all marker stuff. Needs some thinking...
could be solved with a boundbox check for bottom part of 2d window.
Tweak issue: both tweak styles are possible:
- Hold mouse button, move, operator ends on mouse release
- Hold mouse button, move, operator ends on mouse click
Problem is that modally handled operators use fixed keymaps... like ESC,
SPACE, ENTER, or press/release mousebutton for 'assign'. There's a lot
to say for making this all consistant, or become part of 1 general keymap?
Should also be possibe to define 'tweak' defaults for Tablet different
than for mouse...
2008-11-29 15:10:31 +00:00
|
|
|
/* ************** border select operator (template) ***************************** */
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* operator state vars used: (added by default WM callbacks)
|
|
|
|
xmin, ymin
|
|
|
|
xmax, ymax
|
|
|
|
|
|
|
|
customdata: the wmGesture pointer
|
|
|
|
|
|
|
|
callbacks:
|
|
|
|
|
|
|
|
exec() has to be filled in by user
|
|
|
|
|
|
|
|
invoke() default WM function
|
|
|
|
adds modal handler
|
|
|
|
|
|
|
|
modal() default WM function
|
|
|
|
accept modal events while doing it, calls exec(), handles ESC and border drawing
|
|
|
|
|
|
|
|
poll() has to be filled in by user for context
|
|
|
|
*/
|
2.5: work on bringing back SpaceTime options
- RMB select, also with SHIFT
- RMB tweak for translate
- SHIFT+D dupli
- BKEY border select/deselect
- AKEY (de)select all
- XKEY delete
- GKEY grab
Added some XXX comments for future todos, especially for when other
spaces come back with time markers.
Also added ED_util for putting in all to-be-cleaned cruft
Context conflict: input methods for Markers can conflict with other
spacetypes. It was solved in pre-2.5 with manually tweaking it all over,
but I would prefer one keymap for all marker stuff. Needs some thinking...
could be solved with a boundbox check for bottom part of 2d window.
Tweak issue: both tweak styles are possible:
- Hold mouse button, move, operator ends on mouse release
- Hold mouse button, move, operator ends on mouse click
Problem is that modally handled operators use fixed keymaps... like ESC,
SPACE, ENTER, or press/release mousebutton for 'assign'. There's a lot
to say for making this all consistant, or become part of 1 general keymap?
Should also be possibe to define 'tweak' defaults for Tablet different
than for mouse...
2008-11-29 15:10:31 +00:00
|
|
|
#if 0
|
2008-11-19 16:28:11 +00:00
|
|
|
static int border_select_do(bContext *C, wmOperator *op)
|
|
|
|
{
|
2008-11-24 15:51:55 +00:00
|
|
|
int event_type= RNA_int_get(op->ptr, "event_type");
|
2008-11-24 10:45:36 +00:00
|
|
|
|
|
|
|
if(event_type==LEFTMOUSE)
|
|
|
|
printf("border select do select\n");
|
|
|
|
else if(event_type==RIGHTMOUSE)
|
|
|
|
printf("border select deselect\n");
|
|
|
|
else
|
|
|
|
printf("border select do something\n");
|
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ED_SCR_OT_border_select(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name= "Border select";
|
|
|
|
ot->idname= "ED_SCR_OT_border_select";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec= border_select_do;
|
|
|
|
ot->invoke= WM_border_select_invoke;
|
|
|
|
ot->modal= WM_border_select_modal;
|
|
|
|
|
|
|
|
ot->poll= ED_operator_areaactive;
|
2008-11-24 10:45:36 +00:00
|
|
|
|
|
|
|
/* rna */
|
2008-11-24 15:51:55 +00:00
|
|
|
RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
|
2.5: work on bringing back SpaceTime options
- RMB select, also with SHIFT
- RMB tweak for translate
- SHIFT+D dupli
- BKEY border select/deselect
- AKEY (de)select all
- XKEY delete
- GKEY grab
Added some XXX comments for future todos, especially for when other
spaces come back with time markers.
Also added ED_util for putting in all to-be-cleaned cruft
Context conflict: input methods for Markers can conflict with other
spacetypes. It was solved in pre-2.5 with manually tweaking it all over,
but I would prefer one keymap for all marker stuff. Needs some thinking...
could be solved with a boundbox check for bottom part of 2d window.
Tweak issue: both tweak styles are possible:
- Hold mouse button, move, operator ends on mouse release
- Hold mouse button, move, operator ends on mouse click
Problem is that modally handled operators use fixed keymaps... like ESC,
SPACE, ENTER, or press/release mousebutton for 'assign'. There's a lot
to say for making this all consistant, or become part of 1 general keymap?
Should also be possibe to define 'tweak' defaults for Tablet different
than for mouse...
2008-11-29 15:10:31 +00:00
|
|
|
RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
|
|
|
|
RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
|
|
|
|
RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
|
|
|
|
RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
|
2008-11-24 10:45:36 +00:00
|
|
|
|
2008-11-19 16:28:11 +00:00
|
|
|
}
|
2.5: work on bringing back SpaceTime options
- RMB select, also with SHIFT
- RMB tweak for translate
- SHIFT+D dupli
- BKEY border select/deselect
- AKEY (de)select all
- XKEY delete
- GKEY grab
Added some XXX comments for future todos, especially for when other
spaces come back with time markers.
Also added ED_util for putting in all to-be-cleaned cruft
Context conflict: input methods for Markers can conflict with other
spacetypes. It was solved in pre-2.5 with manually tweaking it all over,
but I would prefer one keymap for all marker stuff. Needs some thinking...
could be solved with a boundbox check for bottom part of 2d window.
Tweak issue: both tweak styles are possible:
- Hold mouse button, move, operator ends on mouse release
- Hold mouse button, move, operator ends on mouse click
Problem is that modally handled operators use fixed keymaps... like ESC,
SPACE, ENTER, or press/release mousebutton for 'assign'. There's a lot
to say for making this all consistant, or become part of 1 general keymap?
Should also be possibe to define 'tweak' defaults for Tablet different
than for mouse...
2008-11-29 15:10:31 +00:00
|
|
|
#endif
|
2008-11-19 16:28:11 +00:00
|
|
|
|
|
|
|
/* **************** Assigning operatortypes to global list, adding handlers **************** */
|
|
|
|
|
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.
2008-06-11 10:10:31 +00:00
|
|
|
/* called in spacetypes.c */
|
2008-01-07 18:03:41 +00:00
|
|
|
void ED_operatortypes_screen(void)
|
|
|
|
{
|
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! :)
2008-11-17 18:54:03 +00:00
|
|
|
/* generic UI stuff */
|
|
|
|
WM_operatortype_append(ED_SCR_OT_actionzone);
|
2008-12-03 19:33:42 +00:00
|
|
|
WM_operatortype_append(ED_SCR_OT_repeat_last);
|
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! :)
2008-11-17 18:54:03 +00:00
|
|
|
|
2008-11-24 18:59:59 +00:00
|
|
|
/* screen tools */
|
2008-11-19 16:28:11 +00:00
|
|
|
WM_operatortype_append(ED_SCR_OT_area_move);
|
|
|
|
WM_operatortype_append(ED_SCR_OT_area_split);
|
|
|
|
WM_operatortype_append(ED_SCR_OT_area_join);
|
2008-11-18 13:51:02 +00:00
|
|
|
WM_operatortype_append(ED_SCR_OT_area_rip);
|
2008-12-09 15:59:43 +00:00
|
|
|
WM_operatortype_append(ED_SCR_OT_region_split);
|
2008-12-15 11:59:42 +00:00
|
|
|
WM_operatortype_append(ED_SCR_OT_region_flip);
|
2008-12-09 15:59:43 +00:00
|
|
|
|
2008-12-17 16:21:14 +00:00
|
|
|
/*frame changes*/
|
|
|
|
WM_operatortype_append(ED_SCR_OT_frame_offset);
|
|
|
|
|
2008-11-24 18:59:59 +00:00
|
|
|
/* tools shared by more space types */
|
2.5: work on bringing back SpaceTime options
- RMB select, also with SHIFT
- RMB tweak for translate
- SHIFT+D dupli
- BKEY border select/deselect
- AKEY (de)select all
- XKEY delete
- GKEY grab
Added some XXX comments for future todos, especially for when other
spaces come back with time markers.
Also added ED_util for putting in all to-be-cleaned cruft
Context conflict: input methods for Markers can conflict with other
spacetypes. It was solved in pre-2.5 with manually tweaking it all over,
but I would prefer one keymap for all marker stuff. Needs some thinking...
could be solved with a boundbox check for bottom part of 2d window.
Tweak issue: both tweak styles are possible:
- Hold mouse button, move, operator ends on mouse release
- Hold mouse button, move, operator ends on mouse click
Problem is that modally handled operators use fixed keymaps... like ESC,
SPACE, ENTER, or press/release mousebutton for 'assign'. There's a lot
to say for making this all consistant, or become part of 1 general keymap?
Should also be possibe to define 'tweak' defaults for Tablet different
than for mouse...
2008-11-29 15:10:31 +00:00
|
|
|
ED_marker_operatortypes();
|
2008-11-24 18:59:59 +00:00
|
|
|
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
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.
2008-06-11 10:10:31 +00:00
|
|
|
/* called in spacetypes.c */
|
|
|
|
void ED_keymap_screen(wmWindowManager *wm)
|
2008-01-07 18:03:41 +00:00
|
|
|
{
|
2008-12-08 15:02:57 +00:00
|
|
|
ListBase *keymap= WM_keymap_listbase(wm, "Screen", 0, 0);
|
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! :)
2008-11-17 18:54:03 +00:00
|
|
|
|
2008-12-08 15:02:57 +00:00
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_actionzone", LEFTMOUSE, KM_PRESS, 0, 0);
|
|
|
|
|
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_area_move", LEFTMOUSE, KM_PRESS, 0, 0);
|
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_area_split", EVT_ACTIONZONE, 0, 0, 0); /* action tria */
|
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_area_join", EVT_ACTIONZONE, 0, 0, 0); /* action tria */
|
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0);
|
2.5: gesture code in WM
- Simplified and cleaned previous border code
It was a bit too complex, too many data manipulations
Original idea was to have WM API calls to manage border, circle, lines,
lasso, etc. This now means that WM provides callbacks for custom operators,
so it's very easy to make them. Check bottom of screen_edit.c for an
example.
Currently two borders were coded; with and without cross hair.
Press Bkey in any area-region to test it (note: time window has wrong matrix!)
Some specs to note:
- gestures are in region space, and draw 'over'. That latter still needs some
work when we do real composites.
- only the active region is redrawn.
- on todo is the generic gesture engine for 'tweak' or like how currently grab
gestures in Blender work. These will be configurable per area-region, and WM
then will send the proper "Gesture Event" with properties (N, S, E, W, etc)
to which you then can assign operators. Such events will be generated with low
priority, so other handlers who swallowed mouse events have preference.
2008-11-19 13:16:05 +00:00
|
|
|
|
2008-12-09 15:59:43 +00:00
|
|
|
/* tests */
|
2008-12-15 16:54:47 +00:00
|
|
|
RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, 0, 0)->ptr, "dir", 'h');
|
|
|
|
RNA_enum_set(WM_keymap_add_item(keymap, "ED_SCR_OT_region_split", SKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "dir", 'v');
|
2008-12-17 16:21:14 +00:00
|
|
|
/*frame offsets*/
|
|
|
|
RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", UPARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 10);
|
|
|
|
RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -10);
|
|
|
|
RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", -1);
|
|
|
|
RNA_int_set(WM_keymap_add_item(keymap, "ED_SCR_OT_frame_offset", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
|
|
|
|
|
2008-12-15 11:59:42 +00:00
|
|
|
WM_keymap_add_item(keymap, "ED_SCR_OT_region_flip", F5KEY, KM_PRESS, 0, 0);
|
2008-12-08 15:02:57 +00:00
|
|
|
WM_keymap_verify_item(keymap, "ED_SCR_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
|
2008-12-17 15:38:40 +00:00
|
|
|
|
|
|
|
/* screen level global keymaps */
|
|
|
|
ED_marker_keymap(wm);
|
2008-01-07 18:03:41 +00:00
|
|
|
}
|
|
|
|
|