diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-08-31 15:53:44 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-08-31 15:53:44 +0300 |
commit | 6c87958dac15e8c02c59d5c5c528f1ffb013962a (patch) | |
tree | d4d6cec2e587aceff7be60a5ef9bb766f713d75f /source/blender/draw/modes/edit_text_mode.c | |
parent | d7c58cd8f73938740cab287c303cda9cd5ae8bb1 (diff) |
Fix Text Boxes not drawing
I'm using a different shading group for the active text box and the others.
This way I can assign different colors to them.
The alternative would be to create a new `shgroup_dynlines_dashed_flat_color`,
but I find this overkill for such a simple use case.
Diffstat (limited to 'source/blender/draw/modes/edit_text_mode.c')
-rw-r--r-- | source/blender/draw/modes/edit_text_mode.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/blender/draw/modes/edit_text_mode.c b/source/blender/draw/modes/edit_text_mode.c index f21715ef399..ec8d4fbb25b 100644 --- a/source/blender/draw/modes/edit_text_mode.c +++ b/source/blender/draw/modes/edit_text_mode.c @@ -58,6 +58,7 @@ typedef struct EDIT_TEXT_PassList { struct DRWPass *wire_pass; struct DRWPass *overlay_select_pass; struct DRWPass *overlay_cursor_pass; + struct DRWPass *text_box_pass; } EDIT_TEXT_PassList; typedef struct EDIT_TEXT_FramebufferList { @@ -110,6 +111,8 @@ typedef struct EDIT_TEXT_PrivateData { DRWShadingGroup *wire_shgrp; DRWShadingGroup *overlay_select_shgrp; DRWShadingGroup *overlay_cursor_shgrp; + DRWShadingGroup *box_shgrp; + DRWShadingGroup *box_active_shgrp; } EDIT_TEXT_PrivateData; /* Transient data */ /* *********** FUNCTIONS *********** */ @@ -181,6 +184,67 @@ static void EDIT_TEXT_cache_init(void *vedata) "Font Cursor", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH); stl->g_data->overlay_cursor_shgrp = DRW_shgroup_create(e_data.overlay_cursor_sh, psl->overlay_cursor_pass); + + psl->text_box_pass = DRW_pass_create( + "Font Text Boxes", + DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH); + stl->g_data->box_shgrp = shgroup_dynlines_dashed_uniform_color(psl->text_box_pass, ts.colorWire); + stl->g_data->box_active_shgrp = shgroup_dynlines_dashed_uniform_color(psl->text_box_pass, ts.colorActive); + } +} + +static void edit_text_cache_populate_boxes(void *vedata, Object *ob) +{ + EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl; + const Curve *cu = ob->data; + + DRWShadingGroup *shading_groups[] = { + stl->g_data->box_active_shgrp, + stl->g_data->box_shgrp, + }; + + float vec[3], vec1[3], vec2[3]; + for (int i = 0; i < cu->totbox; i++) { + TextBox *tb = &cu->tb[i]; + + if ((tb->w == 0.0f) && (tb->h == 0.0f)) { + continue; + } + + const bool is_active = i == (cu->actbox - 1); + DRWShadingGroup *shading_group = shading_groups[is_active ? 0 : 1]; + + vec[0] = cu->xof + tb->x; + vec[1] = cu->yof + tb->y + cu->fsize; + vec[2] = 0.001; + + mul_v3_m4v3(vec1, ob->obmat, vec); + vec[0] += tb->w; + mul_v3_m4v3(vec2, ob->obmat, vec); + + DRW_shgroup_call_dynamic_add(shading_group, vec1); + DRW_shgroup_call_dynamic_add(shading_group, vec2); + + vec[1] -= tb->h; + copy_v3_v3(vec1, vec2); + mul_v3_m4v3(vec2, ob->obmat, vec); + + DRW_shgroup_call_dynamic_add(shading_group, vec1); + DRW_shgroup_call_dynamic_add(shading_group, vec2); + + vec[0] -= tb->w; + copy_v3_v3(vec1, vec2); + mul_v3_m4v3(vec2, ob->obmat, vec); + + DRW_shgroup_call_dynamic_add(shading_group, vec1); + DRW_shgroup_call_dynamic_add(shading_group, vec2); + + vec[1] += tb->h; + copy_v3_v3(vec1, vec2); + mul_v3_m4v3(vec2, ob->obmat, vec); + + DRW_shgroup_call_dynamic_add(shading_group, vec1); + DRW_shgroup_call_dynamic_add(shading_group, vec2); } } @@ -218,6 +282,8 @@ static void EDIT_TEXT_cache_populate(void *vedata, Object *ob) if (geom) { DRW_shgroup_call_add(stl->g_data->overlay_cursor_shgrp, geom, ob->obmat); } + + edit_text_cache_populate_boxes(vedata, ob); } } } @@ -255,6 +321,10 @@ static void EDIT_TEXT_draw_scene(void *vedata) DRW_draw_pass(psl->wire_pass); + if (!DRW_pass_is_empty(psl->text_box_pass)) { + DRW_draw_pass(psl->text_box_pass); + } + set_inverted_drawing(1); DRW_draw_pass(psl->overlay_select_pass); DRW_draw_pass(psl->overlay_cursor_pass); |