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