/* -*- Objc -*- */ /* * $Id: UiSdl.m,v 1.1 2003/06/04 16:56:17 zaral Exp $ * * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GNU Hégémonie. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include "Interface/UiSdl.h" @implementation UiSdl /* private functions */ - (void) _handleKeyDown: (SDL_keysym *) keysym { switch (keysym->sym) { case SDLK_ESCAPE: exit (0); break; default: break; } } - (void) _processEvents { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: [self _handleKeyDown: &event.key.keysym]; break; case SDL_QUIT: exit (0); break; } } } - (void) mainLoop { while (1) { [self display]; [self _processEvents]; } } - (void) _sdlInit: (NSSize)screenSize { if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf (stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); exit (1); } SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); if (!SDL_SetVideoMode (screenSize.width, screenSize.height, 0, SDL_OPENGL))//| SDL_FULLSCREEN)) { fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError()); SDL_Quit(); exit(2); } glViewport (0, 0, screenSize.width, screenSize.height); } - (id) initWithScreenSize: (NSSize)size { self = [super init]; if (self != nil) { [self _sdlInit: size]; } return self; } - (void) setDelegate: (id)delegate { NSParameterAssert (delegate); ASSIGN(_delegate, delegate); } - (id) delegate { return _delegate; } - (void) forwardInvocation: (NSInvocation*)objectInvoke { if ([_delegate respondsToSelector: [objectInvoke selector]]) return [objectInvoke invokeWithTarget: _delegate]; else return [self doesNotRecognizeSelector: [objectInvoke selector]]; } @end