tbx  0.7.3
osgraphics.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_OSGRAPHICS_H
26 #define TBX_OSGRAPHICS_H
27 
28 #include "graphics.h"
29 
30 namespace tbx
31 {
36  class OSGraphics : public Graphics
37  {
38  public:
39  OSGraphics();
40 
41  virtual void plot(int code, int x, int y);
43  enum PlotAction {
51  ACTION_OR_NOT};
53  void plot_action(PlotAction action);
54 
55  // Graphic interface
56 
57  // coordinate conversion
58  virtual int os_x(int logical_x) const {return logical_x;}
59  virtual int os_y(int logical_y) const {return logical_y;}
60  virtual int logical_x(int os_x) const {return os_x;}
61  virtual int logical_y(int os_y) const {return os_y;}
62 
63  virtual Point os(const Point &pt) {return pt;}
64  virtual Point logical(const Point &pt) {return pt;}
65  virtual BBox os(const BBox &b) {return b;}
66  virtual BBox logical(const BBox &b) {return b;}
67 
68  virtual void foreground(Colour colour);
69  virtual void background(Colour colour);
70 
71  virtual void wimp_foreground(WimpColour colour);
72  virtual void wimp_background(WimpColour colour);
73 
74  // Drawing
75  virtual void move(int x, int y);
76  virtual void point(int x, int y);
77  virtual void line(int fx, int fy, int tx, int ty);
78  virtual void line(int x, int y);
79  virtual void rectangle(int xmin, int ymin, int xmax, int ymax);
80  virtual void fill_rectangle(int xmin, int ymin, int xmax, int ymax);
81  virtual void circle(int centre_x, int centre_y, int radius);
82  virtual void fill_circle(int centre_x, int centre_y, int radius);
83  virtual void arc(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y);
84  virtual void segment(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y);
85  virtual void sector(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y);
86  virtual void ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y);
87  virtual void fill_ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y);
88 
89  virtual void path(const Point *points, int num);
90  virtual void polygon(const Point *points, int num);
91  virtual void fill_polygon(const Point *points, int num);
92 
93  virtual void text(int x, int y, const std::string &text);
94  virtual void text(int x, int y, const std::string &text, const Font &font);
96  virtual void text_colours(Font &font, Colour foreground, Colour background);
97 
98 
99  // Images
100  virtual void image(int x, int y, const Image &image);
101 
102  // Draw paths
103  virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1);
104  virtual void stroke(int x, int y, const DrawPath &path,DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1,
105  int thickness = 0, DrawCapAndJoin *cap_and_join = 0, DrawDashPattern *dashes = 0);
106 
107  // OS Graphics specific functions
108  void clear();
109 
110  protected:
115  };
116 }
117 
118 #endif
virtual void text_colours(Colour foreground, Colour background)
Set the colours for the desktop font.
Definition: osgraphics.cc:380
Definition: osgraphics.h:45
virtual void foreground(Colour colour)
Set foreground graphics colour to the nearest match to the given colour for the current screen mode...
Definition: osgraphics.cc:76
void clear()
Clear the current graphics window to the background colour.
Definition: osgraphics.cc:428
Definition: osgraphics.h:48
virtual void sector(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)
Draw a sector of a circle.
Definition: osgraphics.cc:248
DrawFillStyle
Enumeration to set the fill style when filling shapes.
Definition: drawpath.h:40
virtual void ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y)
Draw the outline of an ellipse.
Definition: osgraphics.cc:265
virtual int logical_y(int os_y) const
Convert from OS units to logical y value.
Definition: osgraphics.h:61
Class to represent, display and manipulate a graphical path used by the Draw RISC OS module...
Definition: drawpath.h:464
virtual BBox os(const BBox &b)
Convert from logical coordinates to OS units.
Definition: osgraphics.h:65
virtual Point logical(const Point &pt)
Convert from OS units to logical coordinates.
Definition: osgraphics.h:64
PlotAction
Definition: osgraphics.h:43
virtual void segment(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)
Draw a segment of a circle.
Definition: osgraphics.cc:231
virtual void move(int x, int y)
Move graphics position.
Definition: osgraphics.cc:125
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
Definition: osgraphics.h:46
Class to set the cap and joins style for lines that are greater than a single pixel wide...
Definition: drawpath.h:57
Definition: osgraphics.h:50
virtual void arc(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)
Draw arc around a circle.
Definition: osgraphics.cc:214
virtual void fill_polygon(const Point *points, int num)
Fill a polygon.
Definition: osgraphics.cc:345
virtual void plot(int code, int x, int y)
Execute the OS_Plot swi.
Definition: osgraphics.cc:65
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
Class to represent a standard desktop WIMP colour.
Definition: colour.h:146
virtual void point(int x, int y)
Draw a single pixel point.
Definition: osgraphics.cc:133
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 void fill_ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y)
Draw a filled ellipse.
Definition: osgraphics.cc:283
virtual BBox logical(const BBox &b)
Convert from OS units to logical coordinates.
Definition: osgraphics.h:66
virtual void fill_circle(int centre_x, int centre_y, int radius)
Draw a filled circle.
Definition: osgraphics.cc:198
Class to represent a dash pattern for lines.
Definition: drawpath.h:225
non-zero winding number rule.
Definition: drawpath.h:42
Class to represent a position in two dimensional space.
Definition: point.h:36
Definition: osgraphics.h:44
virtual void fill_rectangle(int xmin, int ymin, int xmax, int ymax)
Fill a rectangle the current foreground colour.
Definition: osgraphics.cc:172
int _plot_action
Stores the current Plot action.
Definition: osgraphics.h:114
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
Interface to drawing graphics to the screen.
Definition: graphics.h:43
virtual void circle(int centre_x, int centre_y, int radius)
Draw outline of a circle.
Definition: osgraphics.cc:185
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
void plot_action(PlotAction action)
Sets the plot action.
Definition: osgraphics.cc:52
virtual int os_y(int logical_y) const
Convert from logical y value to OS units.
Definition: osgraphics.h:59
virtual void line(int fx, int fy, int tx, int ty)
Draw a line betweenn the given coordinates.
Definition: osgraphics.cc:150
virtual void wimp_background(WimpColour colour)
Set the graphics background colour to the given WIMP colour.
Definition: osgraphics.cc:112
virtual Point os(const Point &pt)
Convert from logical coordinates to OS units.
Definition: osgraphics.h:63
virtual void polygon(const Point *points, int num)
Draw outline of a polygon.
Definition: osgraphics.cc:320
Class to draw to graphics to the screen using standard OS routines with no translation or scaling...
Definition: osgraphics.h:36
Class to represent a RGB colour.
Definition: colour.h:43
virtual void rectangle(int xmin, int ymin, int xmax, int ymax)
Draw outline of a rectangle.
Definition: osgraphics.cc:159
Definition: osgraphics.h:49
Class to handle painting and measuring text using an outline font.
Definition: font.h:60
Definition: osgraphics.h:47
virtual int logical_x(int os_x) const
Convert from OS units to logical x value.
Definition: osgraphics.h:60
OSGraphics()
Create the graphics class with the default plot action of overwrite.
Definition: osgraphics.cc:40
virtual void background(Colour colour)
Set background graphics colour to the nearest match to the given colour for the current screen mode...
Definition: osgraphics.cc:90
virtual int os_x(int logical_x) const
Convert from logical x value to OS units.
Definition: osgraphics.h:58
virtual void wimp_foreground(WimpColour colour)
Set the graphics foreground colour to the given WIMP colour.
Definition: osgraphics.cc:101