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