compositor f1-f10/j/p shortcuts, opencv upgrade, new stylize,puzzle opencv plugins
[goodguy/history.git] / cinelerra-5.1 / plugins / stylizeobj / stylizeobjwindow.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2014 Adam Williams <broadcast at earthling dot net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * 
19  */
20
21 #include "bcdisplayinfo.h"
22 #include "clip.h"
23 #include "language.h"
24 #include "stylizeobj.h"
25 #include "stylizeobjwindow.h"
26 #include "theme.h"
27
28 StylizeObjWindow::StylizeObjWindow(StylizeObj *plugin)
29  : PluginClientWindow(plugin, 320, 160, 320, 160, 0)
30 {
31         this->plugin = plugin; 
32         smoothing = 0;
33         edge_strength = 0;
34         shade_factor = 0;
35         smooth_title = 0;
36         edge_title = 0;
37         shade_title = 0;
38 }
39
40 StylizeObjWindow::~StylizeObjWindow()
41 {
42 }
43
44 void StylizeObjWindow::create_objects()
45 {
46         int x = 10, y = 10;
47         BC_Title *title = new BC_Title(x, y, _("StylizeObj"));
48         add_subwindow(title);
49         y += title->get_h() + 10;
50         int x1 = x;
51         add_subwindow(title = new BC_Title(x1, y, _("Mode: ")));
52         x1 += title->get_w() + 15;
53         add_subwindow(mode = new StylizeObjMode(this, x1, y, &plugin->config.mode));
54         mode->create_objects();
55         y += mode->get_h() + 10;
56         x0 = x;  y0 = y;
57         update_params();
58         show_window(1);
59 }
60
61 void StylizeObjWindow::update_params()
62 {
63         int x = x0, y = y0;
64         if( plugin->config.mode == MODE_PENCIL_SKETCH ||
65             plugin->config.mode == MODE_COLOR_SKETCH ) {
66                 int x1 = x + 80;
67                 if( !smooth_title )
68                         add_subwindow(smooth_title = new BC_Title(x,y,_("Smooth:")));
69                 if( !smoothing )
70                         add_subwindow(smoothing = new StylizeObjFSlider(this,
71                                 x1,y,180, 0,100, &plugin->config.smoothing));
72                 y += smoothing->get_h() + 10;
73                 if( !edge_title )
74                         add_subwindow(edge_title = new BC_Title(x,y,_("Edges:")));
75                 if( !edge_strength )
76                         add_subwindow(edge_strength = new StylizeObjFSlider(this,
77                                 x1,y,180, 0,100, &plugin->config.edge_strength));
78                 y += edge_strength->get_h() + 10;
79                 if( !shade_title )
80                         add_subwindow(shade_title = new BC_Title(x,y,_("Shade:")));
81                 if( !shade_factor )
82                         add_subwindow(shade_factor = new StylizeObjFSlider(this,
83                                 x1,y,180, 0,100, &plugin->config.shade_factor));
84                 //y += shade_factor->get_h() + 10;
85         }
86         else {
87                 delete smooth_title;    smooth_title = 0;
88                 delete smoothing;       smoothing = 0;
89                 delete edge_title;      edge_title = 0;
90                 delete edge_strength;   edge_strength = 0;
91                 delete shade_title;     shade_title = 0;
92                 delete shade_factor;    shade_factor = 0;
93         }
94 }
95
96 StylizeObjModeItem::StylizeObjModeItem(StylizeObjMode *popup, int type, const char *text)
97  : BC_MenuItem(text)
98 {
99         this->popup = popup;
100         this->type = type;
101 }
102
103 StylizeObjModeItem::~StylizeObjModeItem()
104 {
105 }
106
107 int StylizeObjModeItem::handle_event()
108 {
109         popup->update(type);
110         popup->win->update_params();
111         return popup->handle_event();
112 }
113
114 StylizeObjMode::StylizeObjMode(StylizeObjWindow *win, int x, int y, int *value)
115  : BC_PopupMenu(x, y, 150, "", 1)
116 {
117         this->win = win;
118         this->value = value;
119 }
120
121 StylizeObjMode::~StylizeObjMode()
122 {
123 }
124
125 void StylizeObjMode::create_objects()
126 {
127         add_item(new StylizeObjModeItem(this, MODE_EDGE_SMOOTH,    _("Edge smooth")));
128         add_item(new StylizeObjModeItem(this, MODE_EDGE_RECURSIVE, _("Edge recursive")));
129         add_item(new StylizeObjModeItem(this, MODE_DETAIL_ENHANCE, _("Detail Enhance")));
130         add_item(new StylizeObjModeItem(this, MODE_PENCIL_SKETCH,  _("Pencil Sketch")));
131         add_item(new StylizeObjModeItem(this, MODE_COLOR_SKETCH,   _("Color Sketch")));
132         add_item(new StylizeObjModeItem(this, MODE_STYLIZATION,    _("Stylization")));
133         set_value(*value);
134 }
135
136 int StylizeObjMode::handle_event()
137 {
138         win->plugin->send_configure_change();
139         return 1;
140 }
141
142 void StylizeObjMode::update(int v)
143 {
144         set_value(*value = v);
145 }
146
147 void StylizeObjMode::set_value(int v)
148 {
149         int i = total_items();
150         while( --i >= 0 && ((StylizeObjModeItem*)get_item(i))->type != v );
151         if( i >= 0 ) set_text(get_item(i)->get_text());
152 }
153
154 StylizeObjFSlider::StylizeObjFSlider(StylizeObjWindow *win,
155                 int x, int y, int w, float min, float max, float *output)
156  : BC_FSlider(x, y, 0,w,w, min,max, *output)
157 {
158         this->win = win;
159         this->output = output;
160 }
161 StylizeObjFSlider::~StylizeObjFSlider()
162 {
163 }
164
165 int StylizeObjFSlider::handle_event()
166 {
167         *output = get_value();
168         win->plugin->send_configure_change();
169         return 1;
170 }
171