tbx  0.7.6
visiblearea.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef VISIBLEAREA_H_
26 #define VISIBLEAREA_H_
27 
28 #include "bbox.h"
29 
30 namespace tbx
31 {
37  {
38  private:
39  BBox _bounds;
40  Point _scroll;
41 
42  public:
47 
52  VisibleArea(int *block) :
53  _bounds(block[0], block[1], block[2], block[3]),
54  _scroll(block[4], block[5])
55  {};
56 
61  const BBox &bounds() const {return _bounds;}
62 
67  BBox &bounds() {return _bounds;}
68 
72  const Point &scroll() const {return _scroll;}
73 
77  Point &scroll() {return _scroll;}
78 
82  int work_x(int scr_x) const {return scr_x - (_bounds.min.x - _scroll.x);}
83 
87  int work_y(int scr_y) const {return scr_y - (_bounds.max.y - _scroll.y);}
88 
96  Point &work(const Point &scr_pt, Point &work_pt) const
97  {
98  work_pt.x = scr_pt.x - (_bounds.min.x - _scroll.x);
99  work_pt.y = scr_pt.y - (_bounds.max.y - _scroll.y);
100 
101  return work_pt;
102  }
103 
110  Point work(const Point &scr_pt) const {Point pt; work(scr_pt, pt); return pt;}
111 
112 
120  BBox &work(const BBox &scr_box, BBox &work_box) const
121  {
122  work(scr_box.min, work_box.min);
123  work(scr_box.max, work_box.max);
124  return work_box;
125  }
126 
133  BBox work(const BBox &scr_box) const
134  {
135  BBox work_box;
136  work(scr_box.min, work_box.min);
137  work(scr_box.max, work_box.max);
138  return work_box;
139  }
140 
144  int screen_x(int work_x) const {return work_x + (_bounds.min.x - _scroll.x);}
145 
149  int screen_y(int work_y) const {return work_y + (_bounds.max.y - _scroll.y);}
150 
158  Point &screen(const Point &work_pt, Point &scr_pt) const
159  {
160  scr_pt.x = work_pt.x + (_bounds.min.x - _scroll.x);
161  scr_pt.y = work_pt.y + (_bounds.max.y - _scroll.y);
162 
163  return scr_pt;
164  }
165 
172  Point screen(const Point &work_pt) const {Point pt; screen(work_pt, pt); return pt;}
173 
174 
182  BBox &screen(const BBox &work_box, BBox &scr_box) const
183  {
184  screen(work_box.min, scr_box.min);
185  screen(work_box.max, scr_box.max);
186  return scr_box;
187  }
188 
195  BBox screen(const BBox &work_box) const
196  {
197  BBox scr_box;
198  screen(work_box.min, scr_box.min);
199  screen(work_box.max, scr_box.max);
200  return scr_box;
201  }
202  };
203 }
204 
205 #endif /* VISIBLEAREA_H_ */
tbx::Point::x
int x
Definition: point.h:59
tbx::VisibleArea::screen
BBox screen(const BBox &work_box) const
Convert bounding box from work area coordinates to screen coordinates.
Definition: visiblearea.h:195
tbx::VisibleArea::work_y
int work_y(int scr_y) const
Convert screen y coordinate to work area.
Definition: visiblearea.h:87
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::VisibleArea::bounds
const BBox & bounds() const
The visible area of the window on the screen.
Definition: visiblearea.h:61
tbx::VisibleArea::work_x
int work_x(int scr_x) const
Convert screen x coordinate to work area.
Definition: visiblearea.h:82
tbx::VisibleArea::screen_y
int screen_y(int work_y) const
Convert work area y coordinate to screen area.
Definition: visiblearea.h:149
tbx::VisibleArea::scroll
Point & scroll()
The scroll offset of the work area within the window.
Definition: visiblearea.h:77
tbx::VisibleArea::screen
BBox & screen(const BBox &work_box, BBox &scr_box) const
Convert bounding box from work area coordinates to screen coordinates.
Definition: visiblearea.h:182
tbx::VisibleArea::bounds
BBox & bounds()
The visible area of the window on the screen.
Definition: visiblearea.h:67
tbx::VisibleArea
Class to store information for the Visible area of a window and provide work area to screen conversio...
Definition: visiblearea.h:37
tbx::BBox::min
Point min
Minimum coordinate of the bounding box.
Definition: bbox.h:68
tbx::Point::y
int y
Definition: point.h:60
tbx::BBox
Class to represent a two dimensional bounding box.
Definition: bbox.h:38
tbx::VisibleArea::scroll
const Point & scroll() const
The scroll offset of the work area within the window.
Definition: visiblearea.h:72
tbx::BBox::max
Point max
Maximum coordinate of the bounding box.
Definition: bbox.h:72
tbx::VisibleArea::screen
Point screen(const Point &work_pt) const
Convert point from work area coordinates to screen coordinates.
Definition: visiblearea.h:172
tbx::VisibleArea::work
Point work(const Point &scr_pt) const
Convert point from screen coordinates to work area coordinates.
Definition: visiblearea.h:110
tbx::Point
Class to represent a position in two dimensional space.
Definition: point.h:37
tbx::VisibleArea::VisibleArea
VisibleArea(int *block)
Construct a visible area from an array of 6 integers as provided by Wimp calls.
Definition: visiblearea.h:52
tbx::VisibleArea::screen_x
int screen_x(int work_x) const
Convert work area x coordinate to screen.
Definition: visiblearea.h:144
tbx::VisibleArea::work
Point & work(const Point &scr_pt, Point &work_pt) const
Convert point from screen coordinates to work area coordinates.
Definition: visiblearea.h:96
tbx::VisibleArea::work
BBox work(const BBox &scr_box) const
Convert bounding box from screen coordinates to work area coordinates.
Definition: visiblearea.h:133
tbx::VisibleArea::work
BBox & work(const BBox &scr_box, BBox &work_box) const
Convert bounding box from screen coordinates to work area coordinates.
Definition: visiblearea.h:120
tbx::VisibleArea::screen
Point & screen(const Point &work_pt, Point &scr_pt) const
Convert point from work coordinates to screen area coordinates.
Definition: visiblearea.h:158
tbx::VisibleArea::VisibleArea
VisibleArea()
Construct an uninitialised visible area.
Definition: visiblearea.h:46