2000-02-10 17:53:36 +00:00
|
|
|
// -*- C++ -*-
|
2002-06-12 15:01:32 +00:00
|
|
|
/**
|
|
|
|
* \file Painter.h
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-06-12 15:01:32 +00:00
|
|
|
* \author unknown
|
2002-11-27 10:30:28 +00:00
|
|
|
* \author John Levon
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-12 15:01:32 +00:00
|
|
|
*/
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
#ifndef PAINTER_H
|
|
|
|
#define PAINTER_H
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
#include "support/strfwd.h"
|
2014-05-23 16:59:53 +00:00
|
|
|
#include "support/types.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2014-05-23 16:59:53 +00:00
|
|
|
class Font;
|
2007-10-28 18:51:54 +00:00
|
|
|
class FontInfo;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace graphics { class Image; }
|
2003-07-04 08:23:23 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace frontend {
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/**
|
|
|
|
* Painter - A painter class to encapsulate all graphics parameters and operations
|
|
|
|
*
|
|
|
|
* Every graphics operation in LyX should be made by this class. The
|
|
|
|
* painter is used for drawing on the WorkArea, and is passed around
|
|
|
|
* during draw operations.
|
|
|
|
*
|
|
|
|
* It hides low level windows system parameters so insets and other
|
|
|
|
* clients don't have to worry about them and we can control graphics and
|
|
|
|
* GUI toolkit dependent drawing functions inside this single class.
|
|
|
|
*
|
|
|
|
* The intention for a toolkit is that it uses these methods to paint
|
|
|
|
* onto a backing pixmap. Only when expose events arrive via the event
|
2016-07-18 14:17:38 +00:00
|
|
|
* queue, does the copy onto the actual WorkArea widget take place.
|
2006-11-07 20:46:38 +00:00
|
|
|
*
|
|
|
|
* Caution: All char_type and docstring arguments of the text drawing
|
|
|
|
* methods of this class are no UCS4 chars or strings if the font is a
|
|
|
|
* symbol font. They simply denote the code points of the font instead.
|
|
|
|
* You have to keep this in mind when you implement the methods in a
|
|
|
|
* frontend. You must not pass these parameters to a unicode conversion
|
|
|
|
* function in particular.
|
2000-02-10 17:53:36 +00:00
|
|
|
*/
|
2002-06-12 15:01:32 +00:00
|
|
|
class Painter {
|
2000-02-10 17:53:36 +00:00
|
|
|
public:
|
2017-09-13 10:38:33 +00:00
|
|
|
Painter(double pixel_ratio) : pixel_ratio_(pixel_ratio) {}
|
2010-09-05 14:46:58 +00:00
|
|
|
|
2015-07-14 15:42:45 +00:00
|
|
|
static const int thin_line;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// possible line styles
|
2000-02-10 17:53:36 +00:00
|
|
|
enum line_style {
|
2002-06-12 15:01:32 +00:00
|
|
|
line_solid, //< solid line
|
2016-05-23 10:38:48 +00:00
|
|
|
line_solid_aliased, //< solid line, no anti-aliasing (used as a
|
|
|
|
// workaround to painting issues)
|
2002-06-12 15:01:32 +00:00
|
|
|
line_onoffdash //< dashes with spaces
|
2000-02-10 17:53:36 +00:00
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2014-10-25 21:38:52 +00:00
|
|
|
/// possible fill styles
|
|
|
|
enum fill_style {
|
|
|
|
fill_none,
|
|
|
|
fill_oddeven,
|
|
|
|
fill_winding
|
|
|
|
};
|
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
/// possible character styles of preedit string.
|
|
|
|
/// This is used for CJK input method support.
|
|
|
|
enum preedit_style {
|
|
|
|
preedit_default, //< when unselecting, no cursor and dashed underline.
|
|
|
|
preedit_selecting, //< when selecting.
|
|
|
|
preedit_cursor //< with cursor.
|
|
|
|
};
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
virtual ~Painter() {}
|
|
|
|
|
|
|
|
/// draw a line from point to point
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void line(int x1, int y1, int x2, int y2, Color,
|
2015-07-14 15:42:45 +00:00
|
|
|
line_style = line_solid, int line_width = thin_line) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lines - draw a set of lines
|
|
|
|
* @param xp array of points' x co-ords
|
|
|
|
* @param yp array of points' y co-ords
|
|
|
|
* @param np size of the points array
|
|
|
|
*/
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void lines(int const * xp, int const * yp, int np, Color,
|
2014-10-25 21:38:52 +00:00
|
|
|
fill_style = fill_none, line_style = line_solid,
|
2015-07-14 15:42:45 +00:00
|
|
|
int line_width = thin_line) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2016-01-24 11:49:02 +00:00
|
|
|
/**
|
|
|
|
* path - draw a path with bezier curves
|
|
|
|
* @param xp array of points' x co-ords
|
|
|
|
* @param yp array of points' y co-ords
|
|
|
|
* @param c1x array of first control points' x co-ords
|
|
|
|
* @param c1y array of first control points' y co-ords
|
|
|
|
* @param c2x array of second control points' x co-ords
|
|
|
|
* @param c2y array of second control points' y co-ords
|
|
|
|
* @param np size of the points array
|
|
|
|
*/
|
|
|
|
virtual void path(int const * xp, int const * yp,
|
|
|
|
int const * c1x, int const * c1y,
|
|
|
|
int const * c2x, int const * c2y,
|
|
|
|
int np, Color,
|
|
|
|
fill_style = fill_none, line_style = line_solid,
|
|
|
|
int line_width = thin_line) = 0;
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a rectangle
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void rectangle(int x, int y, int w, int h, Color,
|
2015-07-14 15:42:45 +00:00
|
|
|
line_style = line_solid, int line_width = thin_line) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a filled rectangle
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw an arc
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void arc(int x, int y, unsigned int w, unsigned int h,
|
2009-02-09 20:10:11 +00:00
|
|
|
int a1, int a2, Color) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a pixel
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void point(int x, int y, Color) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw an image from the image cache
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void image(int x, int y, int w, int h,
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::Image const & image) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2016-03-20 19:02:05 +00:00
|
|
|
/// draw a string at position x, y (y is the baseline).
|
|
|
|
virtual void text(int x, int y, docstring const & str, FontInfo const & f) = 0;
|
2016-03-19 16:52:07 +00:00
|
|
|
|
2016-03-20 19:02:05 +00:00
|
|
|
/// draw a char at position x, y (y is the baseline)
|
|
|
|
virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
2014-05-23 16:59:53 +00:00
|
|
|
/** draw a string at position x, y (y is the baseline). The
|
|
|
|
* text direction is enforced by the \c Font.
|
|
|
|
*/
|
2016-03-19 16:52:07 +00:00
|
|
|
virtual void text(int x, int y, docstring const & str, Font const & f,
|
2016-03-20 19:02:05 +00:00
|
|
|
double wordspacing, double textwidth) = 0;
|
2014-05-23 16:59:53 +00:00
|
|
|
|
|
|
|
/** draw a string at position x, y (y is the baseline), but
|
|
|
|
* make sure that the part between \c from and \c to is in
|
|
|
|
* \c other color. The text direction is enforced by the \c Font.
|
|
|
|
*/
|
2016-03-19 16:52:07 +00:00
|
|
|
virtual void text(int x, int y, docstring const & str, Font const & f,
|
|
|
|
Color other, size_type from, size_type to,
|
2016-03-20 19:02:05 +00:00
|
|
|
double wordspacing, double textwidth) = 0;
|
2014-05-23 16:59:53 +00:00
|
|
|
|
2017-07-15 23:25:03 +00:00
|
|
|
// Returns true if the painter does not actually paint.
|
|
|
|
virtual bool isNull() const = 0;
|
2007-11-06 14:07:49 +00:00
|
|
|
|
2014-10-12 17:23:13 +00:00
|
|
|
double pixelRatio() const { return pixel_ratio_; }
|
|
|
|
|
2017-04-04 22:01:19 +00:00
|
|
|
/// draw the underbar, strikeout, xout, uuline and uwave font attributes
|
2012-05-02 16:02:17 +00:00
|
|
|
virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
|
|
|
|
|
2002-07-09 16:23:20 +00:00
|
|
|
/**
|
|
|
|
* Draw a string and enclose it inside a rectangle. If
|
|
|
|
* back color is specified, the background is cleared with
|
|
|
|
* the given color. If frame is specified, a thin frame is drawn
|
|
|
|
* around the text with the given color.
|
|
|
|
*/
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void rectText(int x, int baseline, docstring const & str,
|
2009-02-09 20:10:11 +00:00
|
|
|
FontInfo const & font, Color back, Color frame) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw a string and enclose it inside a button frame
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void buttonText(int x, int baseline, docstring const & s,
|
2017-06-15 13:30:23 +00:00
|
|
|
FontInfo const & font, Color back, Color frame, int offset) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
/// draw a character of a preedit string for cjk support.
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual int preeditText(int x, int y,
|
|
|
|
char_type c, FontInfo const & f, preedit_style style) = 0;
|
2007-04-01 09:14:08 +00:00
|
|
|
|
2007-11-01 10:52:51 +00:00
|
|
|
/// start monochrome painting mode, i.e. map every color into [min,max]
|
2017-07-03 17:45:58 +00:00
|
|
|
virtual void enterMonochromeMode(Color const & min,
|
2009-02-09 20:10:11 +00:00
|
|
|
Color const & max) = 0;
|
2007-11-01 10:52:51 +00:00
|
|
|
/// leave monochrome painting mode
|
|
|
|
virtual void leaveMonochromeMode() = 0;
|
2009-03-28 17:33:20 +00:00
|
|
|
/// draws a wavy line that can be used for underlining.
|
|
|
|
virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
|
2006-10-30 10:09:59 +00:00
|
|
|
private:
|
2014-10-12 17:23:13 +00:00
|
|
|
/// Ratio between physical pixels and device-independent pixels
|
|
|
|
double pixel_ratio_;
|
2000-02-10 17:53:36 +00:00
|
|
|
};
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
#endif // PAINTER_H
|