*** empty log message ***

svn path=/trunk/boinc/; revision=4323
This commit is contained in:
David Anderson 2004-10-13 20:20:19 +00:00
parent 6523866ce3
commit 679fa7507e
2 changed files with 161 additions and 166 deletions

View File

@ -1,5 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include "x_opengl.h"
@ -13,186 +13,174 @@
static bool visible = true;
static int current_graphics_mode = MODE_HIDE_GRAPHICS;
int win_loop_done;
int xpos = 100, ypos = 100; // globals
int clicked_button;
int win;
extern int userclose;
static int acked_graphics_mode;
static int xpos = 100, ypos = 100;
static int clicked_button;
static int win=0;
static extern int userclose;
extern void graphics_thread_init();
extern GRAPHICS_INFO gi;
//extern GRAPHICS_INFO gi;
static void timer_handler();
void set_mode(int mode);
static void set_mode(int mode);
void keyboardU(unsigned char key, int x, int y) {
/* This callback is invoked when a user presses a key.
*/
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
}
// This callback is invoked when a user presses a key.
//
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
}
}
void mouse_click(int button, int state, int x, int y){
clicked_button = button;
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
} else {
if(state)
boinc_app_mouse_button(x, y, button, false);
else
boinc_app_mouse_button(x, y, button, true);
}
clicked_button = button;
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
} 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(current_graphics_mode == MODE_FULLSCREEN){
set_mode(MODE_HIDE_GRAPHICS);
} 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);
}
if (current_graphics_mode == MODE_FULLSCREEN){
set_mode(MODE_HIDE_GRAPHICS);
} 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);
}
}
void keyboardD(unsigned char key, int x, int y) {
/* This callback is invoked when a user presses a key.
*/
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
} else {
}
}
void onIdle(){
static double oldTime = 0;
double currentTime = dtime();
if(userclose == 1){
userclose = 0;
set_mode(MODE_HIDE_GRAPHICS);
}
if(currentTime - oldTime > .001){
timer_handler();
oldTime = currentTime;
}
}
static void make_new_window(int mode){
if(mode == MODE_WINDOW || mode == MODE_FULLSCREEN){
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(xpos, ypos);
glutInitWindowSize(gi.xsize, gi.ysize);
boinc_get_init_data(aid);
if (!strlen(aid.app_name))
strcpy(aid.app_name, "BOINC Application");
win = glutCreateWindow(aid.app_name);
glutReshapeFunc(app_graphics_resize);
glutKeyboardFunc(keyboardD);
glutKeyboardUpFunc(keyboardU);
glutMouseFunc(mouse_click);
glutMotionFunc(mouse_click_move);
glutDisplayFunc(timer_handler);
glutIdleFunc(onIdle);
app_graphics_init();
glEnable(GL_DEPTH_TEST);
if(mode == MODE_FULLSCREEN)
glutFullScreen();
}
}
void set_mode(int mode) {
if(current_graphics_mode == MODE_HIDE_GRAPHICS &&
mode == current_graphics_mode){
make_new_window(MODE_WINDOW);
glutDestroyWindow(win);
}
else if (current_graphics_mode != mode){
if(mode == MODE_HIDE_GRAPHICS){
if(mode != MODE_FULLSCREEN){
xpos = glutGet(GLUT_WINDOW_X);
ypos = glutGet(GLUT_WINDOW_Y);
gi.xsize = glutGet(GLUT_WINDOW_WIDTH);
gi.ysize = glutGet(GLUT_WINDOW_HEIGHT);
}
glutDestroyWindow(win);
}
current_graphics_mode = mode;
make_new_window(mode);
}
// tell the core client that we're entering new mode
//
if (app_client_shm) {
app_client_shm->shm->graphics_reply.send_msg(
xml_graphics_modes[current_graphics_mode]
);
}
}
void* xwin_graphics_event_loop(void*){
if (boinc_is_standalone()) {
set_mode(MODE_WINDOW);
} else {
set_mode(MODE_HIDE_GRAPHICS);
}
glutMainLoop();
return 0;
}
static void timer_handler() {
char buf[MSG_CHANNEL_SIZE];
int width, height, new_mode;
if (app_client_shm) {
if(app_client_shm->shm->graphics_request.get_msg(buf)){
new_mode = app_client_shm->decode_graphics_msg(buf);
switch(new_mode) {
case MODE_REREAD_PREFS:
//only reread graphics prefs if we have a window open
//
switch(current_graphics_mode){
case MODE_WINDOW:
case MODE_FULLSCREEN:
app_graphics_reread_prefs();
break;
}
break;
case MODE_HIDE_GRAPHICS:
case MODE_WINDOW:
case MODE_FULLSCREEN:
case MODE_BLANKSCREEN:
set_mode(new_mode);
break;
}
}
}
if (!visible) return;
if (current_graphics_mode == MODE_HIDE_GRAPHICS) return;
// TODO: remove width, height from API
//
width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);
if (throttled_app_render(width, height, dtime())) {
glutSwapBuffers();
// This callback is invoked when a user presses a key.
//
if (current_graphics_mode == MODE_FULLSCREEN) {
set_mode(MODE_HIDE_GRAPHICS);
}
}
#if 0
float txt_widths[256];
void onIdle(){
static double oldTime = 0;
double currentTime = dtime();
if (userclose == 1){
userclose = 0;
set_mode(MODE_HIDE_GRAPHICS);
}
if (currentTime - oldTime > .001){
timer_handler();
oldTime = currentTime;
}
}
#endif
static void make_new_window(int mode){
if (mode == MODE_WINDOW || mode == MODE_FULLSCREEN){
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(xpos, ypos);
glutInitWindowSize(gi.xsize, gi.ysize);
boinc_get_init_data(aid);
if (!strlen(aid.app_name)) {
strcpy(aid.app_name, "BOINC Application");
}
win = glutCreateWindow(aid.app_name);
glutReshapeFunc(app_graphics_resize);
glutKeyboardFunc(keyboardD);
glutKeyboardUpFunc(keyboardU);
glutMouseFunc(mouse_click);
glutMotionFunc(mouse_click_move);
glutDisplayFunc(timer_handler);
//glutIdleFunc(onIdle);
glutTimerFunc(30,
app_graphics_init();
glEnable(GL_DEPTH_TEST);
if (mode == MODE_FULLSCREEN) {
glutFullScreen();
}
}
}
void KillWindow() {
if (win) {
glutDestroyWindow(win);
win = 0;
}
}
void set_mode(int mode) {
if (mode == current_graphics_mode) return;
KillWindow();
current_graphics_mode = mode;
if (mode != MODE_HIDE_GRAPHICS) {
make_new_window(mode);
}
// tell the core client that we're entering new mode
//
if (app_client_shm) {
}
}
void* xwin_graphics_event_loop(void*){
if (boinc_is_standalone()) {
set_mode(MODE_WINDOW);
} else {
set_mode(MODE_HIDE_GRAPHICS);
}
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
glutMainLoop();
return 0;
}
static void timer_handler(int) {
char buf[MSG_CHANNEL_SIZE];
int width, height, new_mode;
if (app_client_shm) {
if (app_client_shm->shm->graphics_request.get_msg(buf)) {
new_mode = app_client_shm->decode_graphics_msg(buf);
switch (new_mode) {
case MODE_REREAD_PREFS:
//only reread graphics prefs if we have a window open
//
switch (current_graphics_mode){
case MODE_WINDOW:
case MODE_FULLSCREEN:
app_graphics_reread_prefs();
break;
}
break;
case MODE_HIDE_GRAPHICS:
case MODE_WINDOW:
case MODE_FULLSCREEN:
case MODE_BLANKSCREEN:
set_mode(new_mode);
break;
}
}
if (acked_graphics_mode != current_graphics_mode) {
bool sent = app_client_shm->shm->graphics_reply.send_msg(
xml_graphics_modes[current_graphics_mode]
);
if (sent) acked_graphics_mode = current_graphics_mode;
}
}
if (visible && (current_graphics_mode != MODE_HIDE_GRAPHICS) {
width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);
if (throttled_app_render(width, height, dtime())) {
glutSwapBuffers();
}
}
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
}

View File

@ -18339,3 +18339,10 @@ David 13 Oct 2004
cs_apps.C
lib/
prefs.C,h
David 13 Oct 2004
- initial cleanup of x_opengl.C
(e.g. use a timer instead of onIdle)
api/
x_opengl.C