diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-11-01 21:48:14 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-11-01 21:48:59 +0300 |
commit | 88356a24422faf45d6355b449b3855e6904edf51 (patch) | |
tree | d18a1349297a7a04b80a66b44c97fa5ba57616a1 /source | |
parent | a6e1f7560fa4e6308a83d42d701a1b95d7db38a8 (diff) |
Cleanup: use term shape-preset in widget code
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 116 |
1 files changed, 64 insertions, 52 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 44a9d0d91b6..79571e24a4b 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -154,54 +154,54 @@ static const float jit[WIDGET_AA_JITTER][2] = { {-0.272855, 0.269918}, { 0.095909, 0.388710} }; -static const float num_tria_vert[3][2] = { +/* -------------------------------------------------------------------- */ +/** \name Shape Preset Data + * \{ */ + +static const float g_shape_preset_number_arrow_vert[3][2] = { {-0.352077, 0.532607}, {-0.352077, -0.549313}, {0.330000, -0.008353} }; - -static const unsigned int num_tria_face[1][3] = { +static const uint g_shape_preset_number_arrow_face[1][3] = { {0, 1, 2} }; -static const float scroll_circle_vert[16][2] = { +static const float g_shape_preset_scroll_circle_vert[16][2] = { {0.382684, 0.923879}, {0.000001, 1.000000}, {-0.382683, 0.923880}, {-0.707107, 0.707107}, {-0.923879, 0.382684}, {-1.000000, 0.000000}, {-0.923880, -0.382684}, {-0.707107, -0.707107}, {-0.382683, -0.923880}, {0.000000, -1.000000}, {0.382684, -0.923880}, {0.707107, -0.707107}, {0.923880, -0.382684}, {1.000000, -0.000000}, {0.923880, 0.382683}, {0.707107, 0.707107} }; - -static const unsigned int scroll_circle_face[14][3] = { +static const uint g_shape_preset_scroll_circle_face[14][3] = { {0, 1, 2}, {2, 0, 3}, {3, 0, 15}, {3, 15, 4}, {4, 15, 14}, {4, 14, 5}, {5, 14, 13}, {5, 13, 6}, {6, 13, 12}, {6, 12, 7}, {7, 12, 11}, {7, 11, 8}, {8, 11, 10}, {8, 10, 9} }; - -static const float menu_tria_vert[6][2] = { +static const float g_shape_preset_menu_arrow_vert[6][2] = { {-0.33, 0.16}, {0.33, 0.16}, {0, 0.82}, {0, -0.82}, {-0.33, -0.16}, {0.33, -0.16} }; +static const uint g_shape_preset_menu_arrow_face[2][3] = {{2, 0, 1}, {3, 5, 4}}; - - -static const unsigned int menu_tria_face[2][3] = {{2, 0, 1}, {3, 5, 4}}; - -static const float check_tria_vert[6][2] = { +static const float g_shape_preset_checkmark_vert[6][2] = { {-0.578579, 0.253369}, {-0.392773, 0.412794}, {-0.004241, -0.328551}, {-0.003001, 0.034320}, {1.055313, 0.864744}, {0.866408, 1.026895} }; -static const unsigned int check_tria_face[4][3] = { +static const uint g_shape_preset_checkmark_face[4][3] = { {3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3} }; #define OY -0.2 #define SC 0.35 -static const unsigned int hold_action_tri_face[2][3] = {{2, 0, 1}, {3, 5, 4}}; -static const float hold_action_tri_vert[6][2] = { +static const float g_shape_preset_hold_action_vert[6][2] = { {-0.5 + SC, 1.0 + OY}, {0.5, 1.0 + OY}, {0.5, 0.0 + OY + SC}, }; +static const uint g_shape_preset_hold_action_face[2][3] = {{2, 0, 1}, {3, 5, 4}}; #undef OY #undef SC +/** \} */ + /* ************************************************* */ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3) @@ -498,9 +498,12 @@ static void round_box_edges(uiWidgetBase *wt, int roundboxalign, const rcti *rec round_box__edges(wt, roundboxalign, rect, rad, rad - U.pixelsize); } +/* -------------------------------------------------------------------- */ +/** \name Shape Preset Mini API + * \{ */ /* based on button rect, return scaled array of triangles */ -static void widget_draw_tria_ex( +static void shape_preset_init_trias_ex( uiWidgetTrias *tria, const rcti *rect, float triasize, char where, /* input data */ const float verts[][2], const int verts_tot, @@ -539,31 +542,31 @@ static void widget_draw_tria_ex( tria->index = tris; } -static void widget_num_tria(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) +static void shape_preset_init_number_arrows(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) { - widget_draw_tria_ex( + shape_preset_init_trias_ex( tria, rect, triasize, where, - num_tria_vert, ARRAY_SIZE(num_tria_vert), - num_tria_face, ARRAY_SIZE(num_tria_face)); + g_shape_preset_number_arrow_vert, ARRAY_SIZE(g_shape_preset_number_arrow_vert), + g_shape_preset_number_arrow_face, ARRAY_SIZE(g_shape_preset_number_arrow_face)); } -static void widget_hold_action_tria(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) +static void shape_preset_init_hold_action(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) { - widget_draw_tria_ex( + shape_preset_init_trias_ex( tria, rect, triasize, where, - hold_action_tri_vert, ARRAY_SIZE(hold_action_tri_vert), - hold_action_tri_face, ARRAY_SIZE(hold_action_tri_face)); + g_shape_preset_hold_action_vert, ARRAY_SIZE(g_shape_preset_hold_action_vert), + g_shape_preset_hold_action_face, ARRAY_SIZE(g_shape_preset_hold_action_face)); } -static void widget_scroll_circle(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) +static void shape_preset_init_scroll_circle(uiWidgetTrias *tria, const rcti *rect, float triasize, char where) { - widget_draw_tria_ex( + shape_preset_init_trias_ex( tria, rect, triasize, where, - scroll_circle_vert, ARRAY_SIZE(scroll_circle_vert), - scroll_circle_face, ARRAY_SIZE(scroll_circle_face)); + g_shape_preset_scroll_circle_vert, ARRAY_SIZE(g_shape_preset_scroll_circle_vert), + g_shape_preset_scroll_circle_face, ARRAY_SIZE(g_shape_preset_scroll_circle_face)); } -static void widget_trias_draw(uiWidgetTrias *tria) +static void shape_preset_draw_trias(uiWidgetTrias *tria) { glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, tria->vec); @@ -571,7 +574,7 @@ static void widget_trias_draw(uiWidgetTrias *tria) glDisableClientState(GL_VERTEX_ARRAY); } -static void widget_menu_trias(uiWidgetTrias *tria, const rcti *rect) +static void shape_preset_trias_from_rect_menu(uiWidgetTrias *tria, const rcti *rect) { float centx, centy, size; int a; @@ -582,15 +585,15 @@ static void widget_menu_trias(uiWidgetTrias *tria, const rcti *rect) size = 0.4f * BLI_rcti_size_y(rect); for (a = 0; a < 6; a++) { - tria->vec[a][0] = size * menu_tria_vert[a][0] + centx; - tria->vec[a][1] = size * menu_tria_vert[a][1] + centy; + tria->vec[a][0] = size * g_shape_preset_menu_arrow_vert[a][0] + centx; + tria->vec[a][1] = size * g_shape_preset_menu_arrow_vert[a][1] + centy; } tria->tot = 2; - tria->index = menu_tria_face; + tria->index = g_shape_preset_menu_arrow_face; } -static void widget_check_trias(uiWidgetTrias *tria, const rcti *rect) +static void shape_preset_trias_from_rect_checkmark(uiWidgetTrias *tria, const rcti *rect) { float centx, centy, size; int a; @@ -601,14 +604,16 @@ static void widget_check_trias(uiWidgetTrias *tria, const rcti *rect) size = 0.5f * BLI_rcti_size_y(rect); for (a = 0; a < 6; a++) { - tria->vec[a][0] = size * check_tria_vert[a][0] + centx; - tria->vec[a][1] = size * check_tria_vert[a][1] + centy; + tria->vec[a][0] = size * g_shape_preset_checkmark_vert[a][0] + centx; + tria->vec[a][1] = size * g_shape_preset_checkmark_vert[a][1] + centy; } tria->tot = 4; - tria->index = check_tria_face; + tria->index = g_shape_preset_checkmark_face; } +/** \} */ + /* prepares shade colors */ static void shadecolors4(char coltop[4], char coldown[4], const char *color, short shadetop, short shadedown) @@ -809,12 +814,13 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) for (j = 0; j < WIDGET_AA_JITTER; j++) { glTranslate2fv(jit[j]); - if (wtb->tria1.tot) - widget_trias_draw(&wtb->tria1); + if (wtb->tria1.tot) { + shape_preset_draw_trias(&wtb->tria1); + } + if (wtb->tria2.tot) { + shape_preset_draw_trias(&wtb->tria2); + } - if (wtb->tria2.tot) - widget_trias_draw(&wtb->tria2); - glTranslatef(-jit[j][0], -jit[j][1], 0.0f); } } @@ -2673,8 +2679,8 @@ static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int /* decoration */ if (!(state & UI_TEXTINPUT)) { - widget_num_tria(&wtb.tria1, rect, 0.6f, 'l'); - widget_num_tria(&wtb.tria2, rect, 0.6f, 'r'); + shape_preset_init_number_arrows(&wtb.tria1, rect, 0.6f, 'l'); + shape_preset_init_number_arrows(&wtb.tria2, rect, 0.6f, 'r'); } widgetbase_draw(&wtb, wcol); @@ -2809,12 +2815,12 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s wcol->item[3] = 255; if (horizontal) { - widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'l'); - widget_scroll_circle(&wtb.tria2, slider, 0.6f, 'r'); + shape_preset_init_scroll_circle(&wtb.tria1, slider, 0.6f, 'l'); + shape_preset_init_scroll_circle(&wtb.tria2, slider, 0.6f, 'r'); } else { - widget_scroll_circle(&wtb.tria1, slider, 0.6f, 'b'); - widget_scroll_circle(&wtb.tria2, slider, 0.6f, 't'); + shape_preset_init_scroll_circle(&wtb.tria1, slider, 0.6f, 'b'); + shape_preset_init_scroll_circle(&wtb.tria2, slider, 0.6f, 't'); } } widgetbase_draw(&wtb, wcol); @@ -3151,7 +3157,7 @@ static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), round_box_edges(&wtb, roundboxalign, rect, rad); /* decoration */ - widget_menu_trias(&wtb.tria1, rect); + shape_preset_trias_from_rect_menu(&wtb.tria1, rect); widgetbase_draw(&wtb, wcol); @@ -3290,7 +3296,7 @@ static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UN /* decoration */ if (state & UI_SELECT) { - widget_check_trias(&wtb.tria1, &recttemp); + shape_preset_trias_from_rect_checkmark(&wtb.tria1, &recttemp); } widgetbase_draw(&wtb, wcol); @@ -3397,7 +3403,7 @@ static void widget_roundbut_exec(uiWidgetColors *wcol, rcti *rect, int state, in if (state & UI_STATE_HOLD_ACTION) { /* Show that keeping pressed performs another action (typically a menu). */ - widget_hold_action_tria(&wtb.tria1, rect, 0.75f, 'r'); + shape_preset_init_hold_action(&wtb.tria1, rect, 0.75f, 'r'); } /* half rounded */ @@ -3660,6 +3666,10 @@ static int widget_roundbox_set(uiBut *but, rcti *rect) return roundbox; } +/* -------------------------------------------------------------------- */ +/** \name Public API + * \{ */ + /* conversion from old to new buttons, so still messy */ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect) { @@ -4233,3 +4243,5 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int UI_fontstyle_draw(fstyle, &trect, drawstr); } } + +/** \} */ |