3.detailed design
TRANSCRIPT
-
7/30/2019 3.Detailed Design
1/4
Detailed Design Graphics Package using OpenGL
Dept of CSE, RVCE Sept-Dec 2012 10
3. Detailed design
3.1 Window design:
Graphics editor uses the following windows.
Window : Main outer window that holds the menu bar, toolbox and color palette. Screen : Screen is a sub window of the main window which acts as a canvas for the basic 2D
drawing.
Open : It is a dialog window which is used as open, save and save as dialog window. Msgwin : msgwin is a sub window of main window, which is used to display alert message,
whenever user jumps to a new file without saving previous one.
Initially the main window and the screen window will be displayed. Switching between the windows
is handled depending on the events. The main controls such as Menus, Tool buttons, Color buttons are drawn
in main window.
One of the most important things is that window is portable and flexible. The positioning of controls
inside the window is generalized. The controls are placed with respect to the relative values of the window
width and height. This means that the editor is portable to any system having different resolutions. We need to
change only minimal values such as window width and height defined in init.h file.
Fig 3.1 switching between windows
-
7/30/2019 3.Detailed Design
2/4
Detailed Design Graphics Package using OpenGL
Dept of CSE, RVCE Sept-Dec 2012 11
3.2 Main Algorithm:
The main algorithm for the graphics editor is the one shown below.
1. Initiate the graphics mode and the graphics driver.
2. Initiate the mouse drivers.
3. Draw the toolbar icons, menus, and the main window.
4. Repeat the following steps until the user wants to exit
Check if left button of the mouse is clicked.
If so then Check to see if mouse is on one of the buttons on the tool bar. If so execute the functionassociated with that button.
Else check to see if the mouse is on the color palette. If so then change the present color to the selectedcolor.
Else check to see if mouse is on the drawing area. If so carry on with the operation previously beingexecuted.
5.Close the graphics mode and restore back the CRT mode.
As we see above, the main algorithm is an infinite loop continuously polling for mouse movements.
Whenever the mouse is clicked, the position of the mouse is checked and depending on the position of the
mouse the appropriate operation is executed. The loop is exited when the user wants to quit the editor.
Data Structures Used:
There are no other data structures explicitly used. This is mainly because, the editor is designed for
area based operations and not object-based operations. So it is not necessary maintain information about
objects drawn on the drawing area.
3.3 Other Algorithms used
Various algorithms have been used in this editor to provide the functionalities it boasts of. Few of them
have been explained here.
-
7/30/2019 3.Detailed Design
3/4
Detailed Design Graphics Package using OpenGL
Dept of CSE, RVCE Sept-Dec 2012 12
3.3.1 Bresenham's Line and Circle Algorithm:
This is the most important algorithm used here in this editor. This is an accurate and efficient raster
line-generating algorithm that scans converts line using only incremental integer calculations that is adapted
here to display lines. The algorithm can be suitably adapted for drawing circles and other curves.
3.3.2 Free- hand Drawing:
Free- hand drawing is a special case of polyline drawing where we have a large number of points
obtained by continuously poling the mouse position during the time the mouse' left button is clicked.
3.3.3 Translation:
Translation is done by adding the required amount of translation quantities to each of the points of the
objects in the selected area. If P(x,y) be the a point and (tx, ty) translation quantities then the translated point is
given by
P'(x,y) = p(x+tx,y+ty)
3.3.4 Rotation:
The rotation of an object by an angle 'a' is accomplished by rotating each of the points of the object.
The rotated points can be obtained using the formula
Newx = oldx*cos(a) - oldy*sin(a)
Newy = oldx*sin(a) + oldy*cos(a)
3.3.5 Scaling:
The scaling operation on an object can be carried out for an object by multiplying each of the points
(x,y) by the scaling factors sx, sy.
Newx = oldx*sx
Newy = oldy*sy
-
7/30/2019 3.Detailed Design
4/4
Detailed Design Graphics Package using OpenGL
Dept of CSE, RVCE Sept-Dec 2012 13
3.3.6 Rubber-Banding Technique:
Drawing of the various objects such as line, rectangle, polygons, circles etc is based on the rubber-band
technique where the user marks the initial point and then as the cursor moves around the screen the object is
displayed with the current mouse coordinates being taken as the second point. This is useful in applications
where we might want to explore different possibilities before selecting a final position. This can be
accomplished by continuously polling the mouse for its coordinates and drawing in the X-OR mode. By doing
so if the figure has been originally drawn then it would be erased, else it would be newly drawn. By
coordinating this action we can implement rubber-band action.