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.
// 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; }
shape.h