4. Implementation:
4.1.1 Color :
Color is a basic structure for color parameters such as red, green, blue. The fig 4.1 shows the color structure. These structures objects are used in other basic structures to store color values required for the objects.
4.1.2 GLintpoint:
GLintpoint defines a structure for a pixel. The fig. 4.2 shows the GLintpoint structure. Every tool has an object of this structure type to store the details of each and every pixel for the corresponding tool. The attributes of this structure are:
x y
: holds the x position of the pixel : holds the y position of the pixel
ptrn : pattern type for the pixel col : holds the color of the pixel Dept of CSE, RVCE Sept-Dec 2012 14
Implementation end : flag tells whether this pixel is the end of the primitive drawn pfill : flag tells whether pattern filling is enabled for the pixel.
4.1.3 Text:
It is a basic structure for the text tool. Fig 4.3 shows the basic text structure. The text tool uses this structure object to store the text along with the parameters listed below.
x y
: holds the x position of the text : holds the y position of the text
4.1.4 Stack:
This defines the structure for a single level of stack. Fig 4.4 shows the stack structure. The main display stack uses the objects of this structure for each level. This gives the information about the tool active on that level and the start and end index for the tool on that level. The attributes of stack structure are: Dept of CSE, RVCE Sept-Dec 2012 15
Implementation strt: specifies the start index of the tool at this level. end: specifies the end index. tool: specifies the tool at this level.
4.1.5 Disp_stack :
It is a basic display stack which is used to control the display of the objects in the screen. Fig 4.5 shows the disp_stack structure. The parameters of this structures are :
top : points to the current top position. st : It is an actual stack that holds the levels defined by the stack structure.
4.1.6 Button :
Holds all the controls such as menus, submenus, tool buttons, pattern palette button and color buttons. Fig 4.7 shows the Button structure. The following parameters are used to draw and control the button events. x, y w, h state : x and y position of the button [i.e. top left corner] : width and height of the button : state of the button at a particular instance [i.e. 0 or 1]
highlighted : used in mouse passive motion function to catch the highlighted button Dept of CSE, RVCE Sept-Dec 2012 16
Implementation num type col label : button number from a particular type : type of the button like TOOL, MENU etc : color of the button : holds the button text
4.2 Menus :
Menus are created using the structure called Button. The button is a basic structure for all controls in the editor. The button structure takes Button->type value as MENU, to identify it as menu button. To create a submenu we will pass the Button->type value as S_MENU. The Button->num values uniquely identify the button or menu that is highlighted or clicked. The Menus are positioned by specifying the x, y, w, h values to the button object. To display the menu we have a function called drawButtons which is continuously called whenever the main window is redisplayed. To display the submenus the drawButtons function in-turn calls drawSubmenus () function which displays the submenus of the menu which has been selected. We designed the menu to look like similar to the menus from the windows menu system. For odd number of clicks the submenus of the selected menu will be displayed. If we select a menu and goto another then that menu will be selected and is similar to windows menus. Our menu system is so flexible that we can add or remove as many as we want easily. The Button_draw () function will draw the button in proper place and it places the button text in the centre of the
Sept-Dec 2012 17
Implementation
menu by calculating the position according to the type of the button to be displayed To display a button it switches to the required display code for that button. Menus are highlighted whenever the mouse moves over it. If a submenu is selected then the sel_menu will hold the button number of that menu and can be used to perform further operations. The sel_menu can be used globally to check for the selected menu button number. Popup menus are created using the built-in Glut function called glutCreateMenu(). The sub menu entries are specified using the function glutAddSubMenu(). The menu entries are added using the function glutAddMenuEntry().
Sept-Dec 2012 18
Implementation
The save as option will display save as dialog and saves the file. If the file already exists then displays the error message. The exit option is used to quit the editor.
void drawKeyText()
Sept-Dec 2012 19
void draw_pixel(GLint x,GLint y) void plotpixels(GLint h,GLint k,GLint x,GLint y) void drawCircle(int mx1,int my1,int mx2,int my2,GLfloat color[],GLfloat lWidth)
The above functions is used to draw Circle using two points on the canvas
void edit() { int top=0; //if tools selected or submenu selected if(((Toolsflag1)&&(Toolsflag2))||sMenuflag) { for(top=0;top<=t_top;top++) { switch(OBJECTS[top].type) { case SPRAY:if(OBJECTS[top].flag) drawSpray(OBJECTS[top].x1,OBJECTS[top].y1,OBJECTS[top].color,OBJECTS[top].lw); break; Dept of CSE, RVCE Sept-Dec 2012 20
Implementation
Sept-Dec 2012 21
Implementation
4.8 2D drawing :
2D drawings are done in screen window that is used as canvas. For each tool there is an array of GLintpoint structure. This array will hold the details of the pixels to be drawn in favor of particular tool.
The 2D drawing canvas is controlled wholly by a display stack that holds the stack structure objects in each level for each tool. The display stack is continuously called for each redisplay call for the canvas. The display stack top pointer will point to the current stack top. The objects in the stack will be displayed from the top to the bottom every time. Each display stack level will hold the details of current tool, the start and end index of the array for that tool.
Whenever a tool is selected, the disp_stk.top is incremented and the start and end index will be initialized to that tool index. During switching over to another tool, the current tool indices are stored in stack top level and the top pointer is incremented for the next tool. The display stack called from top to bottom hence, we will have the effect of objects drawn one over another.
4.9 Clipping :
There are two types of clipping implemented
First we will identify the rectangular area selected by the select tool. Then perform following functions. If (inside clipping) Draw a rectangular patch covering the selected area. If (outside clipping) Draw four white rectangles from the left, right, top and bottom of the selected area excluding the selected area.
Sept-Dec 2012 22
Implementation
Sept-Dec 2012 23
Implementation
glutPostRedisplay(void), which gives glutMainLoop() a nudge to call the registered display callback at its next opportunity. If your program changes the contents of the window, sometimes you will have to call this function.
You can draw these objects as wireframes or as solid shaded objects with surface normals defined. For example, the routines for a cube and a sphere are as follows:
void glutWireCube(GLdouble size); void glutSolidCube(GLdouble size); void glutWireSphere(GLdouble radius, GLint slices, GLint stacks); void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);
All these models are drawn centered at the origin of the world coordinate system.
Sept-Dec 2012 24
Implementation
Point Details To control the size of a rendered point, use glPointSize() and supply the desired size in pixels as theargument. void glLoadMatrix{fd}(const TYPE *m); Sets the sixteen values of the current matrix to those specified by m. void glMultMatrix{fd}(const TYPE *m); Multiplies the matrix specified by the sixteen values pointed to by m by the current matrix and stores the result as the current matrix. void glLoadIdentity(void); Sets the currently modifiable matrix to the 4 4 identity matrix. void glMatrixMode(GLenum mode); Specifies whether the modelview, projection, or texture matrix will be modified, using the mode attribute. Projecton matrix is used for 2-D purposes whereas Modelview is used for 3-D.
Sept-Dec 2012 25