KGameCanvasItem Class Reference

#include <kgamecanvas.h>

Inheritance diagram for KGameCanvasItem:

Inheritance graph
[legend]
Collaboration diagram for KGameCanvasItem:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 KGameCanvasItem (KGameCanvasAbstract *canvas=NULL)
 Constructor, it allows you to specify the reference canvas or to create an orphan item that will be put into a canvas in a second moment.
virtual ~KGameCanvasItem ()
virtual void changed ()
 schedule an update if the item
bool visible () const
 Returns true if the item is visible.
void setVisible (bool v)
 Set the item as visible or hidden.
bool animated () const
 Returns true if the item is animated.
void setAnimated (bool a)
 Set the item as animated or not.
int opacity () const
 Returns the opacity of the item.
void setOpacity (int o)
 Set the item's opacity value (int the 0-255 range).
void hide ()
 Hides the item.
void show ()
 Shows the item.
void raise ()
 Restacks the item on the top of the canvas.
void lower ()
 Restacks the item on the bottom of the canvas.
void stackOver (KGameCanvasItem *ref)
 Restacks the item immediately over ref.
void stackUnder (KGameCanvasItem *ref)
 Restacks the item immediately under ref.
KGameCanvasAbstractcanvas () const
 Returns the canvas that is actually "owning" the item.
KGameCanvasWidgettopLevelCanvas () const
 Returns the toplevel canvas widget, or NULL.
void putInCanvas (KGameCanvasAbstract *canvas)
 Lets you specify the owning canvas.
QPoint pos () const
 Returns the position of the item.
QPoint absolutePosition () const
 
Returns:
Position of the item relative to the top level canvas.

void moveTo (const QPoint &newpos)
 Sets a new position.
void moveTo (int x, int y)
 Overload, same as above.
virtual void paint (QPainter *p)=0
 Override this function to draw the item with the painter.
virtual QRect rect () const =0
 Override this function to return the rect the item will be drawn into.
virtual bool layered () const
 Override this function to specify if the painting operations will paint over each other.
virtual void advance (int msecs)
 Override this function to handle animations, the default function does nothing.

Friends

class KGameCanvasAbstract
class KGameCanvasWidget
class KGameCanvasGroup
class KGameCanvasAdapter


Detailed Description

An abstract item.

A KGameCanvasItem is an abstract class to represent a generic item that can be put in a canvas.

Definition at line 109 of file kgamecanvas.h.


Constructor & Destructor Documentation

KGameCanvasItem::KGameCanvasItem ( KGameCanvasAbstract canvas = NULL  ) 

Constructor, it allows you to specify the reference canvas or to create an orphan item that will be put into a canvas in a second moment.

The item is always hidden after being created. Note that the restacking functions are quite intelligent and will only repaint if there is an actual need of doing it. So if you call raise on an item that is already (locally) on the top, no redraw will take place

Definition at line 234 of file kgamecanvas.cpp.

References KGameCanvasAbstract::m_items.

KGameCanvasItem::~KGameCanvasItem (  )  [virtual]

Definition at line 244 of file kgamecanvas.cpp.

References KGameCanvasAbstract::invalidate(), KGameCanvasAbstract::m_animated_items, and KGameCanvasAbstract::m_items.

Here is the call graph for this function:


Member Function Documentation

void KGameCanvasItem::changed (  )  [virtual]

schedule an update if the item

Definition at line 254 of file kgamecanvas.cpp.

References KGameCanvasAbstract::ensurePendingUpdate().

Referenced by moveTo(), putInCanvas(), KGameCanvasRectangle::setColor(), KGameCanvasText::setFont(), setOpacity(), KGameCanvasTiledPixmap::setOrigin(), KGameCanvasPicture::setPicture(), KGameCanvasTiledPixmap::setPixmap(), KGameCanvasPixmap::setPixmap(), KGameCanvasRectangle::setSize(), KGameCanvasTiledPixmap::setSize(), KGameCanvasText::setText(), and setVisible().

Here is the call graph for this function:

bool KGameCanvasItem::visible (  )  const [inline]

Returns true if the item is visible.

Definition at line 151 of file kgamecanvas.h.

Referenced by KGameCanvasRectangle::setColor(), KGameCanvasText::setFont(), KGameCanvasTiledPixmap::setOrigin(), KGameCanvasPicture::setPicture(), KGameCanvasTiledPixmap::setPixmap(), KGameCanvasPixmap::setPixmap(), KGameCanvasRectangle::setSize(), KGameCanvasTiledPixmap::setSize(), and KGameCanvasText::setText().

void KGameCanvasItem::setVisible ( bool  v  ) 

Set the item as visible or hidden.

Definition at line 361 of file kgamecanvas.cpp.

References changed(), and KGameCanvasAbstract::invalidate().

Here is the call graph for this function:

bool KGameCanvasItem::animated (  )  const [inline]

Returns true if the item is animated.

Definition at line 157 of file kgamecanvas.h.

void KGameCanvasItem::setAnimated ( bool  a  ) 

Set the item as animated or not.

Definition at line 376 of file kgamecanvas.cpp.

References KGameCanvasAbstract::ensureAnimating(), and KGameCanvasAbstract::m_animated_items.

Referenced by KGameCanvasGroup::advance().

Here is the call graph for this function:

int KGameCanvasItem::opacity (  )  const [inline]

Returns the opacity of the item.

Definition at line 163 of file kgamecanvas.h.

void KGameCanvasItem::setOpacity ( int  o  ) 

Set the item's opacity value (int the 0-255 range).

Definition at line 391 of file kgamecanvas.cpp.

References changed().

Here is the call graph for this function:

void KGameCanvasItem::hide (  )  [inline]

Hides the item.

Definition at line 169 of file kgamecanvas.h.

void KGameCanvasItem::show (  )  [inline]

Shows the item.

Definition at line 172 of file kgamecanvas.h.

void KGameCanvasItem::raise (  ) 

Restacks the item on the top of the canvas.

Definition at line 424 of file kgamecanvas.cpp.

References KGameCanvasAbstract::m_items.

void KGameCanvasItem::lower (  ) 

Restacks the item on the bottom of the canvas.

Definition at line 436 of file kgamecanvas.cpp.

References KGameCanvasAbstract::m_items.

void KGameCanvasItem::stackOver ( KGameCanvasItem ref  ) 

Restacks the item immediately over ref.

Definition at line 449 of file kgamecanvas.cpp.

References m_canvas, and KGameCanvasAbstract::m_items.

void KGameCanvasItem::stackUnder ( KGameCanvasItem ref  ) 

Restacks the item immediately under ref.

Definition at line 473 of file kgamecanvas.cpp.

References m_canvas, and KGameCanvasAbstract::m_items.

KGameCanvasAbstract* KGameCanvasItem::canvas (  )  const [inline]

Returns the canvas that is actually "owning" the item.

Definition at line 187 of file kgamecanvas.h.

Referenced by KGameCanvasRectangle::setColor(), KGameCanvasText::setFont(), KGameCanvasTiledPixmap::setOrigin(), KGameCanvasPicture::setPicture(), KGameCanvasTiledPixmap::setPixmap(), KGameCanvasPixmap::setPixmap(), KGameCanvasRectangle::setSize(), KGameCanvasTiledPixmap::setSize(), and KGameCanvasText::setText().

KGameCanvasWidget* KGameCanvasItem::topLevelCanvas (  )  const [inline]

Returns the toplevel canvas widget, or NULL.

Definition at line 190 of file kgamecanvas.h.

References KGameCanvasWidget::topLevelCanvas().

Here is the call graph for this function:

void KGameCanvasItem::putInCanvas ( KGameCanvasAbstract canvas  ) 

Lets you specify the owning canvas.

Call this function with canvas set to NULL to remove the item from the current canvas.

Definition at line 336 of file kgamecanvas.cpp.

References changed(), KGameCanvasAbstract::ensureAnimating(), KGameCanvasAbstract::invalidate(), KGameCanvasAbstract::m_animated_items, and KGameCanvasAbstract::m_items.

Here is the call graph for this function:

QPoint KGameCanvasItem::pos (  )  const [inline]

Returns the position of the item.

Definition at line 197 of file kgamecanvas.h.

Referenced by KGameCanvasTiledPixmap::origin(), KGameCanvasPicture::paint(), KGameCanvasText::paint(), KGameCanvasTiledPixmap::paint(), KGameCanvasPixmap::paint(), KGameCanvasPicture::rect(), KGameCanvasText::rect(), KGameCanvasRectangle::rect(), KGameCanvasTiledPixmap::rect(), KGameCanvasPixmap::rect(), KGameCanvasTiledPixmap::setMoveOrigin(), KGameCanvasTiledPixmap::setOrigin(), and KGameCanvasText::setPositioning().

QPoint KGameCanvasItem::absolutePosition (  )  const

Returns:
Position of the item relative to the top level canvas.

Definition at line 507 of file kgamecanvas.cpp.

References KGameCanvasAbstract::canvasPosition().

Referenced by KGameCanvasGroup::canvasPosition().

Here is the call graph for this function:

void KGameCanvasItem::moveTo ( const QPoint &  newpos  ) 

Sets a new position.

Note that an update will be posted to the parent canvas, and if you move an item twice in very little time, a region bigger than needed will be updated, causing a possible inefficiency

Definition at line 498 of file kgamecanvas.cpp.

References changed().

Here is the call graph for this function:

void KGameCanvasItem::moveTo ( int  x,
int  y 
) [inline]

Overload, same as above.

Definition at line 208 of file kgamecanvas.h.

virtual void KGameCanvasItem::paint ( QPainter *  p  )  [pure virtual]

Override this function to draw the item with the painter.

Implemented in KGameCanvasDummy, KGameCanvasGroup, KGameCanvasPicture, KGameCanvasPixmap, KGameCanvasTiledPixmap, KGameCanvasRectangle, and KGameCanvasText.

virtual QRect KGameCanvasItem::rect (  )  const [pure virtual]

Override this function to return the rect the item will be drawn into.

Implemented in KGameCanvasDummy, KGameCanvasGroup, KGameCanvasPicture, KGameCanvasPixmap, KGameCanvasTiledPixmap, KGameCanvasRectangle, and KGameCanvasText.

Referenced by KGameCanvasAbstract::itemAt(), KGameCanvasAbstract::itemsAt(), KGameCanvasGroup::rect(), and KGameCanvasAdapter::render().

bool KGameCanvasItem::layered (  )  const [virtual]

Override this function to specify if the painting operations will paint over each other.

If not, the item will be drawn more quickly when opacity is != 255, because it does not have to be painted onto a pixmap first. If you don't care about the item's opacity, don't care about this function as well.

Reimplemented in KGameCanvasPixmap, KGameCanvasTiledPixmap, KGameCanvasRectangle, and KGameCanvasText.

Definition at line 400 of file kgamecanvas.cpp.

void KGameCanvasItem::advance ( int  msecs  )  [virtual]

Override this function to handle animations, the default function does nothing.

The argument is the number of milliseconds from the creation of the canvas, so that you use it to handle the animation.

Reimplemented in KGameCanvasGroup.

Definition at line 402 of file kgamecanvas.cpp.

Referenced by KGameCanvasGroup::advance().


Friends And Related Function Documentation

friend class KGameCanvasAbstract [friend]

Definition at line 112 of file kgamecanvas.h.

friend class KGameCanvasWidget [friend]

Definition at line 113 of file kgamecanvas.h.

friend class KGameCanvasGroup [friend]

Definition at line 114 of file kgamecanvas.h.

friend class KGameCanvasAdapter [friend]

Definition at line 115 of file kgamecanvas.h.


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 08:03:14 2008 for Libkdegames by  doxygen 1.5.3