additional Andrew provided Termux mods +
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / test6.C
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <math.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9
10 #include "bcwindowbase.h"
11 #include "bcwindow.h"
12 #include "bcsignals.h"
13 #include "bccolors.h"
14 #include "clip.h"
15 #include "fonts.h"
16 #include "thread.h"
17 #include "vframe.h"
18
19 /*c++ -g -I/mnt1/build5/cinelerra-5.1/guicast x.C \
20   /mnt1/build5/cinelerra-5.1/guicast/x86_64/libguicast.a \
21   -DHAVE_GL -DHAVE_XFT -I/usr/include/freetype2 -lGL -lX11 -lXext \
22   -lXinerama -lXv -lpng  -lfontconfig -lfreetype -lXft -pthread */
23
24 void wheel(VFrame *dst, float cx, float cy, float rad, int bg_color)
25 {
26         int color_model = dst->get_color_model();
27         int bpp = BC_CModels::calculate_pixelsize(color_model);
28         int bg_r = (bg_color>>16) & 0xff;
29         int bg_g = (bg_color>> 8) & 0xff;
30         int bg_b = (bg_color>> 0) & 0xff;
31         int w = dst->get_w(), h = dst->get_h();
32         unsigned char **rows = dst->get_rows();
33         for( int y=0; y<h; ++y ) {
34                 unsigned char *row = rows[y];
35                 for( int x=0; x<w; ++x,row+=bpp ) {
36                         int dx = cx-x, dy = cy-y;
37                         float d = sqrt(dx*dx + dy*dy);
38                         float r, g, b;
39                         if( d < rad ) {
40                                 float h = TO_DEG(atan2(cx-x, cy-y));
41                                 if( h < 0 ) h += 360;
42                                 float s = d / rad, v = 255;
43                                 HSV::hsv_to_rgb(r, g, b, h, s, v);
44                         }
45                         else {
46                                  r = bg_r; g = bg_g; b = bg_b;
47                         }
48                         row[0] = r; row[1] = g; row[2] = b;
49                 }
50         }
51 }
52
53 class TestWindowGUI : public BC_Window
54 {
55 public:
56         VFrame *wfrm;
57         int bg;
58
59         TestWindowGUI(int x, int y, int w, int h);
60         ~TestWindowGUI();
61
62         void draw(int ww, int wh) {
63                 delete wfrm;
64                 wfrm = new VFrame(ww,wh,BC_RGB888);
65                 float wr = bmin(ww, wh)/2.25;
66                 int bg = get_bg_color();
67                 wheel(wfrm, ww/2,wh/2, wr, bg);
68                 draw_vframe(wfrm);
69                 flash();
70         }
71         int resize_event(int w, int h) {
72                 BC_WindowBase::resize_event(w, h);
73                 draw(w, h);
74                 return 0;
75         }
76 };
77
78 TestWindowGUI::
79 TestWindowGUI(int x, int y, int w, int h)
80  : BC_Window("test", x,y, w,h, 100,100)
81 {
82         wfrm = 0;
83         set_bg_color(0x885533);
84         lock_window("init");
85         clear_box(0,0,w,h);
86         flash();
87         unlock_window();
88 }
89
90 TestWindowGUI::
91 ~TestWindowGUI()
92 {
93 }
94
95
96 class TestWindow : public Thread
97 {
98         TestWindowGUI *gui;
99 public:
100         TestWindow(int x, int y, int w, int h)
101          : Thread(1,0,0) {
102                 gui = new TestWindowGUI(x,y, w,h);
103                 gui->lock_window("init");
104                 gui->resize_event(w, h);
105                 gui->unlock_window();
106                 start();
107         }
108         ~TestWindow() { delete gui; }
109         void run() { gui->run_window(); }
110         void close_window() { gui->close(0); }
111 };
112
113
114 int main(int ac, char **av)
115 {
116         BC_Signals signals;
117         signals.initialize();
118         BC_WindowBase::init_resources(1.);
119         TestWindow test_window(100, 100, 256, 256);
120         test_window.join();
121         return 0;
122 }
123