ubit
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
ubit::UGraph Class Reference

class for drawing on widgets. More...

#include <ugraph.hpp>

Inheritance diagram for ubit::UGraph:
ubit::UGraphAttributes

Classes

class  Glpaint
 for client GL Graphics. More...
 

Public Member Functions

 UGraph (UPaintEvent &)
 constructor for drawing in a UOn::paint callback method. More...
 
UBoxgetBox () const
 returns the widget where this UGraph can draw on. More...
 
UViewgetView () const
 returns the view of the widget where this UGraph can draw on. More...
 
UDispgetDisp () const
 returns the display that is related to this UGraph.
 
URect getClip () const
 returns the drawing zone relatively to the origin of getView().
 
void getClip (URect &) const
 returns the drawing zone relatively to the origin of getView().
 
void setClip (const URect &)
 changes the drawing zone relatively to the origin of getView().
 
void setPaintMode ()
 sets the drawing mode in Paint mode. More...
 
void setXORMode (const UColor &background_color)
 
bool isXORMode () const
 sets the drawing mode in XOR mode. More...
 
void setColor (const UColor &)
 changes the paint color (which can have an alpha component). More...
 
void setColor (const UColor &, float alpha)
 changes the paint color (forces this alpha component, in range [0,1]). More...
 
void setColor (const UColor &, unsigned int alpha)
 changes the paint color (forces this alpha component, in range [0,255]). More...
 
void setBackground (const UColor &)
 changes the background color.
 
void setFont (const UFont &)
 changes the current Font.
 
void setFont (const UFontDesc &)
 changes the current Font.
 
void getFontMetrics (const UFont &, UFontMetrics &) const
 return the corresponding Font Metrics.
 
void setWidth (float)
 changes the line width (when drawing lines, etc). More...
 
float getWidth () const
 returns the current line width. More...
 
void flush () const
 flushes all drawing requests.
 
void draw (const UShape &) const
 draws a shape.
 
void fill (const UShape &) const
 fills a shape.
 
void drawArc (double x, double y, double width, double height, double start_angle, double ext_angle) const
 draws a circular or elliptical arc. More...
 
void fillArc (double x, double y, double width, double height, double start_angle, double ext_angle) const
 fills an arc of a circle (or a complete circle); same arguments as drawArc().
 
void drawEllipse (double x, double y, double width, double height) const
 draws an ellipse or a circle that fits in this rectangle.
 
void fillEllipse (double x, double y, double width, double height) const
 fills an ellipse or a circle that fits in this rectangle.
 
void drawIma (const UIma &, double x, double y, double scale=1.) const
 draws this image with this scale.
 
void drawLine (double x1, double y1, double x2, double y2) const
 draws a line.
 
void drawLine (const UPoint &p1, const UPoint &p2) const
 draws a line.
 
void drawPolygon (const std::vector< UPoint > &points, int type=LINE_LOOP) const
 draws a polyline, polygon or a filled polygon depending on 'type'. More...
 
void drawPolygon (const float *points, int npoints, int type=LINE_LOOP) const
 draws a polyline, polygon or a filled polygon depending on 'type'. More...
 
void drawPolyline (const std::vector< UPoint > &points) const
 draws a polyline.
 
void fillPolygon (const std::vector< UPoint > &points) const
 fills a polygon (that must be convex).
 
void drawRect (double x, double y, double width, double height) const
 draws a rectangle.
 
void fillRect (double x, double y, double width, double height) const
 fills a rectangle.
 
void drawRoundRect (double x, double y, double width, double height, double arc_w, double arc_h) const
 draws a round-cornered rectangle. More...
 
void fillRoundRect (double x, double y, double width, double height, double arc_w, double arc_h) const
 fills a round-cornered rectangle; same arguments as fillRect(), drawRoundRect().
 
void drawString (const UStr &string, double x, double y) const
 draw a character string (the current Font is used: More...
 
void drawString (const char *string, int length, double x, double y) const
 draw a character string (the current Font is used: More...
 
void copyArea (double x, double y, double width, double height, double delta_x, double delta_y, bool paint_events_when_obscured) const
 
 UGraph (UView *)
 copies a rectangular area (X11 only, does not work with OpenGL). More...
 
UHardwinImplgetHardwin () const
 
void getHardwinClip (URect &) const
 [Impl] returns the drawing zone relatively to the current hard window.
 
void setHardwinClip (const URect &)
 [Impl] changes the drawing zone relatively to the current hard window.
 
void set3Dmode (bool state)
 
bool in3Dmode () const
 
void getWinOffset (float &x, float &y) const
 
void setWinOffset (float x, float y) const
 

Static Public Member Functions

static void setViewportOrtho (UHardwinImpl *)
 

Static Public Attributes

static const int LINE_STRIP = 0x0003
 
static const int LINE_LOOP = 0x0002
 
static const int FILLED = 0x0009
 

Protected Attributes

UDispdisp
 
UViewboxview
 
UHardwinImplhardwin
 
UHardFontfont
 
URenderContextrc
 
bool is_client
 

Friends

class UView
 
class U3DcanvasView
 
class UPaintEvent
 
class UFontMetrics
 
class URenderContext
 
class UGlcontext
 
class UX11context
 

Additional Inherited Members

- Public Types inherited from ubit::UGraphAttributes
enum  { OPAQUE, UNIFORM_BLEND, PSEUDO_BLEND, TRUE_BLEND }
 
- Public Attributes inherited from ubit::UGraphAttributes
short font_styles
 
float width
 
unsigned long color
 
unsigned long bgcolor
 
URgba color_rgba
 
URgba bgcolor_rgba
 
enum ubit::UGraphAttributes:: { ... }  blend_mode
 
bool in_xor_mode
 
bool in_3d_mode
 

Detailed Description

class for drawing on widgets.

Widgets inherit from UBox. A box can manage one or several views. UGraph makes it possible to draw graphic primitives on these views.

See also
also: UBox, UView.

Constructor & Destructor Documentation

§ UGraph() [1/2]

ubit::UGraph::UGraph ( UPaintEvent )

constructor for drawing in a UOn::paint callback method.

Example:

  void MyObj::paintCB(UPaintEvent& e) {
       UGraph g(e);
       g.setColor(UColor::red);  // predefined red
       g.drawRect(10, 10, 50, 50);
       g.setColor(UColor(0, 0, 255, 128));  // semi-transparent blue
       g.drawLine(10, 10, 10+50, 10+50);
   }
   int main() {
       MyObj* obj = new MyObj();
       UBox* box = new UBox();
       box->add(UOn::paint / ucall(obj, &MyObj::paintCB));
       .....
   }

The last line adds a paint callback to the box. ucall(...) is a callback object that will fire the paintCB() instance method of MyObj each time the box is repainted. paintCB() could also have arguments or be a static function:

See also
UCall for more details.

The paintCB() method has a UPaintEvent& parameter that can be passed to the UGraph constructor. This will initialize the UGraph object with appropriate attributes and the redraw clip corresponding to this paint event.

Note that UGraph objects should always be created in this way, so that they are implicitely destroyed when the function returns. UGraph objects may not be copied nor stored for future use.

font, colors, and other attributes are undefined when the UGraph object is created, they must be specified by using the appropriate functions (such as UGraph::setFont(), setColor(), etc.

Ubit objects that derive from UBox can have multiple UView(s). The callback function is then fired once for each view (and the UPaintEvent parameter is set accordingly for each view)

Note that this constr. raises an exception if the corresponding UView is null

§ UGraph() [2/2]

ubit::UGraph::UGraph ( UView )

copies a rectangular area (X11 only, does not work with OpenGL).

copies a rectangular area of size (width,height) at location (x,y) to a location shifted by delta_x, delta_y
Notes:

  • does nothing if the toolkit is using OpenGL as its graphics lib
  • CopyArea can't copy obscured parts of the component but will generate refresh events for repainting the missing parts if the last argument is true constructor for drawing in a view. see UGraph(UPaintEvent&) for details. This constr. raises an exception if the UView is null

Member Function Documentation

§ drawArc()

void UGraph::drawArc ( double  x,
double  y,
double  width,
double  height,
double  start_angle,
double  ext_angle 
) const

draws a circular or elliptical arc.

'x,y,width,height' are the top/left position and size of the enclosing rectangle 'start_ang' is the beginning angle and 'ext_ang' the extent of the arc relative to 'start_ang'. Angles are in degrees.

§ drawPolygon() [1/2]

void ubit::UGraph::drawPolygon ( const std::vector< UPoint > &  points,
int  type = LINE_LOOP 
) const

draws a polyline, polygon or a filled polygon depending on 'type'.

type is one of LINE_STRIP (polyline), LINE_LOOP (polygon), FILLED (filled polygon).

§ drawPolygon() [2/2]

void ubit::UGraph::drawPolygon ( const float *  points,
int  npoints,
int  type = LINE_LOOP 
) const

draws a polyline, polygon or a filled polygon depending on 'type'.

'points' format is x0, y0, x1, y1, x2, y2... it must contains 2*npoints values type is one of LINE_STRIP (polyline), LINE_LOOP (polygon), FILLED (filled polygon).

§ drawRoundRect()

void UGraph::drawRoundRect ( double  x,
double  y,
double  width,
double  height,
double  arc_w,
double  arc_h 
) const

draws a round-cornered rectangle.

arc_w, arc_h are the horiz/vert diameters of the arc at the 4 corners

§ drawString() [1/2]

void ubit::UGraph::drawString ( const UStr string,
double  x,
double  y 
) const

draw a character string (the current Font is used:

See also
setFont()).

§ drawString() [2/2]

void ubit::UGraph::drawString ( const char *  string,
int  length,
double  x,
double  y 
) const

draw a character string (the current Font is used:

See also
setFont()).

§ getBox()

UBox * UGraph::getBox ( ) const

returns the widget where this UGraph can draw on.

this function is a shortcut for: getView()->getBox().

See also
: getView().

§ getView()

UView* ubit::UGraph::getView ( ) const
inline

returns the view of the widget where this UGraph can draw on.

widgets inherit from UBox. A box can manage one or several views. view->getBox() returns the box that owns this view (

See also
UView::getBox()).

§ getWidth()

float UGraph::getWidth ( ) const

returns the current line width.

See also
: setWidth()

§ isXORMode()

bool ubit::UGraph::isXORMode ( ) const
inline

sets the drawing mode in XOR mode.

In "XOR mode", drawing primitives alternates the paint and the background colors, which must be set by calling setColor() and setBackground(). NOTES:

  • !!! the current OpenGL implementation does NOT support XOR mode !!!
  • alpha channel cannot be used in in XOR mode
    See also
    : setPaintMode(), setColor(), setBackground().returns the drawing mode. see setXORMode()

§ setColor() [1/3]

void ubit::UGraph::setColor ( const UColor )

changes the paint color (which can have an alpha component).

The paint color is used by all drawing primitives. Example:

  void paintCB(UPaintEvent& e) {
      UGraph g(e);
      g.setColor(UColor::red);  // predefined red
      g.drawRect(10, 10, 50, 50);
      g.setColor(UColor(0, 0, 255, 128));  // semi-transparent blue
      g.drawLine(10, 10, 10+50, 10+50);
  }
See also
also: setPaintMode(), setXORMode(), setBackground().

§ setColor() [2/3]

void ubit::UGraph::setColor ( const UColor ,
float  alpha 
)

changes the paint color (forces this alpha component, in range [0,1]).

See also
setColor(const UColor&).

§ setColor() [3/3]

void ubit::UGraph::setColor ( const UColor ,
unsigned int  alpha 
)

changes the paint color (forces this alpha component, in range [0,255]).

See also
setColor(const UColor&).

§ setPaintMode()

void UGraph::setPaintMode ( )

sets the drawing mode in Paint mode.

"Paint mode" is the default "normal" drawing mode. In Paint Mode, drawing primitives overwrites pixels with the paint color, which must set by calling setColor() and can have an (optional) alpha channel.

See also
: setXORMode(), setColor(), setBackground().

§ setWidth()

void UGraph::setWidth ( float  w)

changes the line width (when drawing lines, etc).

in X11 mode the default value is 0, this will draw 1 pixel width lines in an optimized way


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