3 * Copyright (C) 2020 William Morrow
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/types.h>
31 #include "bcwindowbase.h"
33 #include "bcsignals.h"
40 /*c++ -g -I/mnt1/build5/cinelerra-5.1/guicast x.C \
41 /mnt1/build5/cinelerra-5.1/guicast/x86_64/libguicast.a \
42 -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
43 -lXinerama -lXv -lpng -lfontconfig -lfreetype -lXft -pthread */
45 void wheel(VFrame *dst, float cx, float cy, float rad, int bg_color)
47 int color_model = dst->get_color_model();
48 int bpp = BC_CModels::calculate_pixelsize(color_model);
49 int bg_r = (bg_color>>16) & 0xff;
50 int bg_g = (bg_color>> 8) & 0xff;
51 int bg_b = (bg_color>> 0) & 0xff;
52 int w = dst->get_w(), h = dst->get_h();
53 unsigned char **rows = dst->get_rows();
54 for( int y=0; y<h; ++y ) {
55 unsigned char *row = rows[y];
56 for( int x=0; x<w; ++x,row+=bpp ) {
57 int dx = cx-x, dy = cy-y;
58 float d = sqrt(dx*dx + dy*dy);
61 float h = TO_DEG(atan2(cx-x, cy-y));
63 float s = d / rad, v = 255;
64 HSV::hsv_to_rgb(r, g, b, h, s, v);
67 r = bg_r; g = bg_g; b = bg_b;
69 row[0] = r; row[1] = g; row[2] = b;
74 class TestWindowGUI : public BC_Window
80 TestWindowGUI(int x, int y, int w, int h);
83 void draw(int ww, int wh) {
85 wfrm = new VFrame(ww,wh,BC_RGB888);
86 float wr = bmin(ww, wh)/2.25;
87 int bg = get_bg_color();
88 wheel(wfrm, ww/2,wh/2, wr, bg);
92 int resize_event(int w, int h) {
93 BC_WindowBase::resize_event(w, h);
100 TestWindowGUI(int x, int y, int w, int h)
101 : BC_Window("test", x,y, w,h, 100,100)
104 set_bg_color(0x885533);
117 class TestWindow : public Thread
121 TestWindow(int x, int y, int w, int h)
123 gui = new TestWindowGUI(x,y, w,h);
124 gui->lock_window("init");
125 gui->resize_event(w, h);
126 gui->unlock_window();
129 ~TestWindow() { delete gui; }
130 void run() { gui->run_window(); }
131 void close_window() { gui->close(0); }
135 int main(int ac, char **av)
138 signals.initialize();
139 BC_WindowBase::init_resources(1.);
140 TestWindow test_window(100, 100, 256, 256);