xlat default theme name, fix stop blunder
[goodguy/history.git] / cinelerra-5.1 / plugins / titler / titlerwindow.C
index c295a943c6d3d34c609a90923b734d82aecfe658..01cddf4f7d7c468b1d82a5bfc22ce295b2a67936 100644 (file)
@@ -101,6 +101,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;
@@ -355,8 +357,7 @@ void TitleWindow::create_objects()
        outline = new TitleOutline(client, this, x, y1);
        outline->create_objects();
        x += outline->get_w() + 2*margin;
-#ifdef USE_STOKER
-// to different to be used
+#ifdef USE_STROKER
        add_tool(stroker_title = new BC_Title(x, y, _("Stroker:")));
        stroker = new TitleStroker(client, this, x, y1);
        stroker->create_objects();
@@ -384,6 +385,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);
@@ -458,6 +465,15 @@ int TitleWindow::resize_event(int w, int h)
 
 int TitleWindow::grab_event(XEvent *event)
 {
+       MWindow *mwindow = client->server->mwindow;
+       CWindowGUI *cwindow_gui = mwindow->cwindow->gui;
+       CWindowCanvas *canvas = cwindow_gui->canvas;
+       int cx, cy;  canvas->get_canvas()->get_relative_cursor_xy(cx, cy);
+       if( cx < mwindow->theme->ccanvas_x ) return 0;
+       if( cx >= mwindow->theme->ccanvas_x+mwindow->theme->ccanvas_w ) return 0;
+       if( cy < mwindow->theme->ccanvas_y ) return 0;
+       if( cy >= mwindow->theme->ccanvas_y+mwindow->theme->ccanvas_h ) return 0;
+
        switch( event->type ) {
        case ButtonPress:
                if( !dragging ) break;
@@ -471,11 +487,8 @@ int TitleWindow::grab_event(XEvent *event)
        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;
@@ -497,7 +510,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;
@@ -671,6 +684,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);
@@ -690,7 +711,7 @@ void TitleWindow::update()
        text->update(&client->config.wtext[0]);
        speed->update(client->config.pixels_per_second);
        outline->update((int64_t)client->config.outline_size);
-#ifdef USE_STOKER
+#ifdef USE_STROKER
        stroker->update((int64_t)client->config.stroke_width);
 #endif
        timecode->update(client->config.timecode);
@@ -708,6 +729,7 @@ void TitleWindow::update()
                }
        }
        update_justification();
+       update_stats();
        update_color();
 }
 
@@ -1002,7 +1024,7 @@ void TitleWindow::check_style(const char *font_name, int update)
        if( has_norm && has_bold ) bold->enable();   else bold->disable();
        if( has_norm && has_ital ) italic->enable(); else italic->disable();
        if( update ) {
-               int style = 0;
+               int style = stroker && atof(stroker->get_text()) ? BC_FONT_OUTLINE : 0;
                if( bold->get_value() ) style |= BC_FONT_BOLD;
                if( italic->get_value() ) style |= BC_FONT_ITALIC;
                client->config.style = style;
@@ -1048,13 +1070,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)
@@ -1086,6 +1148,7 @@ int TitleOutline::handle_event()
        return 1;
 }
 
+
 TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
  : BC_TumbleTextBox(window, (int64_t)client->config.stroke_width,
        (int64_t)0, (int64_t)1000, x, y, 70)
@@ -1095,8 +1158,8 @@ TitleStroker::TitleStroker(TitleMain *client, TitleWindow *window, int x, int y)
 }
 int TitleStroker::handle_event()
 {
-       client->config.stroke_width = atol(get_text());
-       if( client->config.stroke_width > 1 )
+       client->config.stroke_width = atof(get_text());
+       if( client->config.stroke_width )
                client->config.style |= BC_FONT_OUTLINE;
        else
                client->config.style &= ~BC_FONT_OUTLINE;
@@ -1268,7 +1331,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;
@@ -1366,7 +1429,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);
@@ -1385,7 +1448,7 @@ void TitleCurPopup::create_objects()
        sub_menu->add_subitem("/%s",item);
        add_item(cur_item = new TitleCurItem(this, item = KW_COLOR));
        cur_item->add_submenu(sub_menu = new TitleCurSubMenu(cur_item));
-       sub_menu->add_subitem(POPUP_COLOR,"%s #",item);
+       sub_menu->add_subitem(POPUP_COLOR,"%s %s",item,_("#"));
        sub_menu->add_subitem("%s ",item);
        sub_menu->add_subitem("/%s",item);
        add_item(cur_item = new TitleCurItem(this, item = KW_ALPHA));
@@ -1542,7 +1605,7 @@ int TitleFontsPopup::handle_event()
 }
 
 TitleColorPopup::TitleColorPopup(TitleMain *client, TitleWindow *window)
- : ColorThread(0, _("Color"))
+ : ColorPicker(0, _("Color"))
 {
        this->client = client;
        this->window = window;