tbx  0.7.6
osgraphics.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2021 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) const {return pt;}
64  virtual Point logical(const Point &pt) const {return pt;}
65  virtual BBox os(const BBox &b) const {return b;}
66  virtual BBox logical(const BBox &b) const {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  BBox clip() const;
110  void clip(const BBox &clip_to);
111 
112  protected:
117  };
118 }
119 
120 #endif
tbx::DrawDashPattern
Class to represent a dash pattern for lines.
Definition: drawpath.h:226
tbx::OSGraphics::segment
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
tbx::DrawCapAndJoin
Class to set the cap and joins style for lines that are greater than a single pixel wide.
Definition: drawpath.h:58
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::OSGraphics::ACTION_OR
@ ACTION_OR
Definition: osgraphics.h:45
tbx::OSGraphics::clear
void clear()
Clear the current graphics window to the background colour.
Definition: osgraphics.cc:428
tbx::DrawPath
Class to represent, display and manipulate a graphical path used by the Draw RISC OS module.
Definition: drawpath.h:465
tbx::WimpColour
Class to represent a standard desktop WIMP colour.
Definition: colour.h:147
tbx::OSGraphics::logical_y
virtual int logical_y(int os_y) const
Convert from OS units to logical y value.
Definition: osgraphics.h:61
tbx::OSGraphics::wimp_foreground
virtual void wimp_foreground(WimpColour colour)
Set the graphics foreground colour to the given WIMP colour.
Definition: osgraphics.cc:101
tbx::Font
Class to handle painting and measuring text using an outline font.
Definition: font.h:61
tbx::OSGraphics::os
virtual Point os(const Point &pt) const
Convert from logical coordinates to OS units.
Definition: osgraphics.h:63
tbx::OSGraphics::move
virtual void move(int x, int y)
Move graphics position.
Definition: osgraphics.cc:125
tbx::OSGraphics::image
virtual void image(int x, int y, const Image &image)
Draw an image at given location.
Definition: osgraphics.cc:397
tbx::OSGraphics::ACTION_AND_NOT
@ ACTION_AND_NOT
Definition: osgraphics.h:50
tbx::OSGraphics::plot
virtual void plot(int code, int x, int y)
Execute the OS_Plot swi.
Definition: osgraphics.cc:65
tbx::OSGraphics::fill_ellipse
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
tbx::OSGraphics::PlotAction
PlotAction
Definition: osgraphics.h:43
tbx::WINDING_NON_ZERO
@ WINDING_NON_ZERO
non-zero winding number rule.
Definition: drawpath.h:42
tbx::OSGraphics::stroke
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
tbx::OSGraphics::text
virtual void text(int x, int y, const std::string &text)
Draw text in current desktop font.
Definition: osgraphics.cc:363
tbx::OSGraphics::arc
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
tbx::OSGraphics::fill_circle
virtual void fill_circle(int centre_x, int centre_y, int radius)
Draw a filled circle.
Definition: osgraphics.cc:198
tbx::OSGraphics
Class to draw to graphics to the screen using standard OS routines with no translation or scaling.
Definition: osgraphics.h:37
tbx::OSGraphics::fill_polygon
virtual void fill_polygon(const Point *points, int num)
Fill a polygon.
Definition: osgraphics.cc:345
tbx::OSGraphics::os
virtual BBox os(const BBox &b) const
Convert from logical coordinates to OS units.
Definition: osgraphics.h:65
tbx::OSGraphics::point
virtual void point(int x, int y)
Draw a single pixel point.
Definition: osgraphics.cc:133
tbx::OSGraphics::fill
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
tbx::OSGraphics::_plot_action
int _plot_action
Stores the current Plot action.
Definition: osgraphics.h:116
tbx::Colour
Class to represent a RGB colour.
Definition: colour.h:44
tbx::OSGraphics::logical
virtual BBox logical(const BBox &b) const
Convert from OS units to logical coordinates.
Definition: osgraphics.h:66
tbx::BBox
Class to represent a two dimensional bounding box.
Definition: bbox.h:38
tbx::OSGraphics::path
virtual void path(const Point *points, int num)
Draw a line through the specified points.
Definition: osgraphics.cc:296
tbx::Graphics
Interface to drawing graphics to the screen.
Definition: graphics.h:44
tbx::Image
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:45
tbx::OSGraphics::clip
BBox clip() const
Get the current Graphics clipping region.
Definition: osgraphics.cc:439
tbx::OSGraphics::plot_action
void plot_action(PlotAction action)
Sets the plot action.
Definition: osgraphics.cc:52
tbx::OSGraphics::fill_rectangle
virtual void fill_rectangle(int xmin, int ymin, int xmax, int ymax)
Fill a rectangle the current foreground colour.
Definition: osgraphics.cc:172
tbx::OSGraphics::os_x
virtual int os_x(int logical_x) const
Convert from logical x value to OS units.
Definition: osgraphics.h:58
tbx::OSGraphics::ACTION_NONE
@ ACTION_NONE
Definition: osgraphics.h:49
tbx::OSGraphics::circle
virtual void circle(int centre_x, int centre_y, int radius)
Draw outline of a circle.
Definition: osgraphics.cc:185
tbx::Point
Class to represent a position in two dimensional space.
Definition: point.h:37
tbx::DrawFillStyle
DrawFillStyle
Enumeration to set the fill style when filling shapes.
Definition: drawpath.h:41
tbx::OSGraphics::ACTION_OVERWRITE
@ ACTION_OVERWRITE
Definition: osgraphics.h:44
tbx::OSGraphics::os_y
virtual int os_y(int logical_y) const
Convert from logical y value to OS units.
Definition: osgraphics.h:59
tbx::OSGraphics::line
virtual void line(int fx, int fy, int tx, int ty)
Draw a line betweenn the given coordinates.
Definition: osgraphics.cc:150
tbx::OSGraphics::rectangle
virtual void rectangle(int xmin, int ymin, int xmax, int ymax)
Draw outline of a rectangle.
Definition: osgraphics.cc:159
tbx::OSGraphics::wimp_background
virtual void wimp_background(WimpColour colour)
Set the graphics background colour to the given WIMP colour.
Definition: osgraphics.cc:112
tbx::OSGraphics::logical
virtual Point logical(const Point &pt) const
Convert from OS units to logical coordinates.
Definition: osgraphics.h:64
tbx::OSGraphics::ACTION_INVERT
@ ACTION_INVERT
Definition: osgraphics.h:48
tbx::OSGraphics::OSGraphics
OSGraphics()
Create the graphics class with the default plot action of overwrite.
Definition: osgraphics.cc:40
tbx::OSGraphics::text_colours
virtual void text_colours(Colour foreground, Colour background)
Set the colours for the desktop font.
Definition: osgraphics.cc:380
tbx::OSGraphics::ACTION_AND
@ ACTION_AND
Definition: osgraphics.h:46
tbx::OSGraphics::background
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
tbx::OSGraphics::polygon
virtual void polygon(const Point *points, int num)
Draw outline of a polygon.
Definition: osgraphics.cc:320
tbx::OSGraphics::sector
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
tbx::OSGraphics::ACTION_XOR
@ ACTION_XOR
Definition: osgraphics.h:47
tbx::OSGraphics::ellipse
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
tbx::OSGraphics::logical_x
virtual int logical_x(int os_x) const
Convert from OS units to logical x value.
Definition: osgraphics.h:60
tbx::OSGraphics::foreground
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