Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/pose_slide.c
| Show First 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | static void draw_overshoot_triangle(const uint8_t color[4], | ||||
| GPU_polygon_smooth(false); | GPU_polygon_smooth(false); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| } | } | ||||
| static void draw_ticks(const float start_factor, | static void draw_ticks(const float start_factor, | ||||
| const float end_factor, | const float end_factor, | ||||
| const struct vec2f line_start, | const float line_start[2], | ||||
| const float base_tick_height, | const float base_tick_height, | ||||
| const float line_width, | const float line_width, | ||||
| const uint8_t color_overshoot[4], | const uint8_t color_overshoot[4], | ||||
| const uint8_t color_line[4]) | const uint8_t color_line[4]) | ||||
| { | { | ||||
| /* Use factor represented as 0-100 int to avoid floating point precision problems. */ | /* Use factor represented as 0-100 int to avoid floating point precision problems. */ | ||||
| const int tick_increment = 10; | const int tick_increment = 10; | ||||
| Show All 9 Lines | while (tick_percentage <= (int)(end_factor * 100)) { | ||||
| } | } | ||||
| else if (tick_percentage % 50 == 0) { | else if (tick_percentage % 50 == 0) { | ||||
| tick_height = base_tick_height * 0.8; | tick_height = base_tick_height * 0.8; | ||||
| } | } | ||||
| else { | else { | ||||
| tick_height = base_tick_height * 0.5; | tick_height = base_tick_height * 0.5; | ||||
| } | } | ||||
| const float x = line_start.x + | const float x = line_start[0] + | ||||
| (((float)tick_percentage / 100) - start_factor) * SLIDE_PIXEL_DISTANCE; | (((float)tick_percentage / 100) - start_factor) * SLIDE_PIXEL_DISTANCE; | ||||
| const struct rctf tick_rect = {.xmin = x - (line_width / 2), | const rctf tick_rect = { | ||||
| .xmin = x - (line_width / 2), | |||||
| .xmax = x + (line_width / 2), | .xmax = x + (line_width / 2), | ||||
| .ymin = line_start.y - (tick_height / 2), | .ymin = line_start[1] - (tick_height / 2), | ||||
| .ymax = line_start.y + (tick_height / 2)}; | .ymax = line_start[1] + (tick_height / 2), | ||||
| }; | |||||
| if (tick_percentage < 0 || tick_percentage > 100) { | if (tick_percentage < 0 || tick_percentage > 100) { | ||||
| UI_draw_roundbox_3ub_alpha(&tick_rect, true, 1, color_overshoot, 255); | UI_draw_roundbox_3ub_alpha(&tick_rect, true, 1, color_overshoot, 255); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_draw_roundbox_3ub_alpha(&tick_rect, true, 1, color_line, 255); | UI_draw_roundbox_3ub_alpha(&tick_rect, true, 1, color_line, 255); | ||||
| } | } | ||||
| tick_percentage += tick_increment; | tick_percentage += tick_increment; | ||||
| } | } | ||||
| } | } | ||||
| static void draw_main_line(const struct rctf main_line_rect, | static void draw_main_line(const rctf *main_line_rect, | ||||
| const float factor, | const float factor, | ||||
| const bool overshoot, | const bool overshoot, | ||||
| const uint8_t color_overshoot[4], | const uint8_t color_overshoot[4], | ||||
| const uint8_t color_line[4]) | const uint8_t color_line[4]) | ||||
| { | { | ||||
| if (overshoot) { | if (overshoot) { | ||||
| /* In overshoot mode, draw the 0-100% range differently to provide a visual reference. */ | /* In overshoot mode, draw the 0-100% range differently to provide a visual reference. */ | ||||
| const float line_zero_percent = main_line_rect.xmin - | const float line_zero_percent = main_line_rect->xmin - | ||||
| ((factor - 0.5f - OVERSHOOT_RANGE_DELTA) * | ((factor - 0.5f - OVERSHOOT_RANGE_DELTA) * | ||||
| SLIDE_PIXEL_DISTANCE); | SLIDE_PIXEL_DISTANCE); | ||||
| const float clamped_line_zero_percent = clamp_f( | const float clamped_line_zero_percent = clamp_f( | ||||
| line_zero_percent, main_line_rect.xmin, main_line_rect.xmax); | line_zero_percent, main_line_rect->xmin, main_line_rect->xmax); | ||||
| const float clamped_line_hundred_percent = clamp_f( | const float clamped_line_hundred_percent = clamp_f( | ||||
| line_zero_percent + SLIDE_PIXEL_DISTANCE, main_line_rect.xmin, main_line_rect.xmax); | line_zero_percent + SLIDE_PIXEL_DISTANCE, main_line_rect->xmin, main_line_rect->xmax); | ||||
| const struct rctf left_overshoot_line_rect = {.xmin = main_line_rect.xmin, | const rctf left_overshoot_line_rect = { | ||||
| .xmin = main_line_rect->xmin, | |||||
| .xmax = clamped_line_zero_percent, | .xmax = clamped_line_zero_percent, | ||||
| .ymin = main_line_rect.ymin, | .ymin = main_line_rect->ymin, | ||||
| .ymax = main_line_rect.ymax}; | .ymax = main_line_rect->ymax, | ||||
| const struct rctf right_overshoot_line_rect = {.xmin = clamped_line_hundred_percent, | }; | ||||
| .xmax = main_line_rect.xmax, | const rctf right_overshoot_line_rect = { | ||||
| .ymin = main_line_rect.ymin, | .xmin = clamped_line_hundred_percent, | ||||
| .ymax = main_line_rect.ymax}; | .xmax = main_line_rect->xmax, | ||||
| .ymin = main_line_rect->ymin, | |||||
| .ymax = main_line_rect->ymax, | |||||
| }; | |||||
| UI_draw_roundbox_3ub_alpha(&left_overshoot_line_rect, true, 0, color_overshoot, 255); | UI_draw_roundbox_3ub_alpha(&left_overshoot_line_rect, true, 0, color_overshoot, 255); | ||||
| UI_draw_roundbox_3ub_alpha(&right_overshoot_line_rect, true, 0, color_overshoot, 255); | UI_draw_roundbox_3ub_alpha(&right_overshoot_line_rect, true, 0, color_overshoot, 255); | ||||
| const struct rctf non_overshoot_line_rect = {.xmin = clamped_line_zero_percent, | const rctf non_overshoot_line_rect = { | ||||
| .xmin = clamped_line_zero_percent, | |||||
| .xmax = clamped_line_hundred_percent, | .xmax = clamped_line_hundred_percent, | ||||
| .ymin = main_line_rect.ymin, | .ymin = main_line_rect->ymin, | ||||
| .ymax = main_line_rect.ymax}; | .ymax = main_line_rect->ymax, | ||||
| }; | |||||
| UI_draw_roundbox_3ub_alpha(&non_overshoot_line_rect, true, 0, color_line, 255); | UI_draw_roundbox_3ub_alpha(&non_overshoot_line_rect, true, 0, color_line, 255); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_draw_roundbox_3ub_alpha(&main_line_rect, true, 0, color_line, 255); | UI_draw_roundbox_3ub_alpha(main_line_rect, true, 0, color_line, 255); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_backdrop(const int fontid, | static void draw_backdrop(const int fontid, | ||||
| const struct rctf main_line_rect, | const rctf *main_line_rect, | ||||
| const float color_bg[4], | const float color_bg[4], | ||||
| const short region_y_size, | const short region_y_size, | ||||
| const float base_tick_height) | const float base_tick_height) | ||||
| { | { | ||||
| float string_pixel_size[2]; | float string_pixel_size[2]; | ||||
| const char *percentage_string_placeholder = "000%%"; | const char *percentage_string_placeholder = "000%%"; | ||||
| BLF_width_and_height(fontid, | BLF_width_and_height(fontid, | ||||
| percentage_string_placeholder, | percentage_string_placeholder, | ||||
| sizeof(percentage_string_placeholder), | sizeof(percentage_string_placeholder), | ||||
| &string_pixel_size[0], | &string_pixel_size[0], | ||||
| &string_pixel_size[1]); | &string_pixel_size[1]); | ||||
| const struct vec2f pad = {.x = (region_y_size - base_tick_height) / 2, .y = 2.0f * U.pixelsize}; | const float pad[2] = {(region_y_size - base_tick_height) / 2, 2.0f * U.pixelsize}; | ||||
| const struct rctf backdrop_rect = {.xmin = main_line_rect.xmin - string_pixel_size[0] - pad.x, | const rctf backdrop_rect = { | ||||
| .xmax = main_line_rect.xmax + pad.x, | .xmin = main_line_rect->xmin - string_pixel_size[0] - pad[0], | ||||
| .ymin = pad.y, | .xmax = main_line_rect->xmax + pad[0], | ||||
| .ymax = region_y_size - pad.y}; | .ymin = pad[1], | ||||
| .ymax = region_y_size - pad[1], | |||||
| }; | |||||
| UI_draw_roundbox_aa(&backdrop_rect, true, 4.0f, color_bg); | UI_draw_roundbox_aa(&backdrop_rect, true, 4.0f, color_bg); | ||||
| } | } | ||||
| /* Draw an on screen Slider for a Pose Slide Operator. */ | /* Draw an on screen Slider for a Pose Slide Operator. */ | ||||
| static void pose_slide_draw_2d_slider(const struct bContext *UNUSED(C), ARegion *region, void *arg) | static void pose_slide_draw_2d_slider(const struct bContext *UNUSED(C), ARegion *region, void *arg) | ||||
| { | { | ||||
| tPoseSlideOp *pso = arg; | tPoseSlideOp *pso = arg; | ||||
| Show All 26 Lines | static void pose_slide_draw_2d_slider(const struct bContext *UNUSED(C), ARegion *region, void *arg) | ||||
| const int fontid = fstyle->uifont_id; | const int fontid = fstyle->uifont_id; | ||||
| BLF_color3ubv(fontid, color_text); | BLF_color3ubv(fontid, color_text); | ||||
| BLF_rotation(fontid, 0.0f); | BLF_rotation(fontid, 0.0f); | ||||
| const float line_width = 1.5 * U.pixelsize; | const float line_width = 1.5 * U.pixelsize; | ||||
| const float base_tick_height = 12.0 * U.pixelsize; | const float base_tick_height = 12.0 * U.pixelsize; | ||||
| const float line_y = region->winy / 2; | const float line_y = region->winy / 2; | ||||
| struct rctf main_line_rect = {.xmin = (region->winx / 2) - (SLIDE_PIXEL_DISTANCE / 2), | rctf main_line_rect = { | ||||
| .xmin = (region->winx / 2) - (SLIDE_PIXEL_DISTANCE / 2), | |||||
| .xmax = (region->winx / 2) + (SLIDE_PIXEL_DISTANCE / 2), | .xmax = (region->winx / 2) + (SLIDE_PIXEL_DISTANCE / 2), | ||||
| .ymin = line_y - line_width / 2, | .ymin = line_y - line_width / 2, | ||||
| .ymax = line_y + line_width / 2}; | .ymax = line_y + line_width / 2, | ||||
| }; | |||||
| float line_start_factor = 0; | float line_start_factor = 0; | ||||
| int handle_pos_x = main_line_rect.xmin + SLIDE_PIXEL_DISTANCE * pso->factor; | int handle_pos_x = main_line_rect.xmin + SLIDE_PIXEL_DISTANCE * pso->factor; | ||||
| if (pso->overshoot) { | if (pso->overshoot) { | ||||
| main_line_rect.xmin = main_line_rect.xmin - SLIDE_PIXEL_DISTANCE * OVERSHOOT_RANGE_DELTA; | main_line_rect.xmin = main_line_rect.xmin - SLIDE_PIXEL_DISTANCE * OVERSHOOT_RANGE_DELTA; | ||||
| main_line_rect.xmax = main_line_rect.xmax + SLIDE_PIXEL_DISTANCE * OVERSHOOT_RANGE_DELTA; | main_line_rect.xmax = main_line_rect.xmax + SLIDE_PIXEL_DISTANCE * OVERSHOOT_RANGE_DELTA; | ||||
| line_start_factor = pso->factor - 0.5f - OVERSHOOT_RANGE_DELTA; | line_start_factor = pso->factor - 0.5f - OVERSHOOT_RANGE_DELTA; | ||||
| handle_pos_x = region->winx / 2; | handle_pos_x = region->winx / 2; | ||||
| } | } | ||||
| draw_backdrop(fontid, main_line_rect, color_bg, pso->region->winy, base_tick_height); | draw_backdrop(fontid, &main_line_rect, color_bg, pso->region->winy, base_tick_height); | ||||
| draw_main_line(main_line_rect, pso->factor, pso->overshoot, color_overshoot, color_line); | draw_main_line(&main_line_rect, pso->factor, pso->overshoot, color_overshoot, color_line); | ||||
| const float factor_range = pso->overshoot ? 1 + OVERSHOOT_RANGE_DELTA * 2 : 1; | const float factor_range = pso->overshoot ? 1 + OVERSHOOT_RANGE_DELTA * 2 : 1; | ||||
| const struct vec2f line_start_position = {.x = main_line_rect.xmin, .y = line_y}; | const float line_start_position[2] = {main_line_rect.xmin, line_y}; | ||||
| draw_ticks(line_start_factor, | draw_ticks(line_start_factor, | ||||
| line_start_factor + factor_range, | line_start_factor + factor_range, | ||||
| line_start_position, | line_start_position, | ||||
| base_tick_height, | base_tick_height, | ||||
| line_width, | line_width, | ||||
| color_overshoot, | color_overshoot, | ||||
| color_line); | color_line); | ||||
| /* Draw triangles at the ends of the line in overshoot mode to indicate direction of 0-100% | /* Draw triangles at the ends of the line in overshoot mode to indicate direction of 0-100% | ||||
| * range.*/ | * range.*/ | ||||
| if (pso->overshoot) { | if (pso->overshoot) { | ||||
| if (pso->factor > 1 + OVERSHOOT_RANGE_DELTA + 0.5) { | if (pso->factor > 1 + OVERSHOOT_RANGE_DELTA + 0.5) { | ||||
| draw_overshoot_triangle(color_line, false, main_line_rect.xmin, line_y); | draw_overshoot_triangle(color_line, false, main_line_rect.xmin, line_y); | ||||
| } | } | ||||
| if (pso->factor < 0 - OVERSHOOT_RANGE_DELTA - 0.5) { | if (pso->factor < 0 - OVERSHOOT_RANGE_DELTA - 0.5) { | ||||
| draw_overshoot_triangle(color_line, true, main_line_rect.xmax, line_y); | draw_overshoot_triangle(color_line, true, main_line_rect.xmax, line_y); | ||||
| } | } | ||||
| } | } | ||||
| char percentage_string[256]; | char percentage_string[256]; | ||||
| /* Draw handle indicating current factor. */ | /* Draw handle indicating current factor. */ | ||||
| const struct rctf handle_rect = {.xmin = handle_pos_x - (line_width), | const rctf handle_rect = { | ||||
| .xmin = handle_pos_x - (line_width), | |||||
| .xmax = handle_pos_x + (line_width), | .xmax = handle_pos_x + (line_width), | ||||
| .ymin = line_y - (base_tick_height / 2), | .ymin = line_y - (base_tick_height / 2), | ||||
| .ymax = line_y + (base_tick_height / 2)}; | .ymax = line_y + (base_tick_height / 2), | ||||
| }; | |||||
| UI_draw_roundbox_3ub_alpha(&handle_rect, true, 1, color_handle, 255); | UI_draw_roundbox_3ub_alpha(&handle_rect, true, 1, color_handle, 255); | ||||
| BLI_snprintf(percentage_string, sizeof(percentage_string), "%.0f%%", pso->factor * 100); | BLI_snprintf(percentage_string, sizeof(percentage_string), "%.0f%%", pso->factor * 100); | ||||
| /* Draw percentage string. */ | /* Draw percentage string. */ | ||||
| float percentage_string_pixel_size[2]; | float percentage_string_pixel_size[2]; | ||||
| BLF_width_and_height(fontid, | BLF_width_and_height(fontid, | ||||
| percentage_string, | percentage_string, | ||||
| ▲ Show 20 Lines • Show All 1,965 Lines • Show Last 20 Lines | |||||