Fun commit for test: the Repeat Last option.
Only the split-area Operator is now added on stack, so that's the only 
one that works. Just split an area, and press F4 to repeat it anywhere.
This commit is contained in:
2008-12-03 19:33:42 +00:00
parent 757fe56314
commit a9374c5941
6 changed files with 52 additions and 22 deletions

View File

@@ -43,7 +43,7 @@ void ED_region_do_listen(ARegion *ar, struct wmNotifier *note);
void ED_region_do_draw(struct bContext *C, ARegion *ar);
void ED_region_do_refresh(struct bContext *C, ARegion *ar);
void ED_region_exit(struct bContext *C, ARegion *ar);
void ED_region_pixelspace(struct bContext *C, ARegion *ar);
void ED_region_pixelspace(const struct bContext *C, ARegion *ar);
/* spaces */
void ED_spacetypes_init(void);

View File

@@ -90,7 +90,7 @@ static void region_draw_emboss(ARegion *ar)
glDisable( GL_BLEND );
}
void ED_region_pixelspace(bContext *C, ARegion *ar)
void ED_region_pixelspace(const bContext *C, ARegion *ar)
{
int width= ar->winrct.xmax-ar->winrct.xmin+1;
int height= ar->winrct.ymax-ar->winrct.ymin+1;

View File

@@ -678,7 +678,8 @@ typedef struct sAreaSplitData
int origval; /* for move areas */
int bigger, smaller; /* constraints for moving new edge */
int delta; /* delta move edge */
int origmin, origsize; /* to calculate fac, for property storage */
ScrEdge *nedge; /* new edge */
ScrArea *sarea; /* start area */
ScrArea *narea; /* new area */
@@ -705,6 +706,8 @@ static int area_split_init(bContext *C, wmOperator *op)
op->customdata= sd;
sd->sarea= C->area;
sd->origsize= dir=='v' ? C->area->winx:C->area->winy;
sd->origmin = dir=='v' ? C->area->totrct.xmin:C->area->totrct.ymin;
return 1;
}
@@ -877,6 +880,7 @@ static int area_split_cancel(bContext *C, wmOperator *op)
static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
{
sAreaSplitData *sd= (sAreaSplitData *)op->customdata;
float fac;
int dir;
/* execute the events */
@@ -887,6 +891,9 @@ static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event)
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);
fac= (dir == 'v') ? event->x-sd->origmin : event->y-sd->origmin;
RNA_float_set(op->ptr, "fac", fac / (float)sd->origsize);
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
break;
@@ -920,7 +927,8 @@ void ED_SCR_OT_area_split(wmOperatorType *ot)
ot->modal= area_split_modal;
ot->poll= ED_operator_areaactive;
ot->flag= OPTYPE_REGISTER;
/* rna */
prop= RNA_def_property(ot->srna, "dir", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, prop_direction_items);
@@ -1210,6 +1218,33 @@ void ED_SCR_OT_area_join(wmOperatorType *ot)
RNA_def_property_int_default(prop, -100);
}
/* ************** repeat last operator ***************************** */
static int repeat_last_exec(bContext *C, wmOperator *op)
{
wmOperator *lastop= C->wm->operators.last;
if(lastop) {
printf("repeat %s\n", op->type->idname);
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 */
ot->exec= repeat_last_exec;
ot->poll= ED_operator_screenactive;
}
/* ************** border select operator (template) ***************************** */
/* operator state vars used: (added by default WM callbacks)
@@ -1276,6 +1311,7 @@ void ED_operatortypes_screen(void)
/* generic UI stuff */
WM_operatortype_append(ED_SCR_OT_cursor_type);
WM_operatortype_append(ED_SCR_OT_actionzone);
WM_operatortype_append(ED_SCR_OT_repeat_last);
/* screen tools */
WM_operatortype_append(ED_SCR_OT_area_move);
@@ -1302,5 +1338,6 @@ void ED_keymap_screen(wmWindowManager *wm)
WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_area_join", EVT_ACTIONZONE, 0, 0, 0); /* action tria */
WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_area_rip", RKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(&wm->screenkeymap, "ED_SCR_OT_repeat_last", F4KEY, KM_PRESS, 0, 0);
}

View File

@@ -85,7 +85,7 @@ static void change_frame_apply(bContext *C, wmOperator *op)
if(cfra!=CFRA)
CFRA= cfra;
WM_event_add_notifier(C, WM_NOTE_SCREEN_CHANGED, 0, NULL);
WM_event_add_notifier(C, WM_NOTE_WINDOW_REDRAW, 0, NULL);
/* XXX: add WM_NOTE_TIME_CHANGED? */
}

View File

@@ -75,8 +75,8 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
int tot;
if(op->ptr) {
MEM_freeN(op->ptr);
op->ptr= NULL;
// MEM_freeN(op->ptr);
// op->ptr= NULL;
}
BLI_addtail(&wm->operators, op);

View File

@@ -602,21 +602,14 @@ void WM_event_set_handler_flag(wmEventHandler *handler, int flag)
wmEventHandler *WM_event_add_modal_handler(bContext *C, ListBase *handlers, wmOperator *op)
{
/* debug test; operator not in registry */
if(op->type->flag & OPTYPE_REGISTER) {
printf("error: handler (%s) cannot be modal, was registered\n", op->type->idname);
}
else {
wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
handler->op= op;
handler->op_area= C->area; /* means frozen screen context for modal handlers! */
handler->op_region= C->region;
BLI_addhead(handlers, handler);
return handler;
}
return NULL;
wmEventHandler *handler= MEM_callocN(sizeof(wmEventHandler), "event handler");
handler->op= op;
handler->op_area= C->area; /* means frozen screen context for modal handlers! */
handler->op_region= C->region;
BLI_addhead(handlers, handler);
return handler;
}
wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, ListBase *keymap)