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