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