[go: up one dir, main page]

File: align.c

package info (click to toggle)
libforms1 1.0-8
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (205 lines) | stat: -rw-r--r-- 4,389 bytes parent folder | download | duplicates (3)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 *
 *  This file is part of the XForms library package.
 *
 * XForms is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1, or
 * (at your option) any later version.
 *
 * XForms is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with XForms; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 *
 */


/*
 * $Id: align.c,v 1.0 2002/05/08 05:16:30 zhao Release $
 *
 *.
 *  This file is part of the XForms library package.
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *.
 *
 * Handles align requests
 *
 */

#include "forms.h"

void
fl_get_hv_align(int align, int *halign, int *valign)
{

    align &= ~FL_ALIGN_INSIDE;

    switch (align)
    {
    case FL_ALIGN_LEFT:
	*halign = FL_ALIGN_LEFT;
	*valign = FL_ALIGN_CENTER;
	break;
    case FL_ALIGN_RIGHT:
	*halign = FL_ALIGN_RIGHT;
	*valign = FL_ALIGN_CENTER;
	break;
    case FL_ALIGN_CENTER:
	*halign = FL_ALIGN_CENTER;
	*valign = FL_ALIGN_CENTER;
	break;
    case FL_ALIGN_TOP:
	*halign = FL_ALIGN_CENTER;
	*valign = FL_ALIGN_TOP;
	break;
    case FL_ALIGN_BOTTOM:
	*halign = FL_ALIGN_CENTER;
	*valign = FL_ALIGN_BOTTOM;
	break;
    case FL_ALIGN_LEFT_BOTTOM:
	*halign = FL_ALIGN_LEFT;
	*valign = FL_ALIGN_BOTTOM;
	break;
    case FL_ALIGN_RIGHT_BOTTOM:
	*halign = FL_ALIGN_RIGHT;
	*valign = FL_ALIGN_BOTTOM;
	break;
    case FL_ALIGN_LEFT_TOP:
	*halign = FL_ALIGN_LEFT;
	*valign = FL_ALIGN_TOP;
	break;
    case FL_ALIGN_RIGHT_TOP:
	*halign = FL_ALIGN_RIGHT;
	*valign = FL_ALIGN_TOP;
	break;
    default:
	Bark("GetAlign", "bad request: %d\n", align);
	*halign = FL_ALIGN_CENTER;
	*valign = FL_ALIGN_CENTER;
	break;
    }
}

void
fl_get_outside_align(int align, int x, int y, int w, int h,
		     int *new_align, int *newx, int *newy)
{
    *newx = x;
    *newy = y;
    *new_align = FL_ALIGN_CENTER;

    align &= ~FL_ALIGN_INSIDE;

    if (align == FL_ALIGN_LEFT)
    {
	*new_align = FL_ALIGN_RIGHT;
	*newx = x - w;
    }
    else if (align == FL_ALIGN_RIGHT)
    {
	*new_align = FL_ALIGN_LEFT;
	*newx = x + w;
    }
    else if (align == FL_ALIGN_TOP)
    {
	*new_align = FL_ALIGN_BOTTOM;
	*newy = y - h;
    }
    else if (align == FL_ALIGN_BOTTOM)
    {
	*new_align = FL_ALIGN_TOP;
	*newy = y + h;
    }
    else if (align == FL_ALIGN_LEFT_TOP)
    {
	*new_align = FL_ALIGN_LEFT_BOTTOM;
	*newy = y - h;
    }
    else if (align == FL_ALIGN_RIGHT_TOP)
    {
	*new_align = FL_ALIGN_RIGHT_BOTTOM;
	*newy = y - h;
    }
    else if (align == FL_ALIGN_LEFT_BOTTOM)
    {
	*new_align = FL_ALIGN_LEFT_TOP;
	*newy = y + h;
    }
    else if (align == FL_ALIGN_RIGHT_BOTTOM)
    {
	*new_align = FL_ALIGN_RIGHT_TOP;
	*newy = y + h;
    }
}


static void
get_align_inside(int align, int x, int y, int w, int h,
		 int xsize, int ysize, int xoff, int yoff,
		 int *xx, int *yy)
{
    int hor, vert;

    fl_get_hv_align(align, &hor, &vert);

    x += xoff;
    y += yoff;
    w -= 2 * xoff;
    h -= 2 * yoff;

    switch (hor)
    {
    case FL_ALIGN_LEFT:
	*xx = x;
	break;
    case FL_ALIGN_RIGHT:
	*xx = x + w - xsize;
	break;
    case FL_ALIGN_CENTER:
    default:
	*xx = x + (w - xsize) / 2;
	break;
    }

    switch (vert)
    {
    case FL_ALIGN_TOP:
	*yy = y;
	break;
    case FL_ALIGN_BOTTOM:
	*yy = y + h - ysize;
	break;
    case FL_ALIGN_CENTER:
    default:
	*yy = y + (h - ysize) / 2;
	break;
    }
}

static void
get_align_outside(int align, int x, int y, int w, int h,
		  int xsize, int ysize, int xoff, int yoff,
		  int *xx, int *yy)
{
    int newx, newy, new_align;

    fl_get_outside_align(align, x, y, w, h, &new_align, &newx, &newy);
    get_align_inside(new_align, newx, newy, w, h,
		     xsize, ysize, xoff, yoff, xx, yy);
}

void
fl_get_align_xy(int align, int x, int y, int w, int h,
		int xsize, int ysize, int xoff, int yoff,
		int *xx, int *yy)
{
    ((align & FL_ALIGN_INSIDE) ? get_align_inside : get_align_outside)
	(align, x, y, w, h, xsize, ysize, xoff, yoff, xx, yy);
}