X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Ftitler%2Ftitlerwindow.C;h=c816d607954de7140e4fd817f1b2c96dddfc49de;hp=e2e1f972644e60fc7b60d8bc8030fe5a8c477ee8;hb=55ccff122957ddfaa871cf8f251cfe866732c870;hpb=80d314adea22f450161d9b2afaaafe108ac988be diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.C b/cinelerra-5.1/plugins/titler/titlerwindow.C index e2e1f972..c816d607 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.C +++ b/cinelerra-5.1/plugins/titler/titlerwindow.C @@ -32,7 +32,9 @@ #include "edlsession.h" #include "keys.h" #include "language.h" +#include "mainerror.h" #include "mwindow.h" +#include "mwindowgui.h" #include "plugin.h" #include "pluginserver.h" #include "theme.h" @@ -101,6 +103,8 @@ TitleWindow::TitleWindow(TitleMain *client) fade_out = 0; text_title = 0; text = 0; + text_chars = 0; + text_bfrsz = 0; justify_title = 0; left = 0; center = 0; right = 0; top = 0; mid = 0; bottom = 0; @@ -253,10 +257,13 @@ void TitleWindow::create_objects() int w1 = italic->get_w(); add_tool(bold = new TitleBold(client, this, x, y + 50)); if( bold->get_w() > w1 ) w1 = bold->get_w(); + add_tool(drag = new TitleDrag(client, this, x, y + 80)); if( drag->get_w() > w1 ) w1 = drag->get_w(); - if( client->config.drag ) - grab(client->server->mwindow->cwindow->gui); + if( client->config.drag ) { + if( !grab(client->server->mwindow->cwindow->gui) ) + eprintf("drag enabled, but compositor already grabbed\n"); + } x += w1 + margin; add_tool(justify_title = new BC_Title(x, y, _("Justify:"))); @@ -383,6 +390,12 @@ void TitleWindow::create_objects() x = 10; add_tool(text_title = new BC_Title(x, y, _("Text:"))); + x += text_title->get_w() + 20; + int wid = BC_Title::calculate_w(this,"0")*10; + add_tool(text_chars = new TitleTextChars(x,y,wid)); + x += text_chars->get_w() + 20; + add_tool(text_bfrsz = new TitleTextBfrSz(x,y,wid)); + y += text_title->get_h() + margin; x = margin; text = new TitleText(client, this, x, y, get_w()-margin - x, get_h() - y - 10); @@ -457,6 +470,25 @@ int TitleWindow::resize_event(int w, int h) int TitleWindow::grab_event(XEvent *event) { + switch( event->type ) { + case ButtonPress: break; + case ButtonRelease: break; + case MotionNotify: break; + default: return 0; + } + + MWindow *mwindow = client->server->mwindow; + CWindowGUI *cwindow_gui = mwindow->cwindow->gui; + CWindowCanvas *canvas = cwindow_gui->canvas; + int cx, cy; cwindow_gui->get_relative_cursor(cx, cy); + cx -= mwindow->theme->ccanvas_x; + cy -= mwindow->theme->ccanvas_y; + + if( !dragging ) { + if( cx < 0 || cx >= mwindow->theme->ccanvas_w ) return 0; + if( cy < 0 || cy >= mwindow->theme->ccanvas_h ) return 0; + } + switch( event->type ) { case ButtonPress: if( !dragging ) break; @@ -466,15 +498,13 @@ int TitleWindow::grab_event(XEvent *event) dragging = 0; return 1; case MotionNotify: - if( dragging ) break; + if( !dragging ) return 0; + break; default: return 0; } - MWindow *mwindow = client->server->mwindow; - CWindowGUI *cwindow_gui = mwindow->cwindow->gui; - CWindowCanvas *canvas = cwindow_gui->canvas; - float cursor_x = canvas->get_canvas()->get_relative_cursor_x(); - float cursor_y = canvas->get_canvas()->get_relative_cursor_y(); + + float cursor_x = cx, cursor_y = cy; canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y); int64_t position = client->get_source_position(); float projector_x, projector_y, projector_z; @@ -496,7 +526,7 @@ int TitleWindow::grab_event(XEvent *event) int y0 = title_y, y1 = title_y+(title_h+1)/2, y2 = title_y+title_h; int drag_dx = 0, drag_dy = 0; if( !dragging ) { // clockwise - if( abs(drag_dx = cursor_x-x0) < r && // x0,y0 + if( abs(drag_dx = cursor_x-x0) < r && // x0,y0 abs(drag_dy = cursor_y-y0) < r ) dragging = 1; else if( abs(drag_dx = cursor_x-x1) < r && // x1,y0 abs(drag_dy = cursor_y-y0) < r ) dragging = 2; @@ -670,6 +700,14 @@ void TitleWindow::update_justification() bottom->update(client->config.vjustification == JUSTIFY_BOTTOM); } +void TitleWindow::update_stats() +{ + text_chars->update(client->config.wlen); + int len = MESSAGESIZE - BCTEXTLEN - strlen(text->get_text()) - 1; + if( len < 0 ) len = 0; + text_bfrsz->update(len); +} + void TitleWindow::update() { title_x->update((int64_t)client->config.title_x); @@ -707,6 +745,7 @@ void TitleWindow::update() } } update_justification(); + update_stats(); update_color(); } @@ -1047,13 +1086,53 @@ int TitleText::button_press_event() int TitleText::handle_event() { window->fonts_popup->deactivate(); + int text_len = strlen(get_text()); + int avail = MESSAGESIZE - BCTEXTLEN; + if( text_len >= avail ) { // back off last utf8 char + char text[2*sizeof(client->config.wtext)]; + strcpy(text, get_text()); + text_len = avail; + while( text_len > 0 && (text[text_len-1] & 0xc0) == 0x80 ) + text[--text_len] = 0; + if( text_len > 0 ) + text[--text_len] = 0; + update(text); + } int len = sizeof(client->config.wtext) / sizeof(wchar_t); wcsncpy(client->config.wtext, get_wtext(), len); client->config.wtext[len-1] = 0; client->config.wlen = wcslen(client->config.wtext); + window->update_stats(); client->send_configure_change(); return 1; } +TitleTextChars::TitleTextChars(int x, int y, int w) + : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w) +{ +} +TitleTextChars::~TitleTextChars() +{ +} +int TitleTextChars::update(int n) +{ + char text[BCSTRLEN]; + sprintf(text, _("chars: %d "),n); + return BC_Title::update(text, 0); +} + +TitleTextBfrSz::TitleTextBfrSz(int x, int y, int w) + : BC_Title(x, y, "", MEDIUMFONT, -1, 0, w) +{ +} +TitleTextBfrSz::~TitleTextBfrSz() +{ +} +int TitleTextBfrSz::update(int n) +{ + char text[BCSTRLEN]; + sprintf(text, _("bfrsz: %d "),n); + return BC_Title::update(text, 0); +} TitleDropShadow::TitleDropShadow(TitleMain *client, TitleWindow *window, int x, int y) @@ -1268,7 +1347,7 @@ int TitleBottom::handle_event() TitleColorThread::TitleColorThread(TitleMain *client, TitleWindow *window, int is_outline) - : ColorThread(1, is_outline? _("Outline Color") : _("Text Color")) + : ColorPicker(1, is_outline? _("Outline Color") : _("Text Color")) { this->client = client; this->window = window; @@ -1305,11 +1384,16 @@ TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y) int TitleDrag::handle_event() { int value = get_value(); - client->config.drag = value; - if( value ) - window->grab(client->server->mwindow->cwindow->gui); + CWindowGUI *cwindow_gui = client->server->mwindow->cwindow->gui; + if( value ) { + if( !window->grab(cwindow_gui) ) { + update(value = 0); + flicker(10,50); + } + } else - window->ungrab(client->server->mwindow->cwindow->gui); + window->ungrab(cwindow_gui); + client->config.drag = value; client->send_configure_change(); return 1; } @@ -1366,7 +1450,7 @@ int TitleCurPopup::handle_event() return 1; } -void TitleCurSubMenu::add_subitem(int popup_type, va_list ap, const char *fmt) +void TitleCurSubMenu::add_subitemx(int popup_type, va_list ap, const char *fmt) { char item[BCSTRLEN]; vsnprintf(item, sizeof(item)-1, fmt, ap); @@ -1488,7 +1572,7 @@ int TitleCurSubMenuItem::handle_event() switch( popup_type ) { case POPUP_FONT: { int px, py; - window->get_pop_cursor_xy(px ,py); + window->get_pop_cursor(px ,py); window->fonts_popup->activate(px, py, 300,200); return 1; } case POPUP_COLOR: { @@ -1542,7 +1626,7 @@ int TitleFontsPopup::handle_event() } TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window) - : ColorThread(0, _("Color")) + : ColorPicker(0, _("Color")) { this->client = client; this->window = window; @@ -1591,13 +1675,12 @@ void TitlePngPopup::handle_done_event(int result) BC_Window *TitlePngPopup::new_gui() { - BC_DisplayInfo display_info; - int x = display_info.get_abs_cursor_x(); - int y = display_info.get_abs_cursor_y(); + MWindow *mwindow = client->server->mwindow; + int x, y; mwindow->gui->get_abs_cursor(x, y); - BC_Window *gui = new BrowseButtonWindow(client->server->mwindow->theme, + BC_Window *gui = new BrowseButtonWindow(mwindow->theme, x-25, y-100, window, "", _("Png file"), _("Png path"), 0); - gui->create_objects(); + gui->create_objects(); return gui; }