From: Matthias Braun Date: Sun, 1 May 2005 19:49:57 +0000 (+0000) Subject: forgot more stuff X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9e89407a97c5dfb035192387121e6102bc45a8fc;p=supertux.git forgot more stuff SVN-Revision: 2381 --- diff --git a/src/audio/musicref.cpp b/src/audio/musicref.cpp new file mode 100644 index 000000000..f3d47ea1a --- /dev/null +++ b/src/audio/musicref.cpp @@ -0,0 +1,70 @@ +// $Id: musicref.cpp 2168 2004-11-24 14:10:27Z matzebraun $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2000 Bill Kendrick +// Copyright (C) 2004 Matthias Braun +// +// 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 "audio/musicref.h" + +using namespace SuperTux; + +MusicRef::MusicRef() + : music(0) +{ +} + +MusicRef::MusicRef(SoundManager::MusicResource* newmusic) + : music(newmusic) +{ + if(music) + music->refcount++; +} + +MusicRef::~MusicRef() +{ + if(music) { + music->refcount--; + if(music->refcount == 0) + music->manager->free_music(music); + } +} + +MusicRef::MusicRef(const MusicRef& other) + : music(other.music) +{ + if(music) + music->refcount++; +} + +MusicRef& +MusicRef::operator =(const MusicRef& other) +{ + SoundManager::MusicResource* oldres = music; + music = other.music; + if(music) + music->refcount++; + if(oldres) { + oldres->refcount--; + if(oldres->refcount == 0) + music->manager->free_music(music); + } + + return *this; +} + diff --git a/src/audio/musicref.h b/src/audio/musicref.h new file mode 100644 index 000000000..98720cdca --- /dev/null +++ b/src/audio/musicref.h @@ -0,0 +1,45 @@ +// $Id: musicref.h 2168 2004-11-24 14:10:27Z matzebraun $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun +// +// 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. + +#ifndef SUPERTUX_MUSICREF_H +#define SUPERTUX_MUSICREF_H + +#include "sound_manager.h" + +/** This class holds a reference to a music file and maintains a correct + * refcount for that file. + */ +class MusicRef +{ +public: + MusicRef(); + MusicRef(const MusicRef& other); + ~MusicRef(); + + MusicRef& operator= (const MusicRef& other); + +private: + friend class SoundManager; + MusicRef(SoundManager::MusicResource* music); + + SoundManager::MusicResource* music; +}; + +#endif /*SUPERTUX_MUSICREF_H*/ + diff --git a/src/audio/semantic.cache b/src/audio/semantic.cache new file mode 100644 index 000000000..56637514e --- /dev/null +++ b/src/audio/semantic.cache @@ -0,0 +1,27 @@ +;; Object semantic.cache +;; SEMANTICDB Tags save file +(semanticdb-project-database "semantic.cache" + :file "semantic.cache" + :tables (list + (semanticdb-table "sound_manager.h" + :file "sound_manager.h" + :pointmax 3413 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_SOUND_MANAGER_H" variable nil nil ((const . t)) nil nil [915 950]) ("string" include t nil nil [949 966]) ("vector" include t nil nil [967 984]) ("map" include t nil nil [985 999]) ("SDL_mixer.h" include nil nil nil [1001 1023]) ("math/vector.h" include nil nil nil [1024 1048]) ("MusicRef" type "class" nil nil nil nil nil [1077 1092]) ("MovingObject" type "class" nil nil nil nil nil [1093 1112]) ("SoundManager" type "class" (("public" label ((reparse-symbol . classsubparts)) [1206 1213]) ("SoundManager" function ("SoundManager" type "class") nil ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1216 1231]) ("SoundManager" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1234 1250]) ("play_sound" function ("void") (("sound" variable ("std::string" type "class") nil ((const . t)) nil nil [1288 1313])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1272 1314]) ("play_sound" function ("void") (("sound" variable ("std::string" type "class") nil ((const . t)) nil nil [1375 1400]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [1401 1419]) ("pos2" variable ("Vector" type "class") nil ((const . t)) nil nil [1426 1445])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1359 1446]) ("play_sound" function ("void") (("sound" variable ("std::string" type "class") nil ((const . t)) nil nil [1523 1548]) ("object" variable ("MovingObject" type "class") nil ((const . t) (pointer . 1)) nil nil [1549 1576]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [1583 1601])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1507 1602]) ("load_music" function ("MusicRef" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [1699 1723])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1679 1724]) ("preload_sound" function ("Mix_Chunk" type "class") (("name" variable ("std::string" type "class") nil ((const . t)) nil nil [1934 1958])) ((pointer . 1) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1909 1959]) ("exists_music" function ("bool" type "class") (("filename" variable ("std::string" type "class") nil ((const . t)) nil nil [2024 2052])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2006 2053]) ("play_music" function ("void") (("music" variable ("MusicRef" type "class") nil ((const . t)) nil nil [2159 2181]) ("loops" variable "int" "-1" nil nil nil [2182 2196])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2143 2198]) ("halt_music" function ("void") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2220 2238]) ("enable_music" function ("void") (("enable" variable ("bool" type "class") nil nil nil nil [2288 2300])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2270 2301]) ("music_enabled" function ("bool" type "class") nil nil nil ((reparse-symbol . classsubparts)) [2329 2385]) ("enable_sound" function ("void") (("enable" variable ("bool" type "class") nil nil nil nil [2435 2447])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2417 2448]) ("sound_enabled" function ("bool" type "class") nil nil nil ((reparse-symbol . classsubparts)) [2476 2532]) ("audio_device_available" function ("bool" type "class") nil nil nil ((reparse-symbol . classsubparts)) [2562 2624]) ("set_audio_device_available" function ("void") (("available" variable ("bool" type "class") nil nil nil nil [2660 2675])) nil nil ((reparse-symbol . classsubparts)) [2628 2713]) ("private" label ((reparse-symbol . classsubparts)) [2715 2723]) ("MusicRef" type "class" nil nil nil nil ((reparse-symbol . classsubparts)) [2733 2748]) ("Setup" type "class" nil nil nil nil ((reparse-symbol . classsubparts)) [2758 2770]) ("MusicResource" type "class" (("public" label ((reparse-symbol . classsubparts)) [2927 2934]) ("MusicResource" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2941 2958]) ("manager" variable ("SoundManager" type "class") nil ((pointer . 1)) nil nil [2966 2988]) ("music" variable ("Mix_Music" type "class") nil ((pointer . 1)) nil nil [2995 3012]) ("refcount" variable "int" nil nil nil nil [3019 3032])) nil nil nil ((reparse-symbol . classsubparts)) [2897 3039]) ("free_music" function ("void") (("music" variable ("MusicResource" type "class") nil ((pointer . 1)) nil nil [3059 3080])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3043 3081]) ("Sounds" type "typedef" nil ("std::map") ((typedef "std::map" type "class")) nil nil [3085 3134]) ("sounds" variable ("Sounds" type "class") nil nil nil nil [3137 3151]) ("Musics" type "typedef" nil ("std::map") ((typedef "std::map" type "class")) nil nil [3155 3207]) ("musics" variable ("Musics" type "class") nil nil nil nil [3210 3224]) ("current_music" variable ("MusicResource" type "class") nil ((pointer . 1)) nil nil [3228 3257]) ("m_music_enabled" variable ("bool" type "class") nil nil nil nil [3260 3281]) ("m_sound_enabled" variable ("bool" type "class") nil nil nil nil [3284 3305]) ("audio_device" variable ("bool" type "class") nil nil nil nil [3308 3326])) nil nil nil nil [1185 3374])) + :unmatched-syntax 'nil + ) + (semanticdb-table "musicref.h" + :file "musicref.h" + :pointmax 1371 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_MUSICREF_H" variable nil nil ((const . t)) nil nil [907 937]) ("sound_manager.h" include nil nil nil [936 962]) ("SuperTux" type "namespace" (("MusicRef" type "class" (("public" label ((reparse-symbol . classsubparts)) [1085 1092]) ("MusicRef" function ("MusicRef" type "class") nil ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1093 1106]) ("MusicRef" function ("MusicRef" type "class") (("other" variable ("MusicRef" type "class") nil ((const . t)) nil nil [1118 1140])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1107 1141]) ("MusicRef" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1142 1156]) ("=" function ("MusicRef" type "class") (("other" variable ("MusicRef" type "class") nil ((const . t)) nil nil [1183 1205])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1160 1206]) ("private" label ((reparse-symbol . classsubparts)) [1208 1216]) ("SoundManager" type "class" nil nil nil nil ((reparse-symbol . classsubparts)) [1226 1245]) ("MusicRef" function ("MusicRef" type "class") (("music" variable ("SoundManager::MusicResource" type "class") nil ((pointer . 1)) nil nil [1257 1292])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1246 1293]) ("music" variable ("SoundManager::MusicResource" type "class") nil ((pointer . 1)) nil nil [1297 1334])) nil nil nil ((reparse-symbol . namespacesubparts)) [1068 1337])) nil nil nil nil [964 1338])) + ) + (semanticdb-table "sound_manager.cpp" + :file "sound_manager.cpp" + :pointmax 5703 + :major-mode 'c++-mode + :tokens '(("config.h" include t nil nil [882 901]) ("cmath" include t nil nil [903 919]) ("cassert" include t nil nil [920 938]) ("sstream" include t nil nil [960 978]) ("audio/sound_manager.h" include nil nil nil [980 1012]) ("audio/musicref.h" include nil nil nil [1013 1040]) ("app/globals.h" include nil nil nil [1041 1065]) ("app/setup.h" include nil nil nil [1066 1088]) ("moving_object.h" include nil nil nil [1089 1115]) ("resources.h" include nil nil nil [1116 1138]) ("SoundManager" function ("SoundManager" type "class") nil ((parent . "SoundManager") (constructor . t)) nil nil [1167 1292]) ("SoundManager" function "void" nil ((parent . "SoundManager") (destructor . t)) nil nil [1294 1448]) ("play_sound" function ("void") (("name" variable ("std::string" type "class") nil ((const . t)) nil nil [1480 1504])) ((parent . "SoundManager")) nil nil [1450 1731]) ("play_sound" function ("void") (("sound" variable ("std::string" type "class") nil ((const . t)) nil nil [1763 1788]) ("object" variable ("MovingObject" type "class") nil ((const . t) (pointer . 1)) nil nil [1789 1816]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [1821 1839])) ((parent . "SoundManager")) nil nil [1733 1976]) ("play_sound" function ("void") (("sound" variable ("std::string" type "class") nil ((const . t)) nil nil [2008 2033]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [2034 2052]) ("pos2" variable ("Vector" type "class") nil ((const . t)) nil nil [2057 2076])) ((parent . "SoundManager")) nil nil [1978 2777]) ("load_music" function ("MusicRef" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [2813 2837])) ((parent . "SoundManager")) nil nil [2779 3197]) ("exists_music" function ("bool" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [3231 3255])) ((parent . "SoundManager")) nil nil [3199 3885]) ("free_music" function ("void") (("" variable ("MusicResource" type "class") nil ((pointer . 1)) nil nil [3917 3933])) ((parent . "SoundManager")) nil nil [3887 4069]) ("play_music" function ("void") (("musicref" variable ("MusicRef" type "class") nil ((const . t)) nil nil [4101 4126]) ("loops" variable "int" nil nil nil nil [4127 4137])) ((parent . "SoundManager")) nil nil [4071 4438]) ("halt_music" function ("void") nil ((parent . "SoundManager")) nil nil [4440 4682]) ("enable_music" function ("void") (("enable" variable ("bool" type "class") nil nil nil nil [4716 4728])) ((parent . "SoundManager")) nil nil [4684 4978]) ("enable_sound" function ("void") (("enable" variable ("bool" type "class") nil nil nil nil [5012 5024])) ((parent . "SoundManager")) nil nil [4980 5091]) ("MusicResource" function "void" nil ((parent . "SoundManager::MusicResource") (destructor . t)) nil nil [5093 5233]) ("preload_sound" function ("Mix_Chunk" type "class") (("name" variable ("std::string" type "class") nil ((const . t)) nil nil [5274 5298])) ((parent . "SoundManager") (pointer . 1)) nil nil [5235 5701])) + :unmatched-syntax 'nil + ) + ) + ) diff --git a/src/audio/sound_manager.cpp b/src/audio/sound_manager.cpp new file mode 100644 index 000000000..c7e624aee --- /dev/null +++ b/src/audio/sound_manager.cpp @@ -0,0 +1,245 @@ +// $Id: sound_manager.cpp 2334 2005-04-04 16:26:14Z grumbel $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun + +#include +#include +#include +#include + +#include "audio/sound_manager.h" +#include "audio/musicref.h" +#include "app/globals.h" +#include "app/setup.h" +#include "moving_object.h" +#include "resources.h" + +using namespace SuperTux; + +SoundManager::SoundManager() + : current_music(0), m_music_enabled(true) , m_sound_enabled(true), + audio_device(false) +{ +} + +SoundManager::~SoundManager() +{ + for(Sounds::iterator i = sounds.begin(); i != sounds.end(); ++i) { + Mix_FreeChunk(i->second); + } + sounds.clear(); +} + +void +SoundManager::play_sound(const std::string& name) +{ + if(!audio_device || !m_sound_enabled) + return; + + Mix_Chunk* chunk = preload_sound(name); + if(chunk == 0) { + std::cerr << "Sound '" << name << "' not found.\n"; + return; + } + Mix_PlayChannel(-1, chunk, 0); +} + +void +SoundManager::play_sound(const std::string& sound, const MovingObject* object, + const Vector& pos) +{ + // TODO keep track of the object later and move the sound along with the + // object. + play_sound(sound, object->get_pos(), pos); +} + +void +SoundManager::play_sound(const std::string& sound, const Vector& pos, + const Vector& pos2) +{ + if(!audio_device || !m_sound_enabled) + return; + + Mix_Chunk* chunk = preload_sound(sound); + if(chunk == 0) { + std::cerr << "Sound '" << sound << "' not found.\n"; + return; + } + + // TODO make sure this formula is good + float distance + = pos2.x- pos.x; + int loud = int(255.0/float(SCREEN_WIDTH*2) * fabsf(distance)); + if(loud > 255) + return; + + int chan = Mix_PlayChannel(-1, chunk, 0); + if(chan < 0) + return; + Mix_SetDistance(chan, loud); + + // very bad way to do this... + if(distance > 100) + Mix_SetPanning(chan, 230, 24); + else if(distance < -100) + Mix_SetPanning(chan, 24, 230); +} + +MusicRef +SoundManager::load_music(const std::string& file) +{ + if(!audio_device) + return MusicRef(0); + + if(!exists_music(file)) { + std::stringstream msg; + msg << "Couldn't load musicfile '" << file << "': " << SDL_GetError(); + throw std::runtime_error(msg.str()); + } + + std::map::iterator i = musics.find(file); + assert(i != musics.end()); + return MusicRef(& (i->second)); +} + +bool +SoundManager::exists_music(const std::string& file) +{ + if(!audio_device) + return true; + + // song already loaded? + std::map::iterator i = musics.find(file); + if(i != musics.end()) { + return true; + } + + Mix_Music* song = Mix_LoadMUS(file.c_str()); + if(song == 0) + return false; + + // insert into music list + std::pair::iterator, bool> result = + musics.insert( + std::make_pair (file, MusicResource())); + MusicResource& resource = result.first->second; + resource.manager = this; + resource.music = song; + + return true; +} + +void +SoundManager::free_music(MusicResource* ) +{ + // TODO free music, currently we can't do this since SDL_mixer seems to have + // some bugs if you load/free alot of mod files. +} + +void +SoundManager::play_music(const MusicRef& musicref, int loops) +{ + if(!audio_device) + return; + + if(musicref.music == 0 || current_music == musicref.music) + return; + + if(current_music) + current_music->refcount--; + + current_music = musicref.music; + current_music->refcount++; + + if(m_music_enabled) + Mix_PlayMusic(current_music->music, loops); +} + +void +SoundManager::halt_music() +{ + if(!audio_device) + return; + + Mix_HaltMusic(); + + if(current_music) { + current_music->refcount--; + if(current_music->refcount == 0) + free_music(current_music); + current_music = 0; + } +} + +void +SoundManager::enable_music(bool enable) +{ + if(!audio_device) + return; + + if(enable == m_music_enabled) + return; + + m_music_enabled = enable; + if(m_music_enabled == false) { + Mix_HaltMusic(); + } else { + if(current_music) + Mix_PlayMusic(current_music->music, -1); + } +} + +void +SoundManager::enable_sound(bool enable) +{ + if(!audio_device) + return; + + m_sound_enabled = enable; +} + +SoundManager::MusicResource::~MusicResource() +{ + // don't free music buggy SDL_Mixer crashs for some mod files + // Mix_FreeMusic(music); +} + +Mix_Chunk* SoundManager::preload_sound(const std::string& name) +{ + if(!audio_device) + return 0; + + Sounds::iterator i = sounds.find(name); + if(i != sounds.end()) { + return i->second; + } + + std::string filename = "sounds/"; + filename += name; + filename += ".wav"; + filename = get_resource_filename(filename); + + Mix_Chunk* chunk = Mix_LoadWAV(filename.c_str()); + if(chunk != 0) { + sounds.insert(std::make_pair(name, chunk)); + } + + return chunk; +} + diff --git a/src/audio/sound_manager.h b/src/audio/sound_manager.h new file mode 100644 index 000000000..d0ddad5cd --- /dev/null +++ b/src/audio/sound_manager.h @@ -0,0 +1,137 @@ +// $Id: sound_manager.h 2353 2005-04-06 23:00:16Z matzebraun $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun +#include +#include + +#include "SDL_mixer.h" +#include "math/vector.h" + +using namespace SuperTux; + +class MusicRef; +class MovingObject; + +/** Sound manager + * This class handles all sounds that are played + */ +class SoundManager +{ +public: + SoundManager(); + ~SoundManager(); + + /// Play sound. + void play_sound(const std::string& sound); + /// Play sound relative to two Vectors. + void play_sound(const std::string& sound, const Vector& pos, + const Vector& pos2); + /// Play sound relative to a MovingObject and a Vector. + void play_sound(const std::string& sound, const MovingObject* object, + const Vector& pos); + + /** Load music. + * Is used to load the music for a MusicRef. + */ + MusicRef load_music(const std::string& file); + + /** + * If the sound isn't loaded yet try to load it. + * Returns an existing instance of the sound, loads a new one and returns that + * or returns 0 if loading failed. + */ + Mix_Chunk* preload_sound(const std::string& name); + + /// Test if a certain music file exists. + bool exists_music(const std::string& filename); + + /** Play music. + * @param loops: Defaults to -1, which means endless loops. + */ + void play_music(const MusicRef& music, int loops = -1); + + /// Halt music. + void halt_music(); + + /// Enable/Disable music. + void enable_music(bool enable); + + /// Is music enabled? + bool music_enabled() + { + return m_music_enabled; + } + + /// Enable/Disable sound. + void enable_sound(bool enable); + + /// Is sound enabled? + bool sound_enabled() + { + return m_sound_enabled; + } + + /// Is audio available? + bool audio_device_available() + { + return audio_device; + } + + void set_audio_device_available(bool available) + { + audio_device = available; + } + +private: + friend class MusicRef; + friend class Setup; + + /// Resource for music. + /** Contains the raw music data and + information for music reference + counting. */ + class MusicResource + { + public: + ~MusicResource(); + + SoundManager* manager; + Mix_Music* music; + int refcount; + }; + + void free_music(MusicResource* music); + + typedef std::map Sounds; + Sounds sounds; + + typedef std::map Musics; + Musics musics; + + MusicResource* current_music; + bool m_music_enabled; + bool m_sound_enabled; + bool audio_device; /* true: available and initialized */ +}; + +#endif /*SUPERTUX_SOUND_MANAGER_H*/ + diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp new file mode 100644 index 000000000..66c1fa153 --- /dev/null +++ b/src/video/drawing_context.cpp @@ -0,0 +1,409 @@ +// $Id: drawing_context.cpp 2334 2005-04-04 16:26:14Z grumbel $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun + +#include +#include +#include + +#include "drawing_context.h" +#include "surface.h" +#include "app/globals.h" +#include "font.h" +#include "gameconfig.h" + +using namespace SuperTux; + +DrawingContext::DrawingContext(SDL_Surface* targetsurface) +{ + if(targetsurface) { + screen = targetsurface; + } else { + screen = SDL_GetVideoSurface(); + } +} + +DrawingContext::~DrawingContext() +{ +} + +void +DrawingContext::draw_surface(const Surface* surface, const Vector& position, + int layer, uint32_t drawing_effect) +{ + assert(surface != 0); + + DrawingRequest request; + + request.type = SURFACE; + request.pos = transform.apply(position); + + if(request.pos.x >= SCREEN_WIDTH || request.pos.y >= SCREEN_HEIGHT + || request.pos.x + surface->w < 0 || request.pos.y + surface->h < 0) + return; + + request.layer = layer; + request.drawing_effect = transform.drawing_effect | drawing_effect; + request.zoom = transform.zoom; + request.alpha = transform.alpha; + request.request_data = const_cast (surface); + + drawingrequests.push_back(request); +} + +void +DrawingContext::draw_surface_part(const Surface* surface, const Vector& source, + const Vector& size, const Vector& dest, int layer, uint32_t drawing_effect) +{ + assert(surface != 0); + + DrawingRequest request; + + request.type = SURFACE_PART; + request.pos = transform.apply(dest); + request.layer = layer; + request.drawing_effect = transform.drawing_effect | drawing_effect; + request.alpha = transform.alpha; + + SurfacePartRequest* surfacepartrequest = new SurfacePartRequest(); + surfacepartrequest->size = size; + surfacepartrequest->source = source; + surfacepartrequest->surface = surface; + + // clip on screen borders + if(request.pos.x < 0) { + surfacepartrequest->size.x += request.pos.x; + if(surfacepartrequest->size.x <= 0) + return; + surfacepartrequest->source.x -= request.pos.x; + request.pos.x = 0; + } + if(request.pos.y < 0) { + surfacepartrequest->size.y += request.pos.y; + if(surfacepartrequest->size.y <= 0) + return; + surfacepartrequest->source.y -= request.pos.y; + request.pos.y = 0; + } + request.request_data = surfacepartrequest; + + drawingrequests.push_back(request); +} + +void +DrawingContext::draw_text(const Font* font, const std::string& text, + const Vector& position, FontAlignment alignment, int layer, + uint32_t drawing_effect) +{ + DrawingRequest request; + + request.type = TEXT; + request.pos = transform.apply(position); + request.layer = layer; + request.drawing_effect = transform.drawing_effect | drawing_effect; + request.zoom = transform.zoom; + request.alpha = transform.alpha; + + TextRequest* textrequest = new TextRequest; + textrequest->font = font; + textrequest->text = text; + textrequest->alignment = alignment; + request.request_data = textrequest; + + drawingrequests.push_back(request); +} + +void +DrawingContext::draw_center_text(const Font* font, const std::string& text, + const Vector& position, int layer, uint32_t drawing_effect) +{ + draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y), + CENTER_ALLIGN, layer, drawing_effect); +} + +void +DrawingContext::draw_gradient(Color top, Color bottom, int layer) +{ + DrawingRequest request; + + request.type = GRADIENT; + request.pos = Vector(0,0); + request.layer = layer; + + request.drawing_effect = transform.drawing_effect; + request.zoom = transform.zoom; + request.alpha = transform.alpha; + + GradientRequest* gradientrequest = new GradientRequest; + gradientrequest->top = top; + gradientrequest->bottom = bottom; + request.request_data = gradientrequest; + + drawingrequests.push_back(request); +} + +void +DrawingContext::draw_filled_rect(const Vector& topleft, const Vector& size, + Color color, int layer) +{ + DrawingRequest request; + + request.type = FILLRECT; + request.pos = transform.apply(topleft); + request.layer = layer; + + request.drawing_effect = transform.drawing_effect; + request.zoom = transform.zoom; + request.alpha = transform.alpha; + + FillRectRequest* fillrectrequest = new FillRectRequest; + fillrectrequest->size = size; + fillrectrequest->color = color; + request.request_data = fillrectrequest; + + drawingrequests.push_back(request); +} + +void +DrawingContext::draw_surface_part(DrawingRequest& request) +{ + SurfacePartRequest* surfacepartrequest + = (SurfacePartRequest*) request.request_data; + + surfacepartrequest->surface->impl->draw_part( + surfacepartrequest->source.x, surfacepartrequest->source.y, + request.pos.x, request.pos.y, + surfacepartrequest->size.x, surfacepartrequest->size.y, request.alpha, + request.drawing_effect); + + delete surfacepartrequest; +} + +void +DrawingContext::draw_gradient(DrawingRequest& request) +{ + GradientRequest* gradientrequest = (GradientRequest*) request.request_data; + const Color& top = gradientrequest->top; + const Color& bottom = gradientrequest->bottom; + +#ifndef NOOPENGL + if(config->use_gl) + { + glBegin(GL_QUADS); + glColor3ub(top.red, top.green, top.blue); + glVertex2f(0, 0); + glVertex2f(SCREEN_WIDTH, 0); + glColor3ub(bottom.red, bottom.green, bottom.blue); + glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT); + glVertex2f(0, SCREEN_HEIGHT); + glEnd(); + } + else + { +#endif + if(&top == &bottom) + { + fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, top.red, top.green, top.blue); + } + else + { + float redstep = (float(bottom.red)-float(top.red)) / float(SCREEN_HEIGHT); + float greenstep = (float(bottom.green)-float(top.green)) / float(SCREEN_HEIGHT); + float bluestep = (float(bottom.blue) - float(top.blue)) / float(SCREEN_HEIGHT); + + for(float y = 0; y < SCREEN_HEIGHT; y += 2) + fillrect(0, (int)y, SCREEN_WIDTH, 2, + int(float(top.red) + redstep * y), + int(float(top.green) + greenstep * y), + int(float(top.blue) + bluestep * y), 255); + } +#ifndef NOOPENGL + + } +#endif + + delete gradientrequest; +} + +void +DrawingContext::draw_text(DrawingRequest& request) +{ + TextRequest* textrequest = (TextRequest*) request.request_data; + + textrequest->font->draw(textrequest->text, request.pos, + textrequest->alignment, request.drawing_effect, request.alpha); + + delete textrequest; +} + +void +DrawingContext::draw_filled_rect(DrawingRequest& request) +{ + FillRectRequest* fillrectrequest = (FillRectRequest*) request.request_data; + + float x = request.pos.x; + float y = request.pos.y; + float w = fillrectrequest->size.x; + float h = fillrectrequest->size.y; + +#ifndef NOOPENGL + if(config->use_gl) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4ub(fillrectrequest->color.red, fillrectrequest->color.green, + fillrectrequest->color.blue, fillrectrequest->color.alpha); + + glBegin(GL_POLYGON); + glVertex2f(x, y); + glVertex2f(x+w, y); + glVertex2f(x+w, y+h); + glVertex2f(x, y+h); + glEnd(); + glDisable(GL_BLEND); + } + else + { +#endif + SDL_Rect src, rect; + SDL_Surface *temp = NULL; + + rect.x = (int)x; + rect.y = (int)y; + rect.w = (int)w; + rect.h = (int)h; + + if(fillrectrequest->color.alpha != 255) + { + temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, + screen->format->Rmask, + screen->format->Gmask, + screen->format->Bmask, + screen->format->Amask); + + + src.x = 0; + src.y = 0; + src.w = rect.w; + src.h = rect.h; + + SDL_FillRect(temp, &src, SDL_MapRGB(screen->format, + fillrectrequest->color.red, fillrectrequest->color.green, + fillrectrequest->color.blue)); + + SDL_SetAlpha(temp, SDL_SRCALPHA, fillrectrequest->color.alpha); + + SDL_BlitSurface(temp,0,screen,&rect); + + SDL_FreeSurface(temp); + } + else + SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, + fillrectrequest->color.red, fillrectrequest->color.green, + fillrectrequest->color.blue)); + +#ifndef NOOPENGL + + } +#endif + + delete fillrectrequest; +} + +void +DrawingContext::do_drawing() +{ +#ifdef DEBUG + assert(transformstack.empty()); +#endif + transformstack.clear(); + + std::stable_sort(drawingrequests.begin(), drawingrequests.end()); + + for(DrawingRequests::iterator i = drawingrequests.begin(); + i != drawingrequests.end(); ++i) { + switch(i->type) { + case SURFACE: + { + const Surface* surface = (const Surface*) i->request_data; + + if(i->zoom != 1.0) + surface->impl->draw_stretched(i->pos.x * i->zoom, i->pos.y * i->zoom, + (int)(surface->w * i->zoom), (int)(surface->h * i->zoom), + i->alpha, i->drawing_effect); + else + surface->impl->draw(i->pos.x, i->pos.y, i->alpha, i->drawing_effect); + break; + } + case SURFACE_PART: + draw_surface_part(*i); + break; + case GRADIENT: + draw_gradient(*i); + break; + case TEXT: + draw_text(*i); + break; + case FILLRECT: + draw_filled_rect(*i); + break; + } + } + + // update screen + if(config->use_gl) + SDL_GL_SwapBuffers(); + else + SDL_Flip(screen); + + drawingrequests.clear(); +} + +void +DrawingContext::push_transform() +{ + transformstack.push_back(transform); +} + +void +DrawingContext::pop_transform() +{ + assert(!transformstack.empty()); + + transform = transformstack.back(); + transformstack.pop_back(); +} + +void +DrawingContext::set_drawing_effect(int effect) +{ + transform.drawing_effect = effect; +} + +void +DrawingContext::set_zooming(float zoom) +{ + transform.zoom = zoom; +} + +void +DrawingContext::set_alpha(int alpha) +{ + transform.alpha = alpha; +} diff --git a/src/video/drawing_context.h b/src/video/drawing_context.h new file mode 100644 index 000000000..0aa7cec2c --- /dev/null +++ b/src/video/drawing_context.h @@ -0,0 +1,190 @@ +// $Id: drawing_context.h 2334 2005-04-04 16:26:14Z grumbel $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2004 Matthias Braun +#include +#include + +#include + +#include "math/vector.h" +#include "video/screen.h" +#include "video/surface.h" +#include "video/font.h" + +using namespace SuperTux; + +class Surface; + +// some constants for predefined layer values +enum { + LAYER_BACKGROUND0 = -300, + LAYER_BACKGROUND1 = -200, + LAYER_BACKGROUNDTILES = -100, + LAYER_TILES = 0, + LAYER_OBJECTS = 100, + LAYER_FOREGROUNDTILES = 200, + LAYER_FOREGROUND0 = 300, + LAYER_FOREGROUND1 = 400, + LAYER_GUI = 500 +}; + +/// Handles drawing of things. +/** + * This class provides functions for drawing things on screen. It also + * maintains a stack of transforms that are applied to graphics. + */ +class DrawingContext +{ +public: + DrawingContext(SDL_Surface* targetsurface = 0); + ~DrawingContext(); + + /// Adds a drawing request for a surface into the request list. + void draw_surface(const Surface* surface, const Vector& position, + int layer, uint32_t drawing_effect = NONE_EFFECT); + /// Adds a drawing request for part of a surface. + void draw_surface_part(const Surface* surface, const Vector& source, + const Vector& size, const Vector& dest, int layer, + uint32_t drawing_effect = NONE_EFFECT); + /// Draws a text. + void draw_text(const Font* font, const std::string& text, + const Vector& position, FontAlignment alignment, int layer, + uint32_t drawing_effect = NONE_EFFECT); + + /// Draws text on screen center (feed Vector.x with a 0). + /// This is the same as draw_text() with a SCREEN_WIDTH/2 position and + /// alignment set to LEFT_ALLIGN + void draw_center_text(const Font* font, const std::string& text, + const Vector& position, int layer, + uint32_t drawing_effect = NONE_EFFECT); + /// Draws a color gradient onto the whole screen */ + void draw_gradient(Color from, Color to, int layer); + /// Fills a rectangle. + void draw_filled_rect(const Vector& topleft, const Vector& size, + Color color, int layer); + + /// Processes all pending drawing requests and flushes the list. + void do_drawing(); + + const Vector& get_translation() const + { return transform.translation; } + uint32_t get_drawing_effect() const + { return transform.drawing_effect; } + + void set_translation(const Vector& newtranslation) + { transform.translation = newtranslation; } + + void push_transform(); + void pop_transform(); + + /// Apply that effect in the next draws (effects are listed on surface.h). + void set_drawing_effect(int effect); + /// apply that zoom in the next draws */ + void set_zooming(float zoom); + /// apply that alpha in the next draws */ + void set_alpha(int alpha); + +private: + class Transform + { + public: + Vector translation; + uint32_t drawing_effect; + float zoom; + int alpha; + + Transform() + : drawing_effect(NONE_EFFECT), zoom(1), alpha(255) + { } + + Vector apply(const Vector& v) const + { + return v - translation; + } + }; + + /// the transform stack + std::vector transformstack; + /// the currently active transform + Transform transform; + + enum RequestType + { + SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT + }; + + struct SurfacePartRequest + { + const Surface* surface; + Vector source, size; + }; + + struct TextRequest + { + const Font* font; + std::string text; + FontAlignment alignment; + }; + + struct GradientRequest + { + Color top, bottom; + Vector size; + }; + + struct FillRectRequest + { + Color color; + Vector size; + }; + + struct DrawingRequest + { + RequestType type; + Vector pos; + + int layer; + uint32_t drawing_effect; + float zoom; + int alpha; + + void* request_data; + + bool operator<(const DrawingRequest& other) const + { + return layer < other.layer; + } + }; + + void draw_surface_part(DrawingRequest& request); + void draw_text(DrawingRequest& request); + void draw_text_center(DrawingRequest& request); + void draw_gradient(DrawingRequest& request); + void draw_filled_rect(DrawingRequest& request); + + typedef std::vector DrawingRequests; + DrawingRequests drawingrequests; + + SDL_Surface* screen; +}; + +#endif diff --git a/src/video/font.cpp b/src/video/font.cpp new file mode 100644 index 000000000..3d2c8ca09 --- /dev/null +++ b/src/video/font.cpp @@ -0,0 +1,196 @@ +// $Id: font.cpp 2298 2005-03-30 12:01:02Z matzebraun $ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser +// +// 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 "app/globals.h" +#include "lisp/parser.h" +#include "lisp/lisp.h" +#include "screen.h" +#include "font.h" +#include "drawing_context.h" + +using namespace SuperTux; + +Font::Font(const std::string& file, FontType ntype, int nw, int nh, + int nshadowsize) + : chars(0), shadow_chars(0), type(ntype), w(nw), h(nh), + shadowsize(nshadowsize) +{ + chars = new Surface(file, true); + + switch(type) { + case TEXT: + first_char = 32; + break; + case NUM: + first_char = 48; + break; + } + last_char = first_char + (chars->h / h) * 16; + if(last_char > 127) // we have left out some control chars at 128-159 + last_char += 32; + + // Load shadow font. + if(shadowsize > 0) { + SDL_Surface* conv = SDL_DisplayFormatAlpha(chars->impl->get_sdl_surface()); + int pixels = conv->w * conv->h; + SDL_LockSurface(conv); + for(int i = 0; i < pixels; ++i) { + Uint32 *p = (Uint32 *)conv->pixels + i; + *p = *p & conv->format->Amask; + } + SDL_UnlockSurface(conv); + SDL_SetAlpha(conv, SDL_SRCALPHA, 128); + shadow_chars = new Surface(conv, true); + SDL_FreeSurface(conv); + } +} + +Font::~Font() +{ + delete chars; + delete shadow_chars; +} + +float +Font::get_text_width(const std::string& text) const +{ + /** Let's calculate the size of the biggest paragraph */ + std::string::size_type l, hl, ol; + hl = 0; l = 0; + while(true) + { + ol = l; + l = text.find("\n", l+1); + if(l == std::string::npos) + break; + if(hl < l-ol) + hl = l-ol; + } + if(hl == 0) + hl = text.size(); + + return hl * w; +} + +float +Font::get_text_height(const std::string& text) const +{ + /** Let's calculate height of the text */ + std::string::size_type l, hh; + hh = h; l = 0; + while(true) + { + l = text.find("\n", l+1); + if(l == std::string::npos) + break; + hh += h + 2; + } + + return hh; +} + +float +Font::get_height() const +{ + return h; +} + +void +Font::draw(const std::string& text, const Vector& pos_, FontAlignment alignment, + uint32_t drawing_effect, uint8_t alpha) const +{ + /* Cut lines changes into seperate strings, needed to support center/right text + alignments with break lines. + Feel free to replace this hack with a more elegant solution + */ + char temp[1024]; + std::string::size_type l, i, y; + bool done = false; + i = y = 0; + + while(!done) { + l = text.find("\n", i); + if(l == std::string::npos) { + l = text.size(); + done = true; + } + + temp[text.copy(temp, l - i, i)] = '\0'; + + // calculate X positions based on the alignment type + Vector pos = Vector(pos_); + if(alignment == CENTER_ALLIGN) + pos.x -= get_text_width(temp) / 2; + else if(alignment == RIGHT_ALLIGN) + pos.x -= get_text_width(temp); + + draw_text(temp, pos + Vector(0,y), drawing_effect, alpha); + + i = l+1; + y += h + 2; + } +} + +void +Font::draw_text(const std::string& text, const Vector& pos, + uint32_t drawing_effect, uint8_t alpha) const +{ + if(shadowsize > 0) + draw_chars(shadow_chars, text, pos + Vector(shadowsize, shadowsize), + drawing_effect, alpha); + + draw_chars(chars, text, pos, drawing_effect, alpha); +} + +void +Font::draw_chars(Surface* pchars, const std::string& text, const Vector& pos, + uint32_t drawing_effect, uint8_t alpha) const +{ + SurfaceImpl* impl = pchars->impl; + + Vector p = pos; + for(size_t i = 0; i < text.size(); ++i) { + int c = (unsigned char) text[i]; + if(c > 127) // correct for the 32 controlchars at 128-159 + c -= 32; + // a non-printable character? + if(c == '\n') { + p.x = pos.x; + p.y += h + 2; + continue; + } + if(c == ' ' || c < first_char || c > last_char) { + p.x += w; + continue; + } + + int index = c - first_char; + int source_x = (index % 16) * w; + int source_y = (index / 16) * h; + + impl->draw_part(source_x, source_y, p.x, p.y, w, h, alpha, drawing_effect); + p.x += w; + } +} diff --git a/src/video/font.h b/src/video/font.h new file mode 100644 index 000000000..9d2db0ef8 --- /dev/null +++ b/src/video/font.h @@ -0,0 +1,93 @@ +// $Id: font.h 2298 2005-03-30 12:01:02Z matzebraun $ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser +// +// 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. +#ifndef SUPERTUX_FONT_H +#define SUPERTUX_FONT_H + +#include +#include + +#include "video/surface.h" +#include "math/vector.h" + +enum FontAlignment { + LEFT_ALLIGN, + CENTER_ALLIGN, + RIGHT_ALLIGN +}; + +class Font +{ +public: + enum FontType { + TEXT, // images for all characters + NUM // only images for numbers + }; + + Font(const std::string& file, FontType type, int w, int h, + int shadowsize=2); + ~Font(); + + /** returns the width of a given text. (Note that I won't add a normal + * get_width function here, as we might switch to variable width fonts in the + * future.) + * Supports breaklines. + */ + float get_text_width(const std::string& text) const; + + /** returns the height of a given text. (Note that I won't add a normal + * get_width function here, as we might switch to variable width fonts in the + * future.) + * Supports breaklines. + * In case, you are positive that your text doesn't use break lines, you can + * just use get_height(). + */ + float get_text_height(const std::string& text) const; + /// returns the height of the font. + float get_height() const; + + /** Draws the given text to the screen. Also needs the position. + * Type of alignment, drawing effect and alpha are optional. */ + void draw(const std::string& text, const Vector& pos, + FontAlignment allignment = LEFT_ALLIGN, + uint32_t drawing_effect = NONE_EFFECT, uint8_t alpha = 255) const; + +private: + friend class DrawingContext; + + void draw_text(const std::string& text, const Vector& pos, + uint32_t drawing_effect = NONE_EFFECT, uint8_t alpha = 255) const; + + void draw_chars(Surface* pchars, const std::string& text, + const Vector& position, uint32_t drawing_effect, uint8_t alpha) const; + + Surface* chars; + Surface* shadow_chars; + FontType type; + int w; + int h; + int shadowsize; + + /// the number of the first character that is represented in the font + int first_char; + /// the number of the last character that is represented in the font + int last_char; +}; + +#endif diff --git a/src/video/screen.cpp b/src/video/screen.cpp new file mode 100644 index 000000000..3ddd9b3f6 --- /dev/null +++ b/src/video/screen.cpp @@ -0,0 +1,302 @@ +// $Id: screen.cpp 2334 2005-04-04 16:26:14Z grumbel $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2000 Bill Kendrick +// +// 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 + +#include + +#include +#include + +#ifndef WIN32 +#include +#include +#endif + +#include "gameconfig.h" +#include "screen.h" +#include "app/globals.h" +#include "video/drawing_context.h" +#include "math/vector.h" + +static const float LOOP_DELAY = 20.0; +extern SDL_Surface* screen; + +using namespace SuperTux; + +/* 'Stolen' from the SDL documentation. + * Return the pixel value at (x, y) + * NOTE: The surface must be locked before calling this! + */ +Uint32 getpixel(SDL_Surface *surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to retrieve */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch(bpp) { + case 1: + return *p; + + case 2: + return *(Uint16 *)p; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + + case 4: + return *(Uint32 *)p; + + default: + return 0; /* shouldn't happen, but avoids warnings */ + } +} + +/* 'Stolen' from the SDL documentation. + * Set the pixel at (x, y) to the given value + * NOTE: The surface must be locked before calling this! + */ +void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + int bpp = surface->format->BytesPerPixel; + /* Here p is the address to the pixel we want to set */ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + + switch(bpp) { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } + else + { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + + default: + assert(false); + } +} + +/* Draw a single pixel on the screen. */ +void drawpixel(int x, int y, Uint32 pixel) +{ + /* Lock the screen for direct access to the pixels */ + if ( SDL_MUSTLOCK(screen) ) + { + if ( SDL_LockSurface(screen) < 0 ) + { + fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError()); + return; + } + } + + if(!(x < 0 || y < 0 || x > SCREEN_WIDTH || y > SCREEN_HEIGHT)) + putpixel(screen, x, y, pixel); + + if ( SDL_MUSTLOCK(screen) ) + { + SDL_UnlockSurface(screen); + } + /* Update just the part of the display that we've changed */ + SDL_UpdateRect(screen, x, y, 1, 1); +} + +/* --- FILL A RECT --- */ + +void fillrect(float x, float y, float w, float h, int r, int g, int b, int a) +{ + if(w < 0) { + x += w; + w = -w; + } + if(h < 0) { + y += h; + h = -h; + } + + if(config->use_gl) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4ub(r, g, b,a); + + glBegin(GL_POLYGON); + glVertex2f(x, y); + glVertex2f(x+w, y); + glVertex2f(x+w, y+h); + glVertex2f(x, y+h); + glEnd(); + glDisable(GL_BLEND); + } else { + SDL_Rect src, rect; + SDL_Surface *temp = NULL; + + rect.x = (int)x; + rect.y = (int)y; + rect.w = (int)w; + rect.h = (int)h; + + if(a != 255) { + temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel, + screen->format->Rmask, + screen->format->Gmask, + screen->format->Bmask, + screen->format->Amask); + + + src.x = 0; + src.y = 0; + src.w = rect.w; + src.h = rect.h; + + SDL_FillRect(temp, &src, SDL_MapRGB(screen->format, r, g, b)); + SDL_SetAlpha(temp, SDL_SRCALPHA, a); + SDL_BlitSurface(temp,0,screen,&rect); + SDL_FreeSurface(temp); + } else { + SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); + } + } +} + +/* Needed for line calculations */ +#define SGN(x) ((x)>0 ? 1 : ((x)==0 ? 0:(-1))) +#define ABS(x) ((x)>0 ? (x) : (-x)) + +void draw_line(float x1, float y1, float x2, float y2, + int r, int g, int b, int a) +{ + if(config->use_gl) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4ub(r, g, b,a); + + glBegin(GL_LINES); + glVertex2f(x1, y1); + glVertex2f(x2, y2); + glEnd(); + glDisable(GL_BLEND); + } else { + /* Basic unantialiased Bresenham line algorithm */ + int lg_delta, sh_delta, cycle, lg_step, sh_step; + Uint32 color = SDL_MapRGBA(screen->format, r, g, b, a); + + lg_delta = (int)(x2 - x1); + sh_delta = (int)(y2 - y1); + lg_step = SGN(lg_delta); + lg_delta = ABS(lg_delta); + sh_step = SGN(sh_delta); + sh_delta = ABS(sh_delta); + if (sh_delta < lg_delta) { + cycle = lg_delta >> 1; + while (x1 != x2) { + drawpixel((int)x1, (int)y1, color); + cycle += sh_delta; + if (cycle > lg_delta) { + cycle -= lg_delta; + y1 += sh_step; + } + x1 += lg_step; + } + drawpixel((int)x1, (int)y1, color); + } + cycle = sh_delta >> 1; + while (y1 != y2) { + drawpixel((int)x1, (int)y1, color); + cycle += lg_delta; + if (cycle > sh_delta) { + cycle -= sh_delta; + x1 += lg_step; + } + y1 += sh_step; + } + drawpixel((int)x1, (int)y1, color); + } +} + + +void fadeout(int fade_time) +{ + float alpha_inc = 256 / (fade_time / LOOP_DELAY); + float alpha = 256; + + while(alpha > 0) { + alpha -= alpha_inc; + fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0,0,0, (int)alpha_inc); // left side + + DrawingContext context; // ugly... + context.do_drawing(); + + SDL_Delay(int(LOOP_DELAY)); + } + + fillrect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 255); +} + +void shrink_fade(const Vector& point, int fade_time) +{ + float left_inc = point.x / ((float)fade_time / LOOP_DELAY); + float right_inc = (SCREEN_WIDTH - point.x) / ((float)fade_time / LOOP_DELAY); + float up_inc = point.y / ((float)fade_time / LOOP_DELAY); + float down_inc = (SCREEN_HEIGHT - point.y) / ((float)fade_time / LOOP_DELAY); + + float left_cor = 0, right_cor = 0, up_cor = 0, down_cor = 0; + + while(left_cor < point.x && right_cor < SCREEN_WIDTH - point.x && + up_cor < point.y && down_cor < SCREEN_HEIGHT - point.y) { + left_cor += left_inc; + right_cor += right_inc; + up_cor += up_inc; + down_cor += down_inc; + + fillrect(0, 0, left_cor, SCREEN_HEIGHT, 0,0,0); // left side + fillrect(SCREEN_WIDTH - right_cor, 0, right_cor, SCREEN_HEIGHT, 0,0,0); // right side + fillrect(0, 0, SCREEN_WIDTH, up_cor, 0,0,0); // up side + fillrect(0, SCREEN_HEIGHT - down_cor, SCREEN_WIDTH, down_cor+1, 0,0,0); // down side + DrawingContext context; // ugly... + context.do_drawing(); + + SDL_Delay(int(LOOP_DELAY)); + } +} diff --git a/src/video/screen.h b/src/video/screen.h new file mode 100644 index 000000000..1da243291 --- /dev/null +++ b/src/video/screen.h @@ -0,0 +1,82 @@ +// $Id: screen.h 1850 2004-08-27 20:34:56Z rmcruz $ +// +// SuperTux - A Jump'n Run +// Copyright (C) 2000 Bill Kendrick +// +// 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. +#ifndef SUPERTUX_SCREEN_H +#define SUPERTUX_SCREEN_H + +#include +#include +#include + +#include +#include "math/vector.h" + +using namespace SuperTux; + +/** Stores 8bit RGBA values. */ +class Color +{ +public: + Color() + : red(0), green(0), blue(0), alpha(255) + {} + + Color(Uint8 red_, Uint8 green_, Uint8 blue_, Uint8 alpha_ = 255) + : red(red_), green(green_), blue(blue_), alpha(alpha_) + {} + + Color(std::vector color) + : red(0), green(0), blue(0), alpha(255) + { if(color.size() >= 3) { red = color[0]; green = color[1]; blue = color[2]; } + if(color.size() == 4) alpha = color[3]; } + + Color(std::vector color) + : red(0), green(0), blue(0), alpha(255) + { if(color.size() >= 3) { red = color[0]; green = color[1]; blue = color[2]; } + if(color.size() == 4) alpha = color[3]; } + + Color(const Color& o) + : red(o.red), green(o.green), blue(o.blue), alpha(o.alpha) + { } + + bool operator==(const Color& o) + { + if(red == o.red && green == o.green && + blue == o.blue && alpha == o.alpha) + return true; + return false; + } + + Uint32 map_rgb(SDL_Surface* surface) + { return SDL_MapRGB(surface->format, red, green, blue); } + Uint32 map_rgba(SDL_Surface* surface) + { return SDL_MapRGBA(surface->format, red, green, blue, alpha); } + + Uint8 red, green, blue, alpha; +}; + +Uint32 getpixel(SDL_Surface* surface, int x, int y); +void putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel); +void drawpixel(int x, int y, Uint32 pixel); +void fillrect(float x, float y, float w, float h, int r, int g, int b, int a = 255); +void draw_line(float x1, float y1, float x2, float y2, int r, int g, int b, int a = 255); + +void fadeout(int fade_time); +void shrink_fade(const Vector& point, int fade_time); + +#endif diff --git a/src/video/semantic.cache b/src/video/semantic.cache new file mode 100644 index 000000000..9e308c633 --- /dev/null +++ b/src/video/semantic.cache @@ -0,0 +1,62 @@ +;; Object semantic.cache +;; SEMANTICDB Tags save file +(semanticdb-project-database "semantic.cache" + :file "semantic.cache" + :tables (list + (semanticdb-table "drawing_context.h" + :file "drawing_context.h" + :pointmax 5205 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_DRAWINGCONTEXT_H" variable nil nil ((const . t)) nil nil [915 951]) ("vector" include t nil nil [950 967]) ("string" include t nil nil [968 985]) ("stdint.h" include t nil nil [986 1005]) ("SDL.h" include t nil nil [1007 1023]) ("math/vector.h" include nil nil nil [1025 1049]) ("video/screen.h" include nil nil nil [1050 1075]) ("video/surface.h" include nil nil nil [1076 1102]) ("video/font.h" include nil nil nil [1103 1126]) ("Surface" type "class" nil nil nil nil nil [1155 1169]) ("" type "enum" (("LAYER_BACKGROUND0" variable "int" (1219 1223) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1226 1250]) ("LAYER_BACKGROUND1" variable "int" (1247 1251) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1254 1278]) ("LAYER_BACKGROUNDTILES" variable "int" (1279 1283) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1282 1310]) ("LAYER_TILES" variable "int" (1301 1302) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1314 1329]) ("LAYER_OBJECTS" variable "int" (1322 1325) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1333 1352]) ("LAYER_FOREGROUNDTILES" variable "int" (1353 1356) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1356 1383]) ("LAYER_FOREGROUND0" variable "int" (1380 1383) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1387 1410]) ("LAYER_FOREGROUND1" variable "int" (1407 1410) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1414 1437]) ("LAYER_GUI" variable "int" (1434 1437) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1441 1464])) nil nil nil nil [1217 1467]) ("DrawingContext" type "class" (("public" label ((reparse-symbol . classsubparts)) [1667 1674]) ("DrawingContext" function ("DrawingContext" type "class") nil ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1677 1694]) ("DrawingContext" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1697 1715]) ("draw_surface" function ("void") (("surface" variable ("Surface" type "class") nil ((const . t) (pointer . 1)) nil nil [1805 1828]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [1829 1852]) ("layer" variable "int" nil nil nil nil [1873 1883]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT)" nil nil nil [1884 1922])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1787 1923]) ("draw_surface_part" function ("void") (("surface" variable ("Surface" type "class") nil ((const . t) (pointer . 1)) nil nil [2001 2024]) ("source" variable ("Vector" type "class") nil ((const . t)) nil nil [2025 2046]) ("size" variable ("Vector" type "class") nil ((const . t)) nil nil [2072 2091]) ("dest" variable ("Vector" type "class") nil ((const . t)) nil nil [2092 2111]) ("layer" variable "int" nil nil nil nil [2112 2122]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT)" nil nil nil [2148 2186])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1978 2187]) ("draw_text" function ("void") (("font" variable ("Font" type "class") nil ((const . t) (pointer . 1)) nil nil [2225 2242]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2243 2267]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [2285 2308]) ("alignment" variable ("FontAlignment" type "class") nil nil nil nil [2309 2333]) ("layer" variable "int" nil nil nil nil [2334 2344]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT)" nil nil nil [2362 2400])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2210 2401]) ("draw_center_text" function ("void") (("font" variable ("Font" type "class") nil ((const . t) (pointer . 1)) nil nil [2597 2614]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2615 2639]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [2664 2687]) ("layer" variable "int" nil nil nil nil [2688 2698]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT)" nil nil nil [2723 2761])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2575 2762]) ("draw_gradient" function ("void") (("from" variable ("Color" type "class") nil nil nil nil [2838 2849]) ("to" variable ("Color" type "class") nil nil nil nil [2850 2859]) ("layer" variable "int" nil nil nil nil [2860 2870])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2819 2871]) ("draw_filled_rect" function ("void") (("topleft" variable ("Vector" type "class") nil ((const . t)) nil nil [2921 2943]) ("size" variable ("Vector" type "class") nil ((const . t)) nil nil [2944 2963]) ("color" variable ("Color" type "class") nil nil nil nil [2988 3000]) ("layer" variable "int" nil nil nil nil [3001 3011])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2899 3012]) ("do_drawing" function ("void") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3085 3103]) ("get_translation" function ("Vector" type "class") nil ((const . t)) nil ((reparse-symbol . classsubparts)) [3109 3184]) ("get_drawing_effect" function ("uint32_t" type "class") nil nil nil ((reparse-symbol . classsubparts)) [3187 3263]) ("set_translation" function ("void") (("newtranslation" variable ("Vector" type "class") nil ((const . t)) nil nil [3290 3319])) nil nil ((reparse-symbol . classsubparts)) [3269 3367]) ("push_transform" function ("void") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3373 3395]) ("pop_transform" function ("void") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3398 3419]) ("set_drawing_effect" function ("void") (("effect" variable "int" nil nil nil nil [3526 3537])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3502 3538]) ("set_zooming" function ("void") (("zoom" variable "float" nil nil nil nil [3601 3612])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3584 3613]) ("set_alpha" function ("void") (("alpha" variable "int" nil nil nil nil [3675 3685])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3660 3686]) ("private" label ((reparse-symbol . classsubparts)) [3690 3698]) ("Transform" type "class" (("public" label ((reparse-symbol . classsubparts)) [3723 3730]) ("translation" variable ("Vector" type "class") nil nil nil nil [3735 3754]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [3759 3783]) ("zoom" variable "float" nil nil nil nil [3788 3799]) ("alpha" variable "int" nil nil nil nil [3804 3814]) ("Transform" function ("Transform" type "class") nil ((constructor . t)) nil ((reparse-symbol . classsubparts)) [3824 3900]) ("apply" function ("Vector" type "class") (("v" variable ("Vector" type "class") nil ((const . t)) nil nil [3923 3939])) nil nil ((reparse-symbol . classsubparts)) [3910 3987])) nil nil nil ((reparse-symbol . classsubparts)) [3701 3992]) ("transformstack" variable ("std::vector" type "class") nil nil nil nil [4024 4062]) ("transform" variable ("Transform" type "class") nil nil nil nil [4102 4122]) ("RequestType" type "enum" (("SURFACE" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [4153 4161]) ("SURFACE_PART" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [4162 4175]) ("TEXT" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [4176 4181]) ("GRADIENT" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [4182 4191]) ("FILLRECT" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [4192 4204])) nil nil nil ((reparse-symbol . classsubparts)) [4128 4205]) ("SurfacePartRequest" type "struct" (("surface" variable ("Surface" type "class") nil ((const . t) (pointer . 1)) nil nil [4245 4268]) ("source" variable ("Vector" type "class") nil nil nil nil [4273 4293]) ("size" variable ("Vector" type "class") nil nil nil nil [4273 4293])) nil nil nil ((reparse-symbol . classsubparts)) [4211 4298]) ("TextRequest" type "struct" (("font" variable ("Font" type "class") nil ((const . t) (pointer . 1)) nil nil [4331 4348]) ("text" variable ("std::string" type "class") nil nil nil nil [4353 4370]) ("alignment" variable ("FontAlignment" type "class") nil nil nil nil [4375 4399])) nil nil nil ((reparse-symbol . classsubparts)) [4304 4404]) ("GradientRequest" type "struct" (("top" variable ("Color" type "class") nil nil nil nil [4441 4459]) ("bottom" variable ("Color" type "class") nil nil nil nil [4441 4459]) ("size" variable ("Vector" type "class") nil nil nil nil [4464 4476])) nil nil nil ((reparse-symbol . classsubparts)) [4410 4481]) ("FillRectRequest" type "struct" (("color" variable ("Color" type "class") nil nil nil nil [4518 4530]) ("size" variable ("Vector" type "class") nil nil nil nil [4535 4547])) nil nil nil ((reparse-symbol . classsubparts)) [4487 4552]) ("DrawingRequest" type "struct" (("type" variable ("RequestType" type "class") nil nil nil nil [4588 4605]) ("pos" variable ("Vector" type "class") nil nil nil nil [4610 4621]) ("layer" variable "int" nil nil nil nil [4647 4657]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [4662 4686]) ("zoom" variable "float" nil nil nil nil [4691 4702]) ("alpha" variable "int" nil nil nil nil [4707 4717]) ("request_data" variable "void" nil ((pointer . 1)) nil nil [4727 4746]) ("<" function ("bool" type "class") (("other" variable ("DrawingRequest" type "class") nil ((const . t)) nil nil [4771 4799])) nil nil ((reparse-symbol . classsubparts)) [4756 4851])) nil nil nil ((reparse-symbol . classsubparts)) [4558 4856]) ("draw_surface_part" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [4885 4909])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4862 4910]) ("draw_text" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [4928 4952])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4913 4953]) ("draw_text_center" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [4978 5002])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4956 5003]) ("draw_gradient" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [5025 5049])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5006 5050]) ("draw_filled_rect" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [5075 5099])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5053 5100]) ("DrawingRequests" type "typedef" nil ("std::vector") ((typedef "std::vector" type "class")) nil nil [5106 5158]) ("drawingrequests" variable ("DrawingRequests" type "class") nil nil nil nil [5161 5193])) nil nil nil nil [1644 5196])) + :unmatched-syntax 'nil + ) + (semanticdb-table "drawing_context.cpp" + :file "drawing_context.cpp" + :pointmax 11591 + :major-mode 'c++-mode + :tokens '(("config.h" include t nil nil [883 902]) ("algorithm" include t nil nil [904 924]) ("cassert" include t nil nil [925 943]) ("iostream" include t nil nil [944 963]) ("drawing_context.h" include nil nil nil [965 993]) ("surface.h" include nil nil nil [994 1014]) ("app/globals.h" include nil nil nil [1015 1039]) ("font.h" include nil nil nil [1040 1057]) ("gameconfig.h" include nil nil nil [1058 1081]) ("DrawingContext" function ("DrawingContext" type "class") (("targetsurface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1141 1168])) ((parent . "DrawingContext") (constructor . t)) nil nil [1110 1273]) ("DrawingContext" function "void" nil ((parent . "DrawingContext") (destructor . t)) nil nil [1275 1312]) ("draw_surface" function ("void") (("surface" variable ("Surface" type "class") nil ((const . t) (pointer . 1)) nil nil [1348 1371]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [1372 1395]) ("layer" variable "int" nil nil nil nil [1400 1410]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [1411 1435])) ((parent . "DrawingContext")) nil nil [1314 1981]) ("draw_surface_part" function ("void") (("surface" variable ("Surface" type "class") nil ((const . t) (pointer . 1)) nil nil [2022 2045]) ("source" variable ("Vector" type "class") nil ((const . t)) nil nil [2046 2067]) ("size" variable ("Vector" type "class") nil ((const . t)) nil nil [2072 2091]) ("dest" variable ("Vector" type "class") nil ((const . t)) nil nil [2092 2111]) ("layer" variable "int" nil nil nil nil [2112 2122]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [2123 2147])) ((parent . "DrawingContext")) nil nil [1983 3117]) ("draw_text" function ("void") (("font" variable ("Font" type "class") nil ((const . t) (pointer . 1)) nil nil [3150 3167]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [3168 3192]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [3197 3220]) ("alignment" variable ("FontAlignment" type "class") nil nil nil nil [3221 3245]) ("layer" variable "int" nil nil nil nil [3246 3256]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [3261 3285])) ((parent . "DrawingContext")) nil nil [3119 3763]) ("draw_center_text" function ("void") (("font" variable ("Font" type "class") nil ((const . t) (pointer . 1)) nil nil [3803 3820]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [3821 3845]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [3850 3873]) ("layer" variable "int" nil nil nil nil [3874 3884]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [3885 3909])) ((parent . "DrawingContext")) nil nil [3765 4031]) ("draw_gradient" function ("void") (("top" variable ("Color" type "class") nil nil nil nil [4068 4078]) ("bottom" variable ("Color" type "class") nil nil nil nil [4079 4092]) ("layer" variable "int" nil nil nil nil [4093 4103])) ((parent . "DrawingContext")) nil nil [4033 4543]) ("draw_filled_rect" function ("void") (("topleft" variable ("Vector" type "class") nil ((const . t)) nil nil [4583 4605]) ("size" variable ("Vector" type "class") nil ((const . t)) nil nil [4606 4625]) ("color" variable ("Color" type "class") nil nil nil nil [4634 4646]) ("layer" variable "int" nil nil nil nil [4647 4657])) ((parent . "DrawingContext")) nil nil [4545 5130]) ("draw_surface_part" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [5171 5195])) ((parent . "DrawingContext")) nil nil [5132 5579]) ("draw_gradient" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [5616 5640])) ((parent . "DrawingContext")) nil nil [5581 6879]) ("draw_text" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [6912 6936])) ((parent . "DrawingContext")) nil nil [6881 7158]) ("draw_filled_rect" function ("void") (("request" variable ("DrawingRequest" type "class") nil nil nil nil [7198 7222])) ((parent . "DrawingContext")) nil nil [7160 9958]) ("do_drawing" function ("void") nil ((parent . "DrawingContext")) nil nil [9960 11121]) ("push_transform" function ("void") nil ((parent . "DrawingContext")) nil nil [11123 11203]) ("pop_transform" function ("void") nil ((parent . "DrawingContext")) nil nil [11205 11347]) ("set_drawing_effect" function ("void") (("effect" variable "int" nil nil nil nil [11389 11400])) ((parent . "DrawingContext")) nil nil [11349 11441]) ("set_zooming" function ("void") (("zoom" variable "float" nil nil nil nil [11476 11487])) ((parent . "DrawingContext")) nil nil [11443 11516]) ("set_alpha" function ("void") (("alpha" variable "int" nil nil nil nil [11549 11559])) ((parent . "DrawingContext")) nil nil [11518 11590])) + :unmatched-syntax 'nil + ) + (semanticdb-table "screen.h" + :file "screen.h" + :pointmax 2675 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_SCREEN_H" variable nil nil ((const . t)) nil nil [906 934]) ("SDL.h" include t nil nil [933 949]) ("SDL_opengl.h" include t nil nil [950 973]) ("iostream" include t nil nil [974 993]) ("vector" include t nil nil [995 1012]) ("math/vector.h" include nil nil nil [1013 1037]) ("Color" type "class" (("public" label ((reparse-symbol . classsubparts)) [1112 1119]) ("Color" function ("Color" type "class") nil ((constructor . t)) nil ((reparse-symbol . classsubparts)) [1122 1178]) ("Color" function ("Color" type "class") (("red_" variable ("Uint8" type "class") nil nil nil nil [1190 1201]) ("green_" variable ("Uint8" type "class") nil nil nil nil [1202 1215]) ("blue_" variable ("Uint8" type "class") nil nil nil nil [1216 1228]) ("alpha_" variable ("Uint8" type "class") "255" nil nil nil [1229 1247])) ((constructor . t)) nil ((reparse-symbol . classsubparts)) [1184 1312]) ("Color" function ("Color" type "class") (("color" variable ("std::vector" type "class") nil nil nil nil [1324 1357])) ((constructor . t)) nil ((reparse-symbol . classsubparts)) [1318 1526]) ("Color" function ("Color" type "class") (("color" variable ("std::vector" type "class") nil nil nil nil [1538 1562])) ((constructor . t)) nil ((reparse-symbol . classsubparts)) [1532 1731]) ("Color" function ("Color" type "class") (("o" variable ("Color" type "class") nil ((const . t)) nil nil [1743 1758])) ((constructor . t)) nil ((reparse-symbol . classsubparts)) [1737 1827]) ("==" function ("bool" type "class") (("o" variable ("Color" type "class") nil ((const . t)) nil nil [1849 1864])) nil nil ((reparse-symbol . classsubparts)) [1833 1995]) ("map_rgb" function ("Uint32" type "class") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2016 2037])) nil nil ((reparse-symbol . classsubparts)) [2001 2097]) ("map_rgba" function ("Uint32" type "class") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2116 2137])) nil nil ((reparse-symbol . classsubparts)) [2100 2205]) ("red" variable ("Uint8" type "class") nil nil nil nil [2211 2241]) ("green" variable ("Uint8" type "class") nil nil nil nil [2211 2241]) ("blue" variable ("Uint8" type "class") nil nil nil nil [2211 2241]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [2211 2241])) nil nil nil nil [1098 2244]) ("getpixel" function ("Uint32" type "class") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2262 2283]) ("x" variable "int" nil nil nil nil [2284 2290]) ("y" variable "int" nil nil nil nil [2291 2297])) ((prototype . t)) nil nil [2246 2298]) ("putpixel" function ("void") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2313 2334]) ("x" variable "int" nil nil nil nil [2335 2341]) ("y" variable "int" nil nil nil nil [2342 2348]) ("pixel" variable ("Uint32" type "class") nil nil nil nil [2349 2362])) ((prototype . t)) nil nil [2299 2363]) ("drawpixel" function ("void") (("x" variable "int" nil nil nil nil [2379 2385]) ("y" variable "int" nil nil nil nil [2386 2392]) ("pixel" variable ("Uint32" type "class") nil nil nil nil [2393 2406])) ((prototype . t)) nil nil [2364 2407]) ("fillrect" function ("void") (("x" variable "float" nil nil nil nil [2422 2430]) ("y" variable "float" nil nil nil nil [2431 2439]) ("w" variable "float" nil nil nil nil [2440 2448]) ("h" variable "float" nil nil nil nil [2449 2457]) ("r" variable "int" nil nil nil nil [2458 2464]) ("g" variable "int" nil nil nil nil [2465 2471]) ("b" variable "int" nil nil nil nil [2472 2478]) ("a" variable "int" "255" nil nil nil [2479 2490])) ((prototype . t)) nil nil [2408 2492]) ("draw_line" function ("void") (("x1" variable "float" nil nil nil nil [2508 2517]) ("y1" variable "float" nil nil nil nil [2518 2527]) ("x2" variable "float" nil nil nil nil [2528 2537]) ("y2" variable "float" nil nil nil nil [2538 2547]) ("r" variable "int" nil nil nil nil [2548 2554]) ("g" variable "int" nil nil nil nil [2555 2561]) ("b" variable "int" nil nil nil nil [2562 2568]) ("a" variable "int" "255" nil nil nil [2569 2580])) ((prototype . t)) nil nil [2493 2582]) ("fadeout" function ("void") (("fade_time" variable "int" nil nil nil nil [2597 2611])) ((prototype . t)) nil nil [2584 2612]) ("shrink_fade" function ("void") (("point" variable ("Vector" type "class") nil ((const . t)) nil nil [2630 2650]) ("fade_time" variable "int" nil nil nil nil [2651 2665])) ((prototype . t)) nil nil [2613 2666])) + :unmatched-syntax 'nil + ) + (semanticdb-table "screen.cpp" + :file "screen.cpp" + :pointmax 8316 + :major-mode 'c++-mode + :tokens '(("config.h" include t nil nil [883 902]) ("iostream" include t nil nil [904 923]) ("cstdio" include t nil nil [924 941]) ("cstdlib" include t nil nil [942 960]) ("cstring" include t nil nil [961 979]) ("cerrno" include t nil nil [980 997]) ("unistd.h" include t nil nil [999 1018]) ("SDL.h" include t nil nil [1020 1036]) ("SDL_image.h" include t nil nil [1037 1059]) ("sys/types.h" include t nil nil [1075 1097]) ("ctype.h" include t nil nil [1098 1116]) ("gameconfig.h" include nil nil nil [1125 1148]) ("screen.h" include nil nil nil [1149 1168]) ("app/globals.h" include nil nil nil [1169 1193]) ("video/drawing_context.h" include nil nil nil [1194 1228]) ("math/vector.h" include nil nil nil [1229 1253]) ("LOOP_DELAY" variable "float" "20.0" ((const . t) (typemodifiers "static")) nil nil [1255 1292]) ("screen" variable ("SDL_Surface" type "class") nil ((typemodifiers "extern") (pointer . 1)) nil nil [1293 1320]) ("getpixel" function ("Uint32" type "class") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1502 1523]) ("x" variable "int" nil nil nil nil [1524 1530]) ("y" variable "int" nil nil nil nil [1531 1537])) nil nil nil [1486 2116]) ("putpixel" function ("void") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2279 2300]) ("x" variable "int" nil nil nil nil [2301 2307]) ("y" variable "int" nil nil nil nil [2308 2314]) ("pixel" variable ("Uint32" type "class") nil nil nil nil [2315 2328])) nil nil nil [2265 3046]) ("drawpixel" function ("void") (("x" variable "int" nil nil nil nil [3104 3110]) ("y" variable "int" nil nil nil nil [3111 3117]) ("pixel" variable ("Uint32" type "class") nil nil nil nil [3118 3131])) nil nil nil [3089 3660]) ("fillrect" function ("void") (("x" variable "float" nil nil nil nil [3703 3711]) ("y" variable "float" nil nil nil nil [3712 3720]) ("w" variable "float" nil nil nil nil [3721 3729]) ("h" variable "float" nil nil nil nil [3730 3738]) ("r" variable "int" nil nil nil nil [3739 3745]) ("g" variable "int" nil nil nil nil [3746 3752]) ("b" variable "int" nil nil nil nil [3753 3759]) ("a" variable "int" nil nil nil nil [3760 3766])) nil nil nil [3689 5025]) ("SGN" variable nil (nil) ((const . t)) nil nil [5062 5108]) ("ABS" variable nil (nil) ((const . t)) nil nil [5109 5144]) ("draw_line" function ("void") (("x1" variable "float" nil nil nil nil [5161 5170]) ("y1" variable "float" nil nil nil nil [5171 5180]) ("x2" variable "float" nil nil nil nil [5181 5190]) ("y2" variable "float" nil nil nil nil [5191 5200]) ("r" variable "int" nil nil nil nil [5226 5232]) ("g" variable "int" nil nil nil nil [5233 5239]) ("b" variable "int" nil nil nil nil [5240 5246]) ("a" variable "int" nil nil nil nil [5247 5253])) nil nil nil [5146 6471]) ("fadeout" function ("void") (("fade_time" variable "int" nil nil nil nil [6487 6501])) nil nil nil [6474 6931]) ("shrink_fade" function ("void") (("point" variable ("Vector" type "class") nil ((const . t)) nil nil [6950 6970]) ("fade_time" variable "int" nil nil nil nil [6971 6985])) nil nil nil [6933 8315])) + :unmatched-syntax 'nil + ) + (semanticdb-table "surface.h" + :file "surface.h" + :pointmax 5586 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_TEXTURE_H" variable nil nil ((const . t)) nil nil [891 920]) ("string" include t nil nil [919 936]) ("list" include t nil nil [937 952]) ("SDL.h" include t nil nil [954 970]) ("SDL_opengl.h" include t nil nil [971 994]) ("math/vector.h" include nil nil nil [996 1020]) ("video/screen.h" include nil nil nil [1021 1046]) ("apply_filter_to_surface" function ("void") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1077 1098]) ("filter" variable "int" nil nil nil nil [1099 1110]) ("value" variable "int" nil nil nil nil [1111 1121])) ((prototype . t)) nil nil [1048 1122]) ("sdl_surface_from_sdl_surface" function ("SDL_Surface" type "class") (("sdl_surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1165 1187]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [1188 1203])) ((pointer . 1) (prototype . t)) nil nil [1123 1204]) ("sdl_surface_from_nothing" function ("SDL_Surface" type "class") nil ((pointer . 1) (prototype . t)) nil nil [1205 1245]) ("SurfaceImpl" type "class" nil nil nil nil nil [1247 1265]) ("SurfaceSDL" type "class" nil nil nil nil nil [1266 1283]) ("SurfaceOpenGL" type "class" nil nil nil nil nil [1284 1304]) ("DrawingContext" type "class" nil nil nil nil nil [1305 1326]) ("" type "enum" (("NONE_EFFECT" variable "int" (1420 1426) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1400 1426]) ("VERTICAL_FLIP" variable "int" (1488 1494) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1468 1494]) ("HORIZONTAL_FLIP" variable "int" (1562 1568) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1542 1568]) ("SEMI_TRANSPARENT" variable "int" (1642 1648) ((const . t)) nil ((reparse-symbol . enumsubparts)) [1622 1648])) nil nil nil nil [1361 1651]) ("" type "enum" (("HORIZONTAL_FLIP_FILTER" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1683 1706]) ("MASK_FILTER" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1709 1721]) ("NONE_FILTER" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1724 1737])) nil nil nil nil [1674 1738]) ("SurfaceData" type "class" (("public" label ((reparse-symbol . classsubparts)) [1830 1837]) ("ConstructorType" type "enum" (("LOAD" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1863 1868]) ("LOAD_PART" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1869 1879]) ("SURFACE" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1880 1888]) ("GRADIENT" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1889 1899])) nil nil nil ((reparse-symbol . classsubparts)) [1840 1900]) ("type" variable ("ConstructorType" type "class") nil nil nil nil [1903 1924]) ("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1927 1948]) ("file" variable ("std::string" type "class") nil nil nil nil [1951 1968]) ("Filter" type "struct" (("type" variable "int" nil nil nil nil [1990 1999]) ("color" variable ("Color" type "class") nil nil nil nil [2000 2012])) nil nil nil ((reparse-symbol . classsubparts)) [1974 2015]) ("applied_filters" variable ("std::vector" type "class") nil nil nil nil [2018 2054]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [2060 2075]) ("x" variable "int" nil nil nil nil [2078 2084]) ("y" variable "int" nil nil nil nil [2087 2093]) ("w" variable "int" nil nil nil nil [2096 2102]) ("h" variable "int" nil nil nil nil [2105 2111]) ("top_gradient" variable ("Color" type "class") nil nil nil nil [2114 2133]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [2136 2158]) ("SurfaceData" function ("SurfaceData" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2176 2194]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [2195 2211])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2164 2212]) ("SurfaceData" function ("SurfaceData" type "class") (("file_" variable ("std::string" type "class") nil ((const . t)) nil nil [2227 2252]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [2253 2269])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2215 2270]) ("SurfaceData" function ("SurfaceData" type "class") (("file_" variable ("std::string" type "class") nil ((const . t)) nil nil [2285 2310]) ("x_" variable "int" nil nil nil nil [2311 2318]) ("y_" variable "int" nil nil nil nil [2319 2326]) ("w_" variable "int" nil nil nil nil [2327 2334]) ("h_" variable "int" nil nil nil nil [2335 2342]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [2343 2359])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2273 2360]) ("SurfaceData" function ("SurfaceData" type "class") (("top_gradient_" variable ("Color" type "class") nil nil nil nil [2375 2395]) ("bottom_gradient_" variable ("Color" type "class") nil nil nil nil [2396 2419]) ("w_" variable "int" nil nil nil nil [2420 2427]) ("h_" variable "int" nil nil nil nil [2428 2435])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2363 2436]) ("SurfaceData" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2439 2454]) ("create_SurfaceSDL" function ("SurfaceSDL" type "class") nil ((pointer . 1) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2460 2492]) ("create_SurfaceOpenGL" function ("SurfaceOpenGL" type "class") nil ((pointer . 1) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2495 2533]) ("create" function ("SurfaceImpl" type "class") nil ((pointer . 1) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2536 2558])) nil nil nil nil [1810 2561]) ("Surface" type "class" (("public" label ((reparse-symbol . classsubparts)) [2711 2718]) ("data" variable ("SurfaceData" type "class") nil nil nil nil [2721 2738]) ("impl" variable ("SurfaceImpl" type "class") nil ((pointer . 1)) nil nil [2741 2759]) ("w" variable "int" nil nil nil nil [2762 2768]) ("h" variable "int" nil nil nil nil [2771 2777]) ("Surfaces" type "typedef" nil ("std::list") ((typedef "std::list" type "class")) nil nil [2783 2820]) ("surfaces" variable ("Surfaces" type "class") nil ((typemodifiers "static")) nil nil [2823 2848]) ("public" label ((reparse-symbol . classsubparts)) [2849 2856]) ("reload_all" function ("void") nil ((typemodifiers "static") (prototype . t)) nil ((reparse-symbol . classsubparts)) [2859 2884]) ("debug_check" function ("void") nil ((typemodifiers "static") (prototype . t)) nil ((reparse-symbol . classsubparts)) [2887 2913]) ("Surface" function ("Surface" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [2927 2945]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [2946 2961])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2919 2962]) ("Surface" function ("Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [2973 2997]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [2998 3013])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [2965 3014]) ("Surface" function ("Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [3025 3049]) ("x" variable "int" nil nil nil nil [3050 3056]) ("y" variable "int" nil nil nil nil [3057 3063]) ("w" variable "int" nil nil nil nil [3064 3070]) ("h" variable "int" nil nil nil nil [3071 3077]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [3078 3093])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3017 3094]) ("Surface" function ("Surface" type "class") (("top_gradient" variable ("Color" type "class") nil nil nil nil [3105 3124]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [3125 3147]) ("w_" variable "int" nil nil nil nil [3148 3155]) ("h_" variable "int" nil nil nil nil [3156 3163])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3097 3164]) ("Surface" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3167 3178]) ("reload" function ("void") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3256 3270]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [3294 3305]) ("color" variable ("Color" type "class") "Color(0,0,0)" nil nil nil [3306 3332])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [3276 3334])) nil nil nil nil [2695 3337]) ("SurfaceImpl" type "class" (("protected" label ((reparse-symbol . classsubparts)) [3445 3455]) ("sdl_surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [3458 3483]) ("public" label ((reparse-symbol . classsubparts)) [3487 3494]) ("w" variable "int" nil nil nil nil [3497 3503]) ("h" variable "int" nil nil nil nil [3506 3512]) ("public" label ((reparse-symbol . classsubparts)) [3516 3523]) ("SurfaceImpl" function ("SurfaceImpl" type "class") nil ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3526 3540]) ("SurfaceImpl" function "void" nil ((typemodifiers "virtual") (destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3543 3566]) ("draw" function ("int") (("x" variable "float" nil nil nil nil [3654 3662]) ("y" variable "float" nil nil nil nil [3663 3671]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [3672 3684]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [3685 3713])) ((typemodifiers "virtual") (prototype . t) (pure-virtual . t)) nil ((reparse-symbol . classsubparts)) [3637 3718]) ("draw_part" function ("int") (("sx" variable "float" nil nil nil nil [3743 3752]) ("sy" variable "float" nil nil nil nil [3753 3762]) ("x" variable "float" nil nil nil nil [3763 3771]) ("y" variable "float" nil nil nil nil [3772 3780]) ("w" variable "float" nil nil nil nil [3781 3789]) ("h" variable "float" nil nil nil nil [3790 3798]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [3800 3812]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [3813 3841])) ((typemodifiers "virtual") (prototype . t) (pure-virtual . t)) nil ((reparse-symbol . classsubparts)) [3721 3846]) ("draw_stretched" function ("int") (("x" variable "float" nil nil nil nil [3876 3884]) ("y" variable "float" nil nil nil nil [3885 3893]) ("w" variable "int" nil nil nil nil [3894 3900]) ("h" variable "int" nil nil nil nil [3901 3907]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [3908 3920]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [3921 3949])) ((typemodifiers "virtual") (prototype . t) (pure-virtual . t)) nil ((reparse-symbol . classsubparts)) [3849 3954]) ("get_sdl_surface" function ("SDL_Surface" type "class") nil ((pointer . 1) (prototype . t)) nil ((reparse-symbol . classsubparts)) [3963 4000]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [4069 4080]) ("color" variable ("Color" type "class") "Color(0,0,0)" nil nil nil [4081 4107])) ((typemodifiers "virtual") (prototype . t) (pure-virtual . t)) nil ((reparse-symbol . classsubparts)) [4043 4113])) nil nil nil nil [3425 4116]) ("SurfaceSDL" type "class" (("public" label ((reparse-symbol . classsubparts)) [4158 4165]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [4179 4197]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4198 4213])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4168 4214]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [4228 4252]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4253 4268])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4217 4269]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [4283 4307]) ("x" variable "int" nil nil nil nil [4308 4314]) ("y" variable "int" nil nil nil nil [4315 4321]) ("w_" variable "int" nil nil nil nil [4322 4329]) ("h_" variable "int" nil nil nil nil [4330 4337]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4338 4353])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4272 4354]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("top_gradient" variable ("Color" type "class") nil nil nil nil [4368 4387]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [4388 4410]) ("w" variable "int" nil nil nil nil [4411 4417]) ("h" variable "int" nil nil nil nil [4418 4424])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4357 4425]) ("SurfaceSDL" function "void" nil ((typemodifiers "virtual") (destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4428 4450]) ("draw" function ("int") (("x" variable "float" nil nil nil nil [4465 4473]) ("y" variable "float" nil nil nil nil [4474 4482]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [4483 4495]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [4496 4524])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4456 4525]) ("draw_part" function ("int") (("sx" variable "float" nil nil nil nil [4542 4551]) ("sy" variable "float" nil nil nil nil [4552 4561]) ("x" variable "float" nil nil nil nil [4562 4570]) ("y" variable "float" nil nil nil nil [4571 4579]) ("w" variable "float" nil nil nil nil [4580 4588]) ("h" variable "float" nil nil nil nil [4589 4597]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [4599 4611]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [4612 4640])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4528 4641]) ("draw_stretched" function ("int") (("x" variable "float" nil nil nil nil [4663 4671]) ("y" variable "float" nil nil nil nil [4672 4680]) ("w" variable "int" nil nil nil nil [4681 4687]) ("h" variable "int" nil nil nil nil [4688 4694]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [4695 4707]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [4708 4736])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4644 4737]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [4761 4772]) ("color" variable ("Color" type "class") nil nil nil nil [4773 4785])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [4743 4786])) (("SurfaceImpl")) nil nil nil [4118 4789]) ("SurfaceOpenGL" type "class" (("public" label ((reparse-symbol . classsubparts)) [4834 4841]) ("gl_texture" variable ("GLuint" type "class") nil nil nil nil [4844 4862]) ("public" label ((reparse-symbol . classsubparts)) [4866 4873]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [4890 4908]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4909 4924])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4876 4925]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [4942 4966]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4967 4982])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4928 4983]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [5000 5024]) ("x" variable "int" nil nil nil nil [5025 5031]) ("y" variable "int" nil nil nil nil [5032 5038]) ("w" variable "int" nil nil nil nil [5039 5045]) ("h" variable "int" nil nil nil nil [5046 5052]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [5053 5068])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [4986 5069]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("top_gradient" variable ("Color" type "class") nil nil nil nil [5086 5105]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [5106 5128]) ("w" variable "int" nil nil nil nil [5129 5135]) ("h" variable "int" nil nil nil nil [5136 5142])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [5072 5143]) ("SurfaceOpenGL" function "void" nil ((typemodifiers "virtual") (destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [5149 5174]) ("draw" function ("int") (("x" variable "float" nil nil nil nil [5189 5197]) ("y" variable "float" nil nil nil nil [5198 5206]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [5207 5219]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [5220 5248])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5180 5249]) ("draw_part" function ("int") (("sx" variable "float" nil nil nil nil [5266 5275]) ("sy" variable "float" nil nil nil nil [5276 5285]) ("x" variable "float" nil nil nil nil [5286 5294]) ("y" variable "float" nil nil nil nil [5295 5303]) ("w" variable "float" nil nil nil nil [5304 5312]) ("h" variable "float" nil nil nil nil [5313 5321]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [5323 5335]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [5336 5364])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5252 5365]) ("draw_stretched" function ("int") (("x" variable "float" nil nil nil nil [5387 5395]) ("y" variable "float" nil nil nil nil [5396 5404]) ("w" variable "int" nil nil nil nil [5405 5411]) ("h" variable "int" nil nil nil nil [5412 5418]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [5419 5431]) ("effect" variable ("Uint32" type "class") "NONE_EFFECT)" nil nil nil [5432 5460])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5368 5461]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [5485 5496]) ("color" variable ("Color" type "class") nil nil nil nil [5497 5509])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5467 5510]) ("private" label ((reparse-symbol . classsubparts)) [5514 5522]) ("create_gl" function ("void") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [5540 5559]) ("tex" variable ("GLuint" type "class") nil ((pointer . 1)) nil nil [5560 5573])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [5525 5574])) (("SurfaceImpl")) nil nil nil [4791 5577])) + :unmatched-syntax 'nil + ) + (semanticdb-table "surface.cpp" + :file "surface.cpp" + :pointmax 26873 + :major-mode 'c++-mode + :tokens '(("config.h" include t nil nil [864 883]) ("cassert" include t nil nil [885 903]) ("iostream" include t nil nil [904 923]) ("algorithm" include t nil nil [924 944]) ("stdexcept" include t nil nil [945 965]) ("sstream" include t nil nil [966 984]) ("SDL.h" include t nil nil [986 1002]) ("SDL_image.h" include t nil nil [1003 1025]) ("gameconfig.h" include nil nil nil [1027 1050]) ("video/surface.h" include nil nil nil [1051 1077]) ("video/screen.h" include nil nil nil [1078 1103]) ("app/globals.h" include nil nil nil [1104 1128]) ("app/setup.h" include nil nil nil [1129 1151]) ("Surface::surfaces" variable ("Surface::Surfaces" type "class") nil nil nil nil [1180 1216]) ("screen" variable ("SDL_Surface" type "class") nil ((typemodifiers "extern") (pointer . 1)) nil nil [1218 1245]) ("SurfaceData" function ("SurfaceData" type "class") (("temp" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [1272 1290]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [1291 1307])) ((parent . "SurfaceData") (constructor . t)) nil nil [1247 2025]) ("SurfaceData" function ("SurfaceData" type "class") (("file_" variable ("std::string" type "class") nil ((const . t)) nil nil [2052 2077]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [2078 2094])) ((parent . "SurfaceData") (constructor . t)) nil nil [2027 2162]) ("SurfaceData" function ("SurfaceData" type "class") (("file_" variable ("std::string" type "class") nil ((const . t)) nil nil [2189 2214]) ("x_" variable "int" nil nil nil nil [2215 2222]) ("y_" variable "int" nil nil nil nil [2223 2230]) ("w_" variable "int" nil nil nil nil [2235 2242]) ("h_" variable "int" nil nil nil nil [2243 2250]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [2251 2267])) ((parent . "SurfaceData") (constructor . t)) nil nil [2164 2372]) ("SurfaceData" function ("SurfaceData" type "class") (("top_gradient_" variable ("Color" type "class") nil nil nil nil [2399 2419]) ("bottom_gradient_" variable ("Color" type "class") nil nil nil nil [2420 2443]) ("w_" variable "int" nil nil nil nil [2448 2455]) ("h_" variable "int" nil nil nil nil [2456 2463])) ((parent . "SurfaceData") (constructor . t)) nil nil [2374 2602]) ("SurfaceData" function "void" nil ((parent . "SurfaceData") (destructor . t)) nil nil [2605 2664]) ("create" function ("SurfaceImpl" type "class") nil ((parent . "SurfaceData") (pointer . 1)) nil nil [2666 2800]) ("create_SurfaceSDL" function ("SurfaceSDL" type "class") nil ((parent . "SurfaceData") (pointer . 1)) nil nil [2802 3161]) ("create_SurfaceOpenGL" function ("SurfaceOpenGL" type "class") nil ((parent . "SurfaceData") (pointer . 1)) nil nil [3163 3577]) ("power_of_two" function ("int") (("input" variable "int" nil nil nil nil [3653 3663])) ((typemodifiers "static")) nil nil [3629 3752]) ("Surface" function ("Surface" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [3771 3789]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [3790 3805])) ((parent . "Surface") (constructor . t)) nil nil [3754 3955]) ("Surface" function ("Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [3974 3998]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [3999 4014])) ((parent . "Surface") (constructor . t)) nil nil [3957 4164]) ("Surface" function ("Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [4183 4207]) ("x" variable "int" nil nil nil nil [4208 4214]) ("y" variable "int" nil nil nil nil [4215 4221]) ("w_" variable "int" nil nil nil nil [4222 4229]) ("h_" variable "int" nil nil nil nil [4230 4237]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [4238 4253])) ((parent . "Surface") (constructor . t)) nil nil [4166 4417]) ("Surface" function ("Surface" type "class") (("top_background" variable ("Color" type "class") nil nil nil nil [4436 4457]) ("bottom_background" variable ("Color" type "class") nil nil nil nil [4458 4482]) ("w_" variable "int" nil nil nil nil [4483 4490]) ("h_" variable "int" nil nil nil nil [4491 4498])) ((parent . "Surface") (constructor . t)) nil nil [4419 4674]) ("reload" function ("void") nil ((parent . "Surface")) nil nil [4676 4979]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [5008 5019]) ("color" variable ("Color" type "class") nil nil nil nil [5020 5032])) ((parent . "Surface")) nil nil [4981 5218]) ("Surface" function "void" nil ((parent . "Surface") (destructor . t)) nil nil [5220 5541]) ("reload_all" function ("void") nil ((parent . "Surface")) nil nil [5543 5674]) ("debug_check" function ("void") nil ((parent . "Surface")) nil nil [5676 5888]) ("apply_filter_to_surface" function ("void") (("surface" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [5919 5940]) ("filter" variable "int" nil nil nil nil [5941 5952]) ("color" variable ("Color" type "class") nil nil nil nil [5953 5965])) nil nil nil [5890 6998]) ("sdl_surface_part_from_file" function ("SDL_Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [7040 7064]) ("x" variable "int" nil nil nil nil [7065 7071]) ("y" variable "int" nil nil nil nil [7072 7078]) ("w" variable "int" nil nil nil nil [7079 7085]) ("h" variable "int" nil nil nil nil [7086 7092]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [7094 7109])) ((pointer . 1)) nil nil [7000 8317]) ("sdl_surface_from_file" function ("SDL_Surface" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [8354 8378]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [8379 8394])) ((pointer . 1)) nil nil [8319 9094]) ("sdl_surface_from_sdl_surface" function ("SDL_Surface" type "class") (("sdl_surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [9138 9160]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [9161 9176])) ((pointer . 1)) nil nil [9096 10116]) ("sdl_surface_from_gradient" function ("SDL_Surface" type "class") (("top" variable ("Color" type "class") nil nil nil nil [10157 10167]) ("bottom" variable ("Color" type "class") nil nil nil nil [10168 10181]) ("w" variable "int" nil nil nil nil [10182 10188]) ("h" variable "int" nil nil nil nil [10189 10195])) ((pointer . 1)) nil nil [10118 11237]) ("SurfaceImpl" function ("SurfaceImpl" type "class") nil ((parent . "SurfaceImpl") (constructor . t)) nil nil [11318 11347]) ("SurfaceImpl" function "void" nil ((parent . "SurfaceImpl") (destructor . t)) nil nil [11349 11412]) ("get_sdl_surface" function ("SDL_Surface" type "class") nil ((parent . "SurfaceImpl") (pointer . 1)) nil nil [11414 11489]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [11520 11538]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [11539 11554])) ((parent . "SurfaceOpenGL") (constructor . t)) nil nil [11491 11704]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [11735 11759]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [11760 11775])) ((parent . "SurfaceOpenGL") (constructor . t)) nil nil [11706 11918]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("file_" variable ("std::string" type "class") nil ((const . t)) nil nil [11949 11974]) ("x_" variable "int" nil nil nil nil [11975 11982]) ("y_" variable "int" nil nil nil nil [11983 11990]) ("w_" variable "int" nil nil nil nil [11995 12002]) ("h_" variable "int" nil nil nil nil [12003 12010]) ("use_alpha_" variable ("bool" type "class") nil nil nil nil [12011 12027])) ((parent . "SurfaceOpenGL") (constructor . t)) nil nil [11920 12193]) ("SurfaceOpenGL" function ("SurfaceOpenGL" type "class") (("top_gradient" variable ("Color" type "class") nil nil nil nil [12224 12243]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [12244 12266]) ("_w" variable "int" nil nil nil nil [12271 12278]) ("_h" variable "int" nil nil nil nil [12279 12286])) ((parent . "SurfaceOpenGL") (constructor . t)) nil nil [12195 12455]) ("SurfaceOpenGL" function "void" nil ((parent . "SurfaceOpenGL") (destructor . t)) nil nil [12457 12528]) ("create_gl" function ("void") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [12560 12579]) ("tex" variable ("GLuint" type "class") nil ((pointer . 1)) nil nil [12580 12593])) ((parent . "SurfaceOpenGL")) nil nil [12530 14870]) ("draw" function ("int") (("x" variable "float" nil nil nil nil [14896 14904]) ("y" variable "float" nil nil nil nil [14905 14913]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [14914 14926]) ("effect" variable ("Uint32" type "class") nil nil nil nil [14927 14941])) ((parent . "SurfaceOpenGL")) nil nil [14872 16605]) ("draw_part" function ("int") (("sx" variable "float" nil nil nil nil [16636 16645]) ("sy" variable "float" nil nil nil nil [16646 16655]) ("x" variable "float" nil nil nil nil [16656 16664]) ("y" variable "float" nil nil nil nil [16665 16673]) ("w" variable "float" nil nil nil nil [16674 16682]) ("h" variable "float" nil nil nil nil [16683 16691]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [16692 16704]) ("effect" variable ("Uint32" type "class") nil nil nil nil [16705 16719])) ((parent . "SurfaceOpenGL")) nil nil [16607 18478]) ("draw_stretched" function ("int") (("x" variable "float" nil nil nil nil [18514 18522]) ("y" variable "float" nil nil nil nil [18523 18531]) ("sw" variable "int" nil nil nil nil [18532 18539]) ("sh" variable "int" nil nil nil nil [18540 18547]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [18548 18560]) ("effect" variable ("Uint32" type "class") nil nil nil nil [18561 18575])) ((parent . "SurfaceOpenGL")) nil nil [18480 20257]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [20292 20303]) ("color" variable ("Color" type "class") nil nil nil nil [20304 20316])) ((parent . "SurfaceOpenGL")) nil nil [20259 20460]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("surf" variable ("SDL_Surface" type "class") nil ((pointer . 1)) nil nil [20485 20503]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [20504 20519])) ((parent . "SurfaceSDL") (constructor . t)) nil nil [20462 20630]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [20655 20679]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [20680 20695])) ((parent . "SurfaceSDL") (constructor . t)) nil nil [20632 20799]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [20824 20848]) ("x" variable "int" nil nil nil nil [20849 20855]) ("y" variable "int" nil nil nil nil [20856 20862]) ("_w" variable "int" nil nil nil nil [20863 20870]) ("_h" variable "int" nil nil nil nil [20871 20878]) ("use_alpha" variable ("bool" type "class") nil nil nil nil [20883 20898])) ((parent . "SurfaceSDL") (constructor . t)) nil nil [20801 21023]) ("SurfaceSDL" function ("SurfaceSDL" type "class") (("top_gradient" variable ("Color" type "class") nil nil nil nil [21048 21067]) ("bottom_gradient" variable ("Color" type "class") nil nil nil nil [21068 21090]) ("_w" variable "int" nil nil nil nil [21095 21102]) ("_h" variable "int" nil nil nil nil [21103 21110])) ((parent . "SurfaceSDL") (constructor . t)) nil nil [21025 21240]) ("draw" function ("int") (("x" variable "float" nil nil nil nil [21263 21271]) ("y" variable "float" nil nil nil nil [21272 21280]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [21281 21293]) ("effect" variable ("Uint32" type "class") nil nil nil nil [21294 21308])) ((parent . "SurfaceSDL")) nil nil [21242 23433]) ("draw_part" function ("int") (("sx" variable "float" nil nil nil nil [23461 23470]) ("sy" variable "float" nil nil nil nil [23471 23480]) ("x" variable "float" nil nil nil nil [23481 23489]) ("y" variable "float" nil nil nil nil [23490 23498]) ("w" variable "float" nil nil nil nil [23499 23507]) ("h" variable "float" nil nil nil nil [23508 23516]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [23517 23529]) ("effect" variable ("Uint32" type "class") nil nil nil nil [23530 23544])) ((parent . "SurfaceSDL")) nil nil [23435 25768]) ("draw_stretched" function ("int") (("x" variable "float" nil nil nil nil [25801 25809]) ("y" variable "float" nil nil nil nil [25810 25818]) ("sw" variable "int" nil nil nil nil [25819 25826]) ("sh" variable "int" nil nil nil nil [25827 25834]) ("alpha" variable ("Uint8" type "class") nil nil nil nil [25835 25847]) ("effect" variable ("Uint32" type "class") nil nil nil nil [25848 25862])) ((parent . "SurfaceSDL")) nil nil [25770 26680]) ("apply_filter" function ("void") (("filter" variable "int" nil nil nil nil [26712 26723]) ("color" variable ("Color" type "class") nil nil nil nil [26724 26736])) ((parent . "SurfaceSDL")) nil nil [26682 26842]) ("SurfaceSDL" function "void" nil ((parent . "SurfaceSDL") (destructor . t)) nil nil [26844 26872])) + :unmatched-syntax 'nil + ) + (semanticdb-table "font.h" + :file "font.h" + :pointmax 2943 + :major-mode 'c++-mode + :tokens '(("SUPERTUX_FONT_H" variable nil nil ((const . t)) nil nil [887 913]) ("string" include t nil nil [912 929]) ("stdint.h" include t nil nil [930 949]) ("video/surface.h" include nil nil nil [951 977]) ("math/vector.h" include nil nil nil [978 1002]) ("FontAlignment" type "enum" (("LEFT_ALLIGN" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1027 1039]) ("CENTER_ALLIGN" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1042 1056]) ("RIGHT_ALLIGN" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1059 1073])) nil nil nil nil [1004 1074]) ("Font" type "class" (("public" label ((reparse-symbol . classsubparts)) [1089 1096]) ("FontType" type "enum" (("TEXT" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1119 1124]) ("NUM" variable "int" nil ((const . t)) nil ((reparse-symbol . enumsubparts)) [1158 1194])) nil nil nil ((reparse-symbol . classsubparts)) [1099 1195]) ("Font" function ("Font" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [1206 1230]) ("type" variable ("FontType" type "class") nil nil nil nil [1231 1245]) ("w" variable "int" nil nil nil nil [1246 1252]) ("h" variable "int" nil nil nil nil [1253 1259]) ("shadowsize" variable "int" "2" nil nil nil [1267 1283])) ((constructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1201 1285]) ("Font" function "void" nil ((destructor . t) (prototype . t)) nil ((reparse-symbol . classsubparts)) [1288 1296]) ("get_text_width" function ("float") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [1522 1546])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1501 1553]) ("get_text_height" function ("float") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [1888 1912])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1866 1919]) ("get_height" function ("float") nil ((prototype . t)) nil ((reparse-symbol . classsubparts)) [1960 1985]) ("draw" function ("void") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2134 2158]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [2159 2177]) ("allignment" variable ("FontAlignment" type "class") "LEFT_ALLIGN," nil nil nil [2190 2229]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT," nil nil nil [2242 2280]) ("alpha" variable ("uint8_t" type "class") "255" nil nil nil [2281 2300])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2124 2308]) ("private" label ((reparse-symbol . classsubparts)) [2312 2320]) ("DrawingContext" type "class" nil nil nil nil ((reparse-symbol . classsubparts)) [2330 2351]) ("draw_text" function ("void") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2372 2396]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [2397 2415]) ("drawing_effect" variable ("uint32_t" type "class") "NONE_EFFECT," nil nil nil [2433 2471]) ("alpha" variable ("uint8_t" type "class") "255" nil nil nil [2472 2491])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2357 2499]) ("draw_chars" function ("void") (("pchars" variable ("Surface" type "class") nil ((pointer . 1)) nil nil [2521 2537]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2538 2562]) ("position" variable ("Vector" type "class") nil ((const . t)) nil nil [2581 2604]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [2605 2629]) ("alpha" variable ("uint8_t" type "class") nil nil nil nil [2630 2644])) ((prototype . t)) nil ((reparse-symbol . classsubparts)) [2505 2651]) ("chars" variable ("Surface" type "class") nil ((pointer . 1)) nil nil [2657 2672]) ("shadow_chars" variable ("Surface" type "class") nil ((pointer . 1)) nil nil [2675 2697]) ("type" variable ("FontType" type "class") nil nil nil nil [2700 2714]) ("w" variable "int" nil nil nil nil [2717 2723]) ("h" variable "int" nil nil nil nil [2726 2732]) ("shadowsize" variable "int" nil nil nil nil [2735 2750]) ("first_char" variable "int" nil nil nil nil [2828 2843]) ("last_char" variable "int" nil nil nil nil [2917 2931])) nil nil nil nil [1076 2934])) + :unmatched-syntax '((FRIEND 2323 . 2329)) + ) + (semanticdb-table "font.cpp" + :file "font.cpp" + :pointmax 4862 + :major-mode 'c++-mode + :tokens '(("config.h" include t nil nil [865 884]) ("cstdlib" include t nil nil [886 904]) ("cstring" include t nil nil [905 923]) ("stdexcept" include t nil nil [924 944]) ("app/globals.h" include nil nil nil [946 970]) ("lisp/parser.h" include nil nil nil [971 995]) ("lisp/lisp.h" include nil nil nil [996 1018]) ("screen.h" include nil nil nil [1019 1038]) ("font.h" include nil nil nil [1039 1056]) ("drawing_context.h" include nil nil nil [1057 1085]) ("Font" function ("Font" type "class") (("file" variable ("std::string" type "class") nil ((const . t)) nil nil [1125 1149]) ("ntype" variable ("FontType" type "class") nil nil nil nil [1150 1165]) ("nw" variable "int" nil nil nil nil [1166 1173]) ("nh" variable "int" nil nil nil nil [1174 1181]) ("nshadowsize" variable "int" nil nil nil nil [1190 1206])) ((parent . "Font") (constructor . t)) nil nil [1114 2067]) ("Font" function "void" nil ((parent . "Font") (destructor . t)) nil nil [2069 2125]) ("get_text_width" function ("float") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2154 2178])) ((parent . "Font")) nil nil [2127 2501]) ("get_text_height" function ("float") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2531 2555])) ((parent . "Font")) nil nil [2503 2789]) ("get_height" function ("float") nil ((parent . "Font")) nil nil [2791 2837]) ("draw" function ("void") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [2855 2879]) ("pos_" variable ("Vector" type "class") nil ((const . t)) nil nil [2880 2899]) ("alignment" variable ("FontAlignment" type "class") nil nil nil nil [2900 2924]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [2929 2953]) ("alpha" variable ("uint8_t" type "class") nil nil nil nil [2954 2968])) ((parent . "Font")) nil nil [2839 3770]) ("draw_text" function ("void") (("text" variable ("std::string" type "class") nil ((const . t)) nil nil [3793 3817]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [3818 3836]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [3842 3866]) ("alpha" variable ("uint8_t" type "class") nil nil nil nil [3867 3881])) ((parent . "Font")) nil nil [3772 4080]) ("draw_chars" function ("void") (("pchars" variable ("Surface" type "class") nil ((pointer . 1)) nil nil [4104 4120]) ("text" variable ("std::string" type "class") nil ((const . t)) nil nil [4121 4145]) ("pos" variable ("Vector" type "class") nil ((const . t)) nil nil [4146 4164]) ("drawing_effect" variable ("uint32_t" type "class") nil nil nil nil [4182 4206]) ("alpha" variable ("uint8_t" type "class") nil nil nil nil [4207 4221])) ((parent . "Font")) nil nil [4082 4861])) + ) + ) + ) diff --git a/src/video/surface.cpp b/src/video/surface.cpp new file mode 100644 index 000000000..fb3e8a038 --- /dev/null +++ b/src/video/surface.cpp @@ -0,0 +1,1063 @@ +// $Id: surface.cpp 2175 2004-11-24 19:02:49Z sik0fewl $ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser +// +// 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 + +#include +#include + +#include "gameconfig.h" +#include "video/surface.h" +#include "video/screen.h" +#include "app/globals.h" +#include "app/setup.h" + +using namespace SuperTux; + +Surface::Surfaces Surface::surfaces; + +extern SDL_Surface* screen; + +SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_) + : type(SURFACE), surface(0), use_alpha(use_alpha_), + x(0), y(0), w(0), h(0) +{ + // Copy the given surface and make sure that it is not stored in + // video memory + surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE), + temp->w, temp->h, + temp->format->BitsPerPixel, + temp->format->Rmask, + temp->format->Gmask, + temp->format->Bmask, + temp->format->Amask); + if(!surface) + throw std::runtime_error("No memory left for surface"); + + SDL_SetAlpha(temp,0,0); + SDL_BlitSurface(temp, NULL, surface, NULL); +} + +SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_) + : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_) +{} + +SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, + int w_, int h_, bool use_alpha_) + : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_), + x(x_), y(y_), w(w_), h(h_) +{} + +SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, + int w_, int h_) + : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_) +{ + top_gradient = top_gradient_; + bottom_gradient = bottom_gradient_; +} + + +SurfaceData::~SurfaceData() +{ + SDL_FreeSurface(surface); +} + +SurfaceImpl* +SurfaceData::create() +{ + if (config->use_gl) + return create_SurfaceOpenGL(); + else + return create_SurfaceSDL(); +} + +SurfaceSDL* +SurfaceData::create_SurfaceSDL() +{ + switch(type) + { + case LOAD: + return new SurfaceSDL(file, use_alpha); + case LOAD_PART: + return new SurfaceSDL(file, x, y, w, h, use_alpha); + case SURFACE: + return new SurfaceSDL(surface, use_alpha); + case GRADIENT: + return new SurfaceSDL(top_gradient, bottom_gradient, w, h); + } + assert(0); +} + +SurfaceOpenGL* +SurfaceData::create_SurfaceOpenGL() +{ + switch(type) + { + case LOAD: + return new SurfaceOpenGL(file, use_alpha); + case LOAD_PART: + return new SurfaceOpenGL(file, x, y, w, h, use_alpha); + case SURFACE: + return new SurfaceOpenGL(surface, use_alpha); + case GRADIENT: + return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h); + default: + assert(false); + } +} + +/* Quick utility function for texture creation */ +static int power_of_two(int input) +{ + int value = 1; + + while ( value < input ) + { + value <<= 1; + } + return value; +} + +Surface::Surface(SDL_Surface* surf, bool use_alpha) + : data(surf, use_alpha), w(0), h(0) +{ + impl = data.create(); + if (impl) + { + w = impl->w; + h = impl->h; + } + surfaces.push_back(this); +} + +Surface::Surface(const std::string& file, bool use_alpha) + : data(file, use_alpha), w(0), h(0) +{ + impl = data.create(); + if (impl) + { + w = impl->w; + h = impl->h; + } + surfaces.push_back(this); +} + +Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use_alpha) + : data(file, x, y, w_, h_, use_alpha), w(0), h(0) +{ + impl = data.create(); + if (impl) + { + w = impl->w; + h = impl->h; + } + surfaces.push_back(this); +} + +Surface::Surface(Color top_background, Color bottom_background, int w_, int h_) + : data(top_background, bottom_background, w_, h_), w(0), h(0) +{ + impl = data.create(); + if (impl) + { + w = impl->w; + h = impl->h; + } + surfaces.push_back(this); +} + +void +Surface::reload() +{ + delete impl; + impl = data.create(); + if (impl) + { + w = impl->w; + h = impl->h; + for(std::vector::iterator i = + data.applied_filters.begin(); i != data.applied_filters.end(); + i++) + impl->apply_filter(i->type, i->color); + } +} + +void Surface::apply_filter(int filter, Color color) +{ + impl->apply_filter(filter, color); + + SurfaceData::Filter apply_filter; + apply_filter.type = filter; + apply_filter.color = color; + data.applied_filters.push_back(apply_filter); +} + +Surface::~Surface() +{ +#ifdef DEBUG + bool found = false; + for(std::list::iterator i = surfaces.begin(); i != surfaces.end(); + ++i) + { + if(*i == this) + { + found = true; break; + } + } + if(!found) + printf("Error: Surface freed twice!!!\n"); +#endif + surfaces.remove(this); + delete impl; +} + +void +Surface::reload_all() +{ + for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i) + { + (*i)->reload(); + } +} + +void +Surface::debug_check() +{ + for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i) + { + printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type, + (*i)->data.file.c_str()); + } +} + +void +apply_filter_to_surface(SDL_Surface* surface, int filter, Color color) +{ + if(filter == HORIZONTAL_FLIP_FILTER) { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); + SDL_BlitSurface(surface, NULL, sur_copy, NULL); + SDL_SetAlpha(sur_copy,0,0); + + SDL_Rect src, dst; + src.y = dst.y = 0; + src.w = dst.w = 1; + src.h = dst.h = sur_copy->h; + for(int x = 0; x < sur_copy->w; x++) + { + src.x = x; dst.x = sur_copy->w-1 - x; + SDL_BlitSurface(sur_copy, &src, surface, &dst); + } + + SDL_FreeSurface(sur_copy); + } else if(filter == MASK_FILTER) { + SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true); + + Uint8 r,g,b,a; + + SDL_LockSurface(sur_copy); + for(int x = 0; x < sur_copy->w; x++) + for(int y = 0; y < sur_copy->h; y++) { + SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a); + if(a != 0) { + putpixel(sur_copy, x,y, color.map_rgba(sur_copy)); + } + } + SDL_UnlockSurface(sur_copy); + + SDL_BlitSurface(sur_copy, NULL, surface, NULL); + SDL_FreeSurface(sur_copy); + } +} + +SDL_Surface* +sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha) +{ + SDL_Rect src; + SDL_Surface * sdl_surface; + SDL_Surface * temp; + SDL_Surface * conv; + + temp = IMG_Load(file.c_str()); + + if (temp == NULL) { + std::stringstream msg; + msg << "Couldn't load '" << file << "': " << SDL_GetError(); + throw std::runtime_error(msg.str()); + } + + /* Set source rectangle for conv: */ + + src.x = x; + src.y = y; + src.w = w; + src.h = h; + + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, temp->format->BitsPerPixel, + temp->format->Rmask, + temp->format->Gmask, + temp->format->Bmask, + temp->format->Amask); + + SDL_SetAlpha(temp,0,0); + + SDL_BlitSurface(temp, &src, conv, NULL); + if(use_alpha == false && !config->use_gl) + sdl_surface = SDL_DisplayFormat(conv); + else + sdl_surface = SDL_DisplayFormatAlpha(conv); + + if (sdl_surface == NULL) { + std::stringstream msg; + msg << "Can't convert file '" << file << "' to display format."; + throw std::runtime_error(msg.str()); + } + + if (use_alpha == false && !config->use_gl) + SDL_SetAlpha(sdl_surface, 0, 0); + + SDL_FreeSurface(temp); + SDL_FreeSurface(conv); + + return sdl_surface; +} + +SDL_Surface* +sdl_surface_from_file(const std::string& file, bool use_alpha) +{ + SDL_Surface* sdl_surface; + SDL_Surface* temp; + + temp = IMG_Load(file.c_str()); + + if (temp == NULL) { + std::stringstream msg; + msg << "Couldn't load file '" << file << "': " << SDL_GetError(); + throw std::runtime_error(msg.str()); + } + + if(use_alpha == false && !config->use_gl) + sdl_surface = SDL_DisplayFormat(temp); + else + sdl_surface = SDL_DisplayFormatAlpha(temp); + + if (sdl_surface == NULL) { + std::stringstream msg; + msg << "Couldn't convert file '" << file << "' to display format"; + throw std::runtime_error(msg.str()); + } + + if (use_alpha == false && !config->use_gl) + SDL_SetAlpha(sdl_surface, 0, 0); + + SDL_FreeSurface(temp); + + return sdl_surface; +} + +SDL_Surface* +sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha) +{ + SDL_Surface* sdl_surface; +#if 0 + Uint32 saved_flags; + Uint8 saved_alpha; + + /* Save the alpha blending attributes */ + saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = sdl_surf->format->alpha; + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(sdl_surf, 0, 0); + } +#endif + + if(use_alpha == false && !config->use_gl) + sdl_surface = SDL_DisplayFormat(sdl_surf); + else + sdl_surface = SDL_DisplayFormatAlpha(sdl_surf); + +#if 0 + /* Restore the alpha blending attributes */ + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha); + } +#endif + + if (sdl_surface == NULL) { + std::stringstream msg; + msg << "Can't convert surface to display format."; + throw std::runtime_error(msg.str()); + } + + if (use_alpha == false && !config->use_gl) + SDL_SetAlpha(sdl_surface, 0, 0); + + return sdl_surface; +} + +SDL_Surface* +sdl_surface_from_gradient(Color top, Color bottom, int w, int h) +{ + SDL_Surface* sdl_surface + = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, + screen->format->BitsPerPixel, screen->format->Rmask, + screen->format->Gmask, screen->format->Bmask, 0); + + if(sdl_surface == 0) + throw std::runtime_error("Can't create gradient surface"); + + if(top == bottom) { + SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format, + top.red, top.green, top.blue)); + } else { + float redstep = (float(bottom.red)-float(top.red)) / float(h); + float greenstep = (float(bottom.green)-float(top.green)) / float(h); + float bluestep = (float(bottom.blue) - float(top.blue)) / float(h); + + SDL_Rect rect; + rect.x = 0; + rect.w = w; + rect.h = 1; + for(float y = 0; y < h; y++) { + rect.y = (int)y; + SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format, + int(float(top.red) + redstep * y), + int(float(top.green) + greenstep * y), + int(float(top.blue) + bluestep * y))); + } + } + + return sdl_surface; +} + +//--------------------------------------------------------------------------- + +SurfaceImpl::SurfaceImpl() +{} + +SurfaceImpl::~SurfaceImpl() +{ + SDL_FreeSurface(sdl_surface); +} + +SDL_Surface* SurfaceImpl::get_sdl_surface() const +{ + return sdl_surface; +} + +SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha) +{ + sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha); + create_gl(sdl_surface,&gl_texture); + + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha) +{ + sdl_surface = sdl_surface_from_file(file, use_alpha); + create_gl(sdl_surface,&gl_texture); + + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, + int w_, int h_, bool use_alpha_) +{ + sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_); + + create_gl(sdl_surface, &gl_texture); + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, + int _w, int _h) +{ + sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h); + create_gl(sdl_surface, &gl_texture); + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceOpenGL::~SurfaceOpenGL() +{ + glDeleteTextures(1, &gl_texture); +} + +void +SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex) +{ + Uint32 saved_flags; + Uint8 saved_alpha; + int w, h; + SDL_Surface *conv; + + w = power_of_two(surf->w); + h = power_of_two(surf->h), + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, + 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); +#else + conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel, + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); +#endif + + /* Save the alpha blending attributes */ + saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = surf->format->alpha; + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, 0, 0); + } + + SDL_BlitSurface(surf, 0, conv, 0); + + /* Restore the alpha blending attributes */ + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, saved_flags, saved_alpha); + } + + // We check all the pixels of the surface to figure out which + // internal format OpenGL should use for storing it, ie. if no alpha + // is present store in RGB instead of RGBA, this saves a few bytes + // of memory, but much more importantly it makes the game look + // *much* better in 16bit color mode + int internal_format = GL_RGB10_A2; + bool has_alpha = false; + + unsigned char* buf = static_cast(conv->pixels); + for (int y = 0; y < surf->h; ++y) + for (int x = 0; x < surf->w; ++x) + { + if (buf[(conv->pitch*y + x*4) + 3] != 255) + { + has_alpha = true; + break; + } + } + + if (!has_alpha) + { + internal_format = GL_RGB; + } + + glGenTextures(1, &*tex); + glBindTexture(GL_TEXTURE_2D , *tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + + SDL_FreeSurface(conv); +} + +int +SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect) +{ + float pw = power_of_two(w); + float ph = power_of_two(h); + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(alpha, alpha, alpha, alpha); + + glBindTexture(GL_TEXTURE_2D, gl_texture); + + glBegin(GL_QUADS); + + if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f(x, (float)h+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f(x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f((float)w+x, y); + } + else if(effect & VERTICAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f(x, (float)h+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, y); + } + else if(effect & HORIZONTAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f((float)w+x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f(x, (float)h+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f((float)w+x, (float)h+y); + } + else + { + glTexCoord2f(0, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)w+x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, (float)h+y); + } + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + return 0; +} + +int +SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect) +{ + float pw = power_of_two(int(this->w)); + float ph = power_of_two(int(this->h)); + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + glBindTexture(GL_TEXTURE_2D, gl_texture); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(alpha, alpha, alpha, alpha); + + glEnable(GL_TEXTURE_2D); + + + glBegin(GL_QUADS); + + if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP) + { + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f((float)w+x, (float)h+y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(x, (float)h+y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(x, y); + + glTexCoord2f(sx / pw, sy / ph); + glVertex2f((float)w+x, y); + } + else if(effect & VERTICAL_FLIP) + { + glTexCoord2f(sx / pw, sy / ph); + glVertex2f(x, y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(w+x, y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(w +x, h+y); + + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f(x, h+y); + } + else if(effect & HORIZONTAL_FLIP) + { + glTexCoord2f(sx / pw, sy / ph); + glVertex2f((float)w+x, y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(x, y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(x, (float)h+y); + + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f((float)w+x, (float)h+y); + } + else + { + glTexCoord2f(sx / pw, (float)(sy+h) / ph); + glVertex2f(x, h+y); + + glTexCoord2f((sx+w) / pw, (sy+h) / ph); + glVertex2f(w +x, h+y); + + glTexCoord2f((float)(sx + w) / pw, sy / ph); + glVertex2f(w+x, y); + + glTexCoord2f(sx / pw, sy / ph); + glVertex2f(x, y); + } + + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + return 0; +} + +int +SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect) +{ + float pw = power_of_two(sw); + float ph = power_of_two(sh); + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glColor4ub(alpha, alpha, alpha, alpha); + + glBindTexture(GL_TEXTURE_2D, gl_texture); + + glBegin(GL_QUADS); + + if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f((float)sw+x, (float)sh+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f(x, (float)sh+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f(x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f((float)sw+x, y); + } + else if(effect & VERTICAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f(x, (float)sh+y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)sw+x, (float)sh+y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)sw+x, y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, y); + } + else if(effect & HORIZONTAL_FLIP) + { + glTexCoord2f(0, 0); + glVertex2f((float)sw+x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f(x, (float)sh+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f((float)sw+x, (float)sh+y); + } + else + { + glTexCoord2f(0, 0); + glVertex2f(x, y); + + glTexCoord2f((float)w / pw, 0); + glVertex2f((float)sw+x, y); + + glTexCoord2f((float)w / pw, (float)h / ph); + glVertex2f((float)sw+x, (float)sh+y); + + glTexCoord2f(0, (float)h / ph); + glVertex2f(x, (float)sh+y); + } + glEnd(); + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + return 0; +} + +void +SurfaceOpenGL::apply_filter(int filter, Color color) +{ + ::apply_filter_to_surface(sdl_surface, filter, color); + create_gl(sdl_surface,&gl_texture); + + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha) +{ + sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha); + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha) +{ + sdl_surface = sdl_surface_from_file(file, use_alpha); + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int _w, int _h, + bool use_alpha) +{ + sdl_surface = sdl_surface_part_from_file(file, x, y, _w, _h, use_alpha); + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, + int _w, int _h) +{ + sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h); + w = sdl_surface->w; + h = sdl_surface->h; +} + +int +SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect) +{ + SDL_Rect dest; + + dest.x = (int)x; + dest.y = (int)y; + dest.w = w; + dest.h = h; + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP) + { + // FIXME: this hack is damn slow. Just keep it cause it isn't that used. + for(float sx = 0; sx < w; sx++) + for(float sy = 0; sy < h; sy++) + if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sy = 0; sy < h; sy++) + if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sx = 0; sx < w; sx++) + if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + + if(alpha != 255) + { + /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha + to temp sur, blit the temp into the screen */ + /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that + already have an alpha mask yet... */ + + SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, + sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel, + sdl_surface->format->Rmask, sdl_surface->format->Gmask, + sdl_surface->format->Bmask, + 0); + int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255); + SDL_FillRect(sdl_surface_copy, NULL, colorkey); + SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey); + + + SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL); + SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha); + + int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest); + + SDL_FreeSurface (sdl_surface_copy); + return ret; + } + + int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest); + + return ret; +} + +int +SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect) +{ + SDL_Rect src, dest; + + src.x = (int)sx; + src.y = (int)sy; + src.w = (int)w; + src.h = (int)h; + + dest.x = (int)x; + dest.y = (int)y; + dest.w = (int)w; + dest.h = (int)h; + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP) + { + // FIXME: this hack is damn slow. Just keep it cause it isn't that used. + for(float sx_ = 0; sx_ < w; sx++) + for(float sy_ = 0; sy_ < h; sy++) + if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sy_ = sy; sy_ < h; sy_++) + if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack + { + for(float sx_ = 0; sx_ < w; sx_++) + if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2) + return -2; + return 0; + } + + if(alpha != 255) + { + /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha + to temp sur, blit the temp into the screen */ + /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that + already have an alpha mask, yet... */ + + SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, + (int)w, (int)h, sdl_surface->format->BitsPerPixel, + sdl_surface->format->Rmask, sdl_surface->format->Gmask, + sdl_surface->format->Bmask, + 0); + int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255); + SDL_FillRect(sdl_surface_copy, NULL, colorkey); + SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey); + + + SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL); + SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha); + + int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest); + + SDL_FreeSurface (sdl_surface_copy); + return ret; + } + + int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest); + + return ret; +} + +int +SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect) +{ + SDL_Rect dest; + + dest.x = (int)x; + dest.y = (int)y; + dest.w = (int)sw; + dest.h = (int)sh; + + if(effect & SEMI_TRANSPARENT) + alpha = 128; + + SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags, + sw, sh, sdl_surface->format->BitsPerPixel, + sdl_surface->format->Rmask, sdl_surface->format->Gmask, + sdl_surface->format->Bmask, + 0); + + SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL); + SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest); + + if(alpha != 255) + SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha); + + int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest); + SDL_FreeSurface(sdl_surface_copy); + + return ret; +} + +void +SurfaceSDL::apply_filter(int filter, Color color) +{ + ::apply_filter_to_surface(sdl_surface, filter, color); + + w = sdl_surface->w; + h = sdl_surface->h; +} + +SurfaceSDL::~SurfaceSDL() +{} diff --git a/src/video/surface.h b/src/video/surface.h new file mode 100644 index 000000000..55f6ed051 --- /dev/null +++ b/src/video/surface.h @@ -0,0 +1,186 @@ +// $Id: surface.h 2175 2004-11-24 19:02:49Z sik0fewl $ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser +// +// 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. +#ifndef SUPERTUX_TEXTURE_H +#define SUPERTUX_TEXTURE_H + +#include +#include + +#include +#include + +#include "math/vector.h" +#include "video/screen.h" + +void apply_filter_to_surface(SDL_Surface *surface, int filter, int value); +SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha); +SDL_Surface* sdl_surface_from_nothing(); + +class SurfaceImpl; +class SurfaceSDL; +class SurfaceOpenGL; +class DrawingContext; + +/// bitset for drawing effects +enum { + /** Don't apply anything */ + NONE_EFFECT = 0x0000, + /** Draw the Surface upside down */ + VERTICAL_FLIP = 0x0001, + /** Draw the Surface from left to down */ + HORIZONTAL_FLIP = 0x0002, + /** Draw the Surface with alpha equal to 128 */ + SEMI_TRANSPARENT = 0x0004 +}; + +/// types of filters +enum { + HORIZONTAL_FLIP_FILTER, + MASK_FILTER, + NONE_FILTER +}; + +/** This class holds all the data necessary to construct a surface */ +class SurfaceData +{ +public: + enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT }; + ConstructorType type; + SDL_Surface* surface; + std::string file; + + struct Filter { int type; Color color; }; + std::vector applied_filters; + + bool use_alpha; + int x; + int y; + int w; + int h; + Color top_gradient; + Color bottom_gradient; + + SurfaceData(SDL_Surface* surf, bool use_alpha_); + SurfaceData(const std::string& file_, bool use_alpha_); + SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_); + SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_); + ~SurfaceData(); + + SurfaceSDL* create_SurfaceSDL(); + SurfaceOpenGL* create_SurfaceOpenGL(); + SurfaceImpl* create(); +}; + + +/** Container class that holds a surface, necessary so that we can + * switch Surface implementations (OpenGL, SDL) on the fly + */ +class Surface +{ +public: + SurfaceData data; + SurfaceImpl* impl; + int w; + int h; + + typedef std::list Surfaces; + static Surfaces surfaces; +public: + static void reload_all(); + static void debug_check(); + + Surface(SDL_Surface* surf, bool use_alpha); + Surface(const std::string& file, bool use_alpha); + Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha); + Surface(Color top_gradient, Color bottom_gradient, int w_, int h_); + ~Surface(); + + /** Reload the surface, which is necesarry in case of a mode swich */ + void reload(); + + void apply_filter(int filter, Color color = Color(0,0,0)); +}; + +/** Surface implementation, all implementation have to inherit from + this class */ +class SurfaceImpl +{ +protected: + SDL_Surface* sdl_surface; + +public: + int w; + int h; + +public: + SurfaceImpl(); + virtual ~SurfaceImpl(); + + /** Return 0 on success, -2 if surface needs to be reloaded */ + virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0; + + + SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function + + virtual void apply_filter(int filter, Color color = Color(0,0,0)) = 0; +}; + +class SurfaceSDL : public SurfaceImpl +{ +public: + SurfaceSDL(SDL_Surface* surf, bool use_alpha); + SurfaceSDL(const std::string& file, bool use_alpha); + SurfaceSDL(const std::string& file, int x, int y, int w_, int h_, bool use_alpha); + SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h); + virtual ~SurfaceSDL(); + + int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + + void apply_filter(int filter, Color color); +}; + +class SurfaceOpenGL : public SurfaceImpl +{ +public: + GLuint gl_texture; + +public: + SurfaceOpenGL(SDL_Surface* surf, bool use_alpha); + SurfaceOpenGL(const std::string& file, bool use_alpha); + SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, bool use_alpha); + SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h); + + virtual ~SurfaceOpenGL(); + + int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT); + + void apply_filter(int filter, Color color); + +private: + void create_gl(SDL_Surface * surf, GLuint * tex); +}; + +#endif