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
|
|
|
|
2009-02-09 20:10:11 +00:00
|
|
|
#include "Color.h"
|
2007-10-25 12:41:02 +00:00
|
|
|
|
2007-11-13 23:00:36 +00:00
|
|
|
#include "support/strfwd.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
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
|
|
|
|
* queue (perhaps generated via Screen::expose), does the copy onto
|
|
|
|
* the actual WorkArea widget take place. Paints are wrapped in (possibly
|
|
|
|
* recursive) calls to start() and end() to facilitate the backing pixmap
|
|
|
|
* management.
|
|
|
|
*
|
|
|
|
* Note that the methods return *this for convenience.
|
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:
|
2007-11-23 21:39:51 +00:00
|
|
|
Painter() : drawing_enabled_(true) {}
|
2010-09-05 14:46:58 +00:00
|
|
|
|
|
|
|
float line_width;
|
2010-09-07 05:14:57 +00:00
|
|
|
static const float 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
|
|
|
|
line_onoffdash //< dashes with spaces
|
2000-02-10 17:53:36 +00:00
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
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,
|
2010-09-07 05:14:57 +00:00
|
|
|
line_style = line_solid, float 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,
|
2010-09-07 05:14:57 +00:00
|
|
|
line_style = line_solid, float line_width = thin_line) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
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,
|
2010-09-07 05:14:57 +00:00
|
|
|
line_style = line_solid, float 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 a filled rectangle with the shape of a 3D button
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
|
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
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a string at position x, y (y is the baseline)
|
2006-10-10 13:24:08 +00:00
|
|
|
/**
|
|
|
|
* \return the width of the drawn text.
|
|
|
|
*/
|
2007-11-23 21:39:51 +00:00
|
|
|
virtual int text(int x, int y, docstring const & str, FontInfo const & f) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
2007-11-23 21:49:58 +00:00
|
|
|
void setDrawingEnabled(bool drawing_enabled)
|
2006-10-30 10:09:59 +00:00
|
|
|
{ drawing_enabled_ = drawing_enabled; }
|
|
|
|
|
2007-11-06 14:07:49 +00:00
|
|
|
/// Indicate wether real screen drawing shall be done or not.
|
|
|
|
bool isDrawingEnabled() const { return drawing_enabled_; }
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a char at position x, y (y is the baseline)
|
2006-10-10 13:24:08 +00:00
|
|
|
/**
|
|
|
|
* \return the width of the drawn text.
|
|
|
|
*/
|
2007-10-28 18:51:54 +00:00
|
|
|
virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
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,
|
|
|
|
FontInfo const & font, bool mouseHover) = 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]
|
2009-02-09 20:10:11 +00:00
|
|
|
virtual void enterMonochromeMode(Color const & min,
|
|
|
|
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:
|
|
|
|
///
|
|
|
|
bool drawing_enabled_;
|
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
|