add edit clear submenu/clear hard_edges, fix tessy gl segv, mask toolgui layout,...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / gwindowgui.C
index f0a050a27b043b3150f1c849419c5072f037a0d1..f90a387815add0beaf2a066a44ae59f8059f5d78 100644 (file)
@@ -49,24 +49,12 @@ GWindowGUI::GWindowGUI(MWindow *mwindow, int w, int h)
        w, h, w, h, 0, 0, 1)
 {
        this->mwindow = mwindow;
-       color_thread = 0;
        camera_xyz = 0;
        projector_xyz = 0;
 }
 
 GWindowGUI::~GWindowGUI()
 {
-       delete color_thread;
-}
-
-void GWindowGUI::start_color_thread(GWindowColorButton *color_button)
-{
-       unlock_window();
-       delete color_thread;
-       color_thread = new GWindowColorThread(this, color_button);
-       int color = auto_colors[color_button->auto_toggle->info->ref];
-       color_thread->start(color);
-       lock_window("GWindowGUI::start_color_thread");
 }
 
 const char *GWindowGUI::non_auto_text[NON_AUTOMATION_TOTAL] =
@@ -75,6 +63,7 @@ const char *GWindowGUI::non_auto_text[NON_AUTOMATION_TOTAL] =
        N_("Titles"),
        N_("Transitions"),
        N_("Plugin Keyframes"),
+       N_("Hard Edges"),
 };
 
 const char *GWindowGUI::auto_text[AUTOMATION_TOTAL] =
@@ -150,6 +139,7 @@ static toggleinfo toggle_order[] =
        {1, AUTOMATION_MODE},
        {1, AUTOMATION_PAN},
        {1, AUTOMATION_MASK},
+       {-1, NON_AUTOMATION_HARD_EDGES},
        {0, -1}, // bar
        {1, AUTOMATION_CAMERA_X},
        {1, AUTOMATION_CAMERA_Y},
@@ -166,7 +156,14 @@ const char *GWindowGUI::toggle_text(toggleinfo *tp)
 {
        if( tp->isauto > 0 ) return _(auto_text[tp->ref]);
        if( !tp->isauto ) return _(non_auto_text[tp->ref]);
-       return _("XYZ");
+       switch( tp->ref ) {
+       case NONAUTOTOGGLES_CAMERA_XYZ:
+       case NONAUTOTOGGLES_PROJECTOR_XYZ:
+               return _("XYZ");
+       case NON_AUTOMATION_HARD_EDGES:
+               return _("Hard Edges");
+       }
+       return "()";
 }
 
 void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
@@ -197,103 +194,39 @@ void GWindowGUI::calculate_extents(BC_WindowBase *gui, int *w, int *h)
        *w += 20;
 }
 
-GWindowColorButton::GWindowColorButton(GWindowToggle *auto_toggle, int x, int y, int w)
- : BC_Button(x, y, w, vframes)
+GWindowColorButton::GWindowColorButton(GWindowToggle *auto_toggle,
+               int x, int y, int w, int color)
+ : ColorCircleButton(auto_toggle->caption, x, y, w, w, color, -1, 1)
 {
        this->auto_toggle = auto_toggle;
-       this->color = 0;
-       for( int i=0; i<3; ++i ) {
-               vframes[i] = new VFrame(w, w, BC_RGBA8888);
-               vframes[i]->clear_frame();
-       }
+       this->color = color;
 }
 
 GWindowColorButton::~GWindowColorButton()
 {
-       for( int i=0; i<3; ++i )
-               delete vframes[i];
 }
 
-void GWindowColorButton::set_color(int color)
+int GWindowColorButton::handle_new_color(int color, int alpha)
 {
        this->color = color;
-       int r = (color>>16) & 0xff;
-       int g = (color>>8) & 0xff;
-       int b = (color>>0) & 0xff;
-       for( int i=0; i<3; ++i ) {
-               VFrame *vframe = vframes[i];
-               int ww = vframe->get_w(), hh = vframe->get_h();
-               int cx = (ww+1)/2, cy = hh/2;
-               double cc = (cx*cx + cy*cy) / 4.;
-               uint8_t *bp = vframe->get_data(), *dp = bp;
-               uint8_t *ep = dp + vframe->get_data_size();
-               int rr = r, gg = g, bb = b;
-               int bpl = vframe->get_bytes_per_line();
-               switch( i ) {
-               case BUTTON_UP:
-                       break;
-               case BUTTON_UPHI:
-                       if( (rr+=48) > 0xff ) rr = 0xff;
-                       if( (gg+=48) > 0xff ) gg = 0xff;
-                       if( (bb+=48) > 0xff ) bb = 0xff;
-                       break;
-               case BUTTON_DOWNHI:
-                       if( (rr-=48) < 0x00 ) rr = 0x00;
-                       if( (gg-=48) < 0x00 ) gg = 0x00;
-                       if( (bb-=48) < 0x00 ) bb = 0x00;
-                       break;
-               }
-               while( dp < ep ) {
-                       int yy = (dp-bp) / bpl, xx = ((dp-bp) % bpl) >> 2;
-                       int dy = cy - yy, dx = cx - xx;
-                       double s = dx*dx + dy*dy - cc;
-                       double ss = s < 0 ? 1 : s >= cc ? 0 : 1 - s/cc;
-                       int aa = ss * 0xff;
-                       *dp++ = rr; *dp++ = gg; *dp++ = bb; *dp++ = aa;
-               }
-       }
-       set_images(vframes);
-}
-
-void GWindowColorButton::update_gui(int color)
-{
-       set_color(color);
-       draw_face();
-}
-
-GWindowColorThread::GWindowColorThread(GWindowGUI *gui, GWindowColorButton *color_button)
- : ColorPicker(0, color_button->auto_toggle->caption)
-{
-       this->gui = gui;
-       this->color_button = color_button;
-       this->color = 0;
-       color_update = new GWindowColorUpdate(this);
-}
-
-GWindowColorThread::~GWindowColorThread()
-{
-       delete color_update;
-}
-
-void GWindowColorThread::start(int color)
-{
-       start_window(color, 0, 1);
-       color_update->start();
+       color_thread->update_lock->unlock();
+       return 1;
 }
 
-void GWindowColorThread::handle_done_event(int result)
+void GWindowColorButton::handle_done_event(int result)
 {
-       color_update->stop();
-       int ref = color_button->auto_toggle->info->ref;
+       ColorCircleButton::handle_done_event(result);
+       int ref = auto_toggle->info->ref;
+       GWindowGUI *gui = auto_toggle->gui;
        gui->lock_window("GWindowColorThread::handle_done_event");
        if( !result ) {
                GWindowGUI::auto_colors[ref] = color;
-               color_button->auto_toggle->update_gui(color);
+               auto_toggle->update_gui(color);
                gui->save_defaults();
        }
        else {
                color = GWindowGUI::auto_colors[ref];
-               color_button->update_gui(color);
+               update_gui(color);
        }
        gui->unlock_window();
        MWindowGUI *mwindow_gui = gui->mwindow->gui;
@@ -302,67 +235,6 @@ void GWindowColorThread::handle_done_event(int result)
        mwindow_gui->unlock_window();
 }
 
-int GWindowColorThread::handle_new_color(int color, int alpha)
-{
-       this->color = color;
-       color_update->update_lock->unlock();
-       return 1;
-}
-
-void GWindowColorThread::update_gui()
-{
-       gui->lock_window("GWindowColorThread::update_gui");
-       color_button->update_gui(color);
-       gui->unlock_window();
-}
-
-GWindowColorUpdate::GWindowColorUpdate(GWindowColorThread *color_thread)
- : Thread(1, 0, 0)
-{
-       this->color_thread = color_thread;
-       this->update_lock = new Condition(0,"GWindowColorUpdate::update_lock");
-       done = 1;
-}
-
-GWindowColorUpdate::~GWindowColorUpdate()
-{
-       stop();
-       delete update_lock;
-}
-
-void GWindowColorUpdate::start()
-{
-       if( done ) {
-               done = 0;
-               Thread::start();
-       }
-}
-
-void GWindowColorUpdate::stop()
-{
-       if( !done ) {
-               done = 1;
-               update_lock->unlock();
-               join();
-       }
-}
-
-void GWindowColorUpdate::run()
-{
-       while( !done ) {
-               update_lock->lock("GWindowColorUpdate::run");
-               if( done ) break;
-               color_thread->update_gui();
-       }
-}
-
-
-int GWindowColorButton::handle_event()
-{
-       GWindowGUI *gui = auto_toggle->gui;
-       gui->start_color_thread(this);
-       return 1;
-}
 
 void GWindowGUI::create_objects()
 {
@@ -393,15 +265,14 @@ void GWindowGUI::create_objects()
                        if( !vframe ) {
                                int wh = toggle->get_h() - 4;
                                GWindowColorButton *color_button =
-                                       new GWindowColorButton(toggle, get_w()-wh-10, y+2, wh);
+                                       new GWindowColorButton(toggle, get_w()-wh-10, y+2, wh, color);
                                add_tool(color_button);
-                               color_button->set_color(color);
-                               color_button->draw_face();
+                               color_button->create_objects();
                        }
                        else
                                draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
                }
-               else if( tp->isauto < 0 ) {
+               else {
                        const char *accel = 0;
                        switch( ref ) {
                        case NONAUTOTOGGLES_CAMERA_XYZ:
@@ -412,6 +283,11 @@ void GWindowGUI::create_objects()
                                projector_xyz = toggle;
                                accel = _("Shift-F2");
                                break;
+                       case NON_AUTOMATION_HARD_EDGES:
+                               VFrame *vframe = mwindow->theme->hardedge_data;
+                               draw_vframe(vframe, get_w()-vframe->get_w()-10, y);
+                               hard_edges = toggle;
+                               break;
                        }
                         if( accel ) {
                                int x1 = get_w() - BC_Title::calculate_w(this, accel) - 10;
@@ -480,7 +356,6 @@ int GWindowGUI::translation_event()
 
 int GWindowGUI::close_event()
 {
-       delete color_thread;  color_thread = 0;
        hide_window();
        mwindow->session->show_gwindow = 0;
        unlock_window();
@@ -496,15 +371,29 @@ int GWindowGUI::close_event()
 
 int GWindowGUI::keypress_event()
 {
-       switch(get_keypress()) {
-       case KEY_F1:
-               if( !ctrl_down() && shift_down() )
+       if( ctrl_down() && shift_down() ) {
+               switch(get_keypress()) {
+               case KEY_F1:
+               case KEY_F2:
+               case KEY_F3:
+               case KEY_F4:
+                       if( ctrl_down() && shift_down() ) {
+                               resend_event(mwindow->gui);
+                               return 1;
+                       }
+               }
+       }
+       else if( !ctrl_down() && shift_down() ) {
+               switch(get_keypress()) {
+               case KEY_F1:
                        toggle_camera_xyz();
-               break;
-       case KEY_F2:
-               if( !ctrl_down() && shift_down() )
+                       return 1;
+               case KEY_F2:
                        toggle_projector_xyz();
-               break;
+                       return 1;
+               }
+       }
+       switch(get_keypress()) {
        case 'w':
        case 'W':
        case '0':
@@ -537,13 +426,12 @@ int* GWindowGUI::get_main_value(toggleinfo *info)
 {
        if( info->isauto > 0 )
                return &mwindow->edl->session->auto_conf->autos[info->ref];
-       if( !info->isauto ) {
-               switch( info->ref ) {
-               case NON_AUTOMATION_ASSETS: return &mwindow->edl->session->show_assets;
-               case NON_AUTOMATION_TITLES: return &mwindow->edl->session->show_titles;
-               case NON_AUTOMATION_TRANSITIONS: return &mwindow->edl->session->auto_conf->transitions;
-               case NON_AUTOMATION_PLUGIN_AUTOS: return &mwindow->edl->session->auto_conf->plugins;
-               }
+       switch( info->ref ) {
+       case NON_AUTOMATION_ASSETS: return &mwindow->edl->session->show_assets;
+       case NON_AUTOMATION_TITLES: return &mwindow->edl->session->show_titles;
+       case NON_AUTOMATION_TRANSITIONS: return &mwindow->edl->session->auto_conf->transitions;
+       case NON_AUTOMATION_PLUGIN_AUTOS: return &mwindow->edl->session->auto_conf->plugins;
+       case NON_AUTOMATION_HARD_EDGES: return &mwindow->edl->session->auto_conf->hard_edges;
        }
        return 0;
 }
@@ -602,6 +490,7 @@ int GWindowToggle::handle_event()
                switch( info->ref ) {
                case NONAUTOTOGGLES_CAMERA_XYZ:     group = AUTOMATION_CAMERA_X;     break;
                case NONAUTOTOGGLES_PROJECTOR_XYZ:  group = AUTOMATION_PROJECTOR_X;  break;
+               case NON_AUTOMATION_HARD_EDGES: *gui->get_main_value(info) = value;  break;
                }
                if( group >= 0 ) {
                        gui->xyz_check(group, value);
@@ -615,7 +504,7 @@ int GWindowToggle::handle_event()
        MWindow *mwindow = gui->mwindow;
        mwindow->gui->lock_window("GWindowToggle::handle_event");
 
-       mwindow->gui->update(1, 1, 0, 0, 1, 0, 0);
+       mwindow->gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
        mwindow->gui->draw_overlays(1);
 
        if( value && info->isauto > 0 ) {