/************************************************************************ * * * Resize a polygon. One of the polygon's has been selected. We need * * to change the position of the vertex and redraw two lines connected * * to that point. * * */ ReactionType Polygon::resize(short x, short y) { // Check for the minimum and maximum limit of the graphics area if ((x < 0) || (y < 0) || (x > Gdev_Win_Width(gdev)) || (y > Gdev_Win_Height(gdev))) return REACTION_NONE; erase_resize(); // Update the current vertex pnt[vertex_selected].x = x; pnt[vertex_selected].y = y; draw_resize(); some_info(TRUE); return REACTION_NONE; }
/************************************************************************ * * * Erase part of a polygon. That is, two lines between * 'vertex_selected' and the neighboring two vertices. * It is called when a user needs to resize a polygon. * * */ void Polygon::erase_resize(void) { if (bkg_pixmap){ // // Erase the two segments // set_clip_region(FRAME_CLIP_TO_IMAGE); if (vertex_selected == 0){ if (closed){ redisplay_bkg(pnt[npnts-1].x, pnt[npnts-1].y, pnt[0].x, pnt[0].y); } }else{ redisplay_bkg(pnt[vertex_selected-1].x, pnt[vertex_selected-1].y, pnt[vertex_selected].x, pnt[vertex_selected].y); } if (vertex_selected == (npnts-1)){ if (closed) { redisplay_bkg(pnt[vertex_selected].x, pnt[vertex_selected].y, pnt[0].x, pnt[0].y); } }else{ redisplay_bkg(pnt[vertex_selected].x, pnt[vertex_selected].y, pnt[vertex_selected+1].x, pnt[vertex_selected+1].y); } }else{ // // XOR the two segments // draw_resize(); } set_clip_region(FRAME_NO_CLIP); }
void main_loop () { #if HAVE_SDL SDL_Event event[1]; #endif #if HAVE_FREEGLUT // Passing the GTK+ signals to the FreeGLUT main loop glutIdleFunc ((void (*)) gtk_main_iteration); // Setting our draw resize function as the FreeGLUT reshape function glutReshapeFunc (draw_resize); // Setting our draw function as the FreeGLUT display function glutDisplayFunc (draw); // FreeGLUT main loop glutMainLoop (); #else #if HAVE_SDL while (1) { while (gtk_events_pending ()) gtk_main_iteration (); while (SDL_PollEvent (event)) { if (event->type == SDL_QUIT) return; if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) draw_resize (event->window.data1, event->window.data2); } #elif HAVE_GLFW while (!glfwWindowShouldClose (window)) { while (gtk_events_pending ()) gtk_main_iteration (); glfwPollEvents (); #endif draw (); } #endif } /** * \fn int main(int argn, char **argc) * \brief Main function * \param argn * \brief Arguments number. * \param argc * \brief Array of arguments. * \return 0 on success. */ int main (int argn, char **argc) { GLenum glew_status; // PARALELLIZING INIT #ifdef G_OS_WIN32 SYSTEM_INFO sysinfo; GetSystemInfo (&sysinfo); nthreads = sysinfo.dwNumberOfProcessors; #else nthreads = (int) sysconf (_SC_NPROCESSORS_CONF); #endif // END // Initing locales #if DEBUG printf ("Initing locales\n"); fflush (stdout); #endif bindtextdomain ("fractal", "./po"); bind_textdomain_codeset ("fractal", "UTF-8"); textdomain ("fractal"); // Initing graphic window #if HAVE_FREEGLUT #if DEBUG printf ("Initing FreeGLUT window\n"); fflush (stdout); #endif glutInit (&argn, argc); glutInitDisplayMode (GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize (window_width, window_height); glutCreateWindow ("fractal"); #elif HAVE_SDL #if DEBUG printf ("Initing SDL window\n"); fflush (stdout); #endif SDL_Init (SDL_INIT_VIDEO); window = SDL_CreateWindow ("fractal", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); if (!window) { printf ("ERROR! unable to create the window: %s\n", SDL_GetError ()); return 1; } SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2); if (!SDL_GL_CreateContext (window)) { printf ("ERROR! SDL_GL_CreateContext: %s\n", SDL_GetError ()); return 1; } #elif HAVE_GLFW #if DEBUG printf ("Initing GLFW window\n"); fflush (stdout); #endif if (!glfwInit ()) { printf ("ERROR! unable to init GLFW\n"); return 1; } window = glfwCreateWindow (window_width, window_height, "fractal", NULL, NULL); if (!window) { printf ("ERROR! unable to open the window\n"); glfwTerminate (); return 1; } glfwMakeContextCurrent (window); #endif // Initing GLEW #if DEBUG printf ("Initing GLEW\n"); fflush (stdout); #endif glew_status = glewInit (); if (glew_status != GLEW_OK) { printf ("ERROR! glewInit: %s\n", glewGetErrorString (glew_status)); return 1; } // Initing FreeType if (FT_Init_FreeType (&ft)) { printf("ERROR! could not init freetype library\n"); return 1; } // Initing GTK+ #if DEBUG printf ("Initing GTK+\n"); fflush (stdout); #endif gtk_init (&argn, &argc); // Initing logo #if DEBUG printf ("Initing logo\n"); fflush (stdout); #endif logo_new ("logo.png"); // Initing drawing data #if DEBUG printf ("Initing drawing data\n"); fflush (stdout); #endif if (!draw_init ()) return 1; // Creating the main GTK+ window #if DEBUG printf ("Creating simulator dialog\n"); fflush (stdout); #endif dialog_simulator_create (dialog_simulator); #if DEBUG printf ("Main loop\n"); fflush (stdout); #endif main_loop (); // Freeing memory #if HAVE_GLFW glfwDestroyWindow (window); glfwTerminate (); #endif return 0; }