[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Shape(3X) manual page Table of Contents

Name

Shape - shape of an interactor’s canvas

Synopsis

#include <ivplus/shape.h>

Description

Shape specifies the desired characteristics of an interactor’s canvas. An interactor should set the fields of its shape when it is reconfigured and should call the Change() operation on its parent if any of these fields change.

The dimensions of a shape are defined by a natural size, a stretch amount, and a shrink amount. The width and height fields indicate the desired sizes. The hstretch, vstretch, hshrink, and vshrink fields define how flexible these desired sizes are.

For example, an interactor may have a natural size of 100, but can adequately handle any size between 50 and 200. The stretchability for this case would be 100 and the shrinkability 50.

The constants hfil and vfil are provided to indicate infinite stretching or shrinking. They are represented as very large numbers and manipulated exactly the same as other stretch and shrink parameters.

The aspect field specifies the desired aspect ratio. A value of zero means any aspect is acceptable.

The hunits and vunits fields indicate that the canvas dimensions should be multiples of some values.

Class Hierarchy

Shape

Constructors

Shape()

Constructs a new shape with undefined natural size and infinite stretchability and shrinkability in both directions.

Public Data

static const int hfil = 1000000;

static const int vfil = 1000000;

Indicate infinite stretch and shrink in pixels.

int width, height;

Desired natural size in pixels.

int hstretch, vstretch;

Stretchability in pixels.

int hshrink, vshrink;

Shrinkability in pixels.

int aspect

Desired aspect ratio (height to width). A value of zero means don’t care.

int hunits, vunits

Can be used to specify multiples for shape dimensions.

Public Operations

boolean Defined()

Tests if the shape’s natural size is defined.

void Rect(int width, int height)

This is a short-hand operation for setting the dimensions of shape. This sets shape to a rectangle of given width and height and forces Rigid().

void Rigid(int hshrink = 0, int hstretch = 0, int vshrink = 0, int vstretch = 0)

This operation is used to set shrink and stretch capabilities for both horizontal and vertical movement. A call to Rigid() with no arguments creates a fixed shape.

void SetUndefined()

Resets the shape’s natural size to be undefined.

void Square(int side)

This is a short-hand operation for setting the dimensions of the shape. Square sets both dimensions to side and sets the aspect ratio to one. It then calls Rigid().

boolean Undefined()

Tests if the shape’s natural size is undefined.

Protected Operations

None.

X Resources

None.

Examples


//                          Shape Example
#include <ivplus/box.h>
#include <ivplus/message.h>
#include <ivplus/frame.h>
#include <ivplus/painter.h>
#include <ivplus/shape.h>
#include <ivplus/world.h>
// Create a derived class from Message to make use of Shape in Reconfig().
class MyMessage : public Message {
public:
   MyMessage(const char* text)
      : Message(text) 
   { };
private:
   void Reconfig();
   void Redraw(IntCoord, IntCoord, IntCoord, IntCoord);
};
void MyMessage::Reconfig()
{
   // The following call will set the shape of MyMessage depending on the
   // text and font used by the message.
   Message::Reconfig();
   // Shape is defined in Interactor class.  We are modifying it
   // to increase the width and height by 100.
   shape->width += 100;
   shape->height += 100;
   // Set the horizontal shrinkability to 20.
   shape->hshrink = 20;
   // Set the horizontal stretchability to a very large value: hfil.
   shape->hstretch = hfil;
   // Set the vertical shrinkability to 20.
   shape->vshrink = 20;
   // Set the vertical stretchability to 100.
   shape->vstretch = 100;
   // The same can be achieved by using the following function:
   // shape->Rigid(20, hfil, 20, 100);
};
void MyMessage::Redraw(IntCoord l, IntCoord b, IntCoord r, IntCoord t)
{
   // This will draw the text.
   Message::Redraw(l, b, r, t);
   // Draw a rectangle around the message.
   output->Rect(canvas, 10, 10, xmax-10, ymax-10);
};
int main(int argc, char **argv)
{
   // Create the world to get the connection with the display.
   World* world = new World("MyApp", argc, argv);
   // Create a two line message.
   MyMessage* msg = new MyMessage("Shape Example\n Message with a border");
   // Map the window.
   world->InsertApplication(new Frame(msg, 1, BevelOut));
   
   // Enter the event loop.
   world->Run();
   return 0;
}

Files


shape.h

See Also

Interactor(3X) , Scene(3X) .


Table of Contents