crikey rework, KP4 fix, added Shift-KPx, valgrind cleanups, hex eye-dropper, resize...
[goodguy/history.git] / cinelerra-5.1 / plugins / titler / titlerwindow.C
index d44140607b00556445ca58ebc54aac3933502b4d..f52d3f21adf8411457259c22cb4e495bf2c7b0b0 100644 (file)
@@ -465,6 +465,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_xy(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;
@@ -474,15 +493,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;
@@ -504,7 +521,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;
@@ -681,7 +698,7 @@ void TitleWindow::update_justification()
 void TitleWindow::update_stats()
 {
        text_chars->update(client->config.wlen);
-       int len = MESSAGESIZE-16 - strlen(text->get_text());
+       int len = MESSAGESIZE - BCTEXTLEN - strlen(text->get_text()) - 1;
        if( len < 0 ) len = 0;
        text_bfrsz->update(len);
 }
@@ -1064,6 +1081,18 @@ 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;
@@ -1411,7 +1440,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);