Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/screen/screen_ops.c
| Context not available. | |||||
| const int m_loc = origval + delta; | const int m_loc = origval + delta; | ||||
| const int axis = (dir == 'v') ? 0 : 1; | const int axis = (dir == 'v') ? 0 : 1; | ||||
| int snap_dist = INT_MAX; | int snap_dist; | ||||
| int dist; | int dist; | ||||
| { | { | ||||
| /* Test the snap to middle. */ | /* Test the snap to middle. */ | ||||
| int middle = origval + (bigger - smaller) / 2; | int middle = origval + (bigger - smaller) / 2; | ||||
| middle -= (middle % AREAGRID); | middle -= (middle % AREAGRID); | ||||
| dist = abs(m_loc - middle); | snap_dist = abs(m_loc - middle); | ||||
| if (dist <= snap_dist) { | final_loc = middle; | ||||
| snap_dist = dist; | |||||
| final_loc = middle; | |||||
| } | |||||
| } | } | ||||
| for (const ScrVert *v1 = sc->vertbase.first; v1; v1 = v1->next) { | for (const ScrVert *v1 = sc->vertbase.first; v1; v1 = v1->next) { | ||||
| Context not available. | |||||
| int delta; /* delta move edge */ | int delta; /* delta move edge */ | ||||
| int origmin, origsize; /* to calculate fac, for property storage */ | int origmin, origsize; /* to calculate fac, for property storage */ | ||||
| int previewmode; /* draw previewline, then split */ | int previewmode; /* draw previewline, then split */ | ||||
| void *draw_callback; /* call `ED_screen_draw_split_preview` */ | |||||
| bool do_snap; | bool do_snap; | ||||
| ScrEdge *nedge; /* new edge */ | ScrEdge *nedge; /* new edge */ | ||||
| Context not available. | |||||
| } sAreaSplitData; | } sAreaSplitData; | ||||
| static void area_split_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | |||||
| { | |||||
| const wmOperator *op = userdata; | |||||
| sAreaSplitData *sd = op->customdata; | |||||
| if (sd->sarea) { | |||||
| int dir = RNA_enum_get(op->ptr, "direction"); | |||||
| float fac = RNA_float_get(op->ptr, "factor"); | |||||
| ED_screen_draw_split_preview(sd->sarea, dir, fac); | |||||
| } | |||||
| } | |||||
| /* generic init, menu case, doesn't need active area */ | /* generic init, menu case, doesn't need active area */ | ||||
| static int area_split_menu_init(bContext *C, wmOperator *op) | static int area_split_menu_init(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Context not available. | |||||
| op->customdata = sd; | op->customdata = sd; | ||||
| sd->sarea = CTX_wm_area(C); | sd->sarea = CTX_wm_area(C); | ||||
| if (sd->sarea) { | |||||
| int dir = RNA_enum_get(op->ptr, "direction"); | |||||
| if (dir == 'h') | |||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_H; | |||||
| else | |||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_V; | |||||
| } | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| Context not available. | |||||
| if (sd->sarea) ED_area_tag_redraw(sd->sarea); | if (sd->sarea) ED_area_tag_redraw(sd->sarea); | ||||
| if (sd->narea) ED_area_tag_redraw(sd->narea); | if (sd->narea) ED_area_tag_redraw(sd->narea); | ||||
| if (sd->sarea) | if (sd->draw_callback) | ||||
| sd->sarea->flag &= ~(AREA_FLAG_DRAWSPLIT_H | AREA_FLAG_DRAWSPLIT_V); | WM_draw_cb_exit(CTX_wm_window(C), sd->draw_callback); | ||||
| MEM_freeN(op->customdata); | MEM_freeN(op->customdata); | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| else { | else { | ||||
| sd->previewmode = 1; | sd->previewmode = 1; | ||||
| sd->draw_callback = WM_draw_cb_activate(win, area_split_draw_cb, op); | |||||
| /* add temp handler for edge move or cancel */ | /* add temp handler for edge move or cancel */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| Context not available. | |||||
| if (sd->previewmode == 0) | if (sd->previewmode == 0) | ||||
| area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, sd->do_snap); | area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, sd->do_snap); | ||||
| else { | else { | ||||
| /* TODO: Snap in preview mode too. */ | |||||
| if (sd->sarea) { | if (sd->sarea) { | ||||
| sd->sarea->flag &= ~(AREA_FLAG_DRAWSPLIT_H | AREA_FLAG_DRAWSPLIT_V); | |||||
| ED_area_tag_redraw(sd->sarea); | ED_area_tag_redraw(sd->sarea); | ||||
| } | } | ||||
| /* area context not set */ | /* area context not set */ | ||||
| Context not available. | |||||
| if (dir == 'v') { | if (dir == 'v') { | ||||
| sd->origsize = sd->sarea->winx; | sd->origsize = sd->sarea->winx; | ||||
| sd->origmin = sd->sarea->totrct.xmin; | sd->origmin = sd->sarea->totrct.xmin; | ||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_V; | |||||
| } | } | ||||
| else { | else { | ||||
| sd->origsize = sd->sarea->winy; | sd->origsize = sd->sarea->winy; | ||||
| sd->origmin = sd->sarea->totrct.ymin; | sd->origmin = sd->sarea->totrct.ymin; | ||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_H; | |||||
| } | } | ||||
| if (sd->do_snap) { | |||||
| ScrArea *sa = sd->sarea; | |||||
| sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 1; | |||||
| int snap_loc = area_snap_calc_location( | |||||
| CTX_wm_screen(C), sd->delta, sd->origval, dir, sd->origmin + sd->origsize, -sd->origmin); | |||||
| sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 0; | |||||
| fac = snap_loc - sd->origmin; | |||||
| } | |||||
| else { | |||||
| fac = (dir == 'v') ? event->x - sd->origmin : event->y - sd->origmin; | |||||
| } | |||||
| RNA_float_set(op->ptr, "factor", fac / (float)sd->origsize); | |||||
| } | } | ||||
| CTX_wm_screen(C)->do_draw = true; | CTX_wm_screen(C)->do_draw = true; | ||||
| } | } | ||||
| fac = (dir == 'v') ? event->x - sd->origmin : event->y - sd->origmin; | |||||
| RNA_float_set(op->ptr, "factor", fac / (float)sd->origsize); | |||||
| break; | break; | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| Context not available. | |||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (sd->sarea) { | if (sd->sarea) { | ||||
| sd->sarea->flag &= ~(AREA_FLAG_DRAWSPLIT_H | AREA_FLAG_DRAWSPLIT_V); | |||||
| ED_area_tag_redraw(sd->sarea); | ED_area_tag_redraw(sd->sarea); | ||||
| if (dir == 'v') { | if (dir == 'v') { | ||||
| RNA_enum_set(op->ptr, "direction", 'h'); | RNA_enum_set(op->ptr, "direction", 'h'); | ||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_H; | |||||
| WM_cursor_set(CTX_wm_window(C), CURSOR_X_MOVE); | WM_cursor_set(CTX_wm_window(C), CURSOR_X_MOVE); | ||||
| } | } | ||||
| else { | else { | ||||
| RNA_enum_set(op->ptr, "direction", 'v'); | RNA_enum_set(op->ptr, "direction", 'v'); | ||||
| sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_V; | |||||
| WM_cursor_set(CTX_wm_window(C), CURSOR_Y_MOVE); | WM_cursor_set(CTX_wm_window(C), CURSOR_Y_MOVE); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| */ | */ | ||||
| typedef struct sAreaJoinData { | typedef struct sAreaJoinData { | ||||
| ScrArea *sa1; /* first area to be considered */ | ScrArea *sa1; /* first area to be considered */ | ||||
| ScrArea *sa2; /* second area to be considered */ | ScrArea *sa2; /* second area to be considered */ | ||||
| ScrArea *scr; /* designed for removal */ | void *draw_callback; /* call `ED_screen_draw_join_shape` */ | ||||
| } sAreaJoinData; | } sAreaJoinData; | ||||
| static void area_join_draw_cb(const struct wmWindow *UNUSED(win), void *userdata) | |||||
| { | |||||
| const wmOperator *op = userdata; | |||||
| sAreaJoinData *sd = op->customdata; | |||||
| if (sd->sa1 && sd->sa2) { | |||||
| ED_screen_draw_join_shape(sd->sa1, sd->sa2); | |||||
| } | |||||
| } | |||||
| /* validate selection inside screen, set variables OK */ | /* validate selection inside screen, set variables OK */ | ||||
| /* return 0: init failed */ | /* return 0: init failed */ | ||||
| /* XXX todo: find edge based on (x,y) and set other area? */ | /* XXX todo: find edge based on (x,y) and set other area? */ | ||||
| Context not available. | |||||
| } | } | ||||
| jd = (sAreaJoinData *)MEM_callocN(sizeof(sAreaJoinData), "op_area_join"); | jd = (sAreaJoinData *)MEM_callocN(sizeof(sAreaJoinData), "op_area_join"); | ||||
| jd->sa1 = sa1; | jd->sa1 = sa1; | ||||
| jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM; | |||||
| jd->sa2 = sa2; | jd->sa2 = sa2; | ||||
| jd->sa2->flag |= AREA_FLAG_DRAWJOINTO; | |||||
| op->customdata = jd; | op->customdata = jd; | ||||
| jd->draw_callback = WM_draw_cb_activate(CTX_wm_window(C), area_join_draw_cb, op); | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| Context not available. | |||||
| /* finish operation */ | /* finish operation */ | ||||
| static void area_join_exit(bContext *C, wmOperator *op) | static void area_join_exit(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| if (op->customdata) { | sAreaJoinData *jd = (sAreaJoinData *)op->customdata; | ||||
| MEM_freeN(op->customdata); | |||||
| if (jd) { | |||||
| if (jd->draw_callback) | |||||
| WM_draw_cb_exit(CTX_wm_window(C), jd->draw_callback); | |||||
| MEM_freeN(jd); | |||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| } | } | ||||
| Context not available. | |||||
| static void area_join_cancel(bContext *C, wmOperator *op) | static void 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; | |||||
| } | |||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | WM_event_add_notifier(C, NC_WINDOW, NULL); | ||||
| area_join_exit(C, op); | area_join_exit(C, op); | ||||
| Context not available. | |||||
| if (jd->sa1 != sa) { | if (jd->sa1 != sa) { | ||||
| dir = area_getorientation(jd->sa1, sa); | dir = area_getorientation(jd->sa1, sa); | ||||
| if (dir != -1) { | if (dir != -1) { | ||||
| if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO; | |||||
| jd->sa2 = sa; | jd->sa2 = sa; | ||||
| jd->sa2->flag |= AREA_FLAG_DRAWJOINTO; | |||||
| } | } | ||||
| else { | else { | ||||
| /* we are not bordering on the previously selected area | /* we are not bordering on the previously selected area | ||||
| Context not available. | |||||
| */ | */ | ||||
| dir = area_getorientation(sa, jd->sa2); | dir = area_getorientation(sa, jd->sa2); | ||||
| if (dir != -1) { | if (dir != -1) { | ||||
| if (jd->sa1) jd->sa1->flag &= ~AREA_FLAG_DRAWJOINFROM; | |||||
| if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO; | |||||
| jd->sa1 = jd->sa2; | jd->sa1 = jd->sa2; | ||||
| jd->sa2 = sa; | jd->sa2 = sa; | ||||
| if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM; | |||||
| if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO; | |||||
| } | } | ||||
| else { | else { | ||||
| if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO; | |||||
| jd->sa2 = NULL; | jd->sa2 = NULL; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| /* we are back in the area previously selected for keeping | /* we are back in the area previously selected for keeping | ||||
| * we swap the areas if possible to allow user to choose */ | * we swap the areas if possible to allow user to choose */ | ||||
| if (jd->sa2 != NULL) { | 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->sa1 = jd->sa2; | ||||
| jd->sa2 = sa; | jd->sa2 = sa; | ||||
| if (jd->sa1) jd->sa1->flag |= AREA_FLAG_DRAWJOINFROM; | |||||
| if (jd->sa2) jd->sa2->flag |= AREA_FLAG_DRAWJOINTO; | |||||
| dir = area_getorientation(jd->sa1, jd->sa2); | dir = area_getorientation(jd->sa1, jd->sa2); | ||||
| if (dir == -1) { | if (dir == -1) { | ||||
| printf("oops, didn't expect that!\n"); | printf("oops, didn't expect that!\n"); | ||||
| Context not available. | |||||
| else { | else { | ||||
| dir = area_getorientation(jd->sa1, sa); | dir = area_getorientation(jd->sa1, sa); | ||||
| if (dir != -1) { | if (dir != -1) { | ||||
| if (jd->sa2) jd->sa2->flag &= ~AREA_FLAG_DRAWJOINTO; | |||||
| jd->sa2 = sa; | jd->sa2 = sa; | ||||
| jd->sa2->flag |= AREA_FLAG_DRAWJOINTO; | |||||
| } | } | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_WINDOW, NULL); | WM_event_add_notifier(C, NC_WINDOW, NULL); | ||||
| Context not available. | |||||