HELP WITH 'DrawBustV2.exe'
For programmers who like to use 2D vector graphics in their programs, there are two main alternatives for producing their
drawings:
1. The hard way: by
plotting on graph-paper the components of their drawing and then manually
typing the coordinates of the results into their computer.
2. The easy way: by
drawing their picture directly on the computer screen with a graphic drawing
program, and then exporting the coordinates of the elements of the drawing to a
text file which can be read by or incorporated into their application program.
The DrawBustV2 program aims to implement the second method. It provides
simple tools for drawing straight lines, circles, rectangles and other polygons
on screen; polygons can be filled with colour if wished. Drawings can be saved
to disk as (drb) files for later reloading and editng. Finally, (and the
ultimate objective of the program), the drawing information for a drawing can
be exported to disk in any one of three ways:
o
In a format that suits programs written
in the Euphoria programming language.
o
As old fashioned BASIC DATA statements.
o
As computer-readable numbers (expressed
as text) which any computer language that can read disk files can use.
Your application programs can use whichever of these three
possible export formats suits best to implement screen-displayed pictures and
even simple animations. You will need some general skill and experience in
programming for graphic display to write your application. Two programs
demonstrating use of pictures produced by DrawBust are provided, along with
their Euphoria source code, to get you pointed in the right direction.
I can't give you a tutorial on graphics' programming. If you are
new to the subject I can recommend two good (if old) books on the subject:
“Computer
Graphics”, John Lansdown; Hodder & Stoughton (1987).
“Computer
Graphics”, Hearn, D. & Baker M. P.
Prentice Hall International (1986).
These books are general, and don't presuppose any particular graphics'
system.
In the DrawBustV2 program a drawing object consists of items
(aka elements, segments, components). A drawing object
composed of n items can be thought of
as having the form:
{ item[1], item[2], ...., item[n] }
In the text to follow, “Click” means
“Left-Click” unless stated otherwise.
The Trial Version of the program is
fully functional and may be run by clicking the Run Program button in the
Activation Dialog. This will run the program until the trial period has expired,
after which you cannot run the program without activating it (next). When the
program has been activated, it runs directly on call without appearance of the
Activation Dialog.
To obtain an activation number follow the instructions in
DrawBustV2.htm.
When you have obtained an activation number, click on the Activate
… Button in the Activation Dialog, type the activation number in to the edit
field that appears and then click the Accept Button.
If activation succeeds, the program will inform you of success and
the Activation Dialog will no longer appear on the main screen.
If activation fails (you will get a failure message), check that
you have typed the activation number correctly; if it is not correct retype it
and try again with the Accept Button.
To get out of the Activation Dialog and abort running the program,
click the Cancel Button.
The picture display is a square area representing a Unit Square
with X and Y coordinate ranges:
-0.5 <= X <= 0.5
-0.5 <= Y <= 0.5
Consequently the origin (0, 0) is at the centre of the
display area. Objects drawn within the display area and entirely within its
bounds area will have coordinates within the defined coordinate ranges when
exported. This choice of coordinates
makes it easy for your application programs to scale, translate, rotate and
otherwise manipulate drawn objects before displaying them.
Your drawing object is normally displayed in colour, as far as the
Insert Point . But when you are actively
drawing a new element of the drawing, that element is displayed as a line
drawing having the colour of the currently selected colour.
The program lets you draw an object made up of elements (standard lines
and shapes). Since the program does not implement a scheme of layering,
elements are drawn on screen in the order in which you create them. This
drawing order is the one in which any Euphoria or other program using a
sequence output generated by this program would normally draw the object.
Consequently, draw the more distant elements of an object first, and
then the elements that are closer. Elements that are partly hidden by closer
element(s) should be drawn before drawing the element(s) that partly conceal
them.
This Group lets you select the colour in which to draw the next element
of a drawing.
The next item you draw will be drawn in the colour displayed in the
Colour Pan. The default drawing colour is Black. To select a different colour,
click on the Colour Pan. A palette of safe colours will appear. Click on the
colour you want to use, then Click on the OK Button. The colour-picking palette
will disappear and the colour of the Colour Pan will now be that of the colour
you picked.
Colour Filling:
If you want the next item you draw to be filled with the current
picked colour, check the “Fill” box. The box will stay checked until you
uncheck it. Circles, rectangles and polygons can be filled with the current
colour.
Note that the colours used by this program are BGR (not RGB);
if they reproduce wrongly in your programs, it will most likely be because your system is using some variation on BGR
- maybe RGB or BRG. Your program will have
to adjust colours accordingly. If your programming language (e.g., some old
BASICs and Euphoria in DOS32 graphics mode) does not allow direct access to BGR
colouring, your programs will have to “translate” the colours into workable
approximations. Alternatively you will have to change the colour codes manually
in exported texts.
The Tools Group on the screen contains the buttons with which you
can select a Drawing Tool. You can't draw anything until you select a Tool by
clicking on its button.
When a Tool is selected, the name of the Active Tool will be
displayed at the bottom left of the screen and drawing cross-hairs will appear
in the drawing area when you pass the mouse over the drawing area.
The Tools behave in different ways. For how to use each Tool, see
below.
To draw a single straight line, select this Tool, then click in
the starting point for the line in the picture area. Then move the cross- hairs
with the mouse to the position for the other end of the line and click again.
The line will be added to the drawing object.
You can draw more lines of this sort without re-selecting the
Tool.
To draw a set of straight line segments joined “head-to-tail”,
select this Tool. Then click in the first point for the polyline. Keep on
clicking points until all the lines are drawn. Finally press the Escape key (or
RIGHT-click on the picture). The polyline will be added to the drawing object
and the updated drawing will reappear in colour with the new polyline included
in it.
Items drawn with this Tool are never filled with colour.
You can draw more lines of this sort without re-selecting the
Tool.
This works very similarly to the Straight Line Tool just
described. Click in the vertices of the polygon and, when complete (at least 3
vertices), press the Escape key (or RIGHT-click on the picture). The polygon
item will be added to the drawing object and the updated drawing will re-appear
in colour with the new polygon included in it.
Note:
You don't have to close a polygon. The program will automatically close the
polygon if the last vertex clicked does not have the same coordinates as the
first vertex.
If the fill box was checked, the new polygon will be filled with
the current picked colour.
You can draw more polygons without having to re-select the Tool.
To draw a free-hand line, select this Tool, then click in the
starting point for the line in the picture area. To draw the line, move the
cross-hairs away from this point with the mouse. To end the line, click once
again. You will be asked if you want to convert this pencil line into a
polygon. If you do, click the Yes Button and the figure will be closed by a
line from the last point to the first point. Click the No Button if you don't
want
it to be a polygon. The line (or polygon) will be added to the
drawing object.
If you elect to make it a polygon, it will be filled with the
current colour if Fill is checked.
You can draw more lines or polygons of
this sort without re-selecting the Tool.
Click on the place in the drawing where the centre of the circle
is to be. Then click on any point that
is to be on the circumference of the circle. Don't press Escape – as soon as
you have clicked in the 2 points the circle will be generated and added to the
drawing object. The updated drawing will re-appear in colour with the new
circle included in it.
If the fill box was checked, the new circle will be filled with
the current picked colour.
You can draw more circles without having to re-select the Tool.
To draw a rectangle, just click in 2 points marking the
extremities of a diagonal of the rectangle. Don't press Escape – as soon as you
have clicked in the 2 points the rectangle will be generated and added to the
drawing object. The updated drawing will re-appear in colour with the new
rectangle included in it. The sides of the drawn rectangle will be vertical and
horizontal.
If the fill box was checked, the new rectangle will be filled with
the current picked colour.
You can draw more rectangles without having to re-select the Tool.
This Tool will draw ellipses that have their axes parallel to the
axes of the coordinate system.
To draw an ellipse, click on the point in the drawing area where
the centre of the ellipse is to be. Then click in a second point; this point
should represent a corner of the (imaginary) rectangle that would surround the
ellipse. Don't press Escape – as soon as you have clicked in the 2 points the
ellipse will be generated and added to the drawing object. The updated drawing
will re-appear in colour with the new ellipse included in it.
If the fill box was checked, the new ellipse will be filled with
the current picked colour.
You can draw more ellipses without having to re-select the Tool.
If you are starting a totally new drawing, you do not see this;
the Insert Point will become the first item you add to the empty drawing. The
Insert Point item is the one that is currently highlighted in the Names List.
If you load an existing drawing from disk, you will see that the
name of the last element of the drawing is highlighted. The Insert Point is
here, If you now add another element to the drawing it will be added immediately
after this element, and the new element name will become the Insert Point.
You can change the Insert Point for a drawing by clicking on the
names of elements in the Names' List. When you do this,
1. The drawing will be displayed in full colour from item
1 up to and including the Insert Point item (name highlighted). Any drawing
elements after the Insert Point will be displayed only as a gray line
drawing.
2. If you add elements they will be INSERTED into the
drawing immediately after the Insert Point and each new element will in turn
become the Insert Point (as indicated by the changing high-lighting in the
Names' List).
This gives you a lot of control over constructing a drawing
object. For instance, you can 'go back' and insert a new element or elements where
ever you like and you can delete an element or elements where ever you like in
the drawing - See: TO DELETE ITEM(S).
You need to keep in mind where the Insert
Point is at all times while you are working on a drawing, so that the
elements you add are incorporated into the drawing in the places you intend.
Explore this by loading an existing drawing from file, and then
clicking at various places in the Names' List to see how this affects display
of the drawing. Try drawing new elements at at least one “internal” insertion
point to see what happens. Play around ... Don't accidentally overwrite (i.e.,
Save) the existing disk drawings with the results of these experiments – unless
of course you like the result.
Under the Names Edit is a piece of text. When there is no picture
in memory, this reads
Selection: NONE
When you load a picture from a file, this will change to
Selection: ALL
While you draw and add new items to the drawing, this Selection
text will update to reflect the current situation. Thus if you added a new
item, it would continue to read
Selection: ALL
meaning that the entire drawing is still selected.
You can change this selection to select an item or a range of
items to which you want to apply a transformation such as moving it, rotating
it, etc. (See: MANAGE GROUP). Here is how to do
selections:
1. TO SELECT ENTIRE DRAWING:
o
Just press Ctl_A at any time needed.
2. TO SELECT AN ITEM:
o
Click on the item in the Names List.
o
Press Ctl_C.
If you
clicked on (say) the 5th item in the drawing the Selection text should change
to
Selection: 5 to 5
3. TO SELECT A RANGE OF ITEMS:
o
Carry out step 2 twice, each click being
at an item at an extreme of the range.
For example if you wanted to select
items 5 to 16 in a drawing you would do and see this:
DO |
SEE |
Click on item 5. Press Ctl-C. |
Selection: 5 to 5 |
Click on item 16. Press Ctl-C. |
Selection: 5 to 16. |
Having selected an item or a range of
items you can do various things with it. - See next.
o
Make your selection
of item(s) to be deleted.
o
Press the Del (delete) key.
You will be prompted to confirm the deletion. If you accept, the
item(s) will be removed from the drawing.
After doing this you will almost certainly need to reset the Insert Point before resuming actual drawing. You
may also need to press Ctl-A (Select All), if that is what you want, to
continue your work.
o
Make your selection
of item(s) to be pasted.
o
Click on the item in the Names List
AFTER which you want the item(s) to be pasted in.
o
Press Ctl-P (paste).
The pasting will take place immediately. Multiple pastes are not
supported.
After doing this you will almost certainly need to reset the Insert Point before resuming actual drawing.
You may also need to press Ctl-A (Select All), if that is what you
want, to continue your work.
Pasting can be used to replicate item(s) of a drawing. After you
paste, the drawing may superficially appear
unchanged. The pasting you have made may need to be itself selected
and manipulated (e.g., moved) before
the change becomes apparent in the drawing.
SEE the OldTrain.drb file for an example of use of copying and pasting
to create all the carriages. The train has 4 carriages. Try selecting and
pasting to give the train 8 carriages (paste them in after the end of the Names
List). The drawing looks unchanged after doing this because the 4 new carriages
are lying on top of the existing 4 carriages – you need now to select the last
4 carriages and move them as a unit leftward to the back of the train.
This Group contains buttons with which you can apply a variety of
operations to an entire drawing, or to selected drawing item(s). You can check
what the various buttons do by moving the mouse over them and
reading the text that appears in the hint display at the top of
the screen.
A variety of operations are available, which are helpful if you
want to draw more accurately or in finer detail on a drawing object:
Arrow Buttons:
Move the currently selected item(s) in the drawing area - Up, Down,
Left, or Right.
Flip Buttons:
Flip the currently selected item(s) across the X-axis or the Y-axis.
Zoom Buttons:
Zoom in (Z+) on drawing or zoom out (Z-) from drawing. This applies only
to the entire drawing and can be done at any time.
Rotate Buttons:
Rotate currently selected item(s) around a clicked point, clockwise or
anti-clockwise.
These operations all affect the size and/or the position of the
object relative to the unit square drawing area, so after you have used these
operations you may wish to use them again to restore the object to close to its
original size and position in the square display area before you save it.
Experiment with these operations on an existing drawing object.
These operations are described more fully in the next 2
sub-sections.
For full drawing manipulation, make sure that the Selection text
reads “Selection: ALL”. If it does not press Ctl-A to force this selection.
The operations of
o
Flipping across axes (double-headed
arrow buttons)
o
Zooming in (Z+ Button) and out (Z-
Button)
o
Moving (single-headed arrow buttons)
are all straight forward and need no
detailed description. If moving, the movement takes place in small steps, and
you have to click the movement button for each step (sorry about that).
If you want to rotate the drawing (rotate buttons) you must click
on a point on the screen AROUND which you want the drawing to rotate just
before you do the rotation. If you don't select the rotation point like this,
the drawing will likely rotate around some unexpected point. The rotation takes
place in small steps and you have to click the rotation button for each step.
Manipulation of selected item(s) with buttons in the Manage Group
is very similar to full drawing (object) manipulation. Make your selection of
item(s) just before you do the manipulations.
If you want to flip selected item(s) across an axis, shift the entire
drawing around before making your selection and doing the flip so that when
flipped, the item(s) will land at the position you want – hard to judge but
trial-and-error will get you there.
Item manipulation gives you a way to modify a drawing fairly easily. By
exporting a sequence of manipulated vector files of the same drawing in between
manipulations you have a way to produce simple internal animation of the
drawing. Experiment. SEE series of drawings Man00.drb, Man01.drb, Man02.drb,
for an example of a walking man, that involved suitable rotations of arms,
hands, legs and feet. Notice my error in drawing the original Man00.drb – I
should have drawn both his legs before I drew the trunk of his body. Try
correcting this by selecting his legs and feet, and pasting them into the Names
List at a point before the trunk of his body; then delete the offending
legs and feet. Use the modified drawing to recreate the set of drawings.
This Group contains a Name edit box, where you can type in a short
custom name for the next item you are going to draw, and a Names' List which
lists names of the items which make up the current drawing object. The uses of
the Name Edit and of the Names List are described in the following
sub-sections.
The program implements a method of automatically naming each item
of an object. Automatic naming kicks in if you have typed no name in the Names'
Edit. The auto-names are a rough guide to the nature of each item, and are not
unique names. e.g.:
It-Line001 A
straight-line(s) item.
It-Rect010 A rectangle
item
It-Circ005 A circle
item
etc.
If you want to give an item a custom name, fill in the Names' Edit
field with your custom name before completing drawing the item. Custom names
can be a help to identifying items when later editing a drawing object.
If you are dissatisfied with the properties of an existing item in
a drawing (item name, item colour, item fill) you can change them. To do so,
click on the item in the Names' List, then RIGHT-click on the names list. A
dialog will pop up displaying the current values of the item's properties.
Change one or more of these and when you are happy with the changes click the
Accept Button. To abandon making changes click the Cancel Button.
Allowed
values for properties are:
Item Name: Anything you like.
Item Type: Polygon or Line.
Item Colour: A legal BGR
colour, typed as hex.
Item Fill : Fill or NoFill.
This Group Contains buttons to start a new drawing, to save the
drawing currently in memory to disk and to load a previously saved drawing into
memory from disk.
Files are given the extension drb, and are saved in a “Euphoria”
format readable by this program. For convenience I keep all these drawings in a
folder called “DrawArch”.
Click this button to start a new drawing
from scratch. If there is a drawing already in memory which you have modified
without saving it, you will be offered a chance to save it before the drawing
on disk is loaded.
This button loads an existing drawing from a disk file. There are
some demo drawings in the folder “DrawArch”. Try loading some of these, using
the “Load Drb” Button; loading is via a standard file dialogue. Any drawing in
memory will be replaced by the loaded drawing. Loadable files have the
extension “drb”.
A drawing in memory can be saved at any time by clicking on the
“Save Drb” Button. Saving is via a standard file dialogue. Keep an eye on file
names; if you save to the name of a file that already exists, the program will
overwrite it without any warning. Files are saved with the extension
“drb”.
This is really the whole point of this
program; to export graphic data information in a form that you can incorporate
into your own programs.
Exported formats are saved to files having auto-names in the form
“Busnnnn.out” where nnnn are digits. Rename those files you want to keep and/or
copy them to folders where you will make use of them. Delete any unwanted export
files to avoid clutter and confusion.
There are three export options provided by the program (below).
To get the hang of these export options, load a simple drawing
such as “Sailboat.drb” into the program. Then export the drawing to each of the
three formats in turn. Load each exported file into a text editor to see what
you've got.
If you click this button the drawing currently in memory will be
written to a text file, in the form of a pretty_printed Euphoria Structure that
can be imported into, or pasted into, a Euphoria program.
If you click this button the drawing currently in memory will be
written to a text file, in the form of a set of BASIC DATA statements, which
can be pasted into a BASIC program (provided your version of BASIC supports
DATA statements).
If you click this button the drawing currently in memory will be
written to a text file, in the form of a set of numbers. The numbers have the
same pattern as those generated by option (2). Option (3) is for those who use
languages that don't support Euphoria' sequences or BASIC's DATA statements,
but which can read in “numbers” from a text file.
In cases(1) and (2) the output is commented to
provide clues as to what individual numbers mean. Comments aren't incorporated
in case (3). In case (3) the order and meaning of the numbers is
the same as in case (2).
You will of course need to write your own programs and subroutines
to process the generated number data and display the information graphically on
screen. Typically, operations you will need your program to perform include:
q to read each Structure item from its file:
o
Euphoria usage - several options:
i.
Copy, then paste the object into an
includable (*.ew) file then modify the text so that the object is part of a
function that returns the structure when a call is made to the function.
ii.
Paste the object directly into a program
so that you have a line like
constant
cname = object
(you will need to consider whether to
surround object above by {} braces; this will depend on what your 2D
vector-drawing routines may expect).
o
BASIC DATA usage:
i.
Paste the statements directly into the
program that will use them, and add a label, e,g., (PICID:) so that you can RESTORE to it for data reading.
ii.
As i, except paste into an INCLUDE file.
Do-able only if your version of BASIC supports an INCLUDE instruction and will
recognize labels in an INCLUDE file.
o
Num File usage:
Your program will need to read the numbers
one by one from the number file and assign them to variables (including arrays)
as needed. Arrays would be needed to hold list(s) of item properties, and also
the coordinates of each item in the drawing object. Have a special routine for
doing this; if your BASIC (or other language) supports an instruction like
REDIM you will find uses for it here. Your language would best allow arrays
having multiple dimensions greater than 3.
q Scale the item up; Each item in the structure will normally
have coordinates in the range
{-0.5,
-0.5} <= {x, y} <= {0.5, 0.5}
so you will be scaling up from that.
q Translate the item to a screen position suitable for
displaying it.
q Display the object; your displaying routine(s) need to
be able to deal with drawing lines, and with filling polygons when needed.
Folder “SimpleDemo” contains a program “TestGraphic.exe” that is a
demo of using output from DrawBustV2 in a very basic Euphoria program. It just
displays the Sailboat drawing, the structure of which
I have pasted directly into the demo program's include-file,
“Sailboat.e” (source code provided). Load the source files “TestGraphic.exw”
and “Sailboat.e” into a text editor to view them; even if Euphoria is not your
language, you should be able to get the drift of what a simple program needs to
do in order to display such a vector drawing – indeed any vector
drawing.
SAILBOATDEMO:
Folder “SailboatDemo” offers another, more complex, demo program,
“Sailboat.exe”, which runs several vector drawings all at once in an OOP-based
animated environment. The complete Euphoria source code is in the folder
“SailboatDemo\Source”. The include-file “ScaleW.ew” is a 2D image scaling, mapping
and drawing library adapted to use with “EuWinGUI.ew”. “PicOOp.ew” is a
Class-Definition and Methods include-file which uses the “EuCanOOP.e” library.
(This program will not run properly from a link, so I can’t provide one here;
you will have to go to the SailBoatDemo folder yourself and run Sailboat.exe
yourself).
Unfortunately I can't provide drawing routines for BASIC or C or
for other languages ... if you're lucky you already have suitable routines in
your stock of graphic routines, otherwise you will have to write, beg or borrow
them yourself.
Drawing Cross-hairs: The program mostly manages these well.
Occasionally it fails to remove a cross-hair cleanly from the drawing area – an
irritating but harmless fault.
Polygon drawing: co-linear points are not checked for; eg,
rectangle drawn with a horizontal diagonal.
DrawBustV2 is a substantial improvement
on its predecessor, DrawBust, already published on the Euphoria website.
While I am happy with the DrawBustV2 program as far as I have got
with it, it does have limitations and could be
improved in various ways, including the following
v
More - and more varied - drawing tools.
v
Improved and more compact format of
storage of data in drb files. The present method, while effective, is fairly
primitive and literally saves every coordinate point of the elements of a
drawing, making drb files unnecessarily big. A better way would be to save only
“instructions” about drawing from which items of a drawing could be reconstructed
in memory. If implemented, this would require a conversion utility so that
existing users of the program could convert old drb files from the old to the
new format.
v
Where feasible and not too disruptive of
the program, to add improvements suggested by users of the program.
v
If the main screen becomes too cluttered
with buttons etc. (you may think it already is!), moving some of them off to
selectable drop-down panels.
So there is lots of room for improvement. Consequently, this
program is still a work-in-progress and I haven’t included its source files.
As usual a big rave for Euphoria, a very flexible and stylish
programming language.
And on my part a big rave for Andrea Cini's EuWinGUI Library,
which has greatly eased my transition to writing programs that use Windows.
This Library lets you write simple or even complicated programs that use
Windows without getting bogged in the seemingly endless complexity of advanced
Windows programming. EuWinGui was used in the writing of this program.
----oooOooo----
Fred Mangan (October 2010)
Mangan_Fred@yahoo.com.au