add wraparound support to C2 physics
[openc2e.git] / SDLBackend.h
blob342165fc972805f24d9c14e74f8c43f7f954951e
1 /*
2 * SDLBackend.h
3 * openc2e
5 * Created by Alyssa Milburn on Sun Oct 24 2004.
6 * Copyright (c) 2004-2006 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #ifndef _SDLBACKEND_H
21 #define _SDLBACKEND_H
23 #include "SDL.h"
24 #include <SDL_net.h>
25 #include "Backend.h"
27 class SDLSurface : public Surface {
28 friend class SDLBackend;
30 protected:
31 class SDLBackend *parent;
32 SDL_Surface *surface;
33 unsigned int width, height;
34 SDL_Color palette[256];
36 SDLSurface(SDLBackend *p) { parent = p; }
38 public:
39 void render(shared_ptr<creaturesImage> image, unsigned int frame, int x, int y, bool trans = false, unsigned char transparency = 0, bool mirror = false, bool is_background = false);
40 void renderLine(int x1, int y1, int x2, int y2, unsigned int colour);
41 void renderText(int x, int y, std::string text, unsigned int colour, unsigned int bgcolour);
42 void blitSurface(Surface *src, int x, int y, int w, int h);
43 unsigned int getWidth() const { return width; }
44 unsigned int getHeight() const { return height; }
45 void renderDone();
48 class SDLBackend : public Backend {
49 friend class SDLSurface;
51 protected:
52 bool networkingup;
54 SDLSurface mainsurface;
55 TCPsocket listensocket;
57 struct _TTF_Font *basicfont;
59 void handleNetworking();
60 void resizeNotify(int _w, int _h);
61 int translateKey(int key);
63 SDL_Surface *getMainSDLSurface() { return mainsurface.surface; }
65 virtual int idealBpp();
67 public:
68 SDLBackend();
69 void init();
70 int networkInit();
71 void shutdown();
73 void resize(unsigned int w, unsigned int h) { resizeNotify(w, h); }
75 bool pollEvent(SomeEvent &e);
77 unsigned int ticks() { return SDL_GetTicks(); }
79 void handleEvents();
81 bool selfRender() { return false; }
82 void requestRender() { }
84 Surface *getMainSurface() { return &mainsurface; }
85 Surface *newSurface(unsigned int width, unsigned int height);
86 void freeSurface(Surface *surf);
87 unsigned int textWidth(std::string text);
89 bool keyDown(int key);
91 void setPalette(uint8 *data);
92 void delay(int msec);
95 #endif