defaults for mxf format + android/termux patches from Andrew
[goodguy/cinelerra.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, xS(320), yS(160), xS(320), yS(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 xs10 = xS(10);
47         int ys10 = yS(10), ys15 = yS(15);
48         int x = xs10, y = ys10;
49         BC_Title *title = new BC_Title(x, y, _("StylizeObj"));
50         add_subwindow(title);
51         y += title->get_h() + ys10;
52         int x1 = x;
53         add_subwindow(title = new BC_Title(x1, y, _("Mode: ")));
54         x1 += title->get_w() + ys15;
55         add_subwindow(mode = new StylizeObjMode(this, x1, y, &plugin->config.mode));
56         mode->create_objects();
57         y += mode->get_h() + ys10;
58         x0 = x;  y0 = y;
59         update_params();
60         show_window(1);
61 }
62
63 void StylizeObjWindow::update_params()
64 {
65         int ys10 = yS(10);
66         int x = x0, y = y0;
67         if( plugin->config.mode == MODE_PENCIL_SKETCH ||
68             plugin->config.mode == MODE_COLOR_SKETCH ) {
69                 int x1 = x + xS(80);
70                 if( !smooth_title )
71                         add_subwindow(smooth_title = new BC_Title(x,y,_("Smooth:")));
72                 if( !smoothing )
73                         add_subwindow(smoothing = new StylizeObjFSlider(this,
74                                 x1,y,xS(180), 0,xS(100), &plugin->config.smoothing));
75                 y += smoothing->get_h() + ys10;
76                 if( !edge_title )
77                         add_subwindow(edge_title = new BC_Title(x,y,_("Edges:")));
78                 if( !edge_strength )
79                         add_subwindow(edge_strength = new StylizeObjFSlider(this,
80                                 x1,y,xS(180), 0,xS(100), &plugin->config.edge_strength));
81                 y += edge_strength->get_h() + ys10;
82                 if( !shade_title )
83                         add_subwindow(shade_title = new BC_Title(x,y,_("Shade:")));
84                 if( !shade_factor )
85                         add_subwindow(shade_factor = new StylizeObjFSlider(this,
86                                 x1,y,xS(180), 0,xS(100), &plugin->config.shade_factor));
87                 //y += shade_factor->get_h() + ys10;
88         }
89         else {
90                 delete smooth_title;    smooth_title = 0;
91                 delete smoothing;       smoothing = 0;
92                 delete edge_title;      edge_title = 0;
93                 delete edge_strength;   edge_strength = 0;
94                 delete shade_title;     shade_title = 0;
95                 delete shade_factor;    shade_factor = 0;
96         }
97 }
98
99 StylizeObjModeItem::StylizeObjModeItem(StylizeObjMode *popup, int type, const char *text)
100  : BC_MenuItem(text)
101 {
102         this->popup = popup;
103         this->type = type;
104 }
105
106 StylizeObjModeItem::~StylizeObjModeItem()
107 {
108 }
109
110 int StylizeObjModeItem::handle_event()
111 {
112         popup->update(type);
113         popup->win->update_params();
114         return popup->handle_event();
115 }
116
117 StylizeObjMode::StylizeObjMode(StylizeObjWindow *win, int x, int y, int *value)
118  : BC_PopupMenu(x, y, xS(150), "", 1)
119 {
120         this->win = win;
121         this->value = value;
122 }
123
124 StylizeObjMode::~StylizeObjMode()
125 {
126 }
127
128 void StylizeObjMode::create_objects()
129 {
130         add_item(new StylizeObjModeItem(this, MODE_EDGE_SMOOTH,    _("Edge smooth")));
131         add_item(new StylizeObjModeItem(this, MODE_EDGE_RECURSIVE, _("Edge recursive")));
132         add_item(new StylizeObjModeItem(this, MODE_DETAIL_ENHANCE, _("Detail Enhance")));
133         add_item(new StylizeObjModeItem(this, MODE_PENCIL_SKETCH,  _("Pencil Sketch")));
134         add_item(new StylizeObjModeItem(this, MODE_COLOR_SKETCH,   _("Color Sketch")));
135         add_item(new StylizeObjModeItem(this, MODE_STYLIZATION,    _("Stylization")));
136         set_value(*value);
137 }
138
139 int StylizeObjMode::handle_event()
140 {
141         win->plugin->send_configure_change();
142         return 1;
143 }
144
145 void StylizeObjMode::update(int v)
146 {
147         set_value(*value = v);
148 }
149
150 void StylizeObjMode::set_value(int v)
151 {
152         int i = total_items();
153         while( --i >= 0 && ((StylizeObjModeItem*)get_item(i))->type != v );
154         if( i >= 0 ) set_text(get_item(i)->get_text());
155 }
156
157 StylizeObjFSlider::StylizeObjFSlider(StylizeObjWindow *win,
158                 int x, int y, int w, float min, float max, float *output)
159  : BC_FSlider(x, y, 0,w,w, min,max, *output)
160 {
161         this->win = win;
162         this->output = output;
163 }
164 StylizeObjFSlider::~StylizeObjFSlider()
165 {
166 }
167
168 int StylizeObjFSlider::handle_event()
169 {
170         *output = get_value();
171         win->plugin->send_configure_change();
172         return 1;
173 }
174