guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
Public Member Functions | List of all members
guit::GGraphics Class Reference

Class for drawing graphics in gagdgets. More...

Inherited by guit::GRenderGraphics.

Public Member Functions

GWindowwindow ()
 window where the graphics is painted.
 
GRect const & frame () const
 frame of the drawing area in the window. More...
 
void translate (float x, float y)
 translates the frame.
 
void setWinClip (GRect const &)
 sets the clipping area in the window. More...
 
void setThickness (float)
 changes outline thickness. More...
 
float wx () const
 position of the drawing area in window coordinates. More...
 
float glx () const
 position of the drawing area in the window in GL coordinates origin = bottom-left corner of the window.
 
float width () const
 size of the drawing area.
 
GDim drawString (float x, float y, GString const &str)
 draws a string. More...
 
void drawImage (GRect const &, GIcon &)
 draws an image or an icon.
 
void drawArc (float x, float y, float w, float h, float start, float extent, bool pie=false)
 Draws an arc. More...
 

Static Public Member Functions

static bool readImage (GIcon &)
 reads an image or an icon.
 
void drawTexture (float x, float y, float w, float h, GTexture texture, GRgba const *={})
 GL textures.
 

Detailed Description

Class for drawing graphics in gagdgets.

Drawing must be performed in a callback function called on a GTrigger::paint trigger. This callback function must create a Graphics object in the stack that won't be reused elsewhere:

Canvas::Canvas() {
*this
<< Background.white
<< on::paint / [this](auto& e) {paint(e);}
<< on::resize / [this](auto& e) {resized(e);}
<< on::mousedown / [this](auto& e) {pressed(e);}
<< on::mouseup / [this](auto& e) {released(e);}
<< on::mousedrag / [this](auto& e) {dragged(e);}
<< on::mousemove / [this](auto& e) {moved(e);};
}
void Canvas::paint(Event& e) {
Graphics g(e);
for (auto& it : polylines) {
g.setColor(it->color);
g.setBgColor(it->bgcolor);
switch (it->mode) {
case PolylineMode:
g.drawPolyline(it->points);
break;
case PolygonMode:
g.drawPolygon(it->points);
break;
}
}
}

All drawXxxx() methods draw relatively to frame(), which is the frame of the gadget that received the paint event. The frame can be translated using translate().

OpenGL can be used for more advanced functionalities. Note that:

Member Function Documentation

float guit::GGraphics::wx ( ) const
inline

position of the drawing area in window coordinates.

origin = top-left corner of the window.

GRect const& guit::GGraphics::frame ( ) const
inline

frame of the drawing area in the window.

origin = top-left corner of the window.

void guit::GGraphics::setWinClip ( GRect const &  clip)

sets the clipping area in the window.

the clip is in window coordinates.

void guit::GGraphics::setThickness ( float  thickness)

changes outline thickness.

note: actual effect depends on GL implmenetaion

GDim guit::GGraphics::drawString ( float  x,
float  y,
GString const &  str 
)

draws a string.

y = lower point, should be baseline !!

x, y = is the leftmost lower point. Returns the size of the rectangle enclosing the text. does not take into account multiline text

void guit::GGraphics::drawArc ( float  x,
float  y,
float  w,
float  h,
float  start,
float  extent,
bool  pie = false 
)

Draws an arc.

  • rect is the enclosing rectangle, the center of the rectangle will be the center of the ellipse
  • start if the starting angle in degrees (0 corresponds to 3 o'clock position),
  • extent is the angular distance (in degrees) from start to the ending angle. A counter-clockwise rotation is performed if extent is positive, a clockwise rotation otherwise.
  • if pie is false drawArc() just draws an arc, otherwise it draws a "pie part", so as drawPie()

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