root/trunk/FRII/gui/_PairMapCanvas.cc

Revision 10, 3.8 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Implementation of a canvas that handles drawing between two (prespecified)
17 // sequences.  This class handles the math involved in computing positions,
18 // and actually draws the line.  That's about it... -- CTB
19
20 #include <iostream>
21 #include <FL/Fl.H>
22 #include <FL/fl_draw.H>
23
24 #include "_PairMapCanvas.hh"
25
26 using namespace gui;
27
28 //
29 // recompute -- the intelligence that computes where things go.
30 //
31
32 void _PairMapCanvas::recompute()
33 {
34   _top_scale = (float) _top_w / (float) (_top_end - _top_start);
35   _bot_scale = (float) _bot_w / (float) (_bot_end - _bot_start);
36 }
37
38 //
39 // draw_feature -- draw a line.
40 //
41
42 void _PairMapCanvas::draw_feature(int top_pos, int bot_pos,
43                                   unsigned int width, int orientation)
44 {
45   for (unsigned int i = 0; i < width; i++) {
46     top_pos++;
47     bot_pos += orientation;
48
49     draw_feature(top_pos, bot_pos);
50   }
51 #if 0
52   top_pos -= _top_start;
53   if (top_pos < 0) top_pos = 0;
54   bot_pos -= _bot_start;
55   if (bot_pos < 0) bot_pos = 0;
56
57   int top_pixel, bot_pixel;
58
59   float top_pixel_width = _top_scale * width;
60   float bot_pixel_width = _bot_scale * width;
61   float max_pixel_width = top_pixel_width > bot_pixel_width ? top_pixel_width :
62     bot_pixel_width;
63
64   // normalize.  One of the steps should now be 1, the other should be <= 1.
65   float top_step = top_pixel_width / max_pixel_width;
66   float bot_step = bot_pixel_width / max_pixel_width;
67
68   int top_pixel_start = (int) (_top_scale * top_pos + .5) + _top_x;
69   int bot_pixel_start = (int) (_bot_scale * bot_pos + .5) + _bot_x;
70  
71   float top = 0;
72   float bot = 0;
73   while (top < max_pixel_width || bot < max_pixel_width) {
74     top_pixel = (int) (top_pixel_start + top);
75     bot_pixel = (int) (bot_pixel_start + bot * orientation);
76
77     fl_line(top_pixel, _top_y, bot_pixel, _bot_y);
78
79     top += top_step;
80     bot += bot_step;
81   }
82 #endif // 0
83 }
84
85 //
86 // draw_feature -- draw a line, without a width or orientation.
87 //
88
89 void _PairMapCanvas::draw_feature(int top_pos, int bot_pos)
90 {
91   if (top_pos < _top_start || top_pos > _top_end ||
92       bot_pos < _bot_start || bot_pos > _bot_end) {
93     return;
94   }
95      
96   top_pos -= _top_start;
97   bot_pos -= _bot_start;
98
99   int top_pixel = (int) (_top_scale * top_pos + .5) + _top_x;
100   int bot_pixel = (int) (_bot_scale * bot_pos + .5) + _bot_x;
101  
102   fl_line(top_pixel, _top_y, bot_pixel, _bot_y);
103 }
104
105 //
106 // set_*_canvas_coords -- set the coordinates of the top/bottom sequences
107 // on the canvas.  Recomputes things.
108 //
109
110 void _PairMapCanvas::set_top_canvas_coords(int x_start, int width, int y)
111 {
112   _top_x = x_start;
113   _top_w = width;
114   _top_y = y;
115
116   recompute();
117 }
118
119 void _PairMapCanvas::set_bot_canvas_coords(int x_start, int width, int y)
120 {
121   _bot_x = x_start;
122   _bot_w = width;
123   _bot_y = y;
124
125   recompute();
126 }
127
128 void _PairMapCanvas::push_clip()
129 {
130   int min_x, max_width;
131   if (_top_x < _bot_x) {
132     min_x = _top_x;
133     max_width = _top_w;
134   } else {
135     min_x = _bot_x;
136     max_width = _bot_w;
137   }
138   fl_push_clip(min_x, _top_y, max_width, _bot_y - _top_y);
139 }
140
141 //
142 // set_*_sequence_coords -- set the coordinates of the displayed part of the
143 // top/bot sequences.  Recomputes things.
144 //
145
146 void _PairMapCanvas::set_top_sequence_coords(int start, int end)
147 {
148   _top_start = start;
149   _top_end = end;
150
151   recompute();
152 }
153
154 void _PairMapCanvas::set_bot_sequence_coords(int start, int end)
155 {
156   _bot_start = start;
157   _bot_end = end;
158
159   recompute();
160 }
Note: See TracBrowser for help on using the browser.