1 /*
2  *	selbox.cc
3  *	Selection box stuff.
4  *	AYM 1998-07-04
5  */
6 
7 
8 /*
9 This file is part of Yadex.
10 
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in
12 1994 by Rapha�l Quinet and Brendon Wyber.
13 
14 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
15 
16 This program is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any later
19 version.
20 
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License along with
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
27 Place, Suite 330, Boston, MA 02111-1307, USA.
28 */
29 
30 
31 #include "yadex.h"
32 #include "gfx.h"
33 #include "selbox.h"
34 
35 
36 static const int flags_1st_corner_set = 1;
37 static const int flags_2nd_corner_set = 1 << 1;
38 static const int flags_displayed      = 1 << 2;
39 
40 
41 
selbox_c(void)42 selbox_c::selbox_c (void)
43 {
44   flags = 0;
45 }
46 
47 
set_1st_corner(int x,int y)48 void selbox_c::set_1st_corner (int x, int y)
49 {
50   x1 = x;
51   y1 = y;
52   flags |= flags_1st_corner_set;
53 }
54 
55 
set_2nd_corner(int x,int y)56 void selbox_c::set_2nd_corner (int x, int y)
57 {
58   x2 = x;
59   y2 = y;
60   flags |= flags_2nd_corner_set;
61 }
62 
63 
get_corners(int * x1,int * y1,int * x2,int * y2)64 void selbox_c::get_corners (int *x1, int *y1, int *x2, int *y2)
65 {
66   if (x1 != NULL)
67     *x1 = this->x1;
68   if (y1 != NULL)
69     *y1 = this->y1;
70   if (x2 != NULL)
71     *x2 = this->x2;
72   if (y2 != NULL)
73     *y2 = this->y2;
74 }
75 
76 
unset_corners(void)77 void selbox_c::unset_corners (void)
78 {
79   flags &= ~ (flags_1st_corner_set | flags_2nd_corner_set);
80 }
81 
82 
draw(void)83 void selbox_c::draw (void)
84 {
85   if ((flags & flags_1st_corner_set) && (flags & flags_2nd_corner_set))
86   {
87     set_colour (CYAN);
88     SetDrawingMode (1);
89     DrawMapLine (x1, y1, x1, y2);
90     DrawMapLine (x1, y2, x2, y2);
91     DrawMapLine (x2, y2, x2, y1);
92     DrawMapLine (x2, y1, x1, y1);
93     SetDrawingMode (0);
94     /* Those are needed by undraw() */
95     x1_disp = x1;
96     y1_disp = y1;
97     x2_disp = x2;
98     y2_disp = y2;
99     flags |= flags_displayed;
100   }
101 }
102 
103 
undraw(void)104 void selbox_c::undraw (void)
105 {
106   if (flags & flags_displayed)
107   {
108     set_colour (CYAN);
109     SetDrawingMode (1);
110     DrawMapLine (x1_disp, y1_disp, x1_disp, y2_disp);
111     DrawMapLine (x1_disp, y2_disp, x2_disp, y2_disp);
112     DrawMapLine (x2_disp, y2_disp, x2_disp, y1_disp);
113     DrawMapLine (x2_disp, y1_disp, x1_disp, y1_disp);
114     SetDrawingMode (0);
115     flags &= ~ flags_displayed;
116   }
117 }
118 
119 
clear(void)120 void selbox_c::clear (void)
121 {
122   flags &= ~ flags_displayed;
123 }
124 
125