tbx  0.7.3
offsetgraphics.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 TBX_OFFSETGRAPHICS_H
26 #define TBX_OFFSETGRAPHICS_H
27 
28 #include "osgraphics.h"
29 #include "visiblearea.h"
30 
31 namespace tbx
32 {
37  class OffsetGraphics : public OSGraphics
38  {
39  private:
40  int _offset_x;
41  int _offset_y;
42  public:
46  OffsetGraphics() {_offset_x = 0; _offset_y = 0;}
53  OffsetGraphics(int offset_x, int offset_y) {_offset_x = offset_x; _offset_y = offset_y;}
54 
63  OffsetGraphics(const VisibleArea &area) {_offset_x = area.screen_x(0); _offset_y = area.screen_y(0);}
64 
70  void offset_x(int new_x) {_offset_x = new_x;}
76  int offset_x() const {return _offset_x;}
82  void offset_y(int new_y) {_offset_y = new_y;}
88  int offset_y() const {return _offset_y;}
89 
95  Point offset() const {return Point(_offset_x, _offset_y);}
101  void offset(const Point &new_offset) {_offset_x = new_offset.x; _offset_y = new_offset.y;}
102 
103  // Override plot to take into account offset
104  virtual void plot(int code, int x, int y) {OSGraphics::plot(code, x + _offset_x, y + _offset_y);}
105 
106  // Graphic interface
107 
108  // coordinate conversion
109  virtual int os_x(int logical_x) const {return logical_x + _offset_x;}
110  virtual int os_y(int logical_y) const {return logical_y + _offset_y;}
111  virtual int logical_x(int os_x) const {return os_x - _offset_x;}
112  virtual int logical_y(int os_y) const {return os_y - _offset_y;}
113  virtual Point os(const Point &pt) {return Point(pt.x+_offset_x, pt.x+_offset_y);}
114  virtual Point logical(const Point &pt) {return Point(pt.x-_offset_x, pt.x-_offset_y);}
115  virtual BBox os(const BBox &b) {return BBox(b.min.x + _offset_x, b.min.y + _offset_y, b.max.x + _offset_x, b.max.y + _offset_y);}
116  virtual BBox logical(const BBox &b) {return BBox(b.min.x - _offset_x, b.min.y - _offset_y, b.max.x - _offset_x, b.max.y - _offset_y);}
117 
118  virtual void text(int x, int y, const std::string &text) {OSGraphics::text(x + _offset_x, y + _offset_y, text);}
119  virtual void text(int x, int y, const std::string &text, const Font &font) {OSGraphics::text(x + _offset_x, y + _offset_y, text, font);}
120 
121  // Images
122  virtual void image(int x, int y, const Image &image) {OSGraphics::image(x + _offset_x, y + _offset_y, image);}
123  virtual void image(const Point &pt, const Image &im) {OSGraphics::image(pt.x + _offset_x, pt.y + _offset_y, im);}
124 
125  // Draw paths
126  virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1) {OSGraphics::fill(x + _offset_x, y + _offset_y, path, fill_style, flatness);}
127  virtual void fill(const Point &pt, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1) {OSGraphics::fill(pt.x + _offset_x, pt.y + _offset_y, path, fill_style, flatness);}
128  virtual void stroke(int x, int y, const DrawPath &path,DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1,
129  int thickness = 0, DrawCapAndJoin *cap_and_join = 0, DrawDashPattern *dashes = 0)
130  {
131  OSGraphics::stroke(x + _offset_x, y + _offset_y, path, fill_style, flatness,
132  thickness, cap_and_join, dashes);
133  }
134  virtual void stroke(const Point &pt, const DrawPath &path,DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1,
135  int thickness = 0, DrawCapAndJoin *cap_and_join = 0, DrawDashPattern *dashes = 0)
136  {
137  OSGraphics::stroke(pt.x + _offset_x, pt.y + _offset_y, path, fill_style, flatness,
138  thickness, cap_and_join, dashes);
139  }
140  };
141 }
142 
143 #endif /* TBX_OFFSETGRAPHICS_H_ */
OffsetGraphics()
Construct with no offset.
Definition: offsetgraphics.h:46
DrawFillStyle
Enumeration to set the fill style when filling shapes.
Definition: drawpath.h:40
virtual int logical_y(int os_y) const
Convert from OS units to logical y value.
Definition: offsetgraphics.h:112
int x
Definition: point.h:59
virtual void fill(const Point &pt, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1)
Fill a draw path.
Definition: offsetgraphics.h:127
Class to represent, display and manipulate a graphical path used by the Draw RISC OS module...
Definition: drawpath.h:464
void offset_x(int new_x)
Set the horizontal offset.
Definition: offsetgraphics.h:70
virtual int os_y(int logical_y) const
Convert from logical y value to OS units.
Definition: offsetgraphics.h:110
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
Class to set the cap and joins style for lines that are greater than a single pixel wide...
Definition: drawpath.h:57
OffsetGraphics(const VisibleArea &area)
Construct from a visible area.
Definition: offsetgraphics.h:63
virtual void image(int x, int y, const Image &image)
Draw an image at given location.
Definition: offsetgraphics.h:122
virtual int logical_x(int os_x) const
Convert from OS units to logical x value.
Definition: offsetgraphics.h:111
Point offset() const
Get the offsets as a point.
Definition: offsetgraphics.h:95
int screen_x(int work_x) const
Convert work area x coordinate to screen.
Definition: visiblearea.h:144
void offset(const Point &new_offset)
Set both offsets from a point.
Definition: offsetgraphics.h:101
virtual void stroke(int x, int y, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1, int thickness=0, DrawCapAndJoin *cap_and_join=0, DrawDashPattern *dashes=0)
Draw lines of a draw path at the given location.
Definition: offsetgraphics.h:128
virtual void plot(int code, int x, int y)
Execute the OS_Plot swi.
Definition: osgraphics.cc:65
virtual void text(int x, int y, const std::string &text)
Draw text in current desktop font.
Definition: offsetgraphics.h:118
virtual void path(const Point *points, int num)
Draw a line through the specified points.
Definition: osgraphics.cc:296
virtual void image(int x, int y, const Image &image)
Draw an image at given location.
Definition: osgraphics.cc:397
Point min
Minimum coordinate of the bounding box.
Definition: bbox.h:68
int y
Definition: point.h:60
virtual void text(int x, int y, const std::string &text)
Draw text in current desktop font.
Definition: osgraphics.cc:363
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:44
virtual BBox logical(const BBox &b)
Convert from OS units to logical coordinates.
Definition: offsetgraphics.h:116
Class to represent a dash pattern for lines.
Definition: drawpath.h:225
virtual void stroke(const Point &pt, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1, int thickness=0, DrawCapAndJoin *cap_and_join=0, DrawDashPattern *dashes=0)
Plot the lines in a path.
Definition: offsetgraphics.h:134
non-zero winding number rule.
Definition: drawpath.h:42
Class to represent a position in two dimensional space.
Definition: point.h:36
virtual void text(int x, int y, const std::string &text, const Font &font)
Draw text in given font.
Definition: offsetgraphics.h:119
virtual void plot(int code, int x, int y)
Execute the OS_Plot swi.
Definition: offsetgraphics.h:104
virtual void stroke(int x, int y, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1, int thickness=0, DrawCapAndJoin *cap_and_join=0, DrawDashPattern *dashes=0)
Draw lines of a draw path at the given location.
Definition: osgraphics.cc:416
virtual BBox os(const BBox &b)
Convert from logical coordinates to OS units.
Definition: offsetgraphics.h:115
Class to store information for the Visible area of a window and provide work area to screen conversio...
Definition: visiblearea.h:36
void offset_y(int new_y)
Set the vertical offset.
Definition: offsetgraphics.h:82
virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1)
Fill an draw path at the given location.
Definition: osgraphics.cc:405
Point max
Maximum coordinate of the bounding box.
Definition: bbox.h:72
virtual Point logical(const Point &pt)
Convert from OS units to logical coordinates.
Definition: offsetgraphics.h:114
int offset_y() const
Get the vertical offset.
Definition: offsetgraphics.h:88
Class to draw to graphics to the screen using standard OS routines with no translation or scaling...
Definition: osgraphics.h:36
virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1)
Fill an draw path at the given location.
Definition: offsetgraphics.h:126
Class to draw to graphics to the screen using standard OS routines off setting the coordinates given...
Definition: offsetgraphics.h:37
Class to handle painting and measuring text using an outline font.
Definition: font.h:60
int screen_y(int work_y) const
Convert work area y coordinate to screen area.
Definition: visiblearea.h:149
virtual void image(const Point &pt, const Image &im)
Draw an image.
Definition: offsetgraphics.h:123
OffsetGraphics(int offset_x, int offset_y)
Construct with given offsets.
Definition: offsetgraphics.h:53
virtual int os_x(int logical_x) const
Convert from logical x value to OS units.
Definition: offsetgraphics.h:109
int offset_x() const
Get the horizontal offset.
Definition: offsetgraphics.h:76
virtual Point os(const Point &pt)
Convert from logical coordinates to OS units.
Definition: offsetgraphics.h:113