]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/xorrectangle.h
[q3map2] Unwind script stack in case of script loading error.
[xonotic/netradiant.git] / libs / gtkutil / xorrectangle.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined ( INCLUDED_XORRECTANGLE_H )
23 #define INCLUDED_XORRECTANGLE_H
24
25 #include <cairo.h>
26 #include <uilib/uilib.h>
27 #include "math/vector.h"
28
29 class rectangle_t {
30 public:
31     rectangle_t()
32             : x(0), y(0), w(0), h(0)
33     {}
34
35     rectangle_t(float _x, float _y, float _w, float _h)
36             : x(_x), y(_y), w(_w), h(_h)
37     {}
38
39     float x;
40     float y;
41     float w;
42     float h;
43 };
44
45 struct Coord2D {
46     float x, y;
47
48     Coord2D(float _x, float _y)
49             : x(_x), y(_y)
50     {
51     }
52 };
53
54 inline Coord2D coord2d_device2screen(const Coord2D &coord, unsigned int width, unsigned int height)
55 {
56     return Coord2D(((coord.x + 1.0f) * 0.5f) * width, ((coord.y + 1.0f) * 0.5f) * height);
57 }
58
59 inline rectangle_t rectangle_from_area(const float min[2], const float max[2], unsigned int width, unsigned int height)
60 {
61     Coord2D botleft(coord2d_device2screen(Coord2D(min[0], min[1]), width, height));
62     Coord2D topright(coord2d_device2screen(Coord2D(max[0], max[1]), width, height));
63     return rectangle_t(botleft.x, botleft.y, topright.x - botleft.x, topright.y - botleft.y);
64 }
65
66 class XORRectangle {
67
68     rectangle_t m_rectangle;
69
70     ui::GLArea m_widget;
71     cairo_t *cr;
72
73     bool initialised() const;
74
75     void lazy_init();
76
77     void draw() const;
78
79 public:
80     XORRectangle(ui::GLArea widget);
81
82     ~XORRectangle();
83
84     void set(rectangle_t rectangle);
85 };
86
87
88 #endif