~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to plot_mouse.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                plot_mouse.c
 
6
 
 
7
Purpose:
 
8
        Handle MotionNotify events if the main window contains hydrophobicity
 
9
        plot(s).
 
10
 
 
11
Input:
 
12
        (1) Pointer to RuntimeS structure, with runtime data.
 
13
        (2) Pointer to GUIS structure, with GUI data.
 
14
        (3) Pointer to NearestAtomS structure.
 
15
        (4) The number of pixels in the main window free area.
 
16
        (5) Pointer to refreshI.
 
17
        (6) Pointer to XMotionEvent structure.
 
18
 
 
19
Output:
 
20
        (1) The information about residue covered by mouse pointer written to
 
21
            the output window.
 
22
        (2) Return value.
 
23
 
 
24
Return value:
 
25
        (1) Positive on success.
 
26
        (2) Zero if event is ignored.
 
27
        (3) Negative on failure.
 
28
 
 
29
========includes:============================================================*/
 
30
 
 
31
#include <stdio.h>
 
32
 
 
33
#include <string.h>
 
34
 
 
35
#include <X11/Xlib.h>
 
36
#include <X11/Xutil.h>
 
37
#include <X11/Xos.h>
 
38
#include <X11/Xatom.h>
 
39
 
 
40
#include "defines.h"
 
41
#include "typedefs.h"
 
42
 
 
43
/*======handle MotionNotify events for hydrophobicity plots:=================*/
 
44
 
 
45
int PlotMouse_ (RuntimeS *runtimeSP, GUIS *guiSP,
 
46
                NearestAtomS *nearest_atomSP, size_t pixelsN,
 
47
                unsigned int refreshI,
 
48
                XMotionEvent *motion_eventSP)
 
49
{
 
50
int                     residue_name_length;
 
51
int                     space_width, space_half_width;
 
52
size_t                  pixelI;
 
53
NearestAtomS            *pixelSP;
 
54
int                     central_residueI, first_residueI, last_residueI;
 
55
int                     residueI;
 
56
char                    *residue_nameP;
 
57
char                    residue_nameA[RESNAMESIZE];
 
58
int                     residue_sequenceI;
 
59
double                  value;
 
60
static char             stringA[STRINGSIZE];
 
61
int                     string_length;
 
62
int                     line_height;
 
63
int                     screen_x0, screen_y0;
 
64
int                     text_width;
 
65
int                     line_x0 = 0, line_x1 = 0;
 
66
int                     width, height;
 
67
 
 
68
/* Residue name length: */
 
69
residue_name_length = RESNAMESIZE - 1;
 
70
 
 
71
/* Space half-width: */
 
72
space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1);
 
73
space_half_width = space_width / 2;
 
74
 
 
75
/* If the event came from child window, return zero: */
 
76
if (motion_eventSP->subwindow != None) return 0;
 
77
 
 
78
/* Pixel index: */
 
79
pixelI = guiSP->main_win_free_area_width * motion_eventSP->y +
 
80
         motion_eventSP->x;
 
81
 
 
82
/* Check the pixel index: */
 
83
if (pixelI >= pixelsN) return -1;
 
84
 
 
85
/* Pointer to NearestAtomS structure assigned with this pixel: */
 
86
pixelSP = nearest_atomSP + pixelI;
 
87
 
 
88
/* Check the refreshI associated with this pixel: */
 
89
if (pixelSP->last_refreshI != refreshI) return 0;
 
90
 
 
91
/* Refresh the output window: */
 
92
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
93
                guiSP->output_winS.bg_colorID);
 
94
XFillRectangle(guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0],
 
95
               0, 0, guiSP->output_winS.width, guiSP->output_winS.height);
 
96
 
 
97
/* The central residue index: */
 
98
central_residueI = pixelSP->atomI;
 
99
 
 
100
/* Space half-width: */
 
101
space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1);
 
102
              space_half_width = space_width / 2;
 
103
 
 
104
/* Prepare the residue name: */
 
105
residue_nameP = runtimeSP->sequenceP + central_residueI * residue_name_length;
 
106
strncpy (residue_nameA, residue_nameP, residue_name_length);
 
107
residue_nameA[residue_name_length] = '\0';
 
108
 
 
109
/* Prepare the residue sequence number: */
 
110
residue_sequenceI = *(runtimeSP->serialIP + central_residueI);
 
111
 
 
112
/* Prepare the function value  (averaged */
 
113
/* hydrophob., hydrophobic moment etc.): */
 
114
value = pixelSP->z;
 
115
 
 
116
/* Prepare the text foreground color: */
 
117
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
118
                guiSP->output_winS.fg_colorID);
 
119
 
 
120
/* Text line height: */
 
121
line_height = guiSP->output_winS.text_line_height;
 
122
 
 
123
/* The initial drawing position: */
 
124
screen_x0 = TEXTMARGIN;
 
125
screen_y0 = guiSP->output_winS.font_height + 5;
 
126
 
 
127
/* Draw residue name and residue sequence number: */
 
128
sprintf (stringA, "%s %d", residue_nameA, residue_sequenceI);
 
129
stringA[SHORTSTRINGSIZE - 1] = '\0';
 
130
XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0],
 
131
             screen_x0, screen_y0, stringA, strlen (stringA));
 
132
 
 
133
/* Draw the function value: */
 
134
screen_y0 += line_height;
 
135
strcpy (stringA, "value:");
 
136
XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0],
 
137
             screen_x0, screen_y0, stringA, strlen (stringA));
 
138
screen_y0 += line_height;
 
139
sprintf (stringA, "%.3f", value);
 
140
XDrawString (guiSP->displaySP, guiSP->output_winS.ID, guiSP->theGCA[0],
 
141
             screen_x0, screen_y0, stringA, strlen (stringA));
 
142
 
 
143
/* Now it's time to draw the sequence neighborhood of the central residue. */
 
144
 
 
145
/* Indices of the first and the last residue in the neighbourhood: */
 
146
first_residueI = central_residueI - NEIGH_HALF_WIDTH;
 
147
if (first_residueI < 0) first_residueI = 0;
 
148
last_residueI = central_residueI + NEIGH_HALF_WIDTH;
 
149
if (last_residueI > runtimeSP->residuesN) last_residueI = runtimeSP->residuesN;
 
150
 
 
151
/* Prepare the string with the left part of the neighborhood: */
 
152
stringA[0] = '\0';
 
153
strcat (stringA, " ");
 
154
for (residueI = first_residueI; residueI <= last_residueI; residueI++)
 
155
        {
 
156
        /* The string width, without the central residue: */
 
157
        if (residueI == central_residueI)
 
158
                {
 
159
                string_length = strlen (stringA);
 
160
                line_x0 = XTextWidth (guiSP->main_winS.fontSP,
 
161
                                      stringA, string_length) -
 
162
                                      space_half_width;
 
163
                }
 
164
 
 
165
        /* Pointer to residue name: */
 
166
        residue_nameP = runtimeSP->sequenceP + residueI * residue_name_length;
 
167
 
 
168
        /* Add the residue name to the output string: */
 
169
        strncpy (residue_nameA, residue_nameP, residue_name_length);
 
170
        residue_nameA[residue_name_length] = '\0';
 
171
        strcat (stringA, residue_nameA);
 
172
        strcat (stringA, " ");
 
173
 
 
174
        /* The string width, including the central residue: */
 
175
        if (residueI == central_residueI)
 
176
                {
 
177
                string_length = strlen (stringA);
 
178
                line_x1 = XTextWidth (guiSP->main_winS.fontSP,
 
179
                                      stringA, string_length) -
 
180
                                      space_half_width;
 
181
                }
 
182
        }
 
183
 
 
184
/* String length: */
 
185
string_length = strlen (stringA);
 
186
 
 
187
/* Text width: */
 
188
text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length);
 
189
 
 
190
/* Prepare text background color: */
 
191
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
192
                guiSP->main_winS.bg_colorID);
 
193
 
 
194
/* Refresh the string background: */
 
195
screen_x0 = 1;
 
196
screen_y0 = 1;
 
197
width = guiSP->control_winS.x0 - guiSP->main_winS.border_width - 2;
 
198
if (width < 0) width = 0;
 
199
height = guiSP->main_winS.font_height + 4;
 
200
XFillRectangle(guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0],
 
201
               screen_x0, screen_y0,
 
202
               (unsigned int) width, (unsigned int) height);
 
203
 
 
204
/* Prepare text color: */
 
205
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
 
206
                guiSP->main_winS.fg_colorID);
 
207
 
 
208
/* Draw the bounding rectangle: */
 
209
XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID,
 
210
                guiSP->theGCA[0],
 
211
                screen_x0, screen_y0,
 
212
                (unsigned int) width, (unsigned int) height);
 
213
 
 
214
/* Draw the string which contains sequence neighborhood: */
 
215
screen_x0 = guiSP->control_winS.x0 / 2 - text_width / 2;
 
216
screen_y0 = guiSP->main_winS.font_height + 1;
 
217
XDrawString (guiSP->displaySP, guiSP->main_winS.ID, guiSP->theGCA[0],
 
218
             screen_x0, screen_y0, stringA, string_length);
 
219
 
 
220
/* Draw rectangle bounding the central residue: */
 
221
line_x0 += guiSP->control_winS.x0 / 2 - text_width / 2;
 
222
line_x1 += guiSP->control_winS.x0 / 2 - text_width / 2;
 
223
width = line_x1 - line_x0 + 1;
 
224
if (width < 0) width = 0;
 
225
height = guiSP->main_winS.font_height - 1;
 
226
if (height < 0) height = 0;
 
227
screen_y0 = height;
 
228
XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID,
 
229
                guiSP->theGCA[0],
 
230
                line_x0, 4,
 
231
                (unsigned int) width, (unsigned int) height);
 
232
 
 
233
/* Return positive value: */
 
234
return 1;
 
235
}
 
236
 
 
237
/*===========================================================================*/
 
238
 
 
239