From 7da4959dff05c704e046215d163d2f8698c907df Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Wed, 30 Apr 2008 19:27:24 +0000 Subject: [PATCH] - API: Fix build break from my last check-in. api/ graphics2_unix.C graphics2_win.C svn path=/trunk/boinc/; revision=15108 --- api/graphics2_unix.C | 469 +++++++++++++++++++++---------------------- api/graphics2_win.C | 5 +- checkin_notes | 8 + 3 files changed, 242 insertions(+), 240 deletions(-) diff --git a/api/graphics2_unix.C b/api/graphics2_unix.C index 3fc85983d7..f8fef5cc39 100644 --- a/api/graphics2_unix.C +++ b/api/graphics2_unix.C @@ -1,237 +1,234 @@ -// Berkeley Open Infrastructure for Network Computing -// http://boinc.berkeley.edu -// Copyright (C) 2008 University of California -// -// This is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; -// either version 2.1 of the License, or (at your option) any later version. -// -// This software is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU Lesser General Public License for more details. -// -// To view the GNU Lesser General Public License visit -// http://www.gnu.org/copyleft/lesser.html -// or write to the Free Software Foundation, Inc., -// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -// unix-specific graphics stuff -// -#include "config.h" -#include -#include -#include -#include -#include -#include -#include -#include "x_opengl.h" - -#include "app_ipc.h" -#include "util.h" -#include "filesys.h" - -#include "boinc_gl.h" -#include "boinc_glut.h" -#include "boinc_api.h" -#include "graphics2.h" - -#define TIMER_INTERVAL_MSEC 30 - -static int xpos = 100, ypos = 100, width = 600, height = 400; -static int clicked_button; -static int win=0; -static int checkparentcounter=0; - -#ifdef __APPLE__ -#include // for MAXPATHLEN - -static bool need_show = false; -#endif - -bool fullscreen; - -void boinc_close_window_and_quit() { - exit(0); -} - -// This callback is invoked when a user presses a key. -// -void keyboardD(unsigned char key, int /*x*/, int /*y*/) { - if (fullscreen) { - boinc_close_window_and_quit(); - } else { - boinc_app_key_press((int) key, 0); - } -} - -void keyboardU(unsigned char key, int /*x*/, int /*y*/) { - if (fullscreen) { - boinc_close_window_and_quit(); - } else { - boinc_app_key_release((int) key, 0); - } -} - -void mouse_click(int button, int state, int x, int y){ - clicked_button = button; - if (fullscreen) { - boinc_close_window_and_quit(); - } else { - if (state) { - boinc_app_mouse_button(x, y, button, false); - } else { - boinc_app_mouse_button(x, y, button, true); - } - } -} - -void mouse_click_move(int x, int y){ - if (fullscreen) { - boinc_close_window_and_quit(); - } else if (clicked_button == 2){ - boinc_app_mouse_move(x, y, false, false, true); - } else if (clicked_button == 1){ - boinc_app_mouse_move(x, y, false, true, false); - } else if (clicked_button == 0){ - boinc_app_mouse_move(x, y, true, false, false); - } else{ - boinc_app_mouse_move(x, y, false, false, false); - } -} - -static void maybe_render() { - int new_xpos, new_ypos, new_width, new_height; - static int size_changed = 0; - - new_xpos = glutGet(GLUT_WINDOW_X); - new_ypos = glutGet(GLUT_WINDOW_Y); - new_width = glutGet(GLUT_WINDOW_WIDTH); - new_height = glutGet(GLUT_WINDOW_HEIGHT); - - - if (throttled_app_render(new_width, new_height, dtime())) { - glutSwapBuffers(); - if (! fullscreen) { - // If user has changed window size, wait until it stops - // changing and then write the new dimensions to file - if ((new_xpos != xpos) || (new_ypos != ypos) || - (new_width != width) || (new_height != height) - ) { - size_changed = 1; - xpos = new_xpos; - ypos = new_ypos; - width = new_width; - height = new_height; - } else { - if (size_changed && (++size_changed > 10)) { - size_changed = 0; - FILE *f = boinc_fopen("gfx_info", "w"); - if (f) { - // ToDo: change this to XML - fprintf(f, "%d %d %d %d\n", xpos, ypos, width, height); - fclose(f); - } - } - } // End if (new size != previous size) else - } // End if (! fullscreen) -#ifdef __APPLE__ - MacGLUTFix(fullscreen); - if (need_show) { - glutShowWindow(); - need_show = false; - } -#endif - } -} - -static void make_window() { - char window_title[256]; - get_window_title(window_title, 256); - - win = glutCreateWindow(window_title); - glutReshapeFunc(app_graphics_resize); - glutKeyboardFunc(keyboardD); - glutKeyboardUpFunc(keyboardU); - glutMouseFunc(mouse_click); - glutMotionFunc(mouse_click_move); - glutDisplayFunc(maybe_render); - glEnable(GL_DEPTH_TEST); - - app_graphics_init(); - -#ifdef __APPLE__ - glutWMCloseFunc(boinc_close_window_and_quit); // Enable the window's close box - BringAppToFront(); - // Show window only after a successful call to throttled_app_render(); - // this avoids momentary display of old image when screensaver restarts - // which made image appear to "jump." - need_show = true; -#endif - - if (fullscreen) { - glutFullScreen(); - } -} - -static void boinc_glut_init(int *argc, char** argv) { - win = 0; - - FILE *f = boinc_fopen("gfx_info", "r"); - if (f) { - // ToDo: change this to XML parsing - fscanf(f, "%d %d %d %d\n", &xpos, &ypos, &width, &height); - fclose(f); - } - - glutInit (argc, argv); - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA); - glutInitWindowPosition(xpos, ypos); - glutInitWindowSize(width, height); -} - -static void timer_handler(int) { - maybe_render(); - // When running under a V5 client, the worker app launches the graphics app - // so this code kills the graphics when the worker application exits. - // Under a V6 client, the Manager or Screensaver launched the graphics app - // so this code kills the graphics when the Manager or Screensaver exits. - if (--checkparentcounter < 0) { - // Check approximately twice per second if parent process still running - checkparentcounter = 500 / TIMER_INTERVAL_MSEC; - if (getppid() == 1) { - // Quit graphics application if parent process no longer running - boinc_close_window_and_quit(); - } - } - glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0); -} - -void boinc_graphics_loop(int argc, char** argv) { - int retval = 0; - - if (!diagnostics_is_initialized()) { - retval = boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS); - if (retval) return retval; +// Berkeley Open Infrastructure for Network Computing +// http://boinc.berkeley.edu +// Copyright (C) 2008 University of California +// +// This is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; +// either version 2.1 of the License, or (at your option) any later version. +// +// This software is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Lesser General Public License for more details. +// +// To view the GNU Lesser General Public License visit +// http://www.gnu.org/copyleft/lesser.html +// or write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +// unix-specific graphics stuff +// +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include "x_opengl.h" + +#include "app_ipc.h" +#include "util.h" +#include "filesys.h" + +#include "boinc_gl.h" +#include "boinc_glut.h" +#include "boinc_api.h" +#include "graphics2.h" + +#define TIMER_INTERVAL_MSEC 30 + +static int xpos = 100, ypos = 100, width = 600, height = 400; +static int clicked_button; +static int win=0; +static int checkparentcounter=0; + +#ifdef __APPLE__ +#include // for MAXPATHLEN + +static bool need_show = false; +#endif + +bool fullscreen; + +void boinc_close_window_and_quit() { + exit(0); +} + +// This callback is invoked when a user presses a key. +// +void keyboardD(unsigned char key, int /*x*/, int /*y*/) { + if (fullscreen) { + boinc_close_window_and_quit(); + } else { + boinc_app_key_press((int) key, 0); } - -#ifdef __APPLE__ - char dir [MAXPATHLEN]; - getcwd(dir, MAXPATHLEN); -#endif - for (int i=1; i 10)) { + size_changed = 0; + FILE *f = boinc_fopen("gfx_info", "w"); + if (f) { + // ToDo: change this to XML + fprintf(f, "%d %d %d %d\n", xpos, ypos, width, height); + fclose(f); + } + } + } // End if (new size != previous size) else + } // End if (! fullscreen) +#ifdef __APPLE__ + MacGLUTFix(fullscreen); + if (need_show) { + glutShowWindow(); + need_show = false; + } +#endif + } +} + +static void make_window() { + char window_title[256]; + get_window_title(window_title, 256); + + win = glutCreateWindow(window_title); + glutReshapeFunc(app_graphics_resize); + glutKeyboardFunc(keyboardD); + glutKeyboardUpFunc(keyboardU); + glutMouseFunc(mouse_click); + glutMotionFunc(mouse_click_move); + glutDisplayFunc(maybe_render); + glEnable(GL_DEPTH_TEST); + + app_graphics_init(); + +#ifdef __APPLE__ + glutWMCloseFunc(boinc_close_window_and_quit); // Enable the window's close box + BringAppToFront(); + // Show window only after a successful call to throttled_app_render(); + // this avoids momentary display of old image when screensaver restarts + // which made image appear to "jump." + need_show = true; +#endif + + if (fullscreen) { + glutFullScreen(); + } +} + +static void boinc_glut_init(int *argc, char** argv) { + win = 0; + + FILE *f = boinc_fopen("gfx_info", "r"); + if (f) { + // ToDo: change this to XML parsing + fscanf(f, "%d %d %d %d\n", &xpos, &ypos, &width, &height); + fclose(f); + } + + glutInit (argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_ALPHA); + glutInitWindowPosition(xpos, ypos); + glutInitWindowSize(width, height); +} + +static void timer_handler(int) { + maybe_render(); + // When running under a V5 client, the worker app launches the graphics app + // so this code kills the graphics when the worker application exits. + // Under a V6 client, the Manager or Screensaver launched the graphics app + // so this code kills the graphics when the Manager or Screensaver exits. + if (--checkparentcounter < 0) { + // Check approximately twice per second if parent process still running + checkparentcounter = 500 / TIMER_INTERVAL_MSEC; + if (getppid() == 1) { + // Quit graphics application if parent process no longer running + boinc_close_window_and_quit(); + } + } + glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0); +} + +void boinc_graphics_loop(int argc, char** argv) { + if (!diagnostics_is_initialized()) { + boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS); + } + +#ifdef __APPLE__ + char dir [MAXPATHLEN]; + getcwd(dir, MAXPATHLEN); +#endif + for (int i=1; i