1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Handle MotionNotify events if the main window contains hydrophobicity
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.
20
(1) The information about residue covered by mouse pointer written to
25
(1) Positive on success.
26
(2) Zero if event is ignored.
27
(3) Negative on failure.
29
========includes:============================================================*/
36
#include <X11/Xutil.h>
38
#include <X11/Xatom.h>
43
/*======handle MotionNotify events for hydrophobicity plots:=================*/
45
int PlotMouse_ (RuntimeS *runtimeSP, GUIS *guiSP,
46
NearestAtomS *nearest_atomSP, size_t pixelsN,
47
unsigned int refreshI,
48
XMotionEvent *motion_eventSP)
50
int residue_name_length;
51
int space_width, space_half_width;
53
NearestAtomS *pixelSP;
54
int central_residueI, first_residueI, last_residueI;
57
char residue_nameA[RESNAMESIZE];
58
int residue_sequenceI;
60
static char stringA[STRINGSIZE];
63
int screen_x0, screen_y0;
65
int line_x0 = 0, line_x1 = 0;
68
/* Residue name length: */
69
residue_name_length = RESNAMESIZE - 1;
71
/* Space half-width: */
72
space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1);
73
space_half_width = space_width / 2;
75
/* If the event came from child window, return zero: */
76
if (motion_eventSP->subwindow != None) return 0;
79
pixelI = guiSP->main_win_free_area_width * motion_eventSP->y +
82
/* Check the pixel index: */
83
if (pixelI >= pixelsN) return -1;
85
/* Pointer to NearestAtomS structure assigned with this pixel: */
86
pixelSP = nearest_atomSP + pixelI;
88
/* Check the refreshI associated with this pixel: */
89
if (pixelSP->last_refreshI != refreshI) return 0;
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);
97
/* The central residue index: */
98
central_residueI = pixelSP->atomI;
100
/* Space half-width: */
101
space_width = XTextWidth (guiSP->main_winS.fontSP, " ", 1);
102
space_half_width = space_width / 2;
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';
109
/* Prepare the residue sequence number: */
110
residue_sequenceI = *(runtimeSP->serialIP + central_residueI);
112
/* Prepare the function value (averaged */
113
/* hydrophob., hydrophobic moment etc.): */
116
/* Prepare the text foreground color: */
117
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
118
guiSP->output_winS.fg_colorID);
120
/* Text line height: */
121
line_height = guiSP->output_winS.text_line_height;
123
/* The initial drawing position: */
124
screen_x0 = TEXTMARGIN;
125
screen_y0 = guiSP->output_winS.font_height + 5;
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));
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));
143
/* Now it's time to draw the sequence neighborhood of the central residue. */
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;
151
/* Prepare the string with the left part of the neighborhood: */
153
strcat (stringA, " ");
154
for (residueI = first_residueI; residueI <= last_residueI; residueI++)
156
/* The string width, without the central residue: */
157
if (residueI == central_residueI)
159
string_length = strlen (stringA);
160
line_x0 = XTextWidth (guiSP->main_winS.fontSP,
161
stringA, string_length) -
165
/* Pointer to residue name: */
166
residue_nameP = runtimeSP->sequenceP + residueI * residue_name_length;
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, " ");
174
/* The string width, including the central residue: */
175
if (residueI == central_residueI)
177
string_length = strlen (stringA);
178
line_x1 = XTextWidth (guiSP->main_winS.fontSP,
179
stringA, string_length) -
185
string_length = strlen (stringA);
188
text_width = XTextWidth (guiSP->main_winS.fontSP, stringA, string_length);
190
/* Prepare text background color: */
191
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
192
guiSP->main_winS.bg_colorID);
194
/* Refresh the string background: */
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);
204
/* Prepare text color: */
205
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
206
guiSP->main_winS.fg_colorID);
208
/* Draw the bounding rectangle: */
209
XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID,
211
screen_x0, screen_y0,
212
(unsigned int) width, (unsigned int) height);
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);
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;
228
XDrawRectangle (guiSP->displaySP, guiSP->main_winS.ID,
231
(unsigned int) width, (unsigned int) height);
233
/* Return positive value: */
237
/*===========================================================================*/