From: Good Guy Date: Thu, 12 Apr 2018 01:35:34 +0000 (-0600) Subject: add dragcheckbox, fix transition plugin title, sams opencv icons, drop libipp in... X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=9a16c85641dee9f15136f40c8a3195d88d45513f;p=goodguy%2Fhistory.git add dragcheckbox, fix transition plugin title, sams opencv icons, drop libipp in opencv --- diff --git a/cinelerra-5.1/Makefile.am b/cinelerra-5.1/Makefile.am index 0667d93c..cd408349 100644 --- a/cinelerra-5.1/Makefile.am +++ b/cinelerra-5.1/Makefile.am @@ -18,6 +18,7 @@ bin: mkdir -p bin bin/applications bin/pixmaps clean-generic: + rm -rf thirdparty/opencv* rm -rf bin inst_sh := $(CURDIR)/inst.sh diff --git a/cinelerra-5.1/Makefile.devel b/cinelerra-5.1/Makefile.devel index 546d2c39..09f7da9b 100644 --- a/cinelerra-5.1/Makefile.devel +++ b/cinelerra-5.1/Makefile.devel @@ -17,6 +17,7 @@ all: clean: for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done + rm -rf thirdparty/opencv* rm -rf bin ./autogen.sh clean diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile index c341abcb..b9d23b7d 100644 --- a/cinelerra-5.1/cinelerra/Makefile +++ b/cinelerra-5.1/cinelerra/Makefile @@ -84,6 +84,7 @@ OBJS = \ $(OBJDIR)/devicempeginput.o \ $(OBJDIR)/devicev4l2base.o \ $(OBJDIR)/devicev4l2input.o \ + $(OBJDIR)/dragcheckbox.o \ $(OBJDIR)/drivesync.o \ $(OBJDIR)/dvbtune.o \ $(OBJDIR)/dvdcreate.o \ diff --git a/cinelerra-5.1/cinelerra/dragcheckbox.C b/cinelerra-5.1/cinelerra/dragcheckbox.C new file mode 100644 index 00000000..559851eb --- /dev/null +++ b/cinelerra-5.1/cinelerra/dragcheckbox.C @@ -0,0 +1,276 @@ +#include "automation.h" +#include "bctoggle.h" +#include "canvas.h" +#include "cwindow.h" +#include "cwindowgui.h" +#include "dragcheckbox.h" +#include "edl.h" +#include "edlsession.h" +#include "mwindow.h" +#include "theme.h" +#include "track.h" +#include "vframe.h" + +DragCheckBox::DragCheckBox(MWindow *mwindow, + int x, int y, const char *text, int *value, + float drag_x, float drag_y, float drag_w, float drag_h) + : BC_CheckBox(x, y, value, text) +{ + this->mwindow = mwindow; + this->drag_x = drag_x; this->drag_y = drag_y; + this->drag_w = drag_w; this->drag_h = drag_h; + drag_dx = drag_dy = 0; + grabbed = 0; + dragging = 0; + pending = 0; +} + +DragCheckBox::~DragCheckBox() +{ + drag_deactivate(); +} + +void DragCheckBox::create_objects() +{ + if( !drag_w ) drag_w = get_drag_track()->track_w; + if( !drag_h ) drag_h = get_drag_track()->track_h; + if( get_value() ) + drag_activate(); +} + +int DragCheckBox::handle_event() +{ + int ret = BC_CheckBox::handle_event(); + if( get_value() ) { + if( drag_activate() ) { + update(*value=0); + flicker(10,50); + } + } + else + drag_deactivate(); + return ret; +} + +int DragCheckBox::drag_activate() +{ + int ret = 0; + if( !grabbed && !(grabbed = grab(mwindow->cwindow->gui)) ) { + ret = 1; + } + pending = 0; + dragging = 0; + return ret; +} + +void DragCheckBox::drag_deactivate() +{ + if( grabbed ) { + ungrab(mwindow->cwindow->gui); + grabbed = 0; + } + pending = 0; + dragging = 0; +} + +int DragCheckBox::check_pending() +{ + if( pending && !grab_event_count() ) { + pending = 0; + update_gui(); + } + return 0; +} + +int DragCheckBox::grab_event(XEvent *event) +{ + switch( event->type ) { + case ButtonPress: break; + case ButtonRelease: break; + case MotionNotify: break; + default: + return check_pending(); + } + + 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 || + cy < 0 || cy >= mwindow->theme->ccanvas_h ) + return check_pending(); + } + + switch( event->type ) { + case ButtonPress: + if( !dragging ) break; + return 1; + case ButtonRelease: + if( !dragging ) return check_pending(); + dragging = 0; + return 1; + case MotionNotify: + if( !dragging ) return check_pending(); + break; + default: + return check_pending(); + } + + Track *track = get_drag_track(); + if( !track ) return 0; + if( !drag_w ) drag_w = track->track_w; + if( !drag_h ) drag_h = track->track_h; + + int64_t position = get_drag_position(); + + float cursor_x = cx, cursor_y = cy; + canvas->canvas_to_output(mwindow->edl, 0, cursor_x, cursor_y); + float projector_x, projector_y, projector_z; + int track_w = track->track_w, track_h = track->track_h; + track->automation->get_projector( + &projector_x, &projector_y, &projector_z, + position, PLAY_FORWARD); + projector_x += mwindow->edl->session->output_w / 2; + projector_y += mwindow->edl->session->output_h / 2; + cursor_x = (cursor_x - projector_x) / projector_z + track_w / 2; + cursor_y = (cursor_y - projector_y) / projector_z + track_h / 2; + float r = MIN(track_w, track_h)/100.f + 2; + float x0 = drag_x, x1 = drag_x+(drag_w+1)/2, x2 = drag_x+drag_w; + float y0 = drag_y, y1 = drag_y+(drag_h+1)/2, y2 = drag_y+drag_h; + if( !dragging ) { // clockwise + if( fabs(drag_dx = cursor_x-x0) < r && // x0,y0 + fabs(drag_dy = cursor_y-y0) < r ) dragging = 1; + else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y0 + fabs(drag_dy = cursor_y-y0) < r ) dragging = 2; + else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y0 + fabs(drag_dy = cursor_y-y0) < r ) dragging = 3; + else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y1 + fabs(drag_dy = cursor_y-y1) < r ) dragging = 4; + else if( fabs(drag_dx = cursor_x-x2) < r && // x2,y2 + fabs(drag_dy = cursor_y-y2) < r ) dragging = 5; + else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y2 + fabs(drag_dy = cursor_y-y2) < r ) dragging = 6; + else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y2 + fabs(drag_dy = cursor_y-y2) < r ) dragging = 7; + else if( fabs(drag_dx = cursor_x-x0) < r && // x0,y1 + fabs(drag_dy = cursor_y-y1) < r ) dragging = 8; + else if( fabs(drag_dx = cursor_x-x1) < r && // x1,y1 + fabs(drag_dy = cursor_y-y1) < r ) dragging = 9; + return 0; + } + int cur_x = cursor_x - drag_dx; + int cur_y = cursor_y - drag_dy; + switch( dragging ) { + case 1: { // x0,y0 + float dx = cur_x - x0; + float dy = cur_y - y0; + if( !dx && !dy ) return 1; + if( (drag_w-=dx) < 1 ) drag_w = 1; + if( (drag_h-=dy) < 1 ) drag_h = 1; + drag_x = cur_x; drag_y = cur_y; + break; } + case 2: { // x1,y0 + float dy = cur_y - y0; + if( !dy ) return 1; + drag_y = cur_y; + if( (drag_h-=dy) < 1 ) drag_h = 1; + break; } + case 3: { // x2,y0 + float dx = cur_x - x2; + float dy = cur_y - y0; + if( (drag_w+=dx) < 1 ) drag_w = 1; + if( (drag_h-=dy) < 1 ) drag_h = 1; + drag_y = cur_y; + break; } + case 4: { // x2,y1 + float dx = cur_x - x2; + if( !dx ) return 1; + if( (drag_w+=dx) < 1 ) drag_w = 1; + break; } + case 5: { // x2,y2 + float dx = cur_x - x2; + float dy = cur_y - y2; + if( (drag_w+=dx) < 1 ) drag_w = 1; + if( (drag_h+=dy) < 1 ) drag_h = 1; + break; } + case 6: { // x1,y2 + float dy = cur_y - y2; + if( !dy ) return 1; + if( (drag_h+=dy) < 1 ) drag_h = 1; + break; } + case 7: { // x0,y2 + float dx = cur_x - x0; + float dy = cur_y - y2; + if( (drag_w-=dx) < 1 ) drag_w = 1; + if( (drag_h+=dy) < 1 ) drag_h = 1; + drag_x = cur_x; + break; } + case 8: { // x0,y1 + float dx = cur_x - x0; + if( !dx ) return 1; + if( (drag_w-=dx) < 1 ) drag_w = 1; + drag_x = cur_x; + break; } + case 9: { // x1,y1 + float dx = cur_x - x1; + float dy = cur_y - y1; + if( !dx && !dy ) return 1; + drag_x += dx; + drag_y += dy; + } + } + if( grab_event_count() ) + pending = 1; + else if( dragging ) { + pending = 0; + update_gui(); + } + return 1; +} + +void DragCheckBox::draw_boundary(VFrame *out, + int x, int y, int w, int h) +{ + int iw = out->get_w(), ih = out->get_h(); + int mr = MIN(iw, ih)/200 + 2, rr = 2*mr; + int r2 = (rr+1)/2; + int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2; + int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2; + int st = 1; + for( int r=2; rset_stiple(st); + + for( int r=mr/2; --r>=0; ) { // bbox + int lft = x+r, rgt = x+w-1-r; + int top = y+r, bot = y+h-1-r; + out->draw_line(lft,top, rgt,top); + out->draw_line(rgt,top, rgt,bot); + out->draw_line(rgt,bot, lft,bot); + out->draw_line(lft,bot, lft,top); + } + + for( int r=mr; rdraw_smooth(x1-r,y1, x1-r,y1+r, x1,y1+r); + out->draw_smooth(x1,y1+r, x1+r,y1+r, x1+r,y1); + out->draw_smooth(x1+r,y1, x1+r,y1-r, x1,y1-r); + out->draw_smooth(x1,y1-r, x1-r,y1-r, x1-r,y1); + } + + for( int r=rr; --r>=0; ) { // edge arrows + out->draw_line(x1-r,y0+r, x1+r,y0+r); + out->draw_line(x2-r,y1-r, x2-r,y1+r); + out->draw_line(x1-r,y2-r, x1+r,y2-r); + out->draw_line(x0+r,y1+r, x0+r,y1-r); + } + x0 += r2; y0 += r2; x2 -= r2; y2 -= r2; + for( int r=2*mr; --r>=0; ) { // corner arrows + out->draw_line(x0,y0+r, x0+r,y0); + out->draw_line(x2,y0+r, x2-r,y0); + out->draw_line(x2,y2-r, x2-r,y2); + out->draw_line(x0,y2-r, x0+r,y2); + } +} + diff --git a/cinelerra-5.1/cinelerra/dragcheckbox.h b/cinelerra-5.1/cinelerra/dragcheckbox.h new file mode 100644 index 00000000..5628b3e6 --- /dev/null +++ b/cinelerra-5.1/cinelerra/dragcheckbox.h @@ -0,0 +1,35 @@ +#ifndef __DRAGCHECKBOX_H__ +#define __DRAGCHECKBOX_H__ + +#include "bctoggle.h" +#include "mwindow.inc" +#include "track.inc" + +class DragCheckBox : public BC_CheckBox +{ +public: + DragCheckBox(MWindow *mwindow, int x, int y, const char *text, int *value, + float drag_x, float drag_y, float drag_w, float drag_h); + ~DragCheckBox(); + virtual Track *get_drag_track() = 0; + virtual int64_t get_drag_position() = 0; + virtual void update_gui() { return; }; + void create_objects(); + static void draw_boundary(VFrame *out, int x, int y, int w, int h); + + int check_pending(); + int drag_activate(); + void drag_deactivate(); + + int handle_event(); + int grab_event(XEvent *event); + + MWindow *mwindow; + int grabbed, dragging, pending; + float drag_x, drag_y; + float drag_w, drag_h; + float drag_dx, drag_dy; +}; + +#endif + diff --git a/cinelerra-5.1/cinelerra/dragcheckbox.inc b/cinelerra-5.1/cinelerra/dragcheckbox.inc new file mode 100644 index 00000000..327e0043 --- /dev/null +++ b/cinelerra-5.1/cinelerra/dragcheckbox.inc @@ -0,0 +1,6 @@ +#ifndef __DRAGCHECKBOX_INC__ +#define __DRAGCHECKBOX_INC__ + +class DragCheckBox; + +#endif diff --git a/cinelerra-5.1/cinelerra/transition.C b/cinelerra-5.1/cinelerra/transition.C index 0b82d0a0..f321c472 100644 --- a/cinelerra-5.1/cinelerra/transition.C +++ b/cinelerra-5.1/cinelerra/transition.C @@ -177,6 +177,7 @@ void Transition::load_xml(FileXML *file) { int result = 0; file->tag.get_property("TITLE", title); + Plugin::fix_plugin_title(title); length = file->tag.get_property("LENGTH", length); on = 0; diff --git a/cinelerra-5.1/opencv_build b/cinelerra-5.1/opencv_build index 097e97f5..e5de69d3 100644 --- a/cinelerra-5.1/opencv_build +++ b/cinelerra-5.1/opencv_build @@ -72,6 +72,7 @@ $(opencv)/build: $(opencv).src mkdir -p $@ cd $@ && cmake \ -DCMAKE_BUILD_TYPE=RELEASE \ + -DWITH_IPP=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DINSTALL_C_EXAMPLES=OFF \ -DINSTALL_PYTHON_EXAMPLES=OFF \ @@ -88,6 +89,7 @@ $(opencv)/build: $(opencv).src mkdir -p $@ cd $@ && cmake \ -DCMAKE_BUILD_TYPE=RELEASE \ + -DWITH_IPP=OFF \ -DBUILD_SHARED_LIBS=ON \ -DINSTALL_C_EXAMPLES=ON \ -DINSTALL_PYTHON_EXAMPLES=ON \ diff --git a/cinelerra-5.1/picon/cinfinity/findobj.png b/cinelerra-5.1/picon/cinfinity/findobj.png index 902d8b69..af004218 100644 Binary files a/cinelerra-5.1/picon/cinfinity/findobj.png and b/cinelerra-5.1/picon/cinfinity/findobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity/flowobj.png b/cinelerra-5.1/picon/cinfinity/flowobj.png new file mode 100644 index 00000000..449e1c58 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity/flowobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity/gaborobj.png b/cinelerra-5.1/picon/cinfinity/gaborobj.png index 5d0d196c..9c601bd2 100644 Binary files a/cinelerra-5.1/picon/cinfinity/gaborobj.png and b/cinelerra-5.1/picon/cinfinity/gaborobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity/moveobj.png b/cinelerra-5.1/picon/cinfinity/moveobj.png new file mode 100644 index 00000000..1f0a5334 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity/moveobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity/puzzleobj.png b/cinelerra-5.1/picon/cinfinity/puzzleobj.png new file mode 100644 index 00000000..1f4e2cdd Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity/puzzleobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity/stylizeobj.png b/cinelerra-5.1/picon/cinfinity/stylizeobj.png new file mode 100644 index 00000000..e41c758d Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity/stylizeobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/findobj.png b/cinelerra-5.1/picon/cinfinity2/findobj.png new file mode 100644 index 00000000..e3635139 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/findobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/flowobj.png b/cinelerra-5.1/picon/cinfinity2/flowobj.png new file mode 100644 index 00000000..29cbe475 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/flowobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/gaborobj.png b/cinelerra-5.1/picon/cinfinity2/gaborobj.png new file mode 100644 index 00000000..bd67bc61 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/gaborobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/moveobj.png b/cinelerra-5.1/picon/cinfinity2/moveobj.png new file mode 100644 index 00000000..e9785ef6 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/moveobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/puzzleobj.png b/cinelerra-5.1/picon/cinfinity2/puzzleobj.png new file mode 100644 index 00000000..fb78b86d Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/puzzleobj.png differ diff --git a/cinelerra-5.1/picon/cinfinity2/stylizeobj.png b/cinelerra-5.1/picon/cinfinity2/stylizeobj.png new file mode 100644 index 00000000..8ff2b080 Binary files /dev/null and b/cinelerra-5.1/picon/cinfinity2/stylizeobj.png differ diff --git a/cinelerra-5.1/plugins/findobj/findobj.C b/cinelerra-5.1/plugins/findobj/findobj.C index 86235f2d..bc9f4f20 100644 --- a/cinelerra-5.1/plugins/findobj/findobj.C +++ b/cinelerra-5.1/plugins/findobj/findobj.C @@ -27,6 +27,9 @@ #include "findobjwindow.h" #include "mutex.h" #include "overlayframe.h" +#include "plugin.h" +#include "pluginserver.h" +#include "track.h" #include #include @@ -39,13 +42,15 @@ FindObjConfig::FindObjConfig() algorithm = NO_ALGORITHM; use_flann = 1; draw_keypoints = 0; - draw_border = 0; + draw_scene_border = 0; replace_object = 0; draw_object_border = 0; object_x = 50; object_y = 50; object_w = 100; object_h = 100; + drag_object = 0; scene_x = 50; scene_y = 50; scene_w = 100; scene_h = 100; + drag_scene = 0; scene_layer = 0; object_layer = 1; replace_layer = 2; @@ -54,6 +59,7 @@ FindObjConfig::FindObjConfig() void FindObjConfig::boundaries() { + bclamp(drag_object, 0, 1); bclamp(drag_scene, 0, 1); bclamp(object_x, 0, 100); bclamp(object_y, 0, 100); bclamp(object_w, 0, 100); bclamp(object_h, 0, 100); bclamp(scene_x, 0, 100); bclamp(scene_y, 0, 100); @@ -70,13 +76,15 @@ int FindObjConfig::equivalent(FindObjConfig &that) algorithm == that.algorithm && use_flann == that.use_flann && draw_keypoints == that.draw_keypoints && - draw_border == that.draw_border && + draw_scene_border == that.draw_scene_border && replace_object == that.replace_object && draw_object_border == that.draw_object_border && object_x == that.object_x && object_y == that.object_y && object_w == that.object_w && object_h == that.object_h && + drag_object == that.drag_object && scene_x == that.scene_x && scene_y == that.scene_y && scene_w == that.scene_w && scene_h == that.scene_h && + drag_scene == that.drag_scene && object_layer == that.object_layer && replace_layer == that.replace_layer && scene_layer == that.scene_layer && @@ -89,13 +97,15 @@ void FindObjConfig::copy_from(FindObjConfig &that) algorithm = that.algorithm; use_flann = that.use_flann; draw_keypoints = that.draw_keypoints; - draw_border = that.draw_border; + draw_scene_border = that.draw_scene_border; replace_object = that.replace_object; draw_object_border = that.draw_object_border; object_x = that.object_x; object_y = that.object_y; object_w = that.object_w; object_h = that.object_h; + drag_object = that.drag_object; scene_x = that.scene_x; scene_y = that.scene_y; scene_w = that.scene_w; scene_h = that.scene_h; + drag_scene = that.drag_scene; object_layer = that.object_layer; replace_layer = that.replace_layer; scene_layer = that.scene_layer; @@ -160,6 +170,7 @@ void FindObjMain::update_gui() window->lock_window("FindObjMain::update_gui"); window->algorithm->set_text(FindObjAlgorithm::to_text(config.algorithm)); window->use_flann->update(config.use_flann); + window->drag_object->update(config.drag_object); window->object_x->update(config.object_x); window->object_x_text->update((float)config.object_x); window->object_y->update(config.object_y); @@ -168,6 +179,7 @@ void FindObjMain::update_gui() window->object_w_text->update((float)config.object_w); window->object_h->update(config.object_h); window->object_h_text->update((float)config.object_h); + window->drag_scene->update(config.drag_scene); window->scene_x->update(config.scene_x); window->scene_x_text->update((float)config.scene_x); window->scene_y->update(config.scene_y); @@ -177,7 +189,7 @@ void FindObjMain::update_gui() window->scene_h->update(config.scene_h); window->scene_h_text->update((float)config.scene_h); window->draw_keypoints->update(config.draw_keypoints); - window->draw_border->update(config.draw_border); + window->draw_scene_border->update(config.draw_scene_border); window->replace_object->update(config.replace_object); window->draw_object_border->update(config.draw_object_border); window->object_layer->update( (int64_t)config.object_layer); @@ -197,16 +209,18 @@ void FindObjMain::save_data(KeyFrame *keyframe) output.tag.set_title("FINDOBJ"); output.tag.set_property("ALGORITHM", config.algorithm); output.tag.set_property("USE_FLANN", config.use_flann); + output.tag.set_property("DRAG_OBJECT", config.drag_object); output.tag.set_property("OBJECT_X", config.object_x); output.tag.set_property("OBJECT_Y", config.object_y); output.tag.set_property("OBJECT_W", config.object_w); output.tag.set_property("OBJECT_H", config.object_h); + output.tag.set_property("DRAG_SCENE", config.drag_scene); output.tag.set_property("SCENE_X", config.scene_x); output.tag.set_property("SCENE_Y", config.scene_y); output.tag.set_property("SCENE_W", config.scene_w); output.tag.set_property("SCENE_H", config.scene_h); output.tag.set_property("DRAW_KEYPOINTS", config.draw_keypoints); - output.tag.set_property("DRAW_BORDER", config.draw_border); + output.tag.set_property("DRAW_SCENE_BORDER", config.draw_scene_border); output.tag.set_property("REPLACE_OBJECT", config.replace_object); output.tag.set_property("DRAW_OBJECT_BORDER", config.draw_object_border); output.tag.set_property("OBJECT_LAYER", config.object_layer); @@ -236,12 +250,14 @@ void FindObjMain::read_data(KeyFrame *keyframe) config.object_y = input.tag.get_property("OBJECT_Y", config.object_y); config.object_w = input.tag.get_property("OBJECT_W", config.object_w); config.object_h = input.tag.get_property("OBJECT_H", config.object_h); + config.drag_object = input.tag.get_property("DRAG_OBJECT", config.drag_object); config.scene_x = input.tag.get_property("SCENE_X", config.scene_x); config.scene_y = input.tag.get_property("SCENE_Y", config.scene_y); config.scene_w = input.tag.get_property("SCENE_W", config.scene_w); config.scene_h = input.tag.get_property("SCENE_H", config.scene_h); + config.drag_scene = input.tag.get_property("DRAG_SCENE", config.drag_scene); config.draw_keypoints = input.tag.get_property("DRAW_KEYPOINTS", config.draw_keypoints); - config.draw_border = input.tag.get_property("DRAW_BORDER", config.draw_border); + config.draw_scene_border = input.tag.get_property("DRAW_SCENE_BORDER", config.draw_scene_border); config.replace_object = input.tag.get_property("REPLACE_OBJECT", config.replace_object); config.draw_object_border = input.tag.get_property("DRAW_OBJECT_BORDER", config.draw_object_border); config.object_layer = input.tag.get_property("OBJECT_LAYER", config.object_layer); @@ -261,10 +277,11 @@ void FindObjMain::draw_line(VFrame *vframe, int x1, int y1, int x2, int y2) void FindObjMain::draw_rect(VFrame *vframe, int x1, int y1, int x2, int y2) { + --x2; --y2; draw_line(vframe, x1, y1, x2, y1); - draw_line(vframe, x2, y1 + 1, x2, y2); - draw_line(vframe, x2 - 1, y2, x1, y2); - draw_line(vframe, x1, y2 - 1, x1, y1 + 1); + draw_line(vframe, x2, y1, x2, y2); + draw_line(vframe, x2, y2, x1, y2); + draw_line(vframe, x1, y2, x1, y1); } void FindObjMain::draw_circle(VFrame *vframe, int x, int y, int r) @@ -408,7 +425,7 @@ void FindObjMain::process_match() { if( config.algorithm == NO_ALGORITHM ) return; if( !config.replace_object && - !config.draw_border && + !config.draw_scene_border && !config.draw_keypoints ) return; if( detector.empty() ) { @@ -481,34 +498,33 @@ int FindObjMain::process_buffer(VFrame **frame, int64_t start_position, double f matcher.release(); } - w = frame[0]->get_w(); - h = frame[0]->get_h(); - object_layer = config.object_layer; scene_layer = config.scene_layer; replace_layer = config.replace_layer; + Track *track = server->plugin->track; + w = track->track_w; + h = track->track_h; int max_layer = PluginClient::get_total_buffers() - 1; object_layer = bclip(config.object_layer, 0, max_layer); scene_layer = bclip(config.scene_layer, 0, max_layer); replace_layer = bclip(config.replace_layer, 0, max_layer); - int cfg_w, cfg_h, cfg_x1, cfg_y1, cfg_x2, cfg_y2; - cfg_w = (int)(config.object_w * w / 100); - cfg_h = (int)(config.object_h * h / 100); - cfg_x1 = (int)(config.object_x * w / 100 - cfg_w / 2); - cfg_y1 = (int)(config.object_y * h / 100 - cfg_h / 2); - cfg_x2 = cfg_x1 + cfg_w; - cfg_y2 = cfg_y1 + cfg_h; + int cfg_w = (int)(w * config.object_w / 100.); + int cfg_h = (int)(h * config.object_h / 100.); + int cfg_x1 = (int)(w * config.object_x / 100. - cfg_w / 2); + int cfg_y1 = (int)(h * config.object_y / 100. - cfg_h / 2); + int cfg_x2 = cfg_x1 + cfg_w; + int cfg_y2 = cfg_y1 + cfg_h; bclamp(cfg_x1, 0, w); object_x = cfg_x1; bclamp(cfg_y1, 0, h); object_y = cfg_y1; bclamp(cfg_x2, 0, w); object_w = cfg_x2 - cfg_x1; bclamp(cfg_y2, 0, h); object_h = cfg_y2 - cfg_y1; - cfg_w = (int)(config.scene_w * w / 100); - cfg_h = (int)(config.scene_h * h / 100); - cfg_x1 = (int)(config.scene_x * w / 100 - cfg_w / 2); - cfg_y1 = (int)(config.scene_y * h / 100 - cfg_h / 2); + cfg_w = (int)(w * config.scene_w / 100.); + cfg_h = (int)(h * config.scene_h / 100.); + cfg_x1 = (int)(w * config.scene_x / 100. - cfg_w / 2); + cfg_y1 = (int)(h * config.scene_y / 100. - cfg_h / 2); cfg_x2 = cfg_x1 + cfg_w; cfg_y2 = cfg_y1 + cfg_h; bclamp(cfg_x1, 0, w); scene_x = cfg_x1; @@ -534,7 +550,7 @@ int FindObjMain::process_buffer(VFrame **frame, int64_t start_position, double f process_match(); } - double w0 = init_border ? 1. : config.blend/100., w1 = 1. - w0; + double w0 = init_border ? (init_border=0, 1.) : config.blend/100., w1 = 1. - w0; obj_x1 = border_x1*w0 + obj_x1*w1; obj_y1 = border_y1*w0 + obj_y1*w1; obj_x2 = border_x2*w0 + obj_x2*w1; obj_y2 = border_y2*w0 + obj_y2*w1; obj_x3 = border_x3*w0 + obj_x3*w1; obj_y3 = border_y3*w0 + obj_y3*w1; @@ -562,15 +578,16 @@ int FindObjMain::process_buffer(VFrame **frame, int64_t start_position, double f } - if( config.draw_border ) { + if( config.draw_scene_border ) { int wh = (w+h)>>8, ss = 1; while( wh>>=1 ) ss<<=1; scene->set_pixel_color(WHITE); scene->set_stiple(ss*2); - draw_line(scene, obj_x1, obj_y1, obj_x2, obj_y2); - draw_line(scene, obj_x2, obj_y2, obj_x3, obj_y3); - draw_line(scene, obj_x3, obj_y3, obj_x4, obj_y4); - draw_line(scene, obj_x4, obj_y4, obj_x1, obj_y1); + draw_rect(scene, scene_x, scene_y, scene_x+scene_w, scene_y+scene_h); + } + if( config.draw_object_border ) { + int wh = (w+h)>>8, ss = 1; while( wh>>=1 ) ss<<=1; + scene->set_pixel_color(YELLOW); scene->set_stiple(ss*3); + draw_rect(scene, object_x, object_y, object_x+object_w, object_y+object_h); } - if( config.draw_keypoints ) { scene->set_pixel_color(RED); scene->set_stiple(0); for( int i=0,n=scn_keypts.size(); i>8, ss = 1; while( wh>>=1 ) ss<<=1; - scene->set_pixel_color(YELLOW); scene->set_stiple(ss*3); - int x1 = object_x, x2 = x1 + object_w - 1; - int y1 = object_y, y2 = y1 + object_h - 1; - draw_rect(scene, x1, y1, x2, y2); - scene->set_pixel_color(GREEN); scene->set_stiple(0); - x1 = scene_x, x2 = x1 + scene_w - 1; - y1 = scene_y, y2 = y1 + scene_h - 1; - draw_rect(scene, x1, y1, x2, y2); + if( gui_open() ) { + if( config.drag_scene ) { + scene->set_pixel_color(WHITE); + DragCheckBox::draw_boundary(scene, scene_x, scene_y, scene_w, scene_h); + } + if( config.drag_object ) { + scene->set_pixel_color(YELLOW); + DragCheckBox::draw_boundary(scene, object_x, object_y, object_w, object_h); + } } scene->set_pixel_color(BLACK); diff --git a/cinelerra-5.1/plugins/findobj/findobj.h b/cinelerra-5.1/plugins/findobj/findobj.h index 8c291b28..4a29b3c9 100644 --- a/cinelerra-5.1/plugins/findobj/findobj.h +++ b/cinelerra-5.1/plugins/findobj/findobj.h @@ -45,6 +45,7 @@ #include "pluginvclient.h" #include "vframe.inc" +#define Mutex CvMutex #include "opencv2/core/types.hpp" #include "opencv2/core/mat.hpp" #include "opencv2/imgproc/imgproc.hpp" @@ -52,6 +53,7 @@ #include "opencv2/calib3d.hpp" #include "opencv2/flann/defines.h" #include "opencv2/flann/params.h" +#undef Mutex #include @@ -100,11 +102,12 @@ public: void boundaries(); int algorithm, use_flann; + int drag_object, drag_scene; float object_x, object_y, object_w, object_h; - float scene_x, scene_y, scene_w, scene_h; + float scene_x, scene_y, scene_w, scene_h; int draw_keypoints; - int draw_border; + int draw_scene_border; int replace_object; int draw_object_border; diff --git a/cinelerra-5.1/plugins/findobj/findobjwindow.C b/cinelerra-5.1/plugins/findobj/findobjwindow.C index 96fe6e68..1c11878c 100644 --- a/cinelerra-5.1/plugins/findobj/findobjwindow.C +++ b/cinelerra-5.1/plugins/findobj/findobjwindow.C @@ -21,10 +21,14 @@ #include "bcdisplayinfo.h" #include "clip.h" +#include "dragcheckbox.h" #include "language.h" #include "findobj.h" #include "findobjwindow.h" +#include "plugin.h" +#include "pluginserver.h" #include "theme.h" +#include "track.h" FindObjWindow::FindObjWindow(FindObjMain *plugin) @@ -75,8 +79,20 @@ void FindObjWindow::create_objects() y += title->get_h(); int y1 = y; - add_subwindow(new BC_Title(x1, y + 10, _("Scene X:"))); + add_subwindow(title = new BC_Title(x1, y + 10, _("Scene X:"))); + Track *track = plugin->server->plugin->track; + int trk_w = track->track_w, trk_h = track->track_h; + float drag_w = trk_w * plugin->config.scene_w / 100.; + float drag_h = trk_h * plugin->config.scene_h / 100.; + float ctr_x = trk_w * plugin->config.scene_x / 100.; + float ctr_y = trk_h * plugin->config.scene_y / 100.; + float drag_x = ctr_x - drag_w/2, drag_y = ctr_y - drag_h/2; + drag_scene = new FindObjDragScene(plugin, this, x1+title->get_w()+10, y+5, + drag_x, drag_y, drag_w, drag_h); + add_subwindow(drag_scene); + drag_scene->create_objects(); y += title->get_h() + 15; + add_subwindow(scene_x = new FindObjScanFloat(plugin, this, x1, y, &plugin->config.scene_x)); add_subwindow(scene_x_text = new FindObjScanFloatText(plugin, this, @@ -116,8 +132,18 @@ void FindObjWindow::create_objects() scene_h_text->center = scene_h; y = y1; - add_subwindow(new BC_Title(x2, y + 10, _("Object X:"))); + add_subwindow(title = new BC_Title(x2, y + 10, _("Object X:"))); + drag_w = trk_w * plugin->config.object_w / 100.; + drag_h = trk_h * plugin->config.object_h / 100.; + ctr_x = trk_w * plugin->config.object_x / 100., + ctr_y = trk_h * plugin->config.object_y / 100.; + drag_x = ctr_x - drag_w/2; drag_y = ctr_y - drag_h/2; + drag_object = new FindObjDragObject(plugin, this, x2+title->get_w()+10, y+5, + drag_x, drag_y, drag_w, drag_h); + add_subwindow(drag_object); + drag_object->create_objects(); y += title->get_h() + 15; + add_subwindow(object_x = new FindObjScanFloat(plugin, this, x2, y, &plugin->config.object_x)); add_subwindow(object_x_text = new FindObjScanFloatText(plugin, this, @@ -159,10 +185,10 @@ void FindObjWindow::create_objects() y += 40 + 15; add_subwindow(draw_keypoints = new FindObjDrawKeypoints(plugin, this, x, y)); y += draw_keypoints->get_h() + plugin->get_theme()->widget_border; - add_subwindow(draw_border = new FindObjDrawBorder(plugin, this, x, y)); - y += draw_border->get_h() + plugin->get_theme()->widget_border; add_subwindow(replace_object = new FindObjReplace(plugin, this, x, y)); y += replace_object->get_h() + plugin->get_theme()->widget_border; + add_subwindow(draw_scene_border = new FindObjDrawSceneBorder(plugin, this, x, y)); + y += draw_scene_border->get_h() + plugin->get_theme()->widget_border; add_subwindow(draw_object_border = new FindObjDrawObjectBorder(plugin, this, x, y)); y += draw_object_border->get_h() + plugin->get_theme()->widget_border; @@ -175,6 +201,22 @@ void FindObjWindow::create_objects() show_window(1); } +void FindObjWindow::update_drag() +{ + Track *track = drag_scene->get_drag_track(); + int trk_w = track->track_w, trk_h = track->track_h; + drag_scene->drag_w = trk_w * plugin->config.scene_w/100.; + drag_scene->drag_h = trk_h * plugin->config.scene_h/100.; + drag_scene->drag_x = trk_w * plugin->config.scene_x/100. - drag_scene->drag_w/2; + drag_scene->drag_y = trk_h * plugin->config.scene_y/100. - drag_scene->drag_h/2; + track = drag_object->get_drag_track(); + trk_w = track->track_w, trk_h = track->track_h; + drag_object->drag_w = trk_w * plugin->config.object_w/100.; + drag_object->drag_h = trk_h * plugin->config.object_h/100.; + drag_object->drag_x = trk_w * plugin->config.object_x/100. - drag_object->drag_w/2; + drag_object->drag_y = trk_h * plugin->config.object_y/100. - drag_object->drag_h/2; + plugin->send_configure_change(); +} FindObjScanFloat::FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui, int x, int y, float *value) @@ -191,10 +233,17 @@ int FindObjScanFloat::handle_event() { *value = get_value(); center_text->update(*value); - plugin->send_configure_change(); + gui->update_drag(); return 1; } +void FindObjScanFloat::update(float v) +{ + BC_FPot::update(*value = v); + center_text->update(v); + plugin->send_configure_change(); +} + FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui, int x, int y, float *value) @@ -211,26 +260,34 @@ int FindObjScanFloatText::handle_event() { *value = atof(get_text()); center->update(*value); - plugin->send_configure_change(); + gui->update_drag(); return 1; } -FindObjDrawBorder::FindObjDrawBorder(FindObjMain *plugin, FindObjWindow *gui, +FindObjDrawSceneBorder::FindObjDrawSceneBorder(FindObjMain *plugin, FindObjWindow *gui, int x, int y) - : BC_CheckBox(x, y, plugin->config.draw_border, _("Draw border")) + : BC_CheckBox(x, y, plugin->config.draw_scene_border, _("Draw scene border")) { this->gui = gui; this->plugin = plugin; } -int FindObjDrawBorder::handle_event() +int FindObjDrawSceneBorder::handle_event() { - plugin->config.draw_border = get_value(); + plugin->config.draw_scene_border = get_value(); plugin->send_configure_change(); return 1; } +FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui, + int x, int y) + : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border")) +{ + this->gui = gui; + this->plugin = plugin; +} + FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui, int x, int y) @@ -264,20 +321,94 @@ int FindObjReplace::handle_event() } -FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui, - int x, int y) - : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border")) +int FindObjDrawObjectBorder::handle_event() +{ + plugin->config.draw_object_border = get_value(); + plugin->send_configure_change(); + return 1; +} + + +FindObjDragScene::FindObjDragScene(FindObjMain *plugin, FindObjWindow *gui, int x, int y, + float drag_x, float drag_y, float drag_w, float drag_h) + : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_scene, + drag_x, drag_y, drag_w, drag_h) { + this->plugin = plugin; this->gui = gui; +} + +FindObjDragScene::~FindObjDragScene() +{ +} + +int FindObjDragScene::handle_event() +{ + int ret = DragCheckBox::handle_event(); + plugin->send_configure_change(); + return ret; +} +Track *FindObjDragScene::get_drag_track() +{ + return plugin->server->plugin->track; +} +int64_t FindObjDragScene::get_drag_position() +{ + return plugin->get_source_position(); +} +void FindObjDragScene::update_gui() +{ + Track *track = get_drag_track(); + int trk_w = track->track_w, trk_h = track->track_h; + float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2; +printf("scene=%f,%f wxh=%fx%f ctr=%f,%f\n",drag_x,drag_y,drag_w,drag_h, ctr_x,ctr_y); + gui->scene_x->update( plugin->config.scene_x = 100. * ctr_x / trk_w ); + gui->scene_y->update( plugin->config.scene_y = 100. * ctr_y / trk_h ); + gui->scene_w->update( plugin->config.scene_w = 100. * drag_w / trk_w ); + gui->scene_h->update( plugin->config.scene_h = 100. * drag_h / trk_h ); + plugin->send_configure_change(); +} + +FindObjDragObject::FindObjDragObject(FindObjMain *plugin, FindObjWindow *gui, int x, int y, + float drag_x, float drag_y, float drag_w, float drag_h) + : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_object, + drag_x, drag_y, drag_w, drag_h) +{ this->plugin = plugin; + this->gui = gui; } -int FindObjDrawObjectBorder::handle_event() +FindObjDragObject::~FindObjDragObject() { - plugin->config.draw_object_border = get_value(); +} + +int FindObjDragObject::handle_event() +{ + int ret = DragCheckBox::handle_event(); plugin->send_configure_change(); - return 1; + return ret; } +Track *FindObjDragObject::get_drag_track() +{ + return plugin->server->plugin->track; +} +int64_t FindObjDragObject::get_drag_position() +{ + return plugin->get_source_position(); +} +void FindObjDragObject::update_gui() +{ + Track *track = get_drag_track(); + int trk_w = track->track_w, trk_h = track->track_h; + float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2; +printf("object %f,%f %fx%f ctr %f,%f\n", drag_x,drag_y,drag_w,drag_h,ctr_x,ctr_y); + gui->object_x->update( plugin->config.object_x = 100. * ctr_x / trk_w ); + gui->object_y->update( plugin->config.object_y = 100. * ctr_y / trk_h ); + gui->object_w->update( plugin->config.object_w = 100. * drag_w / trk_w ); + gui->object_h->update( plugin->config.object_h = 100. * drag_h / trk_h ); + plugin->send_configure_change(); +} + FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y) diff --git a/cinelerra-5.1/plugins/findobj/findobjwindow.h b/cinelerra-5.1/plugins/findobj/findobjwindow.h index 0aa7e4ff..3c2aa634 100644 --- a/cinelerra-5.1/plugins/findobj/findobjwindow.h +++ b/cinelerra-5.1/plugins/findobj/findobjwindow.h @@ -23,16 +23,19 @@ #ifndef __FINDOBJWINDOW_H__ #define __FINDOBJWINDOW_H__ -#include "guicast.h" +#include "dragcheckbox.h" #include "findobj.inc" +#include "guicast.h" class FindObjLayer; class FindObjScanFloat; class FindObjScanFloatText; -class FindObjDrawBorder; +class FindObjDrawSceneBorder; class FindObjDrawKeypoints; class FindObjReplace; class FindObjDrawObjectBorder; +class FindObjDragObject; +class FindObjDragScene; class FindObjAlgorithm; class FindObjBlend; class FindObjWindow; @@ -54,6 +57,7 @@ class FindObjScanFloat : public BC_FPot public: FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui, int x, int y, float *value); int handle_event(); + void update(float v); FindObjMain *plugin; FindObjWindow *gui; FindObjScanFloatText *center_text; @@ -72,10 +76,19 @@ public: }; -class FindObjDrawBorder : public BC_CheckBox +class FindObjDrawSceneBorder : public BC_CheckBox +{ +public: + FindObjDrawSceneBorder(FindObjMain *plugin, FindObjWindow *gui, int x, int y); + int handle_event(); + FindObjMain *plugin; + FindObjWindow *gui; +}; + +class FindObjDrawObjectBorder : public BC_CheckBox { public: - FindObjDrawBorder(FindObjMain *plugin, FindObjWindow *gui, int x, int y); + FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui, int x, int y); int handle_event(); FindObjMain *plugin; FindObjWindow *gui; @@ -99,11 +112,34 @@ public: FindObjWindow *gui; }; -class FindObjDrawObjectBorder : public BC_CheckBox +class FindObjDragScene : public DragCheckBox { public: - FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui, int x, int y); + FindObjDragScene(FindObjMain *plugin, FindObjWindow *gui, int x, int y, + float drag_x, float drag_y, float drag_w, float drag_h); + ~FindObjDragScene(); + int handle_event(); + Track *get_drag_track(); + int64_t get_drag_position(); + void update_gui(); + + FindObjMain *plugin; + FindObjWindow *gui; + +}; + +class FindObjDragObject : public DragCheckBox +{ +public: + FindObjDragObject(FindObjMain *plugin, FindObjWindow *gui, int x, int y, + float drag_x, float drag_y, float drag_w, float drag_h); + ~FindObjDragObject(); + int handle_event(); + Track *get_drag_track(); + int64_t get_drag_position(); + void update_gui(); + FindObjMain *plugin; FindObjWindow *gui; }; @@ -145,6 +181,7 @@ public: FindObjWindow(FindObjMain *plugin); ~FindObjWindow(); void create_objects(); + void update_drag(); FindObjAlgorithm *algorithm; FindObjUseFlann *use_flann; @@ -153,9 +190,11 @@ public: FindObjScanFloat *scene_x, *scene_y, *scene_w, *scene_h; FindObjScanFloatText *scene_x_text, *scene_y_text, *scene_w_text, *scene_h_text; FindObjDrawKeypoints *draw_keypoints; - FindObjDrawBorder *draw_border; + FindObjDrawSceneBorder *draw_scene_border; FindObjReplace *replace_object; FindObjDrawObjectBorder *draw_object_border; + FindObjDragObject *drag_object; + FindObjDragScene *drag_scene; FindObjLayer *object_layer; FindObjLayer *scene_layer; FindObjLayer *replace_layer; diff --git a/cinelerra-5.1/plugins/findobj/findobjwindow.inc b/cinelerra-5.1/plugins/findobj/findobjwindow.inc index ee8b562a..afc26dfd 100644 --- a/cinelerra-5.1/plugins/findobj/findobjwindow.inc +++ b/cinelerra-5.1/plugins/findobj/findobjwindow.inc @@ -25,7 +25,7 @@ class FindObjLayer; class FindObjScanFloat; class FindObjScanFloatText; -class FindObjDrawBorder; +class FindObjDrawSceneBorder; class FindObjDrawKeypoints; class FindObjReplace; class FindObjDrawObjectBorder; diff --git a/cinelerra-5.1/plugins/titler/titler.C b/cinelerra-5.1/plugins/titler/titler.C index 9056bc19..8d964918 100644 --- a/cinelerra-5.1/plugins/titler/titler.C +++ b/cinelerra-5.1/plugins/titler/titler.C @@ -2348,46 +2348,9 @@ int TitleMain::init_freetype() void TitleMain::draw_boundry() { - VFrame &out = *output; - int iw = output->get_w(), ih = output->get_h(); - int mr = MIN(iw, ih)/200 + 2, rr = 2*mr; - int x = title_x, y = title_y, w = title_w, h = title_h; - int r2 = (rr+1)/2; - int x0 = x-r2, x1 = x+(w+1)/2, x2 = x+w+r2; - int y0 = y-r2, y1 = y+(h+1)/2, y2 = y+h+r2; - int st = 1; - for( int r=2; r=0; ) { // bbox - int lft = x+r, rgt = x+w-1-r; - int top = y+r, bot = y+h-1-r; - out.draw_line(lft,top, rgt,top); - out.draw_line(rgt,top, rgt,bot); - out.draw_line(rgt,bot, lft,bot); - out.draw_line(lft,bot, lft,top); - } - - for( int r=mr; r=0; ) { // edge arrows - out.draw_line(x1-r,y0+r, x1+r,y0+r); - out.draw_line(x2-r,y1-r, x2-r,y1+r); - out.draw_line(x1-r,y2-r, x1+r,y2-r); - out.draw_line(x0+r,y1+r, x0+r,y1-r); - } - x0 += r2; y0 += r2; x2 -= r2; y2 -= r2; - for( int r=2*mr; --r>=0; ) { // corner arrows - out.draw_line(x0,y0+r, x0+r,y0); - out.draw_line(x2,y0+r, x2-r,y0); - out.draw_line(x2,y2-r, x2-r,y2); - out.draw_line(x0,y2-r, x0+r,y2); - } + if( !gui_open() ) return; + DragCheckBox::draw_boundary(output, + title_x, title_y, title_w, title_h); } diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.C b/cinelerra-5.1/plugins/titler/titlerwindow.C index f03f8a08..1fc0a1e5 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.C +++ b/cinelerra-5.1/plugins/titler/titlerwindow.C @@ -28,6 +28,7 @@ #include "automation.h" #include "cwindow.h" #include "cwindowgui.h" +#include "dragcheckbox.h" #include "edl.h" #include "edlsession.h" #include "keys.h" @@ -120,7 +121,7 @@ TitleWindow::TitleWindow(TitleMain *client) void TitleWindow::done_event(int result) { - ungrab(client->server->mwindow->cwindow->gui); + drag->drag_deactivate(); color_thread->close_window(); outline_color_thread->close_window(); color_popup->close_window(); @@ -260,9 +261,10 @@ void TitleWindow::create_objects() if( bold->get_w() > w1 ) w1 = bold->get_w(); add_tool(drag = new TitleDrag(client, this, x, y + 80)); + drag->create_objects(); if( drag->get_w() > w1 ) w1 = drag->get_w(); if( client->config.drag ) { - if( !grab(client->server->mwindow->cwindow->gui) ) + if( drag->drag_activate() ) eprintf("drag enabled, but compositor already grabbed\n"); } @@ -473,175 +475,17 @@ int TitleWindow::resize_event(int w, int h) return 1; } -void TitleWindow::send_configure_change() -{ - pending_config = 0; - client->send_configure_change(); -} -int TitleWindow::check_configure_change(int ret) +void TitleWindow::update_drag() { - if( pending_config && !grab_event_count() ) - send_configure_change(); - return ret; + 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; + send_configure_change(); } - -int TitleWindow::grab_event(XEvent *event) +void TitleWindow::send_configure_change() { - switch( event->type ) { - case ButtonPress: break; - case ButtonRelease: break; - case MotionNotify: break; - default: - return check_configure_change(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 || - cy < 0 || cy >= mwindow->theme->ccanvas_h ) - return check_configure_change(0); - } - - switch( event->type ) { - case ButtonPress: - if( !dragging ) break; - return 1; - case ButtonRelease: - if( !dragging ) return check_configure_change(0); - dragging = 0; - return 1; - case MotionNotify: - if( !dragging ) return check_configure_change(0); - break; - default: - return check_configure_change(0); - } - - 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; - Track *track = client->server->plugin->track; - int track_w = track->track_w, track_h = track->track_h; - track->automation->get_projector( - &projector_x, &projector_y, &projector_z, - position, PLAY_FORWARD); - projector_x += mwindow->edl->session->output_w / 2; - projector_y += mwindow->edl->session->output_h / 2; - cursor_x = (cursor_x - projector_x) / projector_z + track_w / 2; - cursor_y = (cursor_y - projector_y) / projector_z + track_h / 2; - int title_x = client->config.title_x, title_y = client->config.title_y; - int title_w = client->config.title_w, title_h = client->config.title_h; - if( !title_w ) title_w = track_w; - if( !title_h ) title_h = track_h; - int r = MIN(track_w, track_h)/100 + 2; - int x0 = title_x, x1 = title_x+(title_w+1)/2, x2 = title_x+title_w; - 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 - 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; - else if( abs(drag_dx = cursor_x-x2) < r && // x2,y0 - abs(drag_dy = cursor_y-y0) < r ) dragging = 3; - else if( abs(drag_dx = cursor_x-x2) < r && // x2,y1 - abs(drag_dy = cursor_y-y1) < r ) dragging = 4; - else if( abs(drag_dx = cursor_x-x2) < r && // x2,y2 - abs(drag_dy = cursor_y-y2) < r ) dragging = 5; - else if( abs(drag_dx = cursor_x-x1) < r && // x1,y2 - abs(drag_dy = cursor_y-y2) < r ) dragging = 6; - else if( abs(drag_dx = cursor_x-x0) < r && // x0,y2 - abs(drag_dy = cursor_y-y2) < r ) dragging = 7; - else if( abs(drag_dx = cursor_x-x0) < r && // x0,y1 - abs(drag_dy = cursor_y-y1) < r ) dragging = 8; - else if( abs(drag_dx = cursor_x-x1) < r && // x1,y1 - abs(drag_dy = cursor_y-y1) < r ) dragging = 9; - return 0; - } - switch( dragging ) { - case 1: { // x0,y0 - int cur_x = cursor_x - drag_dx, dx = cur_x - x0; - int cur_y = cursor_y - drag_dy, dy = cur_y - y0; - if( !dx && !dy ) return 1; - int cur_w = title_w - dx; if( cur_w < 1 ) cur_w = 1; - int cur_h = title_h - dy; if( cur_h < 1 ) cur_h = 1; - this->title_x->update((int64_t)(client->config.title_x = cur_x)); - this->title_y->update((int64_t)(client->config.title_y = cur_y)); - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 2: { // x1,y0 - int cur_y = cursor_y - drag_dy, dy = cur_y - y0; - if( !dy ) return 1; - int cur_h = title_h - dy; if( cur_h < 1 ) cur_h = 1; - this->title_y->update((int64_t)(client->config.title_y = cur_y)); - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 3: { // x2,y0 - int cur_x = cursor_x - drag_dx, dx = cur_x - x2; - int cur_y = cursor_y - drag_dy, dy = cur_y - y0; - int cur_w = title_w + dx; if( cur_w < 1 ) cur_w = 1; - int cur_h = title_h - dy; if( cur_h < 1 ) cur_h = 1; - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - this->title_y->update((int64_t)(client->config.title_y = cur_y)); - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 4: { // x2,y1 - int cur_x = cursor_x - drag_dx, dx = cur_x - x2; - if( !dx ) return 1; - int cur_w = title_w + dx; if( cur_w < 1 ) cur_w = 1; - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - break; } - case 5: { // x2,y2 - int cur_x = cursor_x - drag_dx, dx = cur_x - x2; - int cur_y = cursor_y - drag_dy, dy = cur_y - y2; - int cur_w = title_w + dx; if( cur_w < 1 ) cur_w = 1; - int cur_h = title_h + dy; if( cur_h < 1 ) cur_h = 1; - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 6: { // x1,y2 - int cur_y = cursor_y - drag_dy, dy = cur_y - y2; - if( client->config.title_h == cur_y ) return 1; - int cur_h = title_h + dy; if( cur_h < 1 ) cur_h = 1; - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 7: { // x0,y2 - int cur_x = cursor_x - drag_dx, dx = cur_x - x0; - int cur_y = cursor_y - drag_dy, dy = cur_y - y2; - int cur_w = title_w - dx; if( cur_w < 1 ) cur_w = 1; - int cur_h = title_h + dy; if( cur_h < 1 ) cur_h = 1; - this->title_x->update((int64_t)(client->config.title_x = cur_x)); - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - this->title_h->update((int64_t)(client->config.title_h = cur_h)); - break; } - case 8: { // x0,y1 - int cur_x = cursor_x - drag_dx, dx = cur_x - x0; - if( !dx ) return 1; - int cur_w = title_w - dx; if( cur_w < 1 ) cur_w = 1; - this->title_x->update((int64_t)(client->config.title_x = cur_x)); - this->title_w->update((int64_t)(client->config.title_w = cur_w)); - break; } - case 9: { // x1,y1 - int cur_x = cursor_x - drag_dx, dx = cur_x - x1; - int cur_y = cursor_y - drag_dy, dy = cur_y - y1; - if( title_x == cur_x && title_y == cur_y ) return 1; - this->title_x->update((int64_t)(client->config.title_x += dx)); - this->title_y->update((int64_t)(client->config.title_y += dy)); - } - } - if( !grab_event_count() ) - send_configure_change(); - else - pending_config = 1; - return 1; + client->send_configure_change(); } void TitleWindow::previous_font() @@ -792,7 +636,6 @@ int TitleFontTumble::handle_down_event() } - TitleSizeTumble::TitleSizeTumble(TitleMain *client, TitleWindow *window, int x, int y) : BC_Tumbler(x, y) { @@ -1240,7 +1083,7 @@ TitleX::TitleX(TitleMain *client, TitleWindow *window, int x, int y) int TitleX::handle_event() { client->config.title_x = atof(get_text()); - window->send_configure_change(); + window->update_drag(); return 1; } @@ -1255,7 +1098,7 @@ TitleY::TitleY(TitleMain *client, TitleWindow *window, int x, int y) int TitleY::handle_event() { client->config.title_y = atof(get_text()); - window->send_configure_change(); + window->update_drag(); return 1; } @@ -1269,7 +1112,7 @@ TitleW::TitleW(TitleMain *client, TitleWindow *window, int x, int y) int TitleW::handle_event() { client->config.title_w = atol(get_text()); - window->send_configure_change(); + window->update_drag(); return 1; } @@ -1283,7 +1126,7 @@ TitleH::TitleH(TitleMain *client, TitleWindow *window, int x, int y) int TitleH::handle_event() { client->config.title_h = atol(get_text()); - window->send_configure_change(); + window->update_drag(); return 1; } @@ -1423,27 +1266,42 @@ int TitleColorThread::handle_new_color(int output, int alpha) } TitleDrag::TitleDrag(TitleMain *client, TitleWindow *window, int x, int y) - : BC_CheckBox(x, y, client->config.drag, _("Drag")) + : DragCheckBox(client->server->mwindow, x, y, _("Drag"), &client->config.drag, + client->config.title_x, client->config.title_y, + client->config.title_w, client->config.title_h) { this->client = client; this->window = window; } +Track *TitleDrag::get_drag_track() +{ + return client->server->plugin->track; +} +int64_t TitleDrag::get_drag_position() +{ + return client->get_source_position(); +} + +void TitleDrag::update_gui() +{ + client->config.drag = get_value(); + client->config.title_x = drag_x; + client->config.title_y = drag_y; + client->config.title_w = drag_w+0.5; + client->config.title_h = drag_h+0.5; + window->title_x->update((float)client->config.title_x); + window->title_y->update((float)client->config.title_y); + window->title_w->update((int64_t)client->config.title_w); + window->title_h->update((int64_t)client->config.title_h); + window->send_configure_change(); +} + int TitleDrag::handle_event() { - int value = get_value(); - CWindowGUI *cwindow_gui = client->server->mwindow->cwindow->gui; - if( value ) { - if( !window->grab(cwindow_gui) ) { - update(value = 0); - flicker(10,50); - } - } - else - window->ungrab(cwindow_gui); - client->config.drag = value; + int ret = DragCheckBox::handle_event(); window->send_configure_change(); - return 1; + return ret; } TitleBackground::TitleBackground(TitleMain *client, TitleWindow *window, int x, int y) diff --git a/cinelerra-5.1/plugins/titler/titlerwindow.h b/cinelerra-5.1/plugins/titler/titlerwindow.h index def051b8..0a5122b4 100644 --- a/cinelerra-5.1/plugins/titler/titlerwindow.h +++ b/cinelerra-5.1/plugins/titler/titlerwindow.h @@ -29,6 +29,7 @@ class TitleWindow; class TitleInterlace; #include "colorpicker.h" +#include "dragcheckbox.h" #include "filexml.h" #include "mutex.h" #include "titler.h" @@ -89,7 +90,7 @@ public: void create_objects(); int resize_event(int w, int h); - int grab_event(XEvent *event); + void update_drag(); void update_color(); void update_justification(); void update_stats(); @@ -233,11 +234,15 @@ public: TitleMain *client; TitleWindow *window; }; -class TitleDrag : public BC_CheckBox +class TitleDrag : public DragCheckBox { public: TitleDrag(TitleMain *client, TitleWindow *window, int x, int y); int handle_event(); + void update_gui(); + Track *get_drag_track(); + int64_t get_drag_position(); + TitleMain *client; TitleWindow *window; };