File: draw_labels.c

package info (click to toggle)
garlic 1.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,492 kB
  • ctags: 1,013
  • sloc: ansic: 29,925; makefile: 753
file content (150 lines) | stat: -rw-r--r-- 4,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				draw_labels.c

Purpose:
	Draw atomic labels.

Input:
	(1) Pointer to MolComplexS structure.
	(2) Number of macromolecular complexes.
	(3) Pointer to ConfigS structure.
	(4) Pointer to GUIS structure.

Output:
	(1) Labels drawn to hidden pixmap.
	(2) Return value.

Return value:
	The number of labels drawn.

=============================================================================*/

#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======draw labels:=========================================================*/

size_t DrawLabels_ (MolComplexS *mol_complexSP, int mol_complexesN,
		    ConfigS *configSP, GUIS *guiSP)
{
size_t			labels_drawnN = 0;
int			imageI, imagesN;
int			left_edge[2], right_edge[2];
int			mol_complexI;
MolComplexS		*curr_mol_complexSP;
size_t			atomsN, atomI;
AtomS			*curr_atomSP;
int			screen_x, screen_y;
static char		stringA[SHORTSTRINGSIZE];
int			string_length, text_width;

/* Number of images: */
if (configSP->stereoF) imagesN = 2;
else imagesN = 1;

/* Left and right image edge (in stereo mode there are two images): */
left_edge[0]  = configSP->image_screen_x0[0];
right_edge[0] = configSP->image_screen_x1[0];
left_edge[1]  = configSP->image_screen_x0[1];
right_edge[1] = configSP->image_screen_x1[1];

/* Prepare the text color: */
XSetForeground (guiSP->displaySP, guiSP->theGCA[0],
		guiSP->main_winS.fg_colorID);

/* Check every macromolecular complex: */
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
	{
	/* Pointer to current macromolecular complex: */
	curr_mol_complexSP = mol_complexSP + mol_complexI;

	/* Prepare and check the number of atoms: */
	atomsN = curr_mol_complexSP->atomsN;
	if (atomsN == 0) continue;

	/* Check every atom: */
	for (atomI = 0; atomI < atomsN; atomI++)
		{
		/* Pointer to the current atom: */
		curr_atomSP = curr_mol_complexSP->atomSP + atomI;

		/* Check flag: */
		if (curr_atomSP->labelF != 1) continue;

		/* Check is atom hidden: */
		if (curr_atomSP->hiddenF) continue;

		/* Check is atom inside slab: */
		if (!curr_atomSP->inside_slabF) continue;

		/* Check is atom inside window: */
		if (!curr_atomSP->inside_windowF) continue;

		/* Draw one (mono) or two labels (stereo): */
		for (imageI = 0; imageI < imagesN; imageI++)
			{
			/* Prepare the coordinates: */
			screen_x = curr_atomSP->raw_atomS.screen_x[imageI];
			screen_y = curr_atomSP->raw_atomS.screen_y;

			/* Check is this atom really visible: */
			if (screen_x < left_edge[imageI]) continue;
			if (screen_x > right_edge[imageI]) continue;

			/* Prepare label: */
			if (curr_atomSP->raw_atomS.chainID == ' ')
				{
				sprintf (stringA, "%s %d %s%c",
				    curr_atomSP->raw_atomS.residue_nameA,
				    curr_atomSP->raw_atomS.residue_sequenceI,
				    curr_atomSP->raw_atomS.pure_atom_nameA,
				    curr_atomSP->raw_atomS.alt_location);
				}
			else
				{
				sprintf (stringA, "%s %d%c %s%c",
				    curr_atomSP->raw_atomS.residue_nameA,
				    curr_atomSP->raw_atomS.residue_sequenceI,
				    curr_atomSP->raw_atomS.chainID,
				    curr_atomSP->raw_atomS.pure_atom_nameA,
				    curr_atomSP->raw_atomS.alt_location);
				}

			/* String length: */
			string_length = strlen (stringA);

			/* Prepare the string size in pixels: */
			text_width = XTextWidth (guiSP->main_winS.fontSP,
						 stringA, string_length);

			/* Draw label: */
			XDrawString (guiSP->displaySP,
				     guiSP->main_hidden_pixmapID,
				     guiSP->theGCA[0],
				     screen_x - text_width / 2, screen_y,
				     stringA, string_length);

			/* Update the counter: */
			labels_drawnN++;

			}	/* imageI loop */
		}		/* atomI  loop */
	}			/* mol_complexI loop */

/* Return the number of labels which were drawn: */
return labels_drawnN;
}

/*===========================================================================*/