X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbcwindowdraw.C;h=73b3d03437a04e03a2a9737d139901b5451d7ec7;hp=7164bab70a1cb5f53dcbd438aace39c575c9d09b;hb=eb9df615719cf3afe2bc08035900e5d3451034e1;hpb=0df48ad2d876409c5beeae2e21933a728ea76c33 diff --git a/cinelerra-5.1/guicast/bcwindowdraw.C b/cinelerra-5.1/guicast/bcwindowdraw.C index 7164bab7..73b3d034 100644 --- a/cinelerra-5.1/guicast/bcwindowdraw.C +++ b/cinelerra-5.1/guicast/bcwindowdraw.C @@ -211,21 +211,21 @@ void BC_WindowBase::draw_xft_text(int x, int y, const char *text, int length, BC_Pixmap *pixmap, int is_utf8) { int l = length + 1; - wchar_t wide_text[l]; + wchr_t wide_text[l]; length = BC_Resources::encode( is_utf8 ? "UTF8" : BC_Resources::encoding, BC_Resources::wide_encoding, - (char*)text, length, (char*)wide_text, l*sizeof(wchar_t)) / sizeof(wchar_t); + (char*)text, length, (char*)wide_text, l*sizeof(wchr_t)) / sizeof(wchr_t); draw_xft_text(x, y, wide_text, length, pixmap); } void BC_WindowBase::draw_xft_text(int x, int y, - const wchar_t *text, int length, BC_Pixmap *pixmap) + const wchr_t *text, int length, BC_Pixmap *pixmap) { int dy = -1; - const wchar_t *wsp = text, *wep = wsp + length; + const wchr_t *wsp = text, *wep = wsp + length; int font = top_level->current_font; while( wsp < wep ) { - const wchar_t *wcp = wsp; + const wchr_t *wcp = wsp; while( wcp < wep && *wcp != '\n' ) ++wcp; int len = wcp - wsp; if( len > 0 ) @@ -272,16 +272,16 @@ void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font, } } -int BC_WindowBase::get_single_text_width(int font, const wchar_t *text, int length) +int BC_WindowBase::get_single_text_width(int font, const wchr_t *text, int length) { return draw_single_text(0, font, 0,0, text, length); } int BC_WindowBase::draw_single_text(int draw, int font, - int x, int y, const wchar_t *text, int length, BC_Pixmap *pixmap) + int x, int y, const wchr_t *text, int length, BC_Pixmap *pixmap) { if( length < 0 ) - length = wcslen(text); + length = wstrlen(text); if( !length ) return 0; if( !get_resources()->use_xft ) { @@ -319,7 +319,7 @@ int BC_WindowBase::draw_single_text(int draw, int font, int x0 = x; XftFont *basefont = top_level->get_xft_struct(font); XftFont *curfont = 0, *altfont = 0; - const wchar_t *up = text, *ubp = up, *uep = ubp + length; + const wchr_t *up = text, *ubp = up, *uep = ubp + length; while( up < uep ) { XftFont *xft_font = 0; @@ -380,40 +380,6 @@ int BC_WindowBase::draw_single_text(int draw, int font, return x - x0; } -void BC_WindowBase::truncate_text(char *result, const char *text, int w) -{ - int new_w = get_text_width(current_font, text); - - if( new_w > w ) { - const char* separator = "..."; - int separator_w = get_text_width(current_font, separator); -// can't fit - if( separator_w >= w ) { - strcpy(result, separator); - return; - } - - int text_len = strlen(text); -// widen middle gap until it fits - for( int i=text_len/2; i>0; --i ) { - strncpy(result, text, i); - result[i] = 0; - strcat(result, separator); - strncat(result, text + text_len - i, i); - result[i + strlen(separator) + i] = 0; - new_w = get_text_width(current_font, result); -//printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result); - if(new_w < w) return; - } - -// Didn't fit - strcpy(result, separator); - return; - } - - strcpy(result, text); -} - void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length) { if(length < 0) length = strlen(text); @@ -422,11 +388,18 @@ void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length) draw_text(x, y, text, length); } +void BC_WindowBase::draw_pix(int x, int y, BC_Pixmap *pixmap) +{ // draw_pixel, no BT test + XDrawPoint(top_level->display, + pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, + top_level->gc, x, y); +} + void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap) { BT // Some X drivers can't draw 0 length lines if( x1 == x2 && y1 == y2 ) { - draw_pixel(x1, y1, pixmap); + draw_pix(x1, y1, pixmap); } else { XDrawLine(top_level->display, @@ -435,6 +408,43 @@ void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap) } } +void BC_WindowBase::draw_bline(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap) +{ BT +// Short lines are all overhead to hw or sw setup, use bresenhams + if( y1 > y2 ) { + int tx = x1; x1 = x2; x2 = tx; + int ty = y1; y1 = y2; y2 = ty; + } + + int x = x1, y = y1; + int dx = x2-x1, dy = y2-y1; + int dx2 = 2*dx, dy2 = 2*dy; + if( dx < 0 ) dx = -dx; + int r = dx > dy ? dx : dy, n = r; + int dir = 0; + if( dx2 < 0 ) dir += 1; + if( dy >= dx ) { + if( dx2 >= 0 ) do { /* +Y, +X */ + draw_pix(x, y++, pixmap); + if( (r -= dx2) < 0 ) { r += dy2; ++x; } + } while( --n >= 0 ); + else do { /* +Y, -X */ + draw_pix(x, y++, pixmap); + if( (r += dx2) < 0 ) { r += dy2; --x; } + } while( --n >= 0 ); + } + else { + if( dx2 >= 0 ) do { /* +X, +Y */ + draw_pix(x++, y, pixmap); + if( (r -= dy2) < 0 ) { r += dx2; ++y; } + } while( --n >= 0 ); + else do { /* -X, +Y */ + draw_pix(x--, y, pixmap); + if( (r -= dy2) < 0 ) { r -= dx2; ++y; } + } while( --n >= 0 ); + } +} + void BC_WindowBase::draw_polygon(ArrayList *x, ArrayList *y, BC_Pixmap *pixmap) { BT int npoints = MIN(x->total, y->total);