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
|
|
|
|
2006-09-13 21:13:49 +00:00
|
|
|
#include "support/docstring.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-04-26 17:34:20 +00:00
|
|
|
class Color_color;
|
2007-04-29 18:17:15 +00:00
|
|
|
class Font;
|
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:
|
2006-10-30 10:09:59 +00:00
|
|
|
Painter(): drawing_enabled_(true) {}
|
2002-06-12 15:01:32 +00:00
|
|
|
/// possible line widths
|
2000-02-10 17:53:36 +00:00
|
|
|
enum line_width {
|
2002-06-12 15:01:32 +00:00
|
|
|
line_thin, //< thin line
|
|
|
|
line_thick //< thick line
|
2000-02-10 17:53:36 +00:00
|
|
|
};
|
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
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void line(
|
2002-06-12 15:01:32 +00:00
|
|
|
int x1, int y1,
|
|
|
|
int x2, int y2,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color,
|
2002-06-12 15:01:32 +00:00
|
|
|
line_style = line_solid,
|
|
|
|
line_width = line_thin) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void lines(
|
2002-06-12 15:01:32 +00:00
|
|
|
int const * xp,
|
|
|
|
int const * yp,
|
2000-02-10 17:53:36 +00:00
|
|
|
int np,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color,
|
2002-06-12 15:01:32 +00:00
|
|
|
line_style = line_solid,
|
|
|
|
line_width = line_thin) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a rectangle
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void rectangle(
|
2002-06-12 15:01:32 +00:00
|
|
|
int x, int y,
|
|
|
|
int w, int h,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color,
|
2002-06-12 15:01:32 +00:00
|
|
|
line_style = line_solid,
|
|
|
|
line_width = line_thin) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a filled rectangle
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void fillRectangle(
|
2000-02-10 17:53:36 +00:00
|
|
|
int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
int w, int h,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color) = 0;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw an arc
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void arc(
|
2000-02-10 17:53:36 +00:00
|
|
|
int x, int y,
|
2002-03-21 17:27:08 +00:00
|
|
|
unsigned int w, unsigned int h,
|
2000-02-10 17:53:36 +00:00
|
|
|
int a1, int a2,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a pixel
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void point(
|
2000-02-10 17:53:36 +00:00
|
|
|
int x, int y,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_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
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void button(int x, int y,
|
2006-12-04 04:31:18 +00:00
|
|
|
int w, int h, bool mouseHover);
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw an image from the image cache
|
2004-04-07 20:20:15 +00:00
|
|
|
virtual void image(int x, int y,
|
2002-06-12 15:01:32 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
virtual int text(int x, int y,
|
2007-04-29 18:17:15 +00:00
|
|
|
docstring const & str, Font const & f) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
2006-10-30 10:09:59 +00:00
|
|
|
void setDrawingEnabled(bool drawing_enabled = true)
|
|
|
|
{ drawing_enabled_ = 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-04-29 18:17:15 +00:00
|
|
|
virtual int text(int x, int y, char_type c, Font 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.
|
|
|
|
*/
|
2006-10-30 18:56:22 +00:00
|
|
|
void rectText(int x, int baseline,
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const & str,
|
2007-04-29 18:17:15 +00:00
|
|
|
Font const & font,
|
2007-04-26 17:34:20 +00:00
|
|
|
Color_color back,
|
|
|
|
Color_color frame);
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw a string and enclose it inside a button frame
|
2006-12-04 04:31:18 +00:00
|
|
|
void buttonText(int x, int baseline, docstring const & s,
|
2007-04-29 18:17:15 +00:00
|
|
|
Font const & font, bool mouseHover);
|
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.
|
|
|
|
int preeditText(int x, int y,
|
2007-04-29 18:17:15 +00:00
|
|
|
char_type c, Font const & f, preedit_style style);
|
2007-04-01 09:14:08 +00:00
|
|
|
|
2000-02-18 22:22:42 +00:00
|
|
|
protected:
|
2002-06-12 15:01:32 +00:00
|
|
|
/// check the font, and if set, draw an underline
|
2007-04-29 18:17:15 +00:00
|
|
|
void underline(Font const & f,
|
2002-06-12 15:01:32 +00:00
|
|
|
int x, int y, int width);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2007-04-01 09:14:08 +00:00
|
|
|
/// check the font, and if set, draw an dashed underline
|
2007-04-29 18:17:15 +00:00
|
|
|
void dashedUnderline(Font const & f,
|
2007-04-01 09:14:08 +00:00
|
|
|
int x, int y, int width);
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a bevelled button border
|
2006-10-30 18:56:22 +00:00
|
|
|
void buttonFrame(int x, int y, int w, int h);
|
2006-10-30 10:09:59 +00:00
|
|
|
|
|
|
|
/// Indicate wether real screen drawing shall be done or not.
|
2006-10-30 11:55:13 +00:00
|
|
|
bool isDrawingEnabled() const { return drawing_enabled_; }
|
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
|