tbx  0.7.5
graphics.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2012 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_GRAPHICS_H
26 #define TBX_GRAPHICS_H
27 
28 #include "colour.h"
29 #include "font.h"
30 #include "bbox.h"
31 #include "image.h"
32 #include "drawpath.h"
33 #include <string>
34 
35 namespace tbx
36 {
43  class Graphics
44  {
45  public:
46  Graphics() {}
47  virtual ~Graphics() {}
48 
49  // coordinate conversion
56  virtual int os_x(int logical_x) const = 0;
63  virtual int os_y(int logical_y) const = 0;
70  virtual int logical_x(int os_x) const = 0;
77  virtual int logical_y(int os_y) const = 0;
78 
85  virtual Point os(const Point &pt) {Point o;o.x=os_x(pt.x);o.y=os_y(pt.y);return o;}
92  virtual Point logical(const Point &pt) {Point o;o.x=logical_x(pt.x);o.y=logical_y(pt.y);return o;}
99  virtual BBox os(const BBox &b) {BBox o;o.min = os(b.min);o.max = os(b.max);return o;}
106  virtual BBox logical(const BBox &b) {BBox o;o.min = logical(b.min);o.max = logical(b.max);return o;}
107 
108  // Colours
114  virtual void foreground(Colour colour) = 0;
120  virtual void background(Colour colour) = 0;
121 
128  virtual void wimp_foreground(WimpColour colour) = 0;
135  virtual void wimp_background(WimpColour colour) = 0;
136 
137  // Drawing
144  virtual void move(int x, int y) = 0;
151  virtual void point(int x, int y) = 0;
152 
160  virtual void line(int tx, int ty) = 0;
161 
170  virtual void line(int fx, int fy, int tx, int ty) {move(fx,ty);line(tx,ty);}
179  virtual void rectangle(int xmin, int ymin, int xmax, int ymax) = 0;
188  virtual void fill_rectangle(int xmin, int ymin, int xmax, int ymax) = 0;
189 
196  virtual void path(const Point *points, int num) = 0;
206  virtual void polygon(const Point *points, int num) = 0;
207 
218  virtual void fill_polygon(const Point *points, int num) = 0;
219 
227  virtual void circle(int centre_x, int centre_y, int radius) = 0;
235  virtual void fill_circle(int centre_x, int centre_y, int radius) = 0;
246  virtual void arc(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y) = 0;
257  virtual void segment(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y) = 0;
268  virtual void sector(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y) = 0;
279  virtual void ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y) = 0;
290  virtual void fill_ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y) = 0;
291 
292  // Drawing using points and boxes
298  virtual void move(const Point &point) {move(point.x,point.y);}
304  virtual void point(const Point &pt) {point(pt.x,pt.y);}
311  virtual void line(const Point &to_point) {line(to_point.x,to_point.y);}
318  virtual void line(const Point &from_point, const Point &to_point) {move(from_point);line(to_point);}
325  virtual void rectangle(const Point &min_point, const Point &max_point) {rectangle(min_point.x, min_point.y, max_point.x, max_point.y);}
331  virtual void rectangle(const BBox &r) {rectangle(r.min.x,r.min.y, r.max.x, r.max.y);}
338  virtual void fill_rectangle(const Point &min_point, const Point &max_point) {fill_rectangle(min_point.x, min_point.y, max_point.x, max_point.y);}
344  virtual void fill_rectangle(const BBox &r) {fill_rectangle(r.min.x,r.min.y, r.max.x, r.max.y);}
351  virtual void circle(const Point &centre_point, int radius) {circle(centre_point.x, centre_point.y, radius);}
358  virtual void fill_circle(const Point &centre_point, int radius) {fill_circle(centre_point.x, centre_point.y, radius);}
366  virtual void arc(const Point &centre_point, const Point &start_point, const Point &end_point) {arc(centre_point.x, centre_point.y, start_point.x, start_point.y, end_point.x, end_point.y);}
374  virtual void segment(const Point &centre_point, const Point &start_point, const Point &end_point) {segment(centre_point.x, centre_point.y, start_point.x, start_point.y, end_point.x, end_point.y);}
382  virtual void sector(const Point &centre_point, const Point &start_point, const Point &end_point) {sector(centre_point.x, centre_point.y, start_point.x, start_point.y, end_point.x, end_point.y);}
390  virtual void ellipse(const Point &centre_point, const Point &intersect_point, const Point &high_point) {ellipse(centre_point.x, centre_point.y, intersect_point.x, intersect_point.y, high_point.x, high_point.y);}
398  virtual void fill_ellipse(const Point &centre_point, const Point &intersect_point, const Point &high_point) {fill_ellipse(centre_point.x, centre_point.y, intersect_point.x, intersect_point.y, high_point.x, high_point.y);}
399 
400  // Text
408  virtual void text(int x, int y, const std::string &text) = 0;
417  virtual void text(int x, int y, const std::string &text, const Font &font) = 0;
424  virtual void text_colours(Colour foreground, Colour background) = 0;
432  virtual void text_colours(Font &font, Colour foreground, Colour background) = 0;
439  virtual void text(const Point &pt, const std::string &str) {text(pt.x,pt.y,str);}
447  virtual void text(const Point &pt, const std::string &str, const Font &font) {text(pt.x,pt.y,str,font);}
448 
449  // Image
457  virtual void image(int x, int y, const Image &image) = 0;
464  virtual void image(const Point &pt, const Image &im) {image(pt.x, pt.y, im);}
465 
479  virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1) = 0;
492  virtual void fill(const Point &pt, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1) {fill(pt.x, pt.y, path, fill_style, flatness);}
493 
513  virtual void stroke(int x, int y, const DrawPath &path,DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1,
514  int thickness = 0, DrawCapAndJoin *cap_and_join = 0, DrawDashPattern *dashes = 0) = 0;
515 
534  virtual void stroke(const Point &pt, const DrawPath &path, DrawFillStyle fill_style = WINDING_NON_ZERO, int flatness = 1,
535  int thickness = 0, DrawCapAndJoin *cap_and_join = 0, DrawDashPattern *dashes = 0)
536  {
537  stroke(pt.x, pt.y, path, fill_style, flatness, thickness, cap_and_join, dashes);
538  }
539  };
540 }
541 
542 #endif
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
virtual void text(const Point &pt, const std::string &str, const Font &font)
Draw text at the given location in the given font.
Definition: graphics.h:447
virtual int os_x(int logical_x) const =0
Convert from logical x value to OS units.
virtual Point logical(const Point &pt)
Convert from OS units to logical coordinates.
Definition: graphics.h:92
virtual void arc(const Point &centre_point, const Point &start_point, const Point &end_point)
Draw an arc.
Definition: graphics.h:366
DrawFillStyle
Enumeration to set the fill style when filling shapes.
Definition: drawpath.h:40
virtual int logical_y(int os_y) const =0
Convert from OS units to logical y value.
int x
Definition: point.h:59
Class to represent, display and manipulate a graphical path used by the Draw RISC OS module...
Definition: drawpath.h:464
virtual void rectangle(const BBox &r)
Draw the outline of a rectangle.
Definition: graphics.h:331
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
virtual void arc(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)=0
Draw arc around a circle.
virtual void polygon(const Point *points, int num)=0
Draw the outline of a polygon.
virtual BBox logical(const BBox &b)
Convert from OS units to logical coordinates.
Definition: graphics.h:106
virtual void image(int x, int y, const Image &image)=0
Draw an image.
virtual void sector(const Point &centre_point, const Point &start_point, const Point &end_point)
Draw a sector of a circle.
Definition: graphics.h:382
virtual void point(const Point &pt)
Draw a point at the given location.
Definition: graphics.h:304
virtual void fill_polygon(const Point *points, int num)=0
Draw a filled polygon.
virtual void foreground(Colour colour)=0
Set the foreground colour for graphics.
Class to represent a standard desktop WIMP colour.
Definition: colour.h:146
virtual Point os(const Point &pt)
Convert from logical coordinates to OS units.
Definition: graphics.h:85
Point min
Minimum coordinate of the bounding box.
Definition: bbox.h:68
int y
Definition: point.h:60
Base class image classes providing a consistent interface to plot the to the screen.
Definition: image.h:44
virtual void rectangle(int xmin, int ymin, int xmax, int ymax)=0
Draw the outline of a rectangle.
virtual void line(int tx, int ty)=0
Draw a line from the last point visited to the given location.
virtual void move(const Point &point)
Move the graphics cursor to the given location.
Definition: graphics.h:298
virtual void line(const Point &to_point)
Draw a line from the last point visited to the given location.
Definition: graphics.h:311
virtual void text_colours(Colour foreground, Colour background)=0
Set the text colours for the current WIMP font.
Class to represent a dash pattern for lines.
Definition: drawpath.h:225
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)=0
Plot the lines in a path.
virtual void line(const Point &from_point, const Point &to_point)
Draw a line between the given two points.
Definition: graphics.h:318
non-zero winding number rule.
Definition: drawpath.h:42
virtual BBox os(const BBox &b)
Convert from logical coordinates to OS units.
Definition: graphics.h:99
Class to represent a position in two dimensional space.
Definition: point.h:36
virtual void wimp_background(WimpColour colour)=0
Set the background colour for graphics to one of the standard WIMP colours.
virtual void segment(const Point &centre_point, const Point &start_point, const Point &end_point)
Draw a segment of a circle.
Definition: graphics.h:374
virtual void segment(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)=0
Draw a segment of a circle.
virtual void fill(const Point &pt, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1)
Fill a draw path.
Definition: graphics.h:492
virtual int logical_x(int os_x) const =0
Convert from OS units to logical x value.
virtual void wimp_foreground(WimpColour colour)=0
Set the foreground colour for graphics to one of the standard WIMP colours.
Interface to drawing graphics to the screen.
Definition: graphics.h:43
Point max
Maximum coordinate of the bounding box.
Definition: bbox.h:72
virtual void background(Colour colour)=0
Set the background colour for graphics.
virtual void rectangle(const Point &min_point, const Point &max_point)
Draw the outline of a rectangle.
Definition: graphics.h:325
virtual void fill_ellipse(const Point &centre_point, const Point &intersect_point, const Point &high_point)
Draw a filled ellipse.
Definition: graphics.h:398
virtual void fill_circle(int centre_x, int centre_y, int radius)=0
Draw a filled circle.
virtual void circle(const Point &centre_point, int radius)
Draw the outline of a circle.
Definition: graphics.h:351
virtual void fill(int x, int y, const DrawPath &path, DrawFillStyle fill_style=WINDING_NON_ZERO, int flatness=1)=0
Fill a draw path.
Class to represent a RGB colour.
Definition: colour.h:43
virtual void circle(int centre_x, int centre_y, int radius)=0
Draw the outline of a circle.
virtual void point(int x, int y)=0
Draw a point at the given location.
virtual void fill_ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y)=0
Draw a filled ellipse.
virtual void ellipse(int centre_x, int centre_y, int intersect_x, int intersect_y, int high_x, int high_y)=0
Draw the outline of an ellipse.
Class to handle painting and measuring text using an outline font.
Definition: font.h:60
virtual int os_y(int logical_y) const =0
Convert from logical y value to OS units.
virtual void path(const Point *points, int num)=0
Draw a path of lines connecting the given points.
virtual void fill_rectangle(const BBox &r)
Draw a filled rectangle.
Definition: graphics.h:344
virtual void text(const Point &pt, const std::string &str)
Draw text at the given location in the current WIMP font.
Definition: graphics.h:439
virtual void image(const Point &pt, const Image &im)
Draw an image.
Definition: graphics.h:464
virtual void move(int x, int y)=0
Move the graphics cursor to the given point.
virtual void fill_rectangle(int xmin, int ymin, int xmax, int ymax)=0
Draw a filled rectangle.
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: graphics.h:534
virtual void fill_circle(const Point &centre_point, int radius)
Draw a filled circle.
Definition: graphics.h:358
virtual void text(int x, int y, const std::string &text)=0
Draw text at the given location in the current WIMP font.
virtual void sector(int centre_x, int centre_y, int start_x, int start_y, int end_x, int end_y)=0
Draw a sector of a circle.
virtual void line(int fx, int fy, int tx, int ty)
Draw a line between the given two points.
Definition: graphics.h:170
virtual void fill_rectangle(const Point &min_point, const Point &max_point)
Draw the outline of a rectangle.
Definition: graphics.h:338
virtual void ellipse(const Point &centre_point, const Point &intersect_point, const Point &high_point)
Draw the outline of an ellipse.
Definition: graphics.h:390