Thicker bars, better letters
[mussa.git] / gui / AnnotWindow.cxx
1 //  This file is part of the Mussa source distribution.
2 //  http://mussa.caltech.edu/
3 //  Contact author: Tristan  De Buysscher, tristan@caltech.edu
4
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
9
10
11 #include "AnnotWindow.hh"
12 #include <iostream>
13 #include <FL/fl_show_colormap.H>
14
15 using namespace std;
16
17 annot_color
18 new_blank_annot()
19 {
20   annot_color *a_annot;
21
22   a_annot = new annot_color;
23   a_annot->type = "";
24   a_annot->color = (Fl_Color) 5;
25   //cout << "type: " << a_annot->type << endl;
26
27   return *a_annot;
28 }
29
30
31 void
32 cb_annot_color(Fl_Button* o, void* v)
33
34   annot_instance * blah = (annot_instance *) v;
35   AnnotWindow* T= blah->mw_ptr;
36   T->cb_annot_color_i(o,blah->index);
37 }
38
39 AnnotWindow::AnnotWindow(int w, int h, const char* title, 
40                          vector<annot_color> * some_annots):Fl_Window(w,h,title)
41 {
42   int i, annot_num;
43
44   the_annots = some_annots;
45   annot_count = 0;
46
47   annot_color_buttons.clear();
48
49   begin();
50   annot_input_pack = new Fl_Pack(0, 0, w, h);
51   annot_input_pack->spacing(4);
52
53   // button to add new annot inputs
54   add_annot = new Fl_Button(0,0,100,24,"Add Annot Slot");
55   add_annot->callback((Fl_Callback*)add_annot_cb, this);
56   annot_input_pack->add(add_annot);
57   // test button to make sure annot data is being stored
58   test = new Fl_Button(0,0,100,24,"show annots");
59   test->callback((Fl_Callback*)print_cb, this);
60   annot_input_pack->add(test);
61
62   // creat an initial set of annot input widgets and attach to annot vector
63   annot_num = some_annots->size();
64   for (i = 0; i < annot_num; i++)
65   {
66     add_annot_input(i);
67     annot_count++;
68   }
69
70   add(annot_input_pack);
71
72   end();
73   resizable(this);
74   show();
75 }
76
77     //tmp_input->user_data((void*) i);
78
79 AnnotWindow::~AnnotWindow(){}
80
81 void
82 AnnotWindow::add_annot_input(int index)
83 {
84   Fl_Output * new_input;
85   Fl_Button *new_color_button;
86   annot_instance * something;
87   Fl_Pack * annot_hor_pack;
88
89
90   something = new annot_instance;
91   something->mw_ptr = this;
92   something->index = index;
93
94   annot_hor_pack = new Fl_Pack(0, 0, w(), 24);
95   annot_hor_pack->type(Fl_Pack::HORIZONTAL);
96   annot_hor_pack->spacing(4);
97
98   // setup the color display/selection button
99   new_color_button = new Fl_Button(0, 0, 24, 24, "");
100   new_color_button->color((*the_annots)[index].color);
101   new_color_button->box(FL_FLAT_BOX);
102   new_color_button->callback((Fl_Callback*)cb_annot_color, (void*) something);
103   annot_color_buttons.push_back(new_color_button);
104   annot_hor_pack->add(new_color_button);
105
106
107   // setup the annot inputs
108   new_input = new Fl_Output(0, 0, 200, 24, "");
109   new_input->value( ((*the_annots)[index].type).c_str() );
110   //new_input->callback((Fl_Callback*)cb_annot_in, (void*) something);
111   annot_ins.push_back(new_input);
112   annot_hor_pack->add(new_input);
113
114   annot_input_pack->add(annot_hor_pack);
115 }
116 /*
117   cout << "fee\n";
118   cout << "fie\n";
119   cout << "foe\n";
120   cout << "fum\n";
121 */
122
123 void
124 AnnotWindow::cb_annot_in_i(Fl_Input* o, int i)
125 {
126   (*the_annots)[i].type = o->value();
127 }
128
129 void
130 AnnotWindow::cb_annot_color_i(Fl_Button* o, int i)
131 {
132   //Fl_Color new_color;
133
134   (*the_annots)[i].color = fl_show_colormap((*the_annots)[i].color);
135   //annot_color_buttons[i]->
136   o->color((*the_annots)[i].color);
137   redraw();
138 }
139
140 void AnnotWindow::add_annot_cb(Fl_Button* o, void* v)
141 {
142   AnnotWindow* T=(AnnotWindow*)v;
143   T->add_annot_cb_real(o,v);
144 }
145
146
147 void AnnotWindow::add_annot_cb_real(Fl_Button* , void*)
148 {
149   annot_color blank_annot;
150
151   //blank_annot.name = "";
152   //blank_annot.seq = "";
153   blank_annot = new_blank_annot();
154   (*the_annots).push_back(blank_annot);
155   add_annot_input(annot_count++);
156   redraw();
157 }
158
159
160 void AnnotWindow::print_cb(Fl_Button* o, void* v)
161 {
162   AnnotWindow* T=(AnnotWindow*)v;
163   T->print_cb_real(o,v);
164 }
165
166
167 void AnnotWindow::print_cb_real(Fl_Button* , void*)
168 {
169   int i;
170
171   for (i = 0; i < annot_count; i++)
172     cout << (*the_annots)[i].type << endl; 
173 }
174
175 /*
176 void
177 cb_annot_in(Fl_Input* o, void* v)
178
179   annot_instance * blah = (annot_instance *) v;
180   AnnotWindow* T= blah->mw_ptr;
181   T->cb_annot_in_i(o,blah->index);
182 }
183
184
185 */