static void edbm_bevel_update_header(bContext *C, wmOperator *op) { const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Mode: %s (M), Clamp Overlap: %s (C), " "Vertex Only: %s (V), Profile Control: %s (P), Offset: %s, Segments: %d, Profile: %.3f"); char msg[UI_MAX_DRAW_STR]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); if (sa) { BevelData *opdata = op->customdata; char offset_str[NUM_STR_REP_LEN]; const char *type_str; PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type"); if (hasNumInput(&opdata->num_input[OFFSET_VALUE])) { outputNumInput(&opdata->num_input[OFFSET_VALUE], offset_str, &sce->unit); } else { BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); } RNA_property_enum_name_gettexted(C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &type_str); BLI_snprintf(msg, sizeof(msg), str, type_str, WM_bool_as_string(RNA_boolean_get(op->ptr, "clamp_overlap")), WM_bool_as_string(RNA_boolean_get(op->ptr, "vertex_only")), WM_bool_as_string(opdata->value_mode == PROFILE_VALUE), offset_str, RNA_int_get(op->ptr, "segments"), RNA_float_get(op->ptr, "profile")); ED_area_headerprint(sa, msg); } }
static void walk_update_header(bContext *C, wmOperator *op, WalkInfo *walk) { const bool gravity = (walk->navigation_mode == WALK_MODE_GRAVITY) || ((walk->teleport.state == WALK_TELEPORT_STATE_ON) && (walk->teleport.navigation_mode == WALK_MODE_GRAVITY)); char header[UI_MAX_DRAW_STR]; char buf[UI_MAX_DRAW_STR]; char *p = buf; int available_len = sizeof(buf); #define WM_MODALKEY(_id) \ WM_modalkeymap_operator_items_to_string_buf(op->type, (_id), true, UI_MAX_SHORTCUT_STR, &available_len, &p) BLI_snprintf(header, sizeof(header), IFACE_("%s: confirm, %s: cancel, " "%s: gravity (%s), " "%s|%s|%s|%s: move around, " "%s: fast, %s: slow, " "%s|%s: up and down, " "%s: teleport, %s: jump, " "%s: increase speed, %s: decrease speed"), WM_MODALKEY(WALK_MODAL_CONFIRM), WM_MODALKEY(WALK_MODAL_CANCEL), WM_MODALKEY(WALK_MODAL_TOGGLE), WM_bool_as_string(gravity), WM_MODALKEY(WALK_MODAL_DIR_FORWARD), WM_MODALKEY(WALK_MODAL_DIR_LEFT), WM_MODALKEY(WALK_MODAL_DIR_BACKWARD), WM_MODALKEY(WALK_MODAL_DIR_RIGHT), WM_MODALKEY(WALK_MODAL_FAST_ENABLE), WM_MODALKEY(WALK_MODAL_SLOW_ENABLE), WM_MODALKEY(WALK_MODAL_DIR_UP), WM_MODALKEY(WALK_MODAL_DIR_DOWN), WM_MODALKEY(WALK_MODAL_TELEPORT), WM_MODALKEY(WALK_MODAL_JUMP), WM_MODALKEY(WALK_MODAL_ACCELERATE), WM_MODALKEY(WALK_MODAL_DECELERATE)); #undef WM_MODALKEY ED_area_headerprint(CTX_wm_area(C), header); }
/* draw percentage indicator in header */ static void pose_slide_draw_status(tPoseSlideOp *pso) { char status_str[32]; char mode_str[32]; switch (pso->mode) { case POSESLIDE_PUSH: strcpy(mode_str, "Push Pose"); break; case POSESLIDE_RELAX: strcpy(mode_str, "Relax Pose"); break; case POSESLIDE_BREAKDOWN: strcpy(mode_str, "Breakdown"); break; default: /* unknown */ strcpy(mode_str, "Sliding-Tool"); break; } BLI_snprintf(status_str, sizeof(status_str), "%s: %d %%", mode_str, (int)(pso->percentage * 100.0f)); ED_area_headerprint(pso->sa, status_str); }
static void edbm_inset_update_header(wmOperator *op, bContext *C) { InsetData *opdata = op->customdata; const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RClick), Thickness: %s, " "Depth (Ctrl to tweak): %s (%s), Outset (O): (%s), Boundary (B): (%s), Individual (I): (%s)"); char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); Scene *sce = CTX_data_scene(C); if (sa) { char flts_str[NUM_STR_REP_LEN * 2]; if (hasNumInput(&opdata->num_input)) outputNumInput(&opdata->num_input, flts_str, &sce->unit); else { BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness")); BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth")); } BLI_snprintf(msg, HEADER_LENGTH, str, flts_str, flts_str + NUM_STR_REP_LEN, WM_bool_as_string(opdata->modify_depth), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_outset")), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_boundary")), WM_bool_as_string(RNA_boolean_get(op->ptr, "use_individual")) ); ED_area_headerprint(sa, msg); } }
static void fly_update_header(bContext *C, wmOperator *op, FlyInfo *fly) { char header[UI_MAX_DRAW_STR]; char buf[UI_MAX_DRAW_STR]; char *p = buf; int available_len = sizeof(buf); #define WM_MODALKEY(_id) \ WM_modalkeymap_operator_items_to_string_buf(op->type, (_id), true, UI_MAX_SHORTCUT_STR, &available_len, &p) BLI_snprintf(header, sizeof(header), IFACE_("%s: confirm, %s: cancel, " "%s: pan enable, " "%s|%s|%s|%s|%s|%s: direction, " "%s: slow, %s: free look, " "%s: Upright x axis (%s), " "%s: Upright z axis (%s), " "%s: increase speed, %s: decrease speed"), WM_MODALKEY(FLY_MODAL_CONFIRM), WM_MODALKEY(FLY_MODAL_CANCEL), WM_MODALKEY(FLY_MODAL_PAN_ENABLE), WM_MODALKEY(FLY_MODAL_DIR_FORWARD), WM_MODALKEY(FLY_MODAL_DIR_LEFT), WM_MODALKEY(FLY_MODAL_DIR_BACKWARD), WM_MODALKEY(FLY_MODAL_DIR_RIGHT), WM_MODALKEY(FLY_MODAL_DIR_UP), WM_MODALKEY(FLY_MODAL_DIR_DOWN), WM_MODALKEY(FLY_MODAL_PRECISION_ENABLE), WM_MODALKEY(FLY_MODAL_FREELOOK_ENABLE), WM_MODALKEY(FLY_MODAL_AXIS_LOCK_X), WM_bool_as_string(fly->xlock != FLY_AXISLOCK_STATE_OFF), WM_MODALKEY(FLY_MODAL_AXIS_LOCK_Z), WM_bool_as_string(fly->zlock != FLY_AXISLOCK_STATE_OFF), WM_MODALKEY(FLY_MODAL_ACCELERATE), WM_MODALKEY(FLY_MODAL_DECELERATE)); #undef WM_MODALKEY ED_area_headerprint(CTX_wm_area(C), header); }
/* After previewing poses */ static void poselib_preview_cleanup (bContext *C, wmOperator *op) { tPoseLib_PreviewData *pld= (tPoseLib_PreviewData *)op->customdata; Scene *scene= pld->scene; Object *ob= pld->ob; bPose *pose= pld->pose; bArmature *arm= pld->arm; bAction *act= pld->act; TimeMarker *marker= pld->marker; /* redraw the header so that it doesn't show any of our stuff anymore */ ED_area_headerprint(pld->sa, NULL); /* this signal does one recalc on pose, then unlocks, so ESC or edit will work */ pose->flag |= POSE_DO_UNLOCK; /* clear pose if cancelled */ if (pld->state == PL_PREVIEW_CANCEL) { poselib_backup_restore(pld); /* old optimize trick... this enforces to bypass the depgraph * - note: code copied from transform_generics.c -> recalcData() */ if ((arm->flag & ARM_DELAYDEFORM)==0) DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */ else where_is_pose(scene, ob); } else if (pld->state == PL_PREVIEW_CONFIRM) { /* tag poses as appropriate */ poselib_keytag_pose(C, scene, pld); /* change active pose setting */ act->active_marker= BLI_findindex(&act->markers, marker) + 1; action_set_activemarker(act, marker, NULL); /* Update event for pose and deformation children */ DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* updates */ if (IS_AUTOKEY_MODE(scene, NORMAL)) { //remake_action_ipos(ob->action); } else where_is_pose(scene, ob); } /* free memory used for backups and searching */ poselib_backup_free_data(pld); BLI_freelistN(&pld->searchp); /* free temp data for operator */ MEM_freeN(pld); op->customdata= NULL; }
static void view3d_ruler_header_update(ScrArea *sa) { const char *text = "Ctrl+LMB: Add, " "Del: Remove, " "Ctrl+Drag: Snap, " "Shift+Drag: Thickness, " "Ctrl+C: Copy Value, " "Enter: Store, " "Esc: Cancel"; ED_area_headerprint(sa, text); }
/* free stuff */ static void ed_marker_move_exit(bContext *C, wmOperator *op) { MarkerMove *mm = op->customdata; /* free data */ MEM_freeN(mm->oldframe); MEM_freeN(op->customdata); op->customdata = NULL; /* clear custom header prints */ ED_area_headerprint(CTX_wm_area(C), NULL); }
/* This function updates the header of the UV editor when the stitch tool updates its settings */ static void stitch_update_header(StitchState *stitch_state, bContext *C) { static char str[] = "(S)nap %s, (M)idpoints %s, (L)imit %.2f (Alt Wheel adjust) %s, Switch (I)sland, shift select vertices"; char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); if (sa) { BLI_snprintf(msg, HEADER_LENGTH, str, stitch_state->snap_islands ? "On" : "Off", stitch_state->midpoints ? "On" : "Off", stitch_state->limit_dist, stitch_state->use_limit ? "On" : "Off"); ED_area_headerprint(sa, msg); } }
static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event) { int exit_code; bool do_draw = false; FlyInfo *fly = op->customdata; RegionView3D *rv3d = fly->rv3d; Object *fly_object = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control); fly->redraw = 0; flyEvent(C, op, fly, event); #ifdef WITH_INPUT_NDOF if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer] */ if (event->type == NDOF_MOTION) { flyApply_ndof(C, fly); } } else #endif /* WITH_INPUT_NDOF */ if (event->type == TIMER && event->customdata == fly->timer) { flyApply(C, fly); } do_draw |= fly->redraw; exit_code = flyEnd(C, fly); if (exit_code != OPERATOR_RUNNING_MODAL) do_draw = true; if (do_draw) { if (rv3d->persp == RV3D_CAMOB) { WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, fly_object); } // puts("redraw!"); // too frequent, commented with NDOF_FLY_DRAW_TOOMUCH for now ED_region_tag_redraw(CTX_wm_region(C)); } if (ELEM(exit_code, OPERATOR_FINISHED, OPERATOR_CANCELLED)) ED_area_headerprint(CTX_wm_area(C), NULL); return exit_code; }
static void walk_update_header(bContext *C, WalkInfo *walk) { bool gravity = walk->navigation_mode == WALK_MODE_GRAVITY || (walk->teleport.state == WALK_TELEPORT_STATE_ON && walk->teleport.navigation_mode == WALK_MODE_GRAVITY); #define HEADER_LENGTH 256 char header[HEADER_LENGTH]; BLI_snprintf(header, HEADER_LENGTH, IFACE_("LMB/Return: confirm, Esc/RMB: cancel, " "Tab: gravity (%s), " "WASD: move around, " "QE: up and down, MMB/Space: teleport, V: jump, " "Pad +/Wheel Up: increase speed, Pad -/Wheel Down: decrease speed"), WM_bool_as_string(gravity)); ED_area_headerprint(CTX_wm_area(C), header); #undef HEADER_LENGTH }
static void edbm_bevel_update_header(wmOperator *op, bContext *C) { const char *str = IFACE_("Confirm: Enter/LClick, Cancel: (Esc/RMB), Offset: %s, Segments: %d"); char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); if (sa) { char offset_str[NUM_STR_REP_LEN]; BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); BLI_snprintf(msg, HEADER_LENGTH, str, offset_str, RNA_int_get(op->ptr, "segments") ); ED_area_headerprint(sa, msg); } }
static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); int ret; if (em->bm->totedgesel == 0) { BKE_report(op->reports, RPT_ERROR, "Selected edges/faces required"); return OPERATOR_CANCELLED; } /* if the properties are set or there is no rv3d, * skip model and exec immediately */ if ((CTX_wm_region_view3d(C) == NULL) || (RNA_struct_property_is_set(op->ptr, "plane_co") && RNA_struct_property_is_set(op->ptr, "plane_no"))) { return mesh_bisect_exec(C, op); } ret = WM_gesture_straightline_invoke(C, op, event); if (ret & OPERATOR_RUNNING_MODAL) { View3D *v3d = CTX_wm_view3d(C); wmGesture *gesture = op->customdata; BisectData *opdata; opdata = MEM_mallocN(sizeof(BisectData), "inset_operator_data"); opdata->mesh_backup = EDBM_redo_state_store(em); opdata->is_first = true; gesture->userdata = opdata; /* misc other vars */ G.moving = G_TRANSFORM_EDIT; opdata->twtype = v3d->twtype; v3d->twtype = 0; /* initialize modal callout */ ED_area_headerprint(CTX_wm_area(C), IFACE_("LMB: Click and drag to draw cut line")); } return ret; }
static void ed_marker_move_update_header(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); MarkerMove *mm = op->customdata; TimeMarker *marker, *selmarker = NULL; const int offs = RNA_int_get(op->ptr, "frames"); char str[256]; char str_offs[NUM_STR_REP_LEN]; int totmark; const bool use_time = ed_marker_move_use_time(mm); for (totmark = 0, marker = mm->markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { selmarker = marker; totmark++; } } if (hasNumInput(&mm->num)) { outputNumInput(&mm->num, str_offs, &scene->unit); } else if (use_time) { BLI_snprintf(str_offs, sizeof(str_offs), "%.2f", FRA2TIME(offs)); } else { BLI_snprintf(str_offs, sizeof(str_offs), "%d", offs); } if (totmark == 1 && selmarker) { /* we print current marker value */ if (use_time) { BLI_snprintf(str, sizeof(str), "Marker %.2f offset %s", FRA2TIME(selmarker->frame), str_offs); } else { BLI_snprintf(str, sizeof(str), "Marker %d offset %s", selmarker->frame, str_offs); } } else { BLI_snprintf(str, sizeof(str), "Marker offset %s", str_offs); } ED_area_headerprint(CTX_wm_area(C), str); }
static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event) { int exit_code; bool do_draw = false; WalkInfo *walk = op->customdata; RegionView3D *rv3d = walk->rv3d; Object *walk_object = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control); walk->redraw = false; walkEvent(C, op, walk, event); if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer] */ if (event->type == NDOF_MOTION) { walkApply_ndof(C, walk); } } else if (event->type == TIMER && event->customdata == walk->timer) { walkApply(C, op, walk); } do_draw |= walk->redraw; exit_code = walkEnd(C, walk); if (exit_code != OPERATOR_RUNNING_MODAL) do_draw = true; if (do_draw) { if (rv3d->persp == RV3D_CAMOB) { WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, walk_object); } // puts("redraw!"); // too frequent, commented with NDOF_WALK_DRAW_TOOMUCH for now ED_region_tag_redraw(CTX_wm_region(C)); } if (ELEM(exit_code, OPERATOR_FINISHED, OPERATOR_CANCELLED)) ED_area_headerprint(CTX_wm_area(C), NULL); return exit_code; }
static void edbm_bevel_exit(bContext *C, wmOperator *op) { BevelData *opdata = op->customdata; ScrArea *sa = CTX_wm_area(C); if (sa) { ED_area_headerprint(sa, NULL); } if (opdata->is_modal) { View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); EDBM_redo_state_free(&opdata->mesh_backup, NULL, false); ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel); v3d->twtype = opdata->twtype; G.moving = 0; } MEM_freeN(opdata); op->customdata = NULL; }
static void edbm_bevel_update_header(wmOperator *op, bContext *C) { const char *str = IFACE_("Confirm: (Enter/LMB), Cancel: (Esc/RMB), Offset: %s, Segments: %d"); char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); if (sa) { BevelData *opdata = op->customdata; char offset_str[NUM_STR_REP_LEN]; if (hasNumInput(&opdata->num_input)) { outputNumInput(&opdata->num_input, offset_str); } else { BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset")); } BLI_snprintf(msg, HEADER_LENGTH, str, offset_str, RNA_int_get(op->ptr, "segments")); ED_area_headerprint(sa, msg); } }
/* draw percentage indicator in header */ static void pose_slide_draw_status(tPoseSlideOp *pso) { char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; switch (pso->mode) { case POSESLIDE_PUSH: strcpy(mode_str, "Push Pose"); break; case POSESLIDE_RELAX: strcpy(mode_str, "Relax Pose"); break; case POSESLIDE_BREAKDOWN: strcpy(mode_str, "Breakdown"); break; default: /* unknown */ strcpy(mode_str, "Sliding-Tool"); break; } if (hasNumInput(&pso->num)) { Scene *scene = pso->scene; char str_offs[NUM_STR_REP_LEN]; outputNumInput(&pso->num, str_offs, &scene->unit); BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, str_offs); } else { BLI_snprintf(status_str, sizeof(status_str), "%s: %d %%", mode_str, (int)(pso->percentage * 100.0f)); } ED_area_headerprint(pso->sa, status_str); }
/* Apply the relevant changes to the pose */ static void poselib_preview_apply (bContext *C, wmOperator *op) { tPoseLib_PreviewData *pld= (tPoseLib_PreviewData *)op->customdata; /* only recalc pose (and its dependencies) if pose has changed */ if (pld->redraw == PL_PREVIEW_REDRAWALL) { /* don't clear pose if firsttime */ if ((pld->flag & PL_PREVIEW_FIRSTTIME)==0) poselib_backup_restore(pld); else pld->flag &= ~PL_PREVIEW_FIRSTTIME; /* pose should be the right one to draw (unless we're temporarily not showing it) */ if ((pld->flag & PL_PREVIEW_SHOWORIGINAL)==0) { RNA_int_set(op->ptr, "pose_index", BLI_findindex(&pld->act->markers, pld->marker)); poselib_apply_pose(pld); } else RNA_int_set(op->ptr, "pose_index", -2); /* -2 means don't apply any pose */ /* old optimize trick... this enforces to bypass the depgraph * - note: code copied from transform_generics.c -> recalcData() */ // FIXME: shouldn't this use the builtin stuff? if ((pld->arm->flag & ARM_DELAYDEFORM)==0) DAG_id_tag_update(&pld->ob->id, OB_RECALC_DATA); /* sets recalc flags */ else where_is_pose(pld->scene, pld->ob); } /* do header print - if interactively previewing */ if (pld->state == PL_PREVIEW_RUNNING) { if (pld->flag & PL_PREVIEW_SHOWORIGINAL) { BLI_strncpy(pld->headerstr, "PoseLib Previewing Pose: [Showing Original Pose] | Use Tab to start previewing poses again", sizeof(pld->headerstr)); ED_area_headerprint(pld->sa, pld->headerstr); } else if (pld->searchstr[0]) { char tempstr[65]; char markern[64]; short index; /* get search-string */ index= pld->search_cursor; if (index >= 0 && index <= sizeof(tempstr) - 1) { memcpy(&tempstr[0], &pld->searchstr[0], index); tempstr[index]= '|'; memcpy(&tempstr[index+1], &pld->searchstr[index], (sizeof(tempstr) - 1) - index); } else { BLI_strncpy(tempstr, pld->searchstr, sizeof(tempstr)); } /* get marker name */ BLI_strncpy(markern, pld->marker ? pld->marker->name : "No Matches", sizeof(markern)); BLI_snprintf(pld->headerstr, sizeof(pld->headerstr), "PoseLib Previewing Pose: Filter - [%s] | " "Current Pose - \"%s\" | " "Use ScrollWheel or PageUp/Down to change", tempstr, markern); ED_area_headerprint(pld->sa, pld->headerstr); } else { BLI_snprintf(pld->headerstr, sizeof(pld->headerstr), "PoseLib Previewing Pose: \"%s\" | " "Use ScrollWheel or PageUp/Down to change", pld->marker->name); ED_area_headerprint(pld->sa, pld->headerstr); } } /* request drawing of view + clear redraw flag */ WM_event_add_notifier(C, NC_OBJECT|ND_POSE, pld->ob); pld->redraw= PL_PREVIEW_NOREDRAW; }
/* common code for modal() */ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) { tPoseSlideOp *pso = op->customdata; wmWindow *win = CTX_wm_window(C); const bool has_numinput = hasNumInput(&pso->num); switch (event->type) { case LEFTMOUSE: /* confirm */ case RETKEY: case PADENTER: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* insert keyframes as required... */ pose_slide_autoKeyframe(C, pso); pose_slide_exit(op); /* done! */ return OPERATOR_FINISHED; } case ESCKEY: /* cancel */ case RIGHTMOUSE: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* reset transforms back to original state */ pose_slide_reset(pso); /* depsgraph updates + redraws */ pose_slide_refresh(C, pso); /* clean up temp data */ pose_slide_exit(op); /* canceled! */ return OPERATOR_CANCELLED; } case MOUSEMOVE: /* calculate new position */ { /* only handle mousemove if not doing numinput */ if (has_numinput == false) { /* update percentage based on position of mouse */ pose_slide_mouse_update_percentage(pso, op, event); /* update percentage indicator in header */ pose_slide_draw_status(pso); /* reset transforms (to avoid accumulation errors) */ pose_slide_reset(pso); /* apply... */ pose_slide_apply(C, pso); } break; } default: if ((event->val == KM_PRESS) && handleNumInput(C, &pso->num, event)) { float value; /* Grab percentage from numeric input, and store this new value for redo * NOTE: users see ints, while internally we use a 0-1 float */ value = pso->percentage * 100.0f; applyNumInput(&pso->num, &value); pso->percentage = value / 100.0f; CLAMP(pso->percentage, 0.0f, 1.0f); RNA_float_set(op->ptr, "percentage", pso->percentage); /* update percentage indicator in header */ pose_slide_draw_status(pso); /* reset transforms (to avoid accumulation errors) */ pose_slide_reset(pso); /* apply... */ pose_slide_apply(C, pso); break; } else { /* unhandled event - maybe it was some view manip? */ /* allow to pass through */ return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; } } /* still running... */ return OPERATOR_RUNNING_MODAL; }
static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *event) { Scene *scene = CTX_data_scene(C); MarkerMove *mm = op->customdata; View2D *v2d = UI_view2d_fromcontext(C); TimeMarker *marker, *selmarker = NULL; float dx, fac; char str[256]; switch (event->type) { case ESCKEY: ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; case RIGHTMOUSE: /* press = user manually demands transform to be canceled */ if (event->val == KM_PRESS) { ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; } /* else continue; <--- see if release event should be caught for tweak-end */ case RETKEY: case PADENTER: case LEFTMOUSE: case MIDDLEMOUSE: if (WM_modal_tweak_exit(event, mm->event_type)) { ed_marker_move_exit(C, op); WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL); WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL); return OPERATOR_FINISHED; } break; case MOUSEMOVE: if (hasNumInput(&mm->num)) break; dx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); if (event->x != mm->evtx) { /* XXX maybe init for first time */ int a, offs, totmark = 0; mm->evtx = event->x; fac = ((float)(event->x - mm->firstx) * dx); if (mm->slink->spacetype == SPACE_TIME) apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0); else apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/); offs = (int)fac; RNA_int_set(op->ptr, "frames", offs); ed_marker_move_apply(C, op); /* cruft below is for header print */ for (a = 0, marker = mm->markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { selmarker = marker; a++; totmark++; } } if (totmark == 1) { /* we print current marker value */ if (mm->slink->spacetype == SPACE_TIME) { SpaceTime *stime = (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) BLI_snprintf(str, sizeof(str), "Marker %d offset %d", selmarker->frame, offs); else BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); else BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } else { BLI_snprintf(str, sizeof(str), "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } } else { /* we only print the offset */ if (mm->slink->spacetype == SPACE_TIME) { SpaceTime *stime = (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) BLI_snprintf(str, sizeof(str), "Marker offset %d ", offs); else BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", FRA2TIME(offs)); else BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs)); } else { BLI_snprintf(str, sizeof(str), "Marker offset %.2f ", (double)(offs)); } } ED_area_headerprint(CTX_wm_area(C), str); } } if (event->val == KM_PRESS) { if (handleNumInput(&mm->num, event)) { char str_tx[NUM_STR_REP_LEN]; float value = RNA_int_get(op->ptr, "frames"); applyNumInput(&mm->num, &value); if (hasNumInput(&mm->num)) { outputNumInput(&mm->num, str_tx); } else { BLI_snprintf(str_tx, sizeof(str_tx), "%d", (int)value); } RNA_int_set(op->ptr, "frames", value); ed_marker_move_apply(C, op); // ed_marker_header_update(C, op, str, (int)value); // strcat(str, str_tx); BLI_snprintf(str, sizeof(str), "Marker offset %s", str_tx); ED_area_headerprint(CTX_wm_area(C), str); } } return OPERATOR_RUNNING_MODAL; }
/* common code for modal() */ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) { tPoseSlideOp *pso = op->customdata; wmWindow *win = CTX_wm_window(C); switch (event->type) { case LEFTMOUSE: /* confirm */ case RETKEY: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* insert keyframes as required... */ pose_slide_autoKeyframe(C, pso); pose_slide_exit(op); /* done! */ return OPERATOR_FINISHED; } case ESCKEY: /* cancel */ case RIGHTMOUSE: { /* return to normal cursor and header status */ ED_area_headerprint(pso->sa, NULL); WM_cursor_modal_restore(win); /* reset transforms back to original state */ pose_slide_reset(pso); /* depsgraph updates + redraws */ pose_slide_refresh(C, pso); /* clean up temp data */ pose_slide_exit(op); /* canceled! */ return OPERATOR_CANCELLED; } case MOUSEMOVE: /* calculate new position */ { /* calculate percentage based on position of mouse (we only use x-axis for now. * since this is more convenient for users to do), and store new percentage value */ pso->percentage = (event->x - pso->ar->winrct.xmin) / ((float)pso->ar->winx); RNA_float_set(op->ptr, "percentage", pso->percentage); /* update percentage indicator in header */ pose_slide_draw_status(pso); /* reset transforms (to avoid accumulation errors) */ pose_slide_reset(pso); /* apply... */ pose_slide_apply(C, pso); break; } default: /* unhandled event (maybe it was some view manip? */ /* allow to pass through */ return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; } /* still running... */ return OPERATOR_RUNNING_MODAL; }
static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt) { Scene *scene= CTX_data_scene(C); MarkerMove *mm= op->customdata; View2D *v2d= UI_view2d_fromcontext(C); TimeMarker *marker, *selmarker=NULL; float dx, fac; char str[256]; switch(evt->type) { case ESCKEY: ed_marker_move_cancel(C, op); return OPERATOR_CANCELLED; case LEFTMOUSE: case MIDDLEMOUSE: case RIGHTMOUSE: if(WM_modal_tweak_exit(evt, mm->event_type)) { ed_marker_move_exit(C, op); WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); return OPERATOR_FINISHED; } break; case MOUSEMOVE: dx= v2d->mask.xmax-v2d->mask.xmin; dx= (v2d->cur.xmax-v2d->cur.xmin)/dx; if (evt->x != mm->evtx) { /* XXX maybe init for firsttime */ int a, offs, totmark=0; mm->evtx= evt->x; fac= ((float)(evt->x - mm->firstx)*dx); if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) apply_keyb_grid(evt->shift, evt->ctrl, &fac, 0.0, FPS, 0.1*FPS, 0); else apply_keyb_grid(evt->shift, evt->ctrl, &fac, 0.0, 1.0, 0.1, U.flag & USER_AUTOGRABGRID); offs= (int)fac; RNA_int_set(op->ptr, "frames", offs); ed_marker_move_apply(C, op); /* cruft below is for header print */ for (a=0, marker= mm->markers->first; marker; marker= marker->next) { if (marker->flag & SELECT) { selmarker= marker; a++; totmark++; } } if (totmark==1) { /* we print current marker value */ if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) { SpaceTime *stime= (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) sprintf(str, "Marker %d offset %d", selmarker->frame, offs); else sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs)); else sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } else { sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs)); } } else { /* we only print the offset */ if (ELEM(mm->slink->spacetype, SPACE_TIME, SPACE_SOUND)) { SpaceTime *stime= (SpaceTime *)mm->slink; if (stime->flag & TIME_DRAWFRAMES) sprintf(str, "Marker offset %d ", offs); else sprintf(str, "Marker offset %.2f ", FRA2TIME(offs)); } else if (mm->slink->spacetype == SPACE_ACTION) { SpaceAction *saction= (SpaceAction *)mm->slink; if (saction->flag & SACTION_DRAWTIME) sprintf(str, "Marker offset %.2f ", FRA2TIME(offs)); else sprintf(str, "Marker offset %.2f ", (double)(offs)); } else { sprintf(str, "Marker offset %.2f ", (double)(offs)); } } WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL); ED_area_headerprint(CTX_wm_area(C), str); } } return OPERATOR_RUNNING_MODAL; }
static int view3d_ruler_modal(bContext *C, wmOperator *op, const wmEvent *event) { bool do_draw = false; int exit_code = OPERATOR_RUNNING_MODAL; RulerInfo *ruler_info = op->customdata; ScrArea *sa = ruler_info->sa; ARegion *ar = ruler_info->ar; RegionView3D *rv3d = ar->regiondata; /* its possible to change spaces while running the operator [#34894] */ if (UNLIKELY(ar != CTX_wm_region(C))) { exit_code = OPERATOR_FINISHED; goto exit; } switch (event->type) { case LEFTMOUSE: if (event->val == KM_RELEASE) { if (ruler_info->state == RULER_STATE_DRAG) { /* rubber-band angle removal */ RulerItem *ruler_item = ruler_item_active_get(ruler_info); if (ruler_item && (ruler_item->co_index == 1) && (ruler_item->flag & RULERITEM_USE_ANGLE)) { if (!BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) { ruler_item->flag &= ~RULERITEM_USE_ANGLE; do_draw = true; } } if (ruler_info->snap_flag & RULER_SNAP_OK) { ruler_info->snap_flag &= ~RULER_SNAP_OK; do_draw = true; } ruler_info->state = RULER_STATE_NORMAL; } } else { if (ruler_info->state == RULER_STATE_NORMAL) { if (event->ctrl || /* weak - but user friendly */ BLI_listbase_is_empty(&ruler_info->items)) { View3D *v3d = CTX_wm_view3d(C); const bool use_depth = (v3d->drawtype >= OB_SOLID); /* Create new line */ RulerItem *ruler_item_prev = ruler_item_active_get(ruler_info); RulerItem *ruler_item; /* check if we want to drag an existing point or add a new one */ ruler_info->state = RULER_STATE_DRAG; ruler_item = ruler_item_add(ruler_info); ruler_item_active_set(ruler_info, ruler_item); if (use_depth) { /* snap the first point added, not essential but handy */ ruler_item->co_index = 0; view3d_ruler_item_mousemove(C, ruler_info, event->mval, false, true); copy_v3_v3(ruler_info->drag_start_co, ruler_item->co[ruler_item->co_index]); } else { /* initial depth either previous ruler, view offset */ if (ruler_item_prev) { copy_v3_v3(ruler_info->drag_start_co, ruler_item_prev->co[ruler_item_prev->co_index]); } else { negate_v3_v3(ruler_info->drag_start_co, rv3d->ofs); } copy_v3_v3(ruler_item->co[0], ruler_info->drag_start_co); view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval); } copy_v3_v3(ruler_item->co[2], ruler_item->co[0]); ruler_item->co_index = 2; do_draw = true; } else { float mval_fl[2] = {UNPACK2(event->mval)}; RulerItem *ruler_item_pick; int co_index; /* select and drag */ if (view3d_ruler_pick(ruler_info, mval_fl, &ruler_item_pick, &co_index)) { if (co_index == -1) { if ((ruler_item_pick->flag & RULERITEM_USE_ANGLE) == 0) { /* Add Center Point */ ruler_item_active_set(ruler_info, ruler_item_pick); ruler_item_pick->flag |= RULERITEM_USE_ANGLE; ruler_item_pick->co_index = 1; ruler_info->state = RULER_STATE_DRAG; /* find the factor */ { float co_ss[2][2]; float fac; ED_view3d_project_float_global(ar, ruler_item_pick->co[0], co_ss[0], V3D_PROJ_TEST_NOP); ED_view3d_project_float_global(ar, ruler_item_pick->co[2], co_ss[1], V3D_PROJ_TEST_NOP); fac = line_point_factor_v2(mval_fl, co_ss[0], co_ss[1]); CLAMP(fac, 0.0f, 1.0f); interp_v3_v3v3(ruler_item_pick->co[1], ruler_item_pick->co[0], ruler_item_pick->co[2], fac); } /* update the new location */ view3d_ruler_item_mousemove(C, ruler_info, event->mval, event->shift != 0, event->ctrl != 0); do_draw = true; } } else { ruler_item_active_set(ruler_info, ruler_item_pick); ruler_item_pick->co_index = co_index; ruler_info->state = RULER_STATE_DRAG; /* store the initial depth */ copy_v3_v3(ruler_info->drag_start_co, ruler_item_pick->co[ruler_item_pick->co_index]); do_draw = true; } } else { exit_code = OPERATOR_PASS_THROUGH; } } } } break; case CKEY: { if (event->ctrl) { RulerItem *ruler_item = ruler_item_active_get(ruler_info); if (ruler_item) { const int prec = 8; char numstr[256]; Scene *scene = CTX_data_scene(C); UnitSettings *unit = &scene->unit; ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec); WM_clipboard_text_set((void *) numstr, false); } } break; } case RIGHTCTRLKEY: case LEFTCTRLKEY: { WM_event_add_mousemove(C); break; } case MOUSEMOVE: { if (ruler_info->state == RULER_STATE_DRAG) { if (view3d_ruler_item_mousemove(C, ruler_info, event->mval, event->shift != 0, event->ctrl != 0)) { do_draw = true; } } break; } case ESCKEY: { do_draw = true; exit_code = OPERATOR_CANCELLED; break; } case RETKEY: { view3d_ruler_to_gpencil(C, ruler_info); do_draw = true; exit_code = OPERATOR_FINISHED; break; } case DELKEY: { if (event->val == KM_PRESS) { if (ruler_info->state == RULER_STATE_NORMAL) { RulerItem *ruler_item = ruler_item_active_get(ruler_info); if (ruler_item) { RulerItem *ruler_item_other = ruler_item->prev ? ruler_item->prev : ruler_item->next; ruler_item_remove(ruler_info, ruler_item); ruler_item_active_set(ruler_info, ruler_item_other); do_draw = true; } } } break; } default: exit_code = OPERATOR_PASS_THROUGH; break; } if (do_draw) { view3d_ruler_header_update(sa); /* all 3d views draw rulers */ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL); } exit: if (ELEM(exit_code, OPERATOR_FINISHED, OPERATOR_CANCELLED)) { WM_cursor_modal_restore(ruler_info->win); view3d_ruler_end(C, ruler_info); view3d_ruler_free(ruler_info); op->customdata = NULL; ED_area_headerprint(sa, NULL); } return exit_code; }