WideStudio Programming Guide

| WideStudio Programming Guide | WideStudio Index Table of contents

> ## The drawing area

> ### How to draw pictures on the drawing area

> It is possible to draw pictures freely by drawing area. It has the methods to draw various pictures, which can be used on the event procedure with exposure event WSEV_EXPOSE. The following program shows a basic method to draw pictures by drawing area.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCvdrawingArea.h>
>     #include <WSCvslider.h>

>     void drawep(WSCbase* object){
>       //drawing_a is same as newvdra_000...
>       //You can get it extern WSCvdrawingArea* newvdra000; also.
>       WSCvdrawingArea* drawing_a =
>              (WSCvdrawingArea*)object->cast("WSCvdrawingArea"); //(A)
>       if (drawing_a == NULL){ //(B)
>         return;
>       }

>       drawing_a->setForeColor("#ff0000"); //(C)
>       drawing_a->drawLine(0,0,100,100);  //(D)

>     }
>     static WSCfunctionRegister  op("drawep",(void*)drawep);

> At first access to the method of the drawing area, include the header WSCvdrawingArea.h of the WSCvdrawingArea class and get the native class pointer of the WSCvdrawingArea class at (A). It is impossible to access the native method of WSCvdrawingArea class with the pointer of WSCbase class. If the pointer drawing_a is NULL at (B), the instance is not WSCvdrawingArea, so exit the event procedure. Next, it is the sample to set the color to the drawing area which is used to the other methods for drawing pictures (C). At (D),draws the line from (0,0) to (100,100).
> The drawing area class has the following methods.
> - The rectangle and the filled rectangle
> - The circle,filled circle,arc,chord,oval.
> - The polygon,filled polygon.
> - The string.
> - The image of JPG,BMP.

> ### How to draw images(JPG,BMP) on the drawing area

> It is possible to draw images of JPG,BMP by the method: drawImage(), drawStretchedImage(). The method: drawImage() draws the image as is, and the method: drawStretchedImage() draws the image as specified size.

>     #include <WScom.h>
>     #include <WSCfunctionList.h>
>     #include <WSCbase.h>
>     //----------------------------------------------------------
>     //Function for the event procedure
>     //----------------------------------------------------------
>     #include <WSCvdrawingArea.h>
>     #include <WSCvslider.h>

>     void drawep(WSCbase* object){
>       //drawing_a is same as newvdra_000...
>       //You can get it extern WSCvdrawingArea* newvdra000; also.
>       WSCvdrawingArea* drawing_a =
>              (WSCvdrawingArea*)object->cast("WSCvdrawingArea");
>       if (drawing_a == NULL){
>         return;
>       }
>       WSCushort w = drawing_a->getProperty(WSNwidth);
>       WSCushort h = drawing_a->getProperty(WSNheight);
>       drawing_a->drawStretchedImage(0,0,w,h,"001.jpg");  //(A)

>     }
>     static WSCfunctionRegister  op("drawep",(void*)drawep);

> At (A), draws the image by size as same as the drawing area.

Document Release 3.70 for WideStudio ver 3.70, Feb 2004

WideStudio documents index | Table of contents

Copyright(C) T. Hirabayashi, 2000-2004 | Last modified: Feb 25, 2004