X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Ftitler%2Ftitlerwindow.C;h=21270b6825466d21f3e743118267bf4d9005cba0;hp=84f50a36ca6dd01a2b25b8edd5ef781f66b738f5;hb=128492e56ad719c2173a56379f423f6791f14906;hpb=d17640d4122d028eee849d9fedf8ba35f7f0f6e0 diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.C b/cinelerra-5.1/plugins/titler/titlerwindow.C index 84f50a36..21270b68 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.C +++ b/cinelerra-5.1/plugins/titler/titlerwindow.C @@ -40,9 +40,12 @@ #include "pluginserver.h" #include "theme.h" #include "track.h" +#include "tracks.h" #include "titlerwindow.h" #include "bcfontentry.h" +#define DEFAULT_TIMECODEFORMAT TIME_HMSF + static const int timeunit_formats[] = { TIME_HMS, @@ -138,6 +141,8 @@ TitleWindow::~TitleWindow() delete timecode_format; delete title_x; delete title_y; + delete title_w; + delete title_h; } void TitleWindow::create_objects() @@ -258,13 +263,13 @@ void TitleWindow::create_objects() add_tool(bold = new TitleBold(client, this, x, y + yS(50))); if( bold->get_w() > w1 ) w1 = bold->get_w(); + if( client->drag && drag->drag_activate() ) { + eprintf("drag enabled, but compositor already grabbed\n"); + client->drag = 0; + } add_tool(drag = new TitleDrag(client, this, x, y + yS(80))); drag->create_objects(); if( drag->get_w() > w1 ) w1 = drag->get_w(); - if( client->config.drag ) { - if( drag->drag_activate() ) - eprintf("drag enabled, but compositor already grabbed\n"); - } add_tool(alias = new TitleAlias(client, this, x, y+yS(110))); if( alias->get_w() > w1 ) w1 = drag->get_w(); @@ -368,6 +373,12 @@ void TitleWindow::create_objects() stroker->create_objects(); x += stroker->get_w() + margin; #endif + // my reset button + // + add_tool(reset_button = new TitleResetButton(client, this, x3, y1+yS(30))); + reset_button->create_objects(); + + add_tool(timecode = new TitleTimecode(client, this, x, y)); y += timecode->get_h() + margin; int tw = 0; @@ -443,6 +454,7 @@ int TitleWindow::resize_event(int w, int h) pitch_title->reposition_window(pitch_title->get_x(), pitch_title->get_y()); pitch->reposition_window(pitch->get_x(), pitch->get_y()); + reset_button->reposition_window(reset_button->get_x(), reset_button->get_y()); color_button_title->reposition_window(color_button_title->get_x(), color_button_title->get_y()); color_button->reposition_window(color_button->get_x(), color_button->get_y()); outline_button_title->reposition_window(outline_button_title->get_x(), outline_button_title->get_y()); @@ -530,9 +542,9 @@ int TitleWindow::insert_ibeam(const char *txt, int ofs) { int ibeam = cur_ibeam; int ilen = strlen(txt)+1; - wchar_t wtxt[ilen]; + wchr_t wtxt[ilen]; int len = BC_Resources::encode(client->config.encoding, BC_Resources::wide_encoding, - (char*)txt,ilen, (char *)wtxt,ilen*sizeof(wtxt[0])) / sizeof(wchar_t); + (char*)txt,ilen, (char *)wtxt,ilen*sizeof(wtxt[0])) / sizeof(wchr_t); client->insert_text(wtxt, ibeam); while( len > 0 && !wtxt[len] ) --len; int adv = len+1 + ofs; @@ -571,10 +583,15 @@ void TitleWindow::update_gui() title_y->update((int64_t)client->config.title_y); title_w->update((int64_t)client->config.title_w); title_h->update((int64_t)client->config.title_h); + drag->drag_x = client->config.title_x; + drag->drag_y = client->config.title_y; + drag->drag_w = client->config.title_w; + drag->drag_h = client->config.title_h; italic->update(client->config.style & BC_FONT_ITALIC); bold->update(client->config.style & BC_FONT_BOLD); alias->update(client->config.style & FONT_ALIAS); size->update(client->config.size); + pitch->update((int64_t)client->config.line_pitch); motion->update(TitleMain::motion_to_text(client->config.motion_strategy)); loop->update(client->config.loop); dropshadow->update((int64_t)client->config.dropshadow); @@ -582,7 +599,8 @@ void TitleWindow::update_gui() fade_out->update((float)client->config.fade_out); font->update(client->config.font); check_style(client->config.font,0); - text->update(client->config.wtext ? &client->config.wtext[0] : L""); + wchr_t wz[1] = { 0 }; + text->update(client->config.wtext ? &client->config.wtext[0] : wz); speed->update(client->config.pixels_per_second); outline->update((int64_t)client->config.outline_size); #ifdef USE_STROKER @@ -773,6 +791,62 @@ int TitlePitch::handle_event() return 1; } + + +TitleResetButton::TitleResetButton(TitleMain *client, TitleWindow *window, int x, int y) + : BC_GenericButton (x, y, _("Reset")) +{ + this->client = client; + this->window = window; + set_tooltip("Reset to default values"); +} + +TitleResetButton:: +~TitleResetButton() +{ +} + +int TitleResetButton::handle_event() +{ + strcpy(client->config.font, "fixed"); + client->config.title_x = 0; + client->config.title_y = 0; + client->config.title_w = 0; + client->config.title_h = 0; + client->config.hjustification = JUSTIFY_CENTER; + client->config.vjustification = JUSTIFY_MID; + client->config.style = FONT_ALIAS; + client->config.motion_strategy = NO_MOTION; + client->config.timecode_format = DEFAULT_TIMECODEFORMAT; + client->config.loop = 0; + client->config.dropshadow = 0; + client->config.fade_in = 0; + client->config.fade_out = 0; + client->config.pixels_per_second = 100; + client->config.outline_size = 0; + client->config.outline_color = RED; + client->config.outline_alpha = 0xff; + client->config.color_stroke = 0xff0000; + client->config.size = 48; + client->config.line_pitch = 0; + client->config.color = WHITE; + client->config.alpha = 0xff; + client->config.timecode = 0; + client->config.background = 0; + strcpy(client->config.background_path, ""); +#ifdef USE_STROKER + client->config.stroke_width = 0; +#endif + client->config.loop_playback = 0; + client->config.wlen = 0; + wchr_t wz = { 0 }; + client->config.wtext[0] = wz; + window->send_configure_change(); + window->update_gui(); + window->flush(); + return 1; +} + TitleColorButton::TitleColorButton(TitleMain *client, TitleWindow *window, int x, int y) : ColorCircleButton(_("Text Color"), x, y, COLOR_W, COLOR_H, client->config.color, client->config.alpha, 1) @@ -987,10 +1061,10 @@ int TitleText::button_press_event() int TitleText::handle_event() { window->fonts_popup->deactivate(); - const wchar_t *wtext = get_wtext(); - long wlen = wcslen(wtext); + const wchr_t *wtext = get_wtext(); + long wlen = wstrlen(wtext); client->config.demand(wlen); - wcsncpy(client->config.wtext, wtext, client->config.wsize); + wstrncpy(client->config.wtext, wtext, client->config.wsize); client->config.wlen = wlen; window->update_stats(); window->send_configure_change(); @@ -1226,7 +1300,7 @@ int TitleBottom::handle_event() } TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y) - : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->config.drag, + : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->drag, client->config.title_x, client->config.title_y, client->config.title_w, client->config.title_h) { @@ -1236,8 +1310,10 @@ TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y) Track *TitleDrag::get_drag_track() { - return !client->server->plugin ? 0 : - client->server->plugin->track; + PluginServer *server = client->server; + int plugin_id = server->plugin_id; + Plugin *plugin = server->edl->tracks->plugin_exists(plugin_id); + return !plugin ? 0 : plugin->track; } int64_t TitleDrag::get_drag_position() { @@ -1246,7 +1322,7 @@ int64_t TitleDrag::get_drag_position() void TitleDrag::update_gui() { - client->config.drag = get_value(); + client->drag = get_value(); client->config.title_x = drag_x; client->config.title_y = drag_y; client->config.title_w = drag_w+0.5; @@ -1261,6 +1337,7 @@ void TitleDrag::update_gui() int TitleDrag::handle_event() { int ret = DragCheckBox::handle_event(); + client->drag = get_value(); window->send_configure_change(); return ret; } @@ -1436,11 +1513,75 @@ TitleCurSubMenuItem::TitleCurSubMenuItem(TitleCurSubMenu *submenu, const char *t TitleCurSubMenuItem::~TitleCurSubMenuItem() { } + +// from https://stackoverflow.com/questions/779875/what-function-is-to-replace-a-substring-from-a-string-in-c +void strreplace(char *src, char *str, char *rep) +{ + char *p = strstr(src, str); + if (p) + { + int len = strlen(src)+strlen(rep)-strlen(str); + char r[len]; + memset(r, 0, len); + if ( p >= src ){ + strncpy(r, src, p-src); + r[p-src]='\0'; + strncat(r, rep, strlen(rep)); + strncat(r, p+strlen(str), p+strlen(str)-src+strlen(src)); + strcpy(src, r); + strreplace(p+strlen(rep), str, rep); + } + } +} + + int TitleCurSubMenuItem::handle_event() { TitleCurPopup *popup = submenu->cur_item->popup; TitleWindow *window = popup->window; - const char *item_text = get_text(); + char *item_text = N_(get_text()); + + if (strstr(item_text, _(KW_NUDGE))) { + strreplace(item_text, _(KW_NUDGE), (char*)N_(KW_NUDGE)); + } + else if (strstr(item_text, _(KW_COLOR))) { + strreplace(item_text, _(KW_COLOR), (char*)N_(KW_COLOR)); + } + else if (strstr(item_text, _(KW_ALPHA))) { + strreplace(item_text, _(KW_ALPHA), (char*)N_(KW_ALPHA)); + } + else if (strstr(item_text, _(KW_FONT))) { + strreplace(item_text, _(KW_FONT), (char*)N_(KW_FONT)); + } + else if (strstr(item_text, _(KW_SIZE))) { + strreplace(item_text, _(KW_SIZE), (char*)N_(KW_SIZE)); + } + else if (strstr(item_text, _(KW_BOLD))) { + strreplace(item_text, _(KW_BOLD), (char*)N_(KW_BOLD)); + } + else if (strstr(item_text, _(KW_ITALIC))) { + strreplace(item_text, _(KW_ITALIC), (char*)N_(KW_ITALIC)); + } + else if (strstr(item_text, _(KW_CAPS))) { + strreplace(item_text, _(KW_CAPS), (char*)N_(KW_CAPS)); + } + else if (strstr(item_text, _(KW_UL))) { + strreplace(item_text, _(KW_UL), (char*)N_(KW_UL)); + } + else if (strstr(item_text, _(KW_BLINK))) { + strreplace(item_text, _(KW_BLINK), (char*)N_(KW_BLINK)); + } + else if (strstr(item_text, _(KW_FIXED))) { + strreplace(item_text, _(KW_FIXED), (char*)N_(KW_FIXED)); + } + else if (strstr(item_text, _(KW_ALIAS))) { + strreplace(item_text, _(KW_ALIAS), (char*)N_(KW_ALIAS)); + } + else if (strstr(item_text, _(KW_SUP))) { + strreplace(item_text, _(KW_SUP), (char*)N_(KW_SUP)); + } + + int ofs = *item_text == '/' ? 0 : -1; switch( popup_type ) { case POPUP_FONT: { @@ -1459,8 +1600,51 @@ int TitleCurSubMenuItem::handle_event() break; } char txt[BCSTRLEN]; - sprintf(txt, "<%s>", item_text); - return window->insert_ibeam(txt, ofs); + sprintf(txt, "<%s>", N_(item_text)); + //printf("Item text: %s \n", N_(item_text)); + + if (strstr(item_text, N_(KW_NUDGE))) { + strreplace(item_text, (char*)N_(KW_NUDGE), _(KW_NUDGE)); + } + else if (strstr(item_text, N_(KW_COLOR))) { + strreplace(item_text, (char*)N_(KW_COLOR), _(KW_COLOR)); + } + else if (strstr(item_text, N_(KW_ALPHA))) { + strreplace(item_text, (char*)N_(KW_ALPHA), _(KW_ALPHA)); + } + else if (strstr(item_text, N_(KW_FONT))) { + strreplace(item_text, (char*)N_(KW_FONT), _(KW_FONT)); + } + else if (strstr(item_text, N_(KW_SIZE))) { + strreplace(item_text, (char*)N_(KW_SIZE), _(KW_SIZE)); + } + else if (strstr(item_text, N_(KW_BOLD))) { + strreplace(item_text, (char*)N_(KW_BOLD), _(KW_BOLD)); + } + else if (strstr(item_text, N_(KW_ITALIC))) { + strreplace(item_text, (char*)N_(KW_ITALIC), _(KW_ITALIC)); + } + else if (strstr(item_text, N_(KW_CAPS))) { + strreplace(item_text, (char*)N_(KW_CAPS), _(KW_CAPS)); + } + else if (strstr(item_text, N_(KW_UL))) { + strreplace(item_text, (char*)N_(KW_UL), _(KW_UL)); + } + else if (strstr(item_text, N_(KW_BLINK))) { + strreplace(item_text, (char*)N_(KW_BLINK), _(KW_BLINK)); + } + else if (strstr(item_text, N_(KW_FIXED))) { + strreplace(item_text, (char*)N_(KW_FIXED), _(KW_FIXED)); + } + else if (strstr(item_text, N_(KW_ALIAS))) { + strreplace(item_text, (char*)N_(KW_ALIAS), _(KW_ALIAS)); + } + else if (strstr(item_text, N_(KW_SUP))) { + strreplace(item_text, (char*)N_(KW_SUP), _(KW_SUP)); + } + + + return window->insert_ibeam(N_(txt), ofs); } TitleFontsPopup::TitleFontsPopup(TitleMain *client, TitleWindow *window) @@ -1494,7 +1678,7 @@ int TitleFontsPopup::handle_event() BC_ListBoxItem *item = get_selection(0, 0); if( !item ) return 1; const char *item_text = item->get_text(); - char txt[BCTEXTLEN]; sprintf(txt, "<%s %s>", _(KW_FONT), item_text); + char txt[BCTEXTLEN]; sprintf(txt, "<%s %s>", N_(KW_FONT), item_text); return window->insert_ibeam(txt); } @@ -1545,7 +1729,7 @@ void TitlePngPopup::handle_done_event(int result) if( result ) return; BrowseButtonWindow *gui = (BrowseButtonWindow *)get_gui(); const char *path = gui->get_submitted_path(); - char txt[BCSTRLEN]; sprintf(txt, "<%s %s>", _(KW_PNG), path); + char txt[BCTEXTLEN]; sprintf(txt, "<%s %s>", _(KW_PNG), path); window->lock_window("TitlePngPopup::handle_done_event"); window->insert_ibeam(txt); window->unlock_window();