DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Member Functions | Protected Attributes | Friends
GUI::Drawable Class Reference

A drawable represents a rectangular off-screen drawing area. More...

#include <gui_tk.h>

Inheritance diagram for GUI::Drawable:
GUI::SDL_Drawable

List of all members.

Public Member Functions

 Drawable (int w, int h, RGB clear=Color::Transparent)
 Create an empty drawable object with given dimensions.
 Drawable (Drawable &src, RGB clear=0)
 Deep-copying copy constructor.
 Drawable (Drawable &src, int x, int y, int w, int h)
 Shallow-copying copy constructor with clip & translate. See setClipTranslate(int x, int y, int w, int h).
virtual ~Drawable ()
 Destructor.
void clear (RGB clear=Color::Transparent)
 Clears the surface.
void setColor (RGB c)
 Change current drawing color.
RGB getColor ()
 Return the currently selected drawing color.
void setFont (const Font *f)
 Change current drawing font.
const FontgetFont ()
 Return the currently selected drawing font.
void setLineWidth (int w)
 Change current line width.
int getLineWidth ()
 Return the current line width.
void gotoXY (int x, int y)
 Move the current position to the given coordinates.
int getX ()
 Return current position X.
int getY ()
 Return current position Y.
int getClipX ()
 Return clip width.
int getClipY ()
 Return clip height.
int getClipWidth ()
 Return clip width.
int getClipHeight ()
 Return clip height.
void drawPixel ()
 Paint a single pixel at the current position.
void drawPixel (int x, int y)
 Paint a single pixel at the given coordinates.
RGB getPixel ()
 Return the pixel color at the current position.
RGB getPixel (int x, int y)
 Return the pixel color at the given coordinates.
void drawLine (int x2, int y2)
 Draw a straight line from the current position to the given coordinates.
void drawLine (int x1, int y1, int x2, int y2)
 Draw a straight line from (x1,y1) to (x2,y2).
void drawCircle (int d)
 Draw a circle centered at the current position with diameter d.
void drawCircle (int x, int y, int d)
 Draw a circle centered at the given coordinates with diameter d.
void drawRect (int w, int h)
 Draw a rectangle with top left at the current position and size w, h.
void drawRect (int x, int y, int w, int h)
 Draw a rectangle with top left at the given coordinates and size w, h.
void fill ()
 Flood-fill an area at the current position.
void fill (int x, int y)
 Flood-fill an area at a given position.
void fillCircle (int d)
 Draw a filled circle centered at the current position with diameter d.
void fillCircle (int x, int y, int d)
 Draw a filled circle centered at the given coordinates with diameter d.
void fillRect (int w, int h)
 Draw a filled rectangle with top left at the current position and size w, h.
void fillRect (int x, int y, int w, int h)
 Draw a filled rectangle with top left at the given coordinates and size w, h.
void drawText (const String &text, bool interpret=true, Size start=0, Size len=(Size)-1)
 Draw a text string.
template<typename STR >
void drawText (int x, int y, const STR text, bool interpret, Size start, Size len=(Size)-1)
 Draw a text string at a fixed position.
void drawText (const Char c, bool interpret=false)
 Draw a single character.
void drawText (int x, int y, const Char c, bool interpret=false)
 Draw a single character at a fixed position.
void drawDrawable (Drawable &d, unsigned char alpha=1)
 Copy the contents of another Drawable to this one.
void drawDrawable (int x, int y, Drawable &d, unsigned char alpha=1)
 Copy the contents of another Drawable to this one at a given position.

Protected Attributes

RGB *const buffer
 The actual pixel buffer.
const int width
 Total width of buffer.
const int height
 Total height of buffer.
const bool owner
 true if buffer must be freed by this instance.
RGB color
 Current color.
const Fontfont
 Current font.
int lineWidth
 Current line width.
const int tx
 X translation.
const int ty
 Y translation.
const int cx
 clip x.
const int cy
 clip y.
const int cw
 clip width.
const int ch
 clip height.
int x
 Current position x coordinate.
int y
 Current position y coordinate.

Friends

Ticks Screen::update (void *, Ticks)

Detailed Description

A drawable represents a rectangular off-screen drawing area.

It is an off-screen buffer which can be copied to other drawables or to a Screen's framebuffer. The drawable's origin is at the top left. All operations are silently clipped to the available area. The alpha channel is honoured while copying one drawable to another, but not during other drawing operations.

Drawables have a current font, color and (x,y) position. Drawing takes place at the given point using the given font and color. The current position is then moved to the final point of the drawing primitive unless otherwise noted. Pixel width of all lines is selectable, but be aware that visual appearance of lines with width > 1 is not as sophisticated as in well-known toolkits like Java or Qt.

Some drawing primitives are overloaded to take full coordinates. These ignore the current position, but update it just like their regular brethren.

Definition at line 915 of file gui_tk.h.


Constructor & Destructor Documentation

GUI::Drawable::Drawable ( int  w,
int  h,
RGB  clear = Color::Transparent 
)

Create an empty drawable object with given dimensions.

Optionally, the area is cleared with a given color (default: fully transparent).

Definition at line 194 of file gui_tk.cpp.

References clear().

GUI::Drawable::Drawable ( Drawable src,
RGB  clear = 0 
)

Deep-copying copy constructor.

It honours clip and translate so that the resulting drawable, if drawn to the source drawable at (0,0), yields the same result as drawing directly to the source surface. If fill is not explicitly set, will copy the original surface's contents

Definition at line 209 of file gui_tk.cpp.

References buffer, ch, clear(), cw, tx, ty, and width.


Member Function Documentation

void GUI::Drawable::drawCircle ( int  d)

Draw a circle centered at the current position with diameter d.

The current position is not changed.

Definition at line 291 of file gui_tk.cpp.

References drawPixel(), gotoXY(), lineWidth, x, and y.

void GUI::Drawable::drawCircle ( int  x,
int  y,
int  d 
) [inline]

Draw a circle centered at the given coordinates with diameter d.

The current position is set to the center.

Definition at line 1028 of file gui_tk.h.

References drawCircle(), and gotoXY().

Referenced by drawCircle().

void GUI::Drawable::drawDrawable ( Drawable d,
unsigned char  alpha = 1 
)

Copy the contents of another Drawable to this one.

The top left corner of the source Drawable is put at the current position. The alpha channel is fully honoured. Additionally, an extra alpha value may be given which is multiplied with the source alpha channel. The current position remains unchanged.

Definition at line 378 of file gui_tk.cpp.

References GUI::Color::AlphaShift, GUI::Color::BlueMask, buffer, ch, cw, cx, cy, GUI::Color::GreenMask, GUI::Color::MagentaMask, GUI::Color::RedMask, GUI::Color::Transparent, tx, ty, width, x, and y.

void GUI::Drawable::drawDrawable ( int  x,
int  y,
Drawable d,
unsigned char  alpha = 1 
) [inline]

Copy the contents of another Drawable to this one at a given position.

see drawDrawable(Drawable &d, unsigned char alpha). The current position is moved to the given coordinates.

Definition at line 1088 of file gui_tk.h.

References drawDrawable(), and gotoXY().

Referenced by drawDrawable().

void GUI::Drawable::drawRect ( int  w,
int  h 
)

Draw a rectangle with top left at the current position and size w, h.

The current position is not changed.

Definition at line 313 of file gui_tk.cpp.

References drawLine(), gotoXY(), lineWidth, x, and y.

void GUI::Drawable::drawRect ( int  x,
int  y,
int  w,
int  h 
) [inline]

Draw a rectangle with top left at the given coordinates and size w, h.

The current position is set to the top left corner.

Definition at line 1035 of file gui_tk.h.

References drawRect(), and gotoXY().

Referenced by drawRect().

void GUI::Drawable::drawText ( const String text,
bool  interpret = true,
Size  start = 0,
Size  len = (Size)-1 
)

Draw a text string.

Current position is the leftmost pixel on the baseline of the character. The current position is moved to the next character. Background is not cleared. If interpret is true, some ASCII control characters like backspace, line-feed, tab and ANSI colors are interpreted, and text is word-wrapped at the window borders. You can optionally pass start and length of a substring to print

Definition at line 65 of file gui_tk.cpp.

References GUI::Color::Black, GUI::Color::Blue, color, cw, GUI::Color::Cyan, GUI::Font::drawString(), font, GUI::Font::getHeight(), GUI::Font::getWidth(), gotoXY(), GUI::Color::Green, GUI::Color::Magenta, GUI::Color::Red, setColor(), GUI::Font::toSpecial(), GUI::Color::White, width, x, y, and GUI::Color::Yellow.

Referenced by GUI::Input::checkOffset(), GUI::Input::findPos(), GUI::Label::paint(), GUI::Input::paint(), GUI::ToplevelWindow::paint(), GUI::Menu::paint(), GUI::Menubar::paint(), GUI::Frame::paint(), and GUI::Label::resize().

template<typename STR >
void GUI::Drawable::drawText ( int  x,
int  y,
const STR  text,
bool  interpret,
Size  start,
Size  len = (Size)-1 
) [inline]

Draw a text string at a fixed position.

see drawText(const String& text, bool interpret, Size start, Size len)

Definition at line 1070 of file gui_tk.h.

References drawText(), and gotoXY().

Referenced by drawText().

void GUI::Drawable::drawText ( const Char  c,
bool  interpret = false 
)

Draw a single character.

see drawText(const STR text, bool interpret), except wrapping is performed on this character only

Definition at line 404 of file gui_tk.cpp.

References cw, GUI::Font::drawChar(), font, GUI::Font::getHeight(), GUI::Font::getWidth(), gotoXY(), GUI::Font::toSpecial(), x, and y.

void GUI::Drawable::drawText ( int  x,
int  y,
const Char  c,
bool  interpret = false 
) [inline]

Draw a single character at a fixed position.

see drawText(const Char c, bool interpret).

Definition at line 1077 of file gui_tk.h.

References drawText(), and gotoXY().

Referenced by drawText().

Flood-fill an area at the current position.

A continuous area with the same RGB value as the selected pixel is changed to the current color. The current position is not changed.

Definition at line 325 of file gui_tk.cpp.

References color, cw, drawPixel(), getPixel(), x, and y.

void GUI::Drawable::fill ( int  x,
int  y 
) [inline]

Flood-fill an area at a given position.

see fill(), but moves current position to the given coordinates

Definition at line 1043 of file gui_tk.h.

References fill(), and gotoXY().

Referenced by fill().

void GUI::Drawable::fillCircle ( int  d)

Draw a filled circle centered at the current position with diameter d.

The current position is not changed.

Definition at line 346 of file gui_tk.cpp.

References drawPixel(), gotoXY(), x, and y.

void GUI::Drawable::fillCircle ( int  x,
int  y,
int  d 
) [inline]

Draw a filled circle centered at the given coordinates with diameter d.

The current position is set to the center.

Definition at line 1050 of file gui_tk.h.

References fillCircle(), and gotoXY().

Referenced by fillCircle().

void GUI::Drawable::fillRect ( int  w,
int  h 
)

Draw a filled rectangle with top left at the current position and size w, h.

The current position is not changed.

Definition at line 367 of file gui_tk.cpp.

References drawPixel(), gotoXY(), x, and y.

Referenced by GUI::Input::paint(), GUI::ToplevelWindow::paint(), GUI::Menu::paint(), GUI::Button::paint(), GUI::Menubar::paint(), GUI::Checkbox::paint(), and GUI::Radiobox::paint().

void GUI::Drawable::fillRect ( int  x,
int  y,
int  w,
int  h 
) [inline]

Draw a filled rectangle with top left at the given coordinates and size w, h.

The current position is set to the top left corner.

Definition at line 1057 of file gui_tk.h.

References fillRect(), and gotoXY().

Referenced by fillRect().

void GUI::Drawable::setColor ( RGB  c) [inline]

Change current drawing color.

The alpha part is honoured in all drawing primitives like this: All drawing operations in this window will unconditionally overwrite earlier content of this window. Only when combining this window with it's parent, the alpha channel is fully honoured.

Definition at line 978 of file gui_tk.h.

References color.

Referenced by drawText(), GUI::Label::paint(), GUI::Input::paint(), GUI::ToplevelWindow::paint(), GUI::Menu::paint(), GUI::Button::paint(), GUI::Menubar::paint(), GUI::Checkbox::paint(), GUI::Radiobox::paint(), and GUI::Frame::paint().


The documentation for this class was generated from the following files: