Skip to content

Commit

Permalink
modified: CMakeLists.txt
Browse files Browse the repository at this point in the history
	modified:   external/squirrel/squirrel/sqdebug.cpp
	modified:   src/control/joystickkeyboardcontroller.cpp
	modified:   src/control/joystickkeyboardcontroller.hpp
	modified:   src/gui/button.cpp
	modified:   src/gui/button.hpp
	modified:   src/gui/button_group.cpp
	modified:   src/main.cpp
	modified:   src/physfs/physfs_sdl.cpp
	modified:   src/scripting/functions.cpp
	modified:   src/supertux/console.cpp
	modified:   src/supertux/main.cpp
	modified:   src/supertux/menu/joystick_menu.cpp
	modified:   src/supertux/menu/keyboard_menu.cpp
	modified:   src/supertux/menu/keyboard_menu.hpp
	modified:   src/supertux/screen_manager.cpp
	modified:   src/video/gl/gl_renderer.cpp
	modified:   src/video/sdl/sdl_renderer.cpp
	modified:   src/video/texture_manager.cpp
git add	src/SDL2/
  • Loading branch information
Benjamin Leduc committed Aug 24, 2013
1 parent 9962123 commit 262ce11
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 79 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Expand Up @@ -66,12 +66,12 @@ FIND_PACKAGE(Boost REQUIRED)
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)
Expand Down
2 changes: 1 addition & 1 deletion external/squirrel/squirrel/sqdebug.cpp
Expand Up @@ -74,7 +74,7 @@ SQString *SQVM::PrintObjVal(const SQObject &o)
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:
Expand Down
35 changes: 18 additions & 17 deletions src/control/joystickkeyboardcontroller.cpp
Expand Up @@ -28,6 +28,7 @@
#include "supertux/menu/keyboard_menu.hpp"
#include "util/gettext.hpp"
#include "util/writer.hpp"
//#include <SDL_keycode.h> // add by giby

JoystickKeyboardController::JoystickKeyboardController() :
controller(),
Expand Down Expand Up @@ -138,12 +139,12 @@ JoystickKeyboardController::updateAvailableJoysticks()
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) {
Expand Down Expand Up @@ -196,10 +197,10 @@ JoystickKeyboardController::read(const Reader& lisp)
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) {
Expand All @@ -210,18 +211,18 @@ JoystickKeyboardController::read(const Reader& lisp)
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;
Expand Down Expand Up @@ -510,7 +511,7 @@ JoystickKeyboardController::process_key_event(const SDL_KeyboardEvent& event)
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);
Expand Down Expand Up @@ -562,10 +563,10 @@ JoystickKeyboardController::process_console_key_event(const SDL_KeyboardEvent& e
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;
}
}
Expand Down Expand Up @@ -689,7 +690,7 @@ JoystickKeyboardController::bind_joybutton(JoyId joy_id, int button, Control con
}

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();
Expand All @@ -714,7 +715,7 @@ JoystickKeyboardController::bind_key(SDLKey key, Control control)
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;
Expand All @@ -730,7 +731,7 @@ JoystickKeyboardController::print_joystick_mappings()
std::cout << std::endl;
}

SDLKey
SDL_Keycode
JoystickKeyboardController::reversemap_key(Control c)
{
for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) {
Expand Down
14 changes: 8 additions & 6 deletions src/control/joystickkeyboardcontroller.hpp
Expand Up @@ -20,7 +20,7 @@
#include "control/controller.hpp"

#include <SDL.h>

#include <SDL_keycode.h> // add by giby
#include <map>
#include <string>
#include <vector>
Expand All @@ -33,7 +33,9 @@ class KeyboardMenu;
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;
Expand All @@ -42,7 +44,7 @@ class JoystickKeyboardController
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;
Expand Down Expand Up @@ -74,7 +76,7 @@ class JoystickKeyboardController

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);
Expand All @@ -84,9 +86,9 @@ class JoystickKeyboardController
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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/button.cpp
Expand Up @@ -21,7 +21,7 @@

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(),
Expand Down
4 changes: 2 additions & 2 deletions src/gui/button.hpp
Expand Up @@ -38,7 +38,7 @@ enum {
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();

Expand All @@ -57,7 +57,7 @@ class Button
Vector size;

SurfacePtr image;
SDLKey binding;
SDL_Keycode binding;

int id;
int state;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/button_group.cpp
Expand Up @@ -119,13 +119,13 @@ ButtonGroup::event(SDL_Event &event)

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 +
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -14,7 +14,7 @@
// 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"

Expand Down
4 changes: 2 additions & 2 deletions src/physfs/physfs_sdl.cpp
Expand Up @@ -23,7 +23,7 @@

#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;
Expand All @@ -50,7 +50,7 @@ static int funcSeek(struct SDL_RWops* context, int offset, int whence)
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;

Expand Down
6 changes: 4 additions & 2 deletions src/scripting/functions.cpp
Expand Up @@ -271,8 +271,10 @@ void camera()
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()
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/console.cpp
Expand Up @@ -431,7 +431,7 @@ Console::show()
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
Expand All @@ -451,7 +451,7 @@ Console::hide()
// clear input buffer
inputBuffer = "";
inputBufferPosition = 0;
SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
// SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
}

void
Expand Down
54 changes: 48 additions & 6 deletions src/supertux/main.cpp
Expand Up @@ -433,7 +433,9 @@ Main::init_sdl()
// 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...
Expand All @@ -460,13 +462,14 @@ Main::init_video()
// 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
Expand All @@ -480,12 +483,51 @@ Main::init_video()
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);

Expand Down

0 comments on commit 262ce11

Please sign in to comment.