2000-02-10 17:53:36 +00:00
|
|
|
// -*- C++ -*-
|
2002-06-12 15:01:32 +00:00
|
|
|
/**
|
|
|
|
* \file Painter.h
|
|
|
|
* Copyright 1998-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-06-12 15:01:32 +00:00
|
|
|
* \author unknown
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
#include "LColor.h"
|
|
|
|
|
|
|
|
class LyXFont;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
namespace grfx {
|
2002-06-28 11:22:56 +00:00
|
|
|
class Image;
|
2002-02-27 09:59:52 +00:00
|
|
|
}
|
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.
|
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:
|
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
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
virtual ~Painter() {}
|
|
|
|
|
|
|
|
/// begin painting
|
|
|
|
virtual void start() {}
|
|
|
|
|
|
|
|
/// end painting
|
|
|
|
virtual void end() {}
|
|
|
|
|
|
|
|
/// return the width of the work area in pixels
|
|
|
|
virtual int paperWidth() const = 0;
|
|
|
|
/// return the height of the work area in pixels
|
|
|
|
virtual int paperHeight() const = 0;
|
|
|
|
|
|
|
|
/// draw a line from point to point
|
|
|
|
virtual Painter & line(
|
|
|
|
int x1, int y1,
|
|
|
|
int x2, int y2,
|
2000-02-10 17:53:36 +00:00
|
|
|
LColor::color = LColor::foreground,
|
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
|
|
|
|
*/
|
|
|
|
virtual Painter & lines(
|
|
|
|
int const * xp,
|
|
|
|
int const * yp,
|
2000-02-10 17:53:36 +00:00
|
|
|
int np,
|
|
|
|
LColor::color = LColor::foreground,
|
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
|
|
|
|
virtual Painter & rectangle(
|
|
|
|
int x, int y,
|
|
|
|
int w, int h,
|
2000-02-10 17:53:36 +00:00
|
|
|
LColor::color = LColor::foreground,
|
2002-06-12 15:01:32 +00:00
|
|
|
line_style = line_solid,
|
|
|
|
line_width = line_thin) = 0;
|
|
|
|
|
|
|
|
/// draw a filled rectangle
|
|
|
|
virtual Painter & 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,
|
|
|
|
LColor::color) = 0;
|
|
|
|
|
|
|
|
/// draw a filled (irregular) polygon
|
|
|
|
virtual Painter & fillPolygon(
|
|
|
|
int const * xp,
|
|
|
|
int const * yp,
|
|
|
|
int np,
|
|
|
|
LColor::color = LColor::foreground) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw an arc
|
|
|
|
virtual Painter & 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,
|
|
|
|
LColor::color = LColor::foreground) = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
/// draw a pixel
|
|
|
|
virtual Painter & point(
|
2000-02-10 17:53:36 +00:00
|
|
|
int x, int y,
|
|
|
|
LColor::color = LColor::foreground) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw a filled rectangle with the shape of a 3D button
|
|
|
|
virtual Painter & button(int x, int y,
|
|
|
|
int w, int h);
|
|
|
|
|
|
|
|
/// draw an image from the image cache
|
|
|
|
virtual Painter & image(int x, int y,
|
|
|
|
int w, int h,
|
2002-06-28 11:22:56 +00:00
|
|
|
grfx::Image const & image) = 0;
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw a string at position x, y (y is the baseline)
|
|
|
|
virtual Painter & text(int x, int y,
|
|
|
|
string const & str, LyXFont const & f) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a string at position x, y (y is the baseline)
|
|
|
|
* This is just for fast drawing
|
|
|
|
*/
|
|
|
|
virtual Painter & text(int x, int y,
|
|
|
|
char const * str, size_t l,
|
|
|
|
LyXFont const & f) = 0;
|
|
|
|
|
|
|
|
/// draw a char at position x, y (y is the baseline)
|
|
|
|
virtual Painter & text(int x, int y,
|
|
|
|
char c, LyXFont const & f) = 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.
|
|
|
|
*/
|
2002-06-12 15:01:32 +00:00
|
|
|
Painter & rectText(int x, int baseline,
|
|
|
|
string const & string,
|
|
|
|
LyXFont const & font,
|
2002-07-09 16:23:20 +00:00
|
|
|
LColor::color back = LColor::none,
|
|
|
|
LColor::color frame = LColor::none);
|
2002-06-12 15:01:32 +00:00
|
|
|
|
|
|
|
/// draw a string and enclose it inside a button frame
|
|
|
|
Painter & buttonText(int x,
|
|
|
|
int baseline, string const & s,
|
|
|
|
LyXFont const & font);
|
2002-03-21 17:27: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
|
|
|
|
void underline(LyXFont const & f,
|
|
|
|
int x, int y, int width);
|
|
|
|
|
|
|
|
/// draw a bevelled button border
|
|
|
|
Painter & buttonFrame(int x, int y, int w, int h);
|
2000-02-10 17:53:36 +00:00
|
|
|
};
|
|
|
|
|
2002-06-12 15:01:32 +00:00
|
|
|
#endif // PAINTER_H
|