INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
-FIND_PACKAGE(SDL REQUIRED)
-INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
+#FIND_PACKAGE(SDL REQUIRED)
+INCLUDE_DIRECTORIES("src/SDL2/")
SET(HAVE_SDL TRUE)
-FIND_PACKAGE(SDL_image REQUIRED)
-INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
+#FIND_PACKAGE(SDL_image REQUIRED)
+#INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
IF(ENABLE_OPENGL)
switch(type(o)) {
case OT_STRING: return _string(o);
case OT_INTEGER:
- scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%d"), _integer(o));
+ scsprintf(_sp(rsl(NUMBER_MAX_CHAR+1)), _SC("%ld"), _integer(o));
return SQString::Create(_ss(this), _spval);
break;
case OT_FLOAT:
#include "supertux/menu/keyboard_menu.hpp"
#include "util/gettext.hpp"
#include "util/writer.hpp"
+//#include <SDL_keycode.h> // add by giby
JoystickKeyboardController::JoystickKeyboardController() :
controller(),
SDL_Joystick* joystick = SDL_JoystickOpen(i);
bool good = true;
if(SDL_JoystickNumButtons(joystick) < 2) {
- log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 buttons" << std::endl;
+ log_info << _("Joystick ") << i << ": " << SDL_JoystickID(i) << _(" has less than 2 buttons") << std::endl;
good = false;
}
if(SDL_JoystickNumAxes(joystick) < 2
&& SDL_JoystickNumHats(joystick) == 0) {
- log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 axes and no hat" << std::endl;
+ log_info << _("Joystick ") << i << ": " << SDL_JoystickID(i) << _(" has less than 2 axes and no hat") << std::endl;
good = false;
}
if(!good) {
const lisp::Lisp* map = iter.lisp();
map->get("key", key);
map->get("control", control);
- if(key < SDLK_FIRST || key >= SDLK_LAST) {
- log_info << "Invalid key '" << key << "' in keymap" << std::endl;
- continue;
- }
+// if(key < SDLK_FIRST || key >= SDLK_LAST) {
+// log_info << "Invalid key '" << key << "' in keymap" << std::endl;
+// continue;
+// }
int i = 0;
for(i = 0; Controller::controlNames[i] != 0; ++i) {
log_info << "Invalid control '" << control << "' in keymap" << std::endl;
continue;
}
- keymap[SDLKey(key)] = Control(i);
+ keymap[SDL_Keycode(key)] = Control(i);
}
}
}
- const lisp::Lisp* joystick_lisp = lisp.get_lisp("joystick");
+ const lisp::Lisp* joystick_lisp = lisp.get_lisp(_("joystick"));
if(joystick_lisp) {
joystick_lisp->get("dead-zone", dead_zone);
joystick_lisp->get("jump-with-up", jump_with_up_joy);
lisp::ListIterator iter(joystick_lisp);
while(iter.next()) {
- if(iter.item() == "map") {
+ if(iter.item() == _("map")) {
int button = -1;
int axis = 0;
int hat = -1;
process_menu_key_event(event);
} else if(key_mapping == keymap.end()) {
// default action: update controls
- //log_debug << "Key " << event.key.keysym.sym << " is unbound" << std::endl;
+ //log_debug << "Key " << event.key.SDL_Keycode.sym << " is unbound" << std::endl;
} else {
Control control = key_mapping->second;
bool value = (event.type == SDL_KEYDOWN);
Console::instance->move_cursor(+1);
break;
default:
- int c = event.keysym.unicode;
- if ((c >= 32) && (c <= 126)) {
- Console::instance->input((char)c);
- }
+ // int c = SDL_GetScancodeName(event.keysym);
+ // if ((c >= 32) && (c <= 126)) { <Xeek> you need to move that "unicode" source we were originaly talkinga bout into a new function that gets called from the SDL_TextInput event..... you'll be adding that event.
+ // Console::instance->input((char)c);
+ // }
break;
}
}
}
void
-JoystickKeyboardController::bind_key(SDLKey key, Control control)
+JoystickKeyboardController::bind_key(SDL_Keycode key, Control control)
{
// remove all previous mappings for that control and for that key
for(KeyMap::iterator i = keymap.begin();
void
JoystickKeyboardController::print_joystick_mappings()
{
- std::cout << "Joystick Mappings" << std::endl;
+ std::cout << _("Joystick Mappings") << std::endl;
std::cout << "-----------------" << std::endl;
for(AxisMap::iterator i = joy_axis_map.begin(); i != joy_axis_map.end(); ++i) {
std::cout << "Axis: " << i->first.second << " -> " << i->second << std::endl;
std::cout << std::endl;
}
-SDLKey
+SDL_Keycode
JoystickKeyboardController::reversemap_key(Control c)
{
for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) {
#include "control/controller.hpp"
#include <SDL.h>
-
+#include <SDL_keycode.h> // add by giby
#include <map>
#include <string>
#include <vector>
class JoystickMenu;
class Controller;
-class JoystickKeyboardController
+ //SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
+
+class JoystickKeyboardController // http://wiki.libsdl.org/moin.fcg/SDL_Joystick for info
{
private:
friend class KeyboardMenu;
typedef Controller::Control Control;
typedef Uint8 JoyId;
- typedef std::map<SDLKey, Control> KeyMap;
+ typedef std::map<SDL_Keycode, Control> KeyMap;
typedef std::map<std::pair<JoyId, int>, Control> ButtonMap;
typedef std::map<std::pair<JoyId, int>, Control> AxisMap;
typedef std::map<std::pair<JoyId, int>, Control> HatMap;
void print_joystick_mappings();
- SDLKey reversemap_key(Control c);
+ SDL_Keycode reversemap_key(Control c);
int reversemap_joybutton(Control c);
int reversemap_joyaxis(Control c);
int reversemap_joyhat(Control c);
void bind_joybutton(JoyId joy_id, int button, Control c);
void bind_joyaxis(JoyId joy_id, int axis, Control c);
void bind_joyhat(JoyId joy_id, int dir, Control c);
- void bind_key(SDLKey key, Control c);
+ void bind_key(SDL_Keycode key, Control c);
- void set_joy_controls(Control id, bool value);
+ void set_joy_controls(Control id, bool value);
private:
Controller *controller;
FontPtr Button::info_font;
-Button::Button(SurfacePtr image_, std::string info_, SDLKey binding_) :
+Button::Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_) :
pos(),
size(),
image(),
class Button
{
public:
- Button(SurfacePtr image_, std::string info_, SDLKey binding_);
+ Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_);
Button(const Button& rhs);
~Button();
Vector size;
SurfacePtr image;
- SDLKey binding;
+ SDL_Keycode binding;
int id;
int state;
caught_event = true;
- if(event.button.button == SDL_BUTTON_WHEELUP)
+ if(event.button.button == SDL_MOUSEBUTTONUP)
{
row--;
if(row < 0)
row = 0;
}
- else if(event.button.button == SDL_BUTTON_WHEELDOWN)
+ else if(event.button.button == SDL_MOUSEBUTTONDOWN)
{
row++;
if(row > (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y +
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <SDL.h>
+#include "SDL2/SDL.h"
#include "supertux/main.hpp"
#include "util/log.hpp"
-static int funcSeek(struct SDL_RWops* context, int offset, int whence)
+static Sint64 funcSeek(struct SDL_RWops* context, Sint64 offset, int whence)
{
PHYSFS_file* file = (PHYSFS_file*) context->hidden.unknown.data1;
int res;
return (int) PHYSFS_tell(file);
}
-static int funcRead(struct SDL_RWops* context, void* ptr, int size, int maxnum)
+static size_t funcRead(struct SDL_RWops* context, void* ptr, size_t size, size_t maxnum)
{
PHYSFS_file* file = (PHYSFS_file*) context->hidden.unknown.data1;
log_info << "Camera is at " << Sector::current()->camera->get_translation().x << "," << Sector::current()->camera->get_translation().y << std::endl;
}
-void set_gamma(float gamma) {
- SDL_SetGamma(gamma, gamma, gamma);
+ SDL_Window *screen;
+
+void set_gamma(const Uint16 * gamma) {
+ SDL_SetWindowGammaRamp(screen,gamma, gamma, gamma);
}
void quit()
focused = true;
height = 256;
alpha = 1.0;
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
+// SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Useless in SDL2 : if you want to disable repeat, then you need to check if the key was repeated and ignore it.
}
void
// clear input buffer
inputBuffer = "";
inputBufferPosition = 0;
- SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
+ // SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
}
void
// just to be sure
atexit(SDL_Quit);
- SDL_EnableUNICODE(1);
+ // SDL_EnableUNICODE(1); //old code, mofif by giby
+ // SDL_JoystickID myID = SDL_JoystickInstanceID(myOpenedStick);
+
// wait 100ms and clear SDL event queue because sometimes we have random
// joystick events in the queue on startup...
// FIXME: Add something here
SCREEN_WIDTH = 800;
SCREEN_HEIGHT = 600;
-
+
+/* SDL_Window *window; // Declare a pointer to an SDL_Window
context_pointer->init_renderer();
- g_screen = SDL_GetVideoSurface();
+ g_screen = SDL_GetWindowSurface(*window);*/
- SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
+ // SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
- // set icon
+ /* // set icon -- Original part B4 SDL2
#ifdef MACOSX
const char* icon_fname = "images/engine/icons/supertux-256x256.png";
#else
log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
}
if(icon != 0) {
- SDL_WM_SetIcon(icon, 0);
+ SDL_WM_SetIcon(icon, 0); //now SDL_SetWindowIcon(window, surface); if needed
SDL_FreeSurface(icon);
}
else {
log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
}
+ */
+
+ // SDL_WM_SetCaption(PACKAGE_NAME " " PACKAGE_VERSION, 0);
+
+ // set icon
+#ifdef MACOSX
+ const char* icon_fname = "images/engine/icons/supertux-256x256.png";
+#else
+ const char* icon_fname = "images/engine/icons/supertux.xpm";
+#endif
+ SDL_Window* icon;
+ try {
+ //icon = IMG_Load_RW(get_physfs_SDLRWops(icon_fname), true);
+ } catch (const std::runtime_error& err) {
+ icon = 0;
+ log_warning << "Couldn't load icon '" << icon_fname << "': " << err.what() << std::endl;
+ }
+ if(icon != 0) {
+ // SDL_SetWindowIcon(icon, 0); //now SDL_SetWindowIcon(window, surface); if needed
+ // SDL_FreeSurface(icon);
+ }
+ else {
+ log_warning << "Couldn't load icon '" << icon_fname << "'" << std::endl;
+ }
+
+
+ /* // set icon
+#ifdef MACOSX
+ const char* icon_fname = "images/engine/icons/supertux-256x256.png";
+#else
+ const char* icon_fname = "images/engine/icons/supertux.xpm";
+#endif
+
+ SDL_Window icon = SDL_CreateWindow(PACKAGE_NAME " " PACKAGE_VERSION,
+ SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ 640, 480,
+ SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
+ // not sure of that */
SDL_ShowCursor(0);
}
add_inactive(-1,"");
add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
-
- //Show Joysticks currently activated:
+ //Show Joysticks currently activated: //edit by giby
+ joy = SDL_JoystickOpen(0)
+ if (SDL_NumJoysticks() > 0) {joy = SDL_JoystickOpen(0);
for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
i != controller->joysticks.end(); ++i) {
if(*i != 0)
- add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) );
+ add_inactive(-1, SDL_JoystickName(joy) );
}
add_hl();
}
std::string
-JoystickMenu::get_button_name(int button)
+/*JoystickMenu::get_button_name(int button)
{
if(button < 0)
return _("None");
std::ostringstream name;
name << "Button " << button;
return name.str();
-}
+}*/
void
JoystickMenu::menu_action(MenuItem* item)
{}
std::string
-KeyboardMenu::get_key_name(SDLKey key)
+KeyboardMenu::get_key_name(SDL_Keycode key)
{
switch(key) {
case SDLK_UNKNOWN:
case SDLK_LALT:
return _("Left Alt");
default:
- return SDL_GetKeyName((SDLKey) key);
+ return SDL_GetKeyName((SDL_Keycode) key);
}
}
~KeyboardMenu();
void update();
- std::string get_key_name(SDLKey key);
+ std::string SDL_GetKeyName(SDL_Keycode* key);
virtual void menu_action(MenuItem* item);
JoystickKeyboardController* controller;
void check_menu() {}
ScreenManager::process_events()
{
g_jk_controller->update();
- Uint8* keystate = SDL_GetKeyState(NULL);
+const Uint8 *keystate = SDL_GetKeyboardState(NULL); //edited by giby
SDL_Event event;
while(SDL_PollEvent(&event))
{
quit();
break;
- case SDL_VIDEORESIZE:
- Renderer::instance()->resize(event.resize.w, event.resize.h);
- MenuManager::recalc_pos();
- break;
+ // case SDL_ResizeEvent: //edit by giby
+ // Renderer::instance()->resize(event.resize.w, event.resize.h);
+ // MenuManager::recalc_pos();
+ // break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_F10)
Renderer::instance()->apply_config();
MenuManager::recalc_pos();
}
- else if (event.key.keysym.sym == SDLK_PRINT ||
+ else if (event.key.keysym.sym == SDLK_PRINTSCREEN ||
event.key.keysym.sym == SDLK_F12)
{
take_screenshot();
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+// Updated by GiBy 2013 for SDL2 <giby_the_kid@yahoo.fr>
//
// 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
#include <iomanip>
#include <iostream>
#include <physfs.h>
+#include "SDL2/SDL.h"
+//#include "SDL/SDL.h"
+//#include "SDL/SDL_opengl.h"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#ifdef SDL_GL_SWAP_CONTROL
if(config->try_vsync) {
/* we want vsync for smooth scrolling */
- SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+ SDL_GL_SetSwapInterval(1);
}
#endif
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetSwapInterval(SDL_GL_DOUBLEBUFFER, 1);
// FIXME: Hu? 16bit rendering?
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+ SDL_GL_SetSwapInterval(5);
+ SDL_GL_SetSwapInterval(5);
+ SDL_GL_SetSwapInterval(5);
if(g_config->use_fullscreen)
{
GLRenderer::flip()
{
assert_gl("drawing");
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(screen)();
}
void
{
// This causes the screen to go black, which is annoying, but seems
// unavoidable with SDL at the moment
- SDL_SetVideoMode(w, h, 0, SDL_OPENGL | SDL_RESIZABLE);
+ SDL_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_OPENGL | SDL_RESIZABLE));
g_config->window_size = Size(w, h);
// Clear both buffers so that we get a clean black border without junk
glClear(GL_COLOR_BUFFER_BIT);
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(screen);
glClear(GL_COLOR_BUFFER_BIT);
- SDL_GL_SwapBuffers();
+ SDL_GL_SwapWindow(screen);
glViewport(std::max(0, (screen_size.width - new_size.width) / 2),
std::max(0, (screen_size.height - new_size.height) / 2),
flags |= SDL_RESIZABLE;
}
- if (SDL_Surface *screen = SDL_SetVideoMode(size.width, size.height, 0, flags))
+ if (SDL_Surface *screen = SDL_CreateWindow(SDL_GL_CreateContext( size.width, size.height, 0, flags)))
{
screen_size = Size(screen->w, screen->h);
fullscreen_active = fullscreen;
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+// Updated by GiBy 2013 for SDL2 <giby_the_kid@yahoo.fr>
//
// 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
#include <physfs.h>
#include <sstream>
#include <stdexcept>
+#include "SDL2/SDL_video.h"
+//#include "SDL/SDL.h"
+//#include "SDL/SDL_opengl.h"
+
namespace {
log_info << "Software to hardware blits with alpha are " << (info->blit_sw_A ? "" : "not ") << "accelerated." << std::endl;
log_info << "Color fills are " << (info->blit_fill ? "" : "not ") << "accelerated." << std::endl;
- int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
- if(g_config->use_fullscreen)
- flags |= SDL_FULLSCREEN;
+ // int flags = SDL_SWSURFACE | SDL_ANYFORMAT;
+ // if(g_config->use_fullscreen)
+ // flags |= SDL_FULLSCREEN;
int width = 800; //FIXME: config->screenwidth;
int height = 600; //FIXME: config->screenheight;
-
- screen = SDL_SetVideoMode(width, height, 0, flags);
- if(screen == 0) {
+
+ SDL_Window *window; // Declare a pointer to an SDL_Window
+
+ SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
+
+ window = SDL_CreateWindow("SuperTux",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width, height, 0, SDL_WINDOW_OPENGL );
+ SDL_GLContext glcontext = SDL_GL_CreateContext(window);
+
+ if(window == 0) {
std::stringstream msg;
msg << "Couldn't set video mode (" << width << "x" << height
<< "): " << SDL_GetError();
throw std::runtime_error("SDL_CreateRGBSurfaceFrom() call failed");
}
- if (image->format->palette)
+ /* if (image->format->palette)
{ // copy the image palette to subimage if present
- SDL_SetColors(subimage.get(), image->format->palette->colors, 0, image->format->palette->ncolors);
- }
+ SDL_SetSurfacePalette(subimage.get(), image->format->palette->colors); //edited by giby
+ } */
return VideoSystem::new_texture(subimage.get());
}