Commit: b64b18f8acb757e79756a2ffad064a3cc82e522d
Author: Severin
Date:   Thu Dec 4 19:12:05 2014 +0100
Branches: input_method_editor
https://developer.blender.org/rBb64b18f8acb757e79756a2ffad064a3cc82e522d

IME: Refactor Underline Drawing Code

* ED_text_draw_underline is now UI_text_draw_underline and is used for all
IDE appearances
* usual minor cleanup

===================================================================

M       source/blender/editors/include/ED_space_api.h
M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_draw.c
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/interface/interface_widgets.c
M       source/blender/editors/space_info/textview.c
M       source/blender/editors/space_text/text_draw.c
M       source/blender/editors/util/ed_util.c

===================================================================

diff --git a/source/blender/editors/include/ED_space_api.h 
b/source/blender/editors/include/ED_space_api.h
index 204c0e1..d268c57 100644
--- a/source/blender/editors/include/ED_space_api.h
+++ b/source/blender/editors/include/ED_space_api.h
@@ -78,6 +78,5 @@ void *ED_region_draw_cb_customdata(void *handle);
 /* generic callbacks */
 /* ed_util.c */
 void ED_region_draw_mouse_line_cb(const struct bContext *C, struct ARegion 
*ar, void *arg_info);
-void ED_text_draw_underline(int x, int y, int len, int height);
 
 #endif /* __ED_SPACE_API_H__ */
diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index f7e34c9..402d54c 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -313,6 +313,7 @@ void UI_draw_box_shadow(unsigned char alpha, float minx, 
float miny, float maxx,
 void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, 
float maxy, float rad);
 void UI_draw_roundbox_shade_x(int mode, float minx, float miny, float maxx, 
float maxy, float rad, float shadetop, float shadedown);
 void UI_draw_roundbox_shade_y(int mode, float minx, float miny, float maxx, 
float maxy, float rad, float shadeLeft, float shadeRight);
+void UI_text_draw_underline(int pos_x, int pos_y, int len, int height);
 
 /* state for scrolldrawing */
 #define UI_SCROLL_PRESSED       (1 << 0)
diff --git a/source/blender/editors/interface/interface_draw.c 
b/source/blender/editors/interface/interface_draw.c
index 4dd952f..c145092 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -395,6 +395,11 @@ void UI_draw_roundbox(float minx, float miny, float maxx, 
float maxy, float rad)
        ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad, 
roundboxtype & UI_RB_ALPHA);
 }
 
+void UI_text_draw_underline(int pos_x, int pos_y, int len, int height) {
+       short ofs_y = 4 * U.pixelsize;
+       glRecti(pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * 
U.pixelsize));
+}
+
 /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
 
 void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors 
*UNUSED(wcol), const rcti *rect)
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index fef9e20..e18150d 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -2455,6 +2455,7 @@ void ui_but_ime_reposition(uiBut *but, int x, int y, int 
complete)
        wm_window_IME_begin(but->active->window, x, y - 4, 0, 0, complete);
 }
 
+/* should be ui_but_ime_data_get */
 wmImeData *ui_but_get_ime_data(uiBut *but) 
 {
        if (but->active && but->active->window)
diff --git a/source/blender/editors/interface/interface_widgets.c 
b/source/blender/editors/interface/interface_widgets.c
index c027406..97f3567 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1236,6 +1236,48 @@ static void ui_text_clip_right_label(uiFontStyle 
*fstyle, uiBut *but, const rcti
                BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
 }
 
+#ifdef WITH_INPUT_IME
+static void widget_draw_text_ime_underline(uiFontStyle *fstyle, uiWidgetColors 
*wcol, uiBut *but, rcti *rect, wmImeData *ime_data, char *drawstr)
+{
+       int ofs_x, width;
+       int rect_x = BLI_rcti_size_x(rect);
+       int target_start = ime_data->target_start, target_end = 
ime_data->target_end;
+
+       if (drawstr[0] != 0) {
+               if (but->pos >= but->ofs) {
+                       ofs_x = BLF_width(fstyle->uifont_id, drawstr + 
but->ofs, but->pos - but->ofs);
+               }
+               else {
+                       ofs_x = 0;
+               }
+
+               width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
+                                 ime_data->composite_len + but->pos - 
but->ofs);
+
+               glColor4ubv((unsigned char *)wcol->text);
+               UI_text_draw_underline(rect->xmin + ofs_x, rect->ymin + 6 * 
U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1);
+
+               /* draw the thick line */
+               if (target_start != -1 && target_end != -1) {
+                       target_end -= target_start;
+                       target_start += but->pos;
+
+                       if (target_start >= but->ofs) {
+                               ofs_x = BLF_width(fstyle->uifont_id, drawstr + 
but->ofs, target_start - but->ofs);
+                       }
+                       else {
+                               ofs_x = 0;
+                       }
+
+                       width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
+                                         target_end + target_start - but->ofs);
+
+                       UI_text_draw_underline(rect->xmin + ofs_x, rect->ymin + 
6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2);
+               }
+       }
+}
+#endif
+
 static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut 
*but, rcti *rect)
 {
        int drawstr_left_len = UI_MAX_DRAW_STR;
@@ -1278,16 +1320,13 @@ static void widget_draw_text(uiFontStyle *fstyle, 
uiWidgetColors *wcol, uiBut *b
 
                        if (ime_data && ime_data->composite_len) {
                                /* insert composite string into cursor pos */
-                               BLI_snprintf(drawstr, UI_MAX_DRAW_STR, 
"%s%s%s", /* XXX drawstr is limited to 400 chars - check if that's enough */
+                               BLI_snprintf(drawstr, UI_MAX_DRAW_STR, "%s%s%s",
                                             but->editstr, ime_data->composite,
                                             but->editstr + but->pos);
                        }
-                       else {
-#else
-                       if (1) {
+                       else
 #endif
                                drawstr = but->editstr;
-                       }
                }
        }
 
@@ -1322,13 +1361,12 @@ static void widget_draw_text(uiFontStyle *fstyle, 
uiWidgetColors *wcol, uiBut *b
 
                /* text cursor */
                vpos = but->pos;
+
 #ifdef WITH_INPUT_IME
                /* if is ime compositing, move the cursor */
                if (ime_data && ime_data->composite_len && 
ime_data->cursor_position != -1) {
                        vpos += ime_data->cursor_position;
                }
-#else
-               (void)ime;
 #endif
 
                if (but->pos >= but->ofs) {
@@ -1342,60 +1380,26 @@ static void widget_draw_text(uiFontStyle *fstyle, 
uiWidgetColors *wcol, uiBut *b
 
                        glColor3f(0.20, 0.6, 0.9);
 
-#ifdef WITH_INPUT_IME
                        tx = rect->xmin + t + 2;
                        ty = rect->ymin + 2;
-                       glRecti(rect->xmin + t, ty, tx, rect->ymax - 2);
 
-                       /* ime cursor following */
-                       ui_but_ime_reposition(but, tx + 5, ty + 3, false);
+                       /* draw cursor */
+                       glRecti(rect->xmin + t, ty, tx, rect->ymax - 2);
                }
 
-               /* composite underline */
+#ifdef WITH_INPUT_IME
                if (ime_data && ime_data->composite_len) {
-                       int draw_start, draw_end, target_start = 
ime_data->target_start, target_end = ime_data->target_end;
-
-                       if (drawstr[0] != 0) {
-
-                               if (but->pos >= but->ofs) {
-                                       draw_start = 
BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->pos - but->ofs);
-                               }
-                               else {
-                                       draw_start = 0;
-                               }
-
-                               draw_end = BLF_width(fstyle->uifont_id, drawstr 
+ but->ofs, 
-                                                    ime_data->composite_len + 
but->pos - but->ofs);
-
-                               glColor4ubv((unsigned char *)wcol->text);
-                               glRecti(rect->xmin + draw_start,
-                                       rect->ymin + 2,
-                                       min_ii(rect->xmin + draw_end, 
rect->xmax - 2), rect->ymin + 1);
-
-                               /* draw the thick line */
-                               if (target_start != -1 && target_end != -1) {
-                                       target_end -= target_start;
-                                       target_start += but->pos;
-
-                                       if (target_start >= but->ofs) {
-                                               draw_start = 
BLF_width(fstyle->uifont_id, drawstr + but->ofs, target_start - but->ofs);
-                                       }
-                                       else {
-                                               draw_start = 0;
-                                       }
-
-                                       draw_end = BLF_width(fstyle->uifont_id, 
drawstr + but->ofs,
-                                                            target_end + 
target_start - but->ofs);
-
-                                       glRecti(rect->xmin + draw_start,
-                                               rect->ymin + 3,
-                                               min_ii(rect->xmin + draw_end, 
rect->xmax - 2), rect->ymin + 1);
-                               }
+                       /* ime cursor following */
+                       if (but->pos >= but->ofs) {
+                               ui_but_ime_reposition(but, tx + 5, ty + 3, 
false);
                        }
+
+                       /* composite underline */
+                       widget_draw_text_ime_underline(fstyle, wcol, but, rect, 
ime_data, drawstr);
+               }
 #else
-                       (void)ty; (void)tx;
+                       (void)ime_data;
 #endif
-               }
        }
        
        if (fstyle->kerning == 1)
diff --git a/source/blender/editors/space_info/textview.c 
b/source/blender/editors/space_info/textview.c
index 5ce5237..592a2dd 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -46,6 +46,8 @@
 
 #include "textview.h"
 
+#include "UI_interface.h"
+
 #include "WM_types.h"
 
 static void console_font_begin(TextViewContext *sc)
@@ -92,19 +94,19 @@ static void console_draw_sel(const char *str, const int 
sel[2], const int xy[2],
 }
 
 static void console_draw_underline(const char *str, const int sel[2], const 
int xy[2], const int str_len_draw,
-                                                              int cwidth, int 
lheight, const unsigned char bg_sel[4])
+                                                              const int 
cwidth, const int height, const unsigned char bg_sel[4])
 {
        if (sel[0] <= str_len_draw && sel[1] >= 0) {
-               const int sta = txt_utf8_offset_to_column(str, max_ii(sel[0], 
0));
-               const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], 
str_len_draw));
-               int tmp[2];
+               const int col_xmin = txt_utf8_offset_to_column(str, 
max_ii(sel[0], 0));
+               const int col_xmax = txt_utf8_offset_to_column(str, 
min_ii(sel[1], str_len_draw));
+
+               const int x = xy[0] + (cwidth * col_xmin);
+               const int y = xy[1];
+               const int width = (xy[0] + (cwidth * col_xmax)) - x;
 
                glColor3ubv(bg_sel);
 
-               /* return the coord for IME window following */
-               tmp[0] = xy[0] + (cwidth * end);
-               tmp[1] = xy[1] - 2;
-               glRecti(xy[0] + (cwidth * sta), xy[1] - 2 + lheight, tmp[0], 
tmp[1]);
+               UI_text_draw_underline(x, y, width, height);
        }
 }
 
diff --git a/source/blender/editors/space_text/text_draw.c 
b/source/blender/editors/space_text/text_draw.c
index 216937b..91b1a0d 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -48,8 +48,6 @@
 
 #include "BIF_gl.h"
 
-#include "ED_space_api.h"
-
 #include "UI_interface.h"
 #include "UI_resources.h"
 #include "UI_view2d.h"
@@ -425,10 +423,10 @@ static int text_draw_wrapped(SpaceText *st, const char 
*str, int x, int y, int w
                                len = text_font_draw_character_utf8(st, x, y, 
str + ma);
                                /* draw underline */
                                if (format && format[a] == FMT_TYPE_ULINE)
-                                       ED_text_draw_underline(x, y, len, 1);
+                                       UI_text_draw_underline(x, y, len, 1);
                                else
                                if (format && format[a] == FMT_TYPE_TULINE)
-                                       ED_text_draw_underline(x, y, len, 2);
+                                       UI_text_draw_underline(x, y, len, 2);
                                

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to