Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / test9.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2018-2020 William Morrow
4  *
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.
9  *
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.
14  *
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
18  * USA
19  */
20
21
22 #include "bcsignals.h"
23 #include "guicast.h"
24 #include "pys_icon_png.h"
25
26 class TestList : public BC_ListBox
27 {
28 public:
29         TestList(int x, int y, int w, int h, 
30                 ArrayList<BC_ListBoxItem*> *items);
31         int handle_event();
32         int selection_changed();
33 };
34
35 TestList::TestList(int x, int y, int w, int h, 
36                 ArrayList<BC_ListBoxItem*> *items)
37  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, items,
38         0, 0, 1, 0, 0, LISTBOX_SINGLE, ICON_LEFT, 0)
39 {
40 }
41
42 int TestList::handle_event()
43 {
44         printf("handle_event\n");
45         return 1;
46 }
47
48 int TestList::selection_changed()
49 {
50         BC_ListBoxItem *item = get_selection(0, 0);
51         printf("selection_changed %s\n", !item ? "<nul>" : item->get_text());
52         return 1;
53 }
54
55 class TestWindow : public BC_Window
56 {
57 public:
58         TestWindow() : BC_Window("Test9", 0, 0, 320, 240) {};
59         void create_objects();
60         int keypress_event();
61         BC_ListBox *list;
62         ArrayList<BC_ListBoxItem*> items;
63 };
64
65 void TestWindow::create_objects()
66 {
67         lock_window("AWindowRemovePluginGUI::create_objects");
68         set_color(BLACK);
69         set_font(LARGEFONT);
70         int x = 10, y = 20;
71         draw_text(x, y, "Hello world");
72         y += 25;
73         BC_Button *ok_button = new BC_OKButton(this);
74         add_subwindow(ok_button);
75         BC_Button *cancel_button = new BC_CancelButton(this);
76         add_subwindow(cancel_button);
77         BC_ListBoxItem *thing;
78         ArrayList<BC_ListBoxItem*> *sublist;
79         items.append(thing = new BC_ListBoxItem("thing 1"));
80         VFrame *pys_icon = new VFramePng(pys_icon_png);
81         thing->set_icon_vframe(pys_icon);
82         int pw = pys_icon->get_w(), ph = pys_icon->get_h();
83         BC_Pixmap *pys_picon = new BC_Pixmap(this, pw, ph);
84         pys_picon->draw_vframe(pys_icon, 0, 0, pw, pw, 0, 0);
85         thing->set_icon(pys_picon);
86         sublist = thing->new_sublist(1);
87         BC_ListBoxItem *fish, *cat, *hat;
88         sublist->append(fish = new BC_ListBoxItem("fish"));
89         ArrayList<BC_ListBoxItem*> *fish_list = fish->new_sublist(1);
90         fish_list->append(new BC_ListBoxItem("green"));
91         fish_list->append(new BC_ListBoxItem("eggs"));
92         fish_list->append(new BC_ListBoxItem("ham"));
93         sublist->append(cat = new BC_ListBoxItem("cat"));
94         ArrayList<BC_ListBoxItem*> *cat_list = cat->new_sublist(1);
95         cat_list->append(new BC_ListBoxItem("videos"));
96         sublist->append(hat = new BC_ListBoxItem("hat"));
97         ArrayList<BC_ListBoxItem*> *hat_list = hat->new_sublist(1);
98         hat_list->append(new BC_ListBoxItem("bonnet"));
99         hat_list->append(new BC_ListBoxItem("cap"));
100         hat_list->append(new BC_ListBoxItem("sombrero"));
101         items.append(thing = new BC_ListBoxItem("thing 2"));
102         int lw = get_w()-x-10, lh = ok_button->get_y() - y - 5;
103         add_subwindow(list = new TestList(x, y, lw, lh, &items));
104         show_window();
105         unlock_window();
106 }
107
108 int TestWindow::keypress_event()
109 {
110         switch( get_keypress() ) {
111         case 'v':
112                 switch( list->get_format() ) {
113                 case LISTBOX_TEXT:
114                         list->update_format(LISTBOX_ICONS, 1);
115                         break;
116                 case LISTBOX_ICONS:
117                         list->update_format(LISTBOX_ICONS_PACKED, 1);
118                         break;
119                 case LISTBOX_ICONS_PACKED:
120                         list->update_format(LISTBOX_ICON_LIST, 1);
121                         break;
122                 case LISTBOX_ICON_LIST:
123                         list->update_format(LISTBOX_TEXT, 1);
124                         break;
125                 }
126                 break;
127         }
128         return 1;
129 }
130
131 int main()
132 {
133         new BC_Signals;
134         TestWindow window;
135         window.create_objects();
136         window.run_window();
137 }
138