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