Remove SDL1.2 code

This removes all legacy SDL1.2 code. It was done by invoking:
coan source --replace --no-transients -D"SDL_VERSION_ATLEAST(X, Y, Z)"=1 <file>
on each file.
This commit is contained in:
Andreas Löf 2016-03-13 11:14:15 +13:00
parent 5c6e7c7d20
commit 358bd1235f
77 changed files with 2 additions and 3637 deletions

View file

@ -7,9 +7,7 @@
#import "SDL.h"
#import "SDLMain.h"
#if SDL_VERSION_ATLEAST(2, 0, 0)
extern int wesnoth_main(int argc, char **argv);
#endif
static int gArgc;
static char **gArgv;
@ -75,11 +73,7 @@ static char **gArgv;
//setenv("PYTHONHOME", ".", 1); //not needed because we don't use Python anymore
/* Hand off to main application code */
#if SDL_VERSION_ATLEAST(2, 0, 0)
status = wesnoth_main (gArgc, gArgv);
#else
status = SDL_main (gArgc, gArgv);
#endif
/* We're done, thank you for playing */
exit(status);

View file

@ -16,9 +16,7 @@ extern "C" {
#define SDL_GPU_VERSION_PATCH 0
/* Auto-detect if we're using the SDL2 API by the headers available. */
#if SDL_VERSION_ATLEAST(2,0,0)
#define SDL_GPU_USE_SDL2
#endif
typedef struct GPU_Renderer GPU_Renderer;
typedef struct GPU_Target GPU_Target;

View file

@ -44,12 +44,7 @@
#include <map> // for map, map<>::mapped_type
#include <ostream> // for operator<<, basic_ostream, etc
#if !SDL_VERSION_ATLEAST(2,0,0)
#include "SDL_keysym.h" // for ::SDLK_ESCAPE, ::SDLK_DOWN, etc
#include "SDL_video.h" // for SDL_Rect, SDL_Surface, etc
#else
#include "sdl/alpha.hpp"
#endif
/**
* @namespace about

View file

@ -504,7 +504,6 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
int bar_len = std::max<int>(static_cast<int>((prob * (bar_space - 4)) + 0.5), 2);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 100));
@ -516,19 +515,6 @@ void battle_prediction_pane::get_hp_distrib_surface(const std::vector<std::pair<
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.a, 0));
#else
SDL_Rect bar_rect_1 = sdl::create_rect(hp_sep + 4, 6 + (fs + 2) * i, bar_len, 8);
sdl::fill_rect(surf, &bar_rect_1, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 100));
SDL_Rect bar_rect_2 = sdl::create_rect(hp_sep + 4, 7 + (fs + 2) * i, bar_len, 6);
sdl::fill_rect(surf, &bar_rect_2, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 66));
SDL_Rect bar_rect_3 = sdl::create_rect(hp_sep + 4, 8 + (fs + 2) * i, bar_len, 4);
sdl::fill_rect(surf, &bar_rect_3, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 33));
SDL_Rect bar_rect_4 = sdl::create_rect(hp_sep + 4, 9 + (fs + 2) * i, bar_len, 2);
sdl::fill_rect(surf, &bar_rect_4, blend_rgba(surf, row_color.r, row_color.g, row_color.b, row_color.unused, 0));
#endif
// Draw probability percentage, aligned right.
format_prob(str_buf, prob);

View file

@ -81,15 +81,8 @@ version_table_manager::version_table_manager()
SDL_VERSION(&sdl_version);
compiled[LIB_SDL] = format_version(sdl_version);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_GetVersion(&sdl_version);
linked[LIB_SDL] = format_version(sdl_version);
#else
sdl_rt_version = SDL_Linked_Version();
if(sdl_rt_version) {
linked[LIB_SDL] = format_version(*sdl_rt_version);
}
#endif
names[LIB_SDL] = "SDL";

View file

@ -105,27 +105,9 @@ void controller_base::handle_event(const SDL_Event& event)
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true, get_display());
}
break;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_ACTIVEEVENT:
if (event.active.state == SDL_APPMOUSEFOCUS && event.active.gain == 0) {
if (get_mouse_handler_base().is_dragging()) {
//simulate mouse button up when the app has lost mouse focus
//this should be a general fix for the issue when the mouse
//is dragged out of the game window and then the button is released
int x, y;
Uint8 mouse_flags = SDL_GetMouseState(&x, &y);
if ((mouse_flags & SDL_BUTTON_LEFT) == 0) {
get_mouse_handler_base().mouse_press(event.button, is_browsing());
}
}
}
break;
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
case SDL_MOUSEWHEEL:
get_mouse_handler_base().mouse_wheel(event.wheel.x, event.wheel.y, is_browsing());
break;
#endif
default:
break;
}

View file

@ -114,9 +114,7 @@ protected:
*/
void handle_event(const SDL_Event& event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
void handle_window_event(const SDL_Event& ) {}
#endif
/**
* Process keydown (only when the general map display does not have focus).

View file

@ -26,21 +26,13 @@
#include "video.hpp"
#include <iostream>
#if SDL_VERSION_ATLEAST(2,0,0)
#include <boost/logic/tribool.hpp>
using boost::logic::tribool;
using boost::logic::indeterminate;
#endif
static bool use_color_cursors()
{
#if defined(__APPLE__) && !SDL_VERSION_ATLEAST(2,0,0)
// Color cursors on OS X are known to be unusable, so don't use them ever.
// See bug #18112.
return false;
#else
return game_config::editor == false && preferences::use_color_cursors();
#endif
}
static SDL_Cursor* create_cursor(surface surf)
@ -92,12 +84,10 @@ static SDL_Cursor* create_cursor(surface surf)
namespace {
SDL_Cursor* cache[cursor::NUM_CURSORS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
#if SDL_VERSION_ATLEAST(2,0,0)
tribool cache_color[cursor::NUM_CURSORS] = {
indeterminate, indeterminate, indeterminate, indeterminate,
indeterminate, indeterminate, indeterminate, indeterminate,
};
#endif
// This array must have members corresponding to cursor::CURSOR_TYPE enum members
// Apple need 16x16 b&w cursors
@ -116,18 +106,12 @@ const int shift_y[cursor::NUM_CURSORS] = {0, 0, 0, 0, 0, 20, 22, 0};
cursor::CURSOR_TYPE current_cursor = cursor::NORMAL;
#if !SDL_VERSION_ATLEAST(2,0,0)
int cursor_x = -1, cursor_y = -1;
surface cursor_buf = NULL;
bool color_ready = false;
#endif
bool have_focus = true;
}
static SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
{
#if SDL_VERSION_ATLEAST(2,0,0)
bool is_color = use_color_cursors();
if(cache[type] == NULL || indeterminate(cache_color[type]) || cache_color[type] != is_color) {
const std::string prefix = is_color ? "cursors/" : "cursors-bw/";
@ -139,13 +123,6 @@ static SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
}
cache_color[type] = is_color;
}
#else
if(cache[type] == NULL) {
static const std::string prefix = "cursors-bw/";
const surface surf(image::get_image(prefix + bw_images[type]));
cache[type] = create_cursor(surf);
}
#endif
return cache[type];
}
@ -158,11 +135,6 @@ static void clear_cache()
cache[n] = NULL;
}
}
#if !SDL_VERSION_ATLEAST(2,0,0)
if(cursor_buf != NULL) {
cursor_buf = NULL;
}
#endif
}
namespace cursor
@ -191,13 +163,7 @@ void set(CURSOR_TYPE type)
current_cursor = NORMAL;
}
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_Cursor * cursor_image = get_cursor(current_cursor);
#else
const CURSOR_TYPE new_cursor = use_color_cursors() && color_ready ? cursor::NO_CURSOR : current_cursor;
SDL_Cursor * cursor_image = get_cursor(new_cursor);
#endif
// Causes problem on Mac:
//if (cursor_image != NULL && cursor_image != SDL_GetCursor())
@ -235,9 +201,6 @@ void set_focus(bool focus)
{
have_focus = focus;
if (focus==false) {
#if !SDL_VERSION_ATLEAST(2,0,0)
color_ready = false;
#endif
set();
}
}
@ -252,91 +215,6 @@ setter::~setter()
set(old_);
}
#if !SDL_VERSION_ATLEAST(2,0,0)
void draw(surface screen)
{
if(use_color_cursors() == false) {
return;
}
if(current_cursor == NUM_CURSORS) {
current_cursor = NORMAL;
}
if(have_focus == false) {
cursor_buf = NULL;
return;
}
if (!color_ready) {
// Display start to draw cursor
// so it can now display color cursor
color_ready = true;
// Reset the cursor to be sure that we hide the b&w
set();
}
/** @todo FIXME: don't parse the file path every time
*/
const surface surf(image::get_image("cursors/" + color_images[current_cursor]));
if(surf == NULL) {
// Fall back to b&w cursors
std::cerr << "could not load color cursors. Falling back to hardware cursors\n";
preferences::set_color_cursors(false);
return;
}
if(cursor_buf != NULL && (cursor_buf->w != surf->w || cursor_buf->h != surf->h)) {
cursor_buf = NULL;
}
if(cursor_buf == NULL) {
cursor_buf = create_compatible_surface(surf);
if(cursor_buf == NULL) {
std::cerr << "Could not allocate surface for mouse cursor\n";
return;
}
}
int new_cursor_x, new_cursor_y;
SDL_GetMouseState(&new_cursor_x,&new_cursor_y);
const bool must_update = new_cursor_x != cursor_x || new_cursor_y != cursor_y;
cursor_x = new_cursor_x;
cursor_y = new_cursor_y;
// Save the screen area where the cursor is being drawn onto the back buffer
SDL_Rect area = sdl::create_rect(cursor_x - shift_x[current_cursor]
, cursor_y - shift_y[current_cursor]
, surf->w
, surf->h);
sdl_copy_portion(screen,&area,cursor_buf,NULL);
// Blit the surface
sdl_blit(surf,NULL,screen,&area);
if(must_update) {
update_rect(area);
}
}
void undraw(surface screen)
{
if(use_color_cursors() == false) {
return;
}
if(cursor_buf == NULL) {
return;
}
SDL_Rect area = sdl::create_rect(cursor_x - shift_x[current_cursor]
, cursor_y - shift_y[current_cursor]
, cursor_buf->w
, cursor_buf->h);
sdl_blit(cursor_buf,NULL,screen,&area);
update_rect(area);
}
#endif
} // end namespace cursor

View file

@ -39,10 +39,8 @@ void set_dragging(bool drag);
CURSOR_TYPE get();
// These aren't used, but leaving the prototypes doesn't hurt and allows avoiding an SDL include
//#if !SDL_VERSION_ATLEAST(2,0,0)
void draw(surface screen);
void undraw(surface screen);
//#endif
void set_focus(bool focus);

View file

@ -23,7 +23,6 @@
#include <SDL_events.h>
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST(2,0,0)
#include <SDL_clipboard.h>
@ -68,592 +67,3 @@ bool available()
} // end namespace desktop
#else
#if defined(_X11) && !defined(__APPLE__)
#define CLIPBOARD_FUNCS_DEFINED
#include "SDL_syswm.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <unistd.h>
/**
The following are two classes which wrap the SDL's interface to X,
including locking/unlocking, and which manage the atom internment.
They exist mainly to make the actual clipboard code somewhat readable.
*/
class XHelper
{
private:
XHelper() :
wmInf_(),
acquireCount_(0)
{
acquire();
// Intern some atoms;
const char* atoms[] = {
"CLIPBOARD",
"TEXT",
"COMPOUND_TEXT",
"UTF8_STRING",
"WESNOTH_PASTE",
"TARGETS"
};
XInternAtoms(dpy(), const_cast<char**>(reinterpret_cast<const char**>(atoms)), 6, false, atomTable_);
release();
}
static XHelper* s_instance_;
SDL_SysWMinfo wmInf_;
Atom atomTable_[6];
int acquireCount_;
public:
static XHelper* instance()
{
if (!s_instance_)
s_instance_ = new XHelper;
return s_instance_;
}
Atom XA_CLIPBOARD() const
{
return atomTable_[0];
}
Atom XA_TEXT() const
{
return atomTable_[1];
}
Atom XA_COMPOUND_TEXT() const
{
return atomTable_[2];
}
Atom UTF8_STRING() const
{
return atomTable_[3];
}
Atom WES_PASTE() const
{
return atomTable_[4];
}
Atom XA_TARGETS() const
{
return atomTable_[5];
}
Display* dpy() const
{
return wmInf_.info.x11.display;
}
Window window() const
{
return wmInf_.info.x11.window;
}
void acquire()
{
++acquireCount_;
if (acquireCount_ == 1) {
SDL_VERSION (&wmInf_.version);
SDL_GetWMInfo(&wmInf_);
wmInf_.info.x11.lock_func();
}
}
void release()
{
--acquireCount_;
if (acquireCount_ == 0)
wmInf_.info.x11.unlock_func();
}
};
XHelper* XHelper::s_instance_ = 0;
class UseX
{
public:
UseX()
{
XHelper::instance()->acquire();
}
~UseX()
{
XHelper::instance()->release();
}
XHelper* operator->()
{
return XHelper::instance();
}
};
/**
Note: unfortunately, SDL does not keep track of event timestamps.
This means we are forced to use CurrentTime in many spots and
are unable to perform many safety checks.
Hence, the code below is not compliant to the ICCCM, and
may occasionally suffer from race conditions if an X client
is connected to the server over a slow/high-latency link.
This implementation is also very minimal.
The text is assumed to be reasonably small, as INCR transactions
are not supported.
MULTIPLE is not supported either.
We provide UTF8_STRING, COMPOUND_TEXT, and TEXT,
and try to grab all of them, plus STRING (which is latin1).
*/
/**
We primarily. keep a copy of the string to response to data requests,
but it also has an another function: in case we're both the source
and destination, we just copy it across; this is so that we don't
have to handle SelectionRequest events while waiting for SelectionNotify.
To make this work, however, this gets cleared when we loose CLIPBOARD.
*/
static std::string clipboard_string;
/**
The following string is used for the mouse selection aka PRIMARY
Unix behavior is mouse selection is stored in primary
active selection goes to CLIPBOARD.
*/
static std::string primary_string;
namespace desktop {
namespace clipboard {
void handle_system_event(const SDL_Event& event)
{
XEvent& xev = event.syswm.msg->event.xevent;
if (xev.type == SelectionRequest) {
UseX x11;
// Since wesnoth does not notify us of selections,
// we set both selection + clipboard when copying.
if ((xev.xselectionrequest.owner == x11->window()) &&
((xev.xselectionrequest.selection == XA_PRIMARY) ||
(xev.xselectionrequest.selection == x11->XA_CLIPBOARD()))) {
XEvent responseEvent;
responseEvent.xselection.type = SelectionNotify;
responseEvent.xselection.display = x11->dpy();
responseEvent.xselection.requestor = xev.xselectionrequest.requestor;
responseEvent.xselection.selection = xev.xselectionrequest.selection;
responseEvent.xselection.target = xev.xselectionrequest.target;
responseEvent.xselection.property = None; //nothing available, by default
responseEvent.xselection.time = xev.xselectionrequest.time;
//std::cout<<"Request for target:"<<XGetAtomName(x11->dpy(), xev.xselectionrequest.target)<<"\n";
//### presently don't handle XA_STRING as it must be latin1
if (xev.xselectionrequest.target == x11->XA_TARGETS()) {
responseEvent.xselection.property = xev.xselectionrequest.property;
Atom supported[] = {
x11->XA_TEXT(),
x11->XA_COMPOUND_TEXT(),
x11->UTF8_STRING(),
x11->XA_TARGETS()
};
XChangeProperty(x11->dpy(), responseEvent.xselection.requestor,
xev.xselectionrequest.property, XA_ATOM, 32, PropModeReplace,
const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(supported)), 4);
}
// The encoding of XA_TEXT and XA_COMPOUND_TEXT is not specified
// by the ICCCM... So we assume wesnoth native/utf-8 for simplicity.
// Modern apps are going to use UTF8_STRING anyway.
if (xev.xselectionrequest.target == x11->XA_TEXT()
|| xev.xselectionrequest.target == x11->XA_COMPOUND_TEXT()
|| xev.xselectionrequest.target == x11->UTF8_STRING()) {
responseEvent.xselection.property = xev.xselectionrequest.property;
std::string& selection = (xev.xselectionrequest.selection == XA_PRIMARY) ?
primary_string : clipboard_string;
XChangeProperty(x11->dpy(), responseEvent.xselection.requestor,
xev.xselectionrequest.property,
xev.xselectionrequest.target, 8, PropModeReplace,
reinterpret_cast<const unsigned char*>(selection.c_str()), selection.length());
}
XSendEvent(x11->dpy(), xev.xselectionrequest.requestor, False, NoEventMask,
&responseEvent);
}
}
if (xev.type == SelectionClear) {
//We no longer own the clipboard, don't try in-process C&P
UseX x11;
if(xev.xselectionclear.selection == x11->XA_CLIPBOARD()) {
clipboard_string.clear();
} else if(xev.xselectionclear.selection == XA_PRIMARY) {
primary_string.clear();
}
}
}
void copy_to_clipboard(const std::string& text, const bool mouse)
{
if (text.empty()) {
return;
}
UseX x11;
if(mouse) {
primary_string = text;
XSetSelectionOwner(x11->dpy(), XA_PRIMARY, x11->window(), CurrentTime);
} else {
clipboard_string = text;
XSetSelectionOwner(x11->dpy(), x11->XA_CLIPBOARD(), x11->window(), CurrentTime);
}
}
} // end namespace clipboard
} // end namespace desktop
/**
* Tries to grab a given target.
* Returns true if successful, false otherwise.
*/
static bool try_grab_target(Atom source, Atom target, std::string& ret)
{
UseX x11;
// Cleanup previous data
XDeleteProperty(x11->dpy(), x11->window(), x11->WES_PASTE());
XSync (x11->dpy(), False);
//std::cout<<"We request target:"<<XGetAtomName(x11->dpy(), target)<<"\n";
// Request information
XConvertSelection(x11->dpy(), source, target,
x11->WES_PASTE(), x11->window(), CurrentTime);
// Wait (with timeout) for a response SelectionNotify
for (int attempt = 0; attempt < 15; attempt++) {
if (XPending(x11->dpy())) {
XEvent selectNotify;
while (XCheckTypedWindowEvent(x11->dpy(), x11->window(), SelectionNotify, &selectNotify)) {
if (selectNotify.xselection.property == None)
//Not supported. Say so.
return false;
else if (selectNotify.xselection.property == x11->WES_PASTE() &&
selectNotify.xselection.target == target) {
// The size
unsigned long length = 0;
unsigned char* data;
// These 3 XGetWindowProperty returns but we don't use
Atom typeRet;
int formatRet;
unsigned long remaining;
// std::cout<<"Grab:"<<XGetAtomName(x11->dpy(), target)<<"\n";
// Grab the text out of the property
XGetWindowProperty(x11->dpy(), x11->window(),
selectNotify.xselection.property,
0, 65535/4, True, target,
&typeRet, &formatRet, &length, &remaining, &data);
if (data && length) {
ret = reinterpret_cast<char*>(data);
XFree(data);
return true;
} else {
return false;
}
}
}
}
usleep(10000);
}
// Timed out -- return empty string
return false;
}
namespace desktop {
namespace clipboard {
std::string copy_from_clipboard(const bool mouse)
{
// in-wesnoth copy-paste
if(mouse && !primary_string.empty()) {
return primary_string;
}
if (!mouse && !clipboard_string.empty()) {
return clipboard_string;
}
UseX x11;
std::string ret;
const Atom& source = mouse ? XA_PRIMARY : x11->XA_CLIPBOARD();
if (try_grab_target(source, x11->UTF8_STRING(), ret))
return ret;
if (try_grab_target(source, x11->XA_COMPOUND_TEXT(), ret))
return ret;
if (try_grab_target(source, x11->XA_TEXT(), ret))
return ret;
if (try_grab_target(source, XA_STRING, ret)) // acroread only provides this
return ret;
return "";
}
bool available()
{
return true;
}
} // end namespace clipboard
} // end namespace desktop
#endif
#ifdef _WIN32
#include <windows.h>
#define CLIPBOARD_FUNCS_DEFINED
namespace desktop {
namespace clipboard {
void handle_system_event(const SDL_Event& )
{}
void copy_to_clipboard(const std::string& text, const bool)
{
if(text.empty())
return;
if(!OpenClipboard(NULL))
return;
EmptyClipboard();
// Convert newlines
std::string str;
str.reserve(text.size());
std::string::const_iterator last = text.begin();
while(last != text.end()) {
if(*last != '\n') {
str.push_back(*last);
} else {
str.append("\r\n");
}
++last;
}
std::wstring wstr = unicode_cast<std::wstring>(str);
const HGLOBAL hglb = GlobalAlloc(GMEM_MOVEABLE, (wstr.size() + 1) * sizeof(wchar_t));
if(hglb == NULL) {
CloseClipboard();
return;
}
wchar_t* const buffer = reinterpret_cast<wchar_t* const>(GlobalLock(hglb));
wcscpy(buffer, wstr.c_str());
GlobalUnlock(hglb);
SetClipboardData(CF_UNICODETEXT, hglb);
CloseClipboard();
}
std::string copy_from_clipboard(const bool)
{
if(!IsClipboardFormatAvailable(CF_UNICODETEXT))
return "";
if(!OpenClipboard(NULL))
return "";
HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
if(hglb == NULL) {
CloseClipboard();
return "";
}
wchar_t const * buffer = reinterpret_cast<wchar_t*>(GlobalLock(hglb));
if(buffer == NULL) {
CloseClipboard();
return "";
}
std::wstring str(buffer);
// Convert newlines
str.erase(std::remove(str.begin(),str.end(), L'\r'), str.end());
GlobalUnlock(hglb);
CloseClipboard();
return unicode_cast<std::string>(str);
}
bool available()
{
return true;
}
} // end namespace clipboard
} // end namespace desktop
#endif
#ifdef __APPLE__
#define CLIPBOARD_FUNCS_DEFINED
#include <Carbon/Carbon.h>
namespace desktop {
namespace clipboard {
void copy_to_clipboard(const std::string& text, const bool)
{
std::string new_str;
new_str.reserve(text.size());
for (unsigned int i = 0; i < text.size(); ++i)
{
if (text[i] == '\n')
{
new_str.push_back('\r');
} else {
new_str.push_back(text[i]);
}
}
OSStatus err = noErr;
PasteboardRef clipboard;
PasteboardSyncFlags syncFlags;
CFDataRef textData = NULL;
err = PasteboardCreate(kPasteboardClipboard, &clipboard);
if (err != noErr) return;
err = PasteboardClear(clipboard);
if (err != noErr) return;
syncFlags = PasteboardSynchronize(clipboard);
if ((syncFlags&kPasteboardModified) && !(syncFlags&kPasteboardClientIsOwner)) return;
textData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)new_str.c_str(), text.size());
PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0);
}
std::string copy_from_clipboard(const bool)
{
OSStatus err = noErr;
PasteboardRef clipboard;
PasteboardSyncFlags syncFlags;
ItemCount count;
err = PasteboardCreate(kPasteboardClipboard, &clipboard);
if (err != noErr) return "";
syncFlags = PasteboardSynchronize(clipboard);
if (syncFlags&kPasteboardModified) return "";
err = PasteboardGetItemCount(clipboard, &count);
if (err != noErr) return "";
for (UInt32 k = 1; k <= count; k++) {
PasteboardItemID itemID;
CFArrayRef flavorTypeArray;
CFIndex flavorCount;
err = PasteboardGetItemIdentifier(clipboard, k, &itemID);
if (err != noErr) return "";
err = PasteboardCopyItemFlavors(clipboard, itemID, &flavorTypeArray);
if (err != noErr) return "";
flavorCount = CFArrayGetCount(flavorTypeArray);
for (CFIndex j = 0; j < flavorCount; j++) {
CFStringRef flavorType;
CFDataRef flavorData;
CFIndex flavorDataSize;
flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, j);
if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text"))) {
err = PasteboardCopyItemFlavorData(clipboard, itemID, flavorType, &flavorData);
if (err != noErr) {
CFRelease(flavorTypeArray);
return "";
}
flavorDataSize = CFDataGetLength(flavorData);
std::string str;
str.reserve(flavorDataSize);
str.resize(flavorDataSize);
CFDataGetBytes(flavorData, CFRangeMake(0, flavorDataSize), (UInt8 *)str.data());
for (unsigned int i = 0; i < str.size(); ++i) {
if (str[i] == '\r') str[i] = '\n';
}
return str;
}
}
}
return "";
}
void handle_system_event(const SDL_Event& /*event*/)
{
}
bool available()
{
return true;
}
} // end namespace clipboard
} // end namespace desktop
#endif
#ifndef CLIPBOARD_FUNCS_DEFINED
namespace desktop {
namespace clipboard {
void copy_to_clipboard(const std::string& /*text*/, const bool)
{
}
std::string copy_from_clipboard(const bool)
{
return "";
}
void handle_system_event(const SDL_Event& /*event*/)
{
}
bool available()
{
return false;
}
} // end namespace clipboard
} // end namespace desktop
#endif
#endif

View file

@ -20,11 +20,7 @@
#include "sdl/compat.hpp"
#if SDL_VERSION_ATLEAST(2,0,0)
#include "video.hpp" //SDL_GetAppState()
#else
#include "SDL_active.h"
#endif
#ifdef HAVE_LIBDBUS
#include "dbus_notification.hpp"

View file

@ -20,9 +20,7 @@
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "video.hpp" // CVideo class holds the twindow -> SDL_Window object which contains the handle of the main window
#endif
NOTIFYICONDATA* windows_tray_notification::nid = NULL;
bool windows_tray_notification::message_reset = false;
@ -44,29 +42,16 @@ void windows_tray_notification::destroy_tray_icon()
void windows_tray_notification::handle_system_event(const SDL_Event& event)
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (event.syswm.msg->msg != WM_TRAYNOTIFY) {
#else
if (event.syswm.msg->msg.win.msg != WM_TRAYNOTIFY) {
#endif
return;
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (event.syswm.msg->lParam == NIN_BALLOONUSERCLICK) {
#else
if (event.syswm.msg->msg.win.lParam == NIN_BALLOONUSERCLICK) {
#endif
switch_to_wesnoth_window();
destroy_tray_icon();
#if !SDL_VERSION_ATLEAST(2, 0, 0)
} else if (event.syswm.msg->lParam == NIN_BALLOONTIMEOUT) {
#else
} else if (event.syswm.msg->msg.win.lParam == NIN_BALLOONTIMEOUT) {
#endif
destroy_tray_icon();
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
// Scenario: More than one notification arrives before the time-out triggers the tray icon destruction.
// Problem: Events seem to be triggered differently in SDL 2.0. For the example of two notifications arriving at once:
// 1. Balloon created for first notification
@ -82,7 +67,6 @@ void windows_tray_notification::handle_system_event(const SDL_Event& event)
else if (event.syswm.msg->msg.win.lParam == 0x0200 && !message_reset) {
destroy_tray_icon();
}
#endif
}
bool windows_tray_notification::create_tray_icon()
@ -190,21 +174,13 @@ HWND windows_tray_notification::get_window_handle()
{
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (SDL_GetWMInfo(&wmInfo) != 1) {
#else
sdl::twindow* window = CVideo::get_singleton().get_window();
// SDL 1.2 keeps track of window handles internally whereas SDL 2.0 allows the caller control over which window to use
if (!window || SDL_GetWindowWMInfo (static_cast<SDL_Window *> (*window), &wmInfo) != SDL_TRUE) {
#endif
return NULL;
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
return wmInfo.window;
#else
return wmInfo.info.win.window;
#endif
}
void windows_tray_notification::switch_to_wesnoth_window()

View file

@ -58,10 +58,6 @@
#include <cmath>
// Includes for bug #17573
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
#include <gnu/libc-version.h>
#include <cstdio>
#endif
static lg::log_domain log_display("display");
#define ERR_DP LOG_STREAM(err, log_display)
@ -228,9 +224,6 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
, update_panel_image_(true),
panel_image_()
#endif
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
, do_reverse_memcpy_workaround_(false)
#endif
{
//The following assertion fails when starting a campaign
assert(singleton_ == NULL);
@ -261,19 +254,6 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
create_buttons();
}
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
// Runtime checks for bug #17573
// Get glibc runtime version information
int glibc, glibc_minor;
sscanf(gnu_get_libc_version(), "%d.%d", &glibc, &glibc_minor);
// Get SDL runtime version information
const SDL_version* v = SDL_Linked_Version();
do_reverse_memcpy_workaround_ = (glibc > 2 || (glibc == 2 && glibc_minor >= 13)) &&
(v->major < 1 || (v->major == 1 && v->minor < 2) ||
(v->major == 1 && v->minor == 2 && v->patch < 15) );
#endif
}
display::~display()
@ -1450,15 +1430,9 @@ void display::flip()
font::draw_floating_labels(frameBuffer);
#endif
events::raise_volatile_draw_event();
#if !SDL_VERSION_ATLEAST(2,0,0)
cursor::draw(frameBuffer);
#endif
video().flip();
#if !SDL_VERSION_ATLEAST(2,0,0)
cursor::undraw(frameBuffer);
#endif
events::raise_volatile_undraw_event();
#ifdef SDL_GPU
font::undraw_floating_labels(screen_);
@ -2263,23 +2237,9 @@ bool display::scroll(int xmove, int ymove, bool force)
/* TODO: This is a workaround for a SDL2 bug when blitting on overlapping surfaces.
* The bug only strikes during scrolling, but will then duplicate textures across
* the entire map. */
#if SDL_VERSION_ATLEAST(2,0,0)
surface screen_copy = make_neutral_surface(screen);
SDL_SetSurfaceBlendMode(screen_copy, SDL_BLENDMODE_NONE);
SDL_BlitSurface(screen_copy,&srcrect,screen,&dstrect);
#else
// Hack to workaround bug #17573
#if defined(__GLIBC__)
if (do_reverse_memcpy_workaround_) {
surface screen_copy = make_neutral_surface(screen);
SDL_BlitSurface(screen_copy,&srcrect,screen,&dstrect);
} else {
SDL_BlitSurface(screen,&srcrect,screen,&dstrect);
}
#else
SDL_BlitSurface(screen,&srcrect,screen,&dstrect);
#endif
#endif
}
//This is necessary to avoid a crash in some SDL versions on some systems
@ -3821,7 +3781,6 @@ void display::process_reachmap_changes()
reach_map_changed_ = false;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void display::handle_window_event(const SDL_Event& event) {
if (event.type == SDL_WINDOWEVENT) {
switch (event.window.event) {
@ -3836,7 +3795,6 @@ void display::handle_window_event(const SDL_Event& event) {
}
#endif
void display::handle_event(const SDL_Event& event) {
if (event.type == DRAW_ALL_EVENT) {

View file

@ -637,9 +637,7 @@ public:
void write(config& cfg) const;
virtual void handle_event(const SDL_Event& );
#if SDL_VERSION_ATLEAST(2, 0, 0)
virtual void handle_window_event(const SDL_Event& event);
#endif
private:
void read(const config& cfg);
@ -1171,10 +1169,6 @@ private:
sdl::timage panel_image_;
#endif
#if defined(__GLIBC__) && !SDL_VERSION_ATLEAST(2,0,0)
/** Flag for bug #17573 - this is set in the constructor **/
bool do_reverse_memcpy_workaround_;
#endif
public:
void replace_overlay_map(overlay_map* overlays) { overlays_ = overlays; }

View file

@ -163,11 +163,7 @@ context_manager::~context_manager()
}
// Restore default window title
#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_WM_SetCaption(game_config::get_default_title_string().c_str(), NULL);
#else
CVideo::get_singleton().set_window_title(game_config::get_default_title_string());
#endif
}
void context_manager::refresh_all()
@ -1029,11 +1025,7 @@ void context_manager::set_window_title()
}
const std::string& wm_title_string = map_name + " - " + game_config::get_default_title_string();
#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
#else
CVideo::get_singleton().set_window_title(wm_title_string);
#endif
}
} //Namespace editor

View file

@ -169,27 +169,7 @@ void palette_manager::handle_event(const SDL_Event& event) {
const SDL_MouseButtonEvent &mouse_button_event = event.button;
#if !SDL_VERSION_ATLEAST(2,0,0)
if (mouse_button_event.type == SDL_MOUSEBUTTONDOWN) {
if (mouse_button_event.button == SDL_BUTTON_WHEELUP) {
scroll_up();
}
if (mouse_button_event.button == SDL_BUTTON_WHEELDOWN) {
scroll_down();
}
if (mouse_button_event.button == SDL_BUTTON_WHEELLEFT) {
active_palette().prev_group();
scroll_top();
}
if (mouse_button_event.button == SDL_BUTTON_WHEELRIGHT) {
active_palette().next_group();
scroll_top();
}
//set_dirty(true);
}
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
if (event.type == SDL_MOUSEWHEEL) {
if (event.wheel.y > 0) {
scroll_up();
@ -205,7 +185,6 @@ void palette_manager::handle_event(const SDL_Event& event) {
scroll_top();
}
}
#endif
if (mouse_button_event.type == SDL_MOUSEBUTTONUP) {
//set_dirty(true);

View file

@ -172,16 +172,10 @@ event_context::~event_context()
}
sdl_handler::sdl_handler(const bool auto_join) :
#if !SDL_VERSION_ATLEAST(2, 0, 0)
unicode_(SDL_EnableUNICODE(1)),
#endif
has_joined_(false),
has_joined_global_(false)
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
#endif
if(auto_join) {
assert(!event_contexts.empty());
event_contexts.back().add_handler(this);
@ -197,9 +191,6 @@ sdl_handler::~sdl_handler()
if (has_joined_global_)
leave_global();
#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_EnableUNICODE(unicode_);
#endif
}
void sdl_handler::join()
@ -320,7 +311,6 @@ bool has_focus(const sdl_handler* hand, const SDL_Event* event)
return false;
}
#if SDL_VERSION_ATLEAST(2,0,0)
const Uint32 resize_timeout = 100;
SDL_Event last_resize_event;
@ -343,14 +333,11 @@ static bool remove_on_resize(const SDL_Event &a) {
return false;
}
#endif
void pump()
{
SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(2,0,0)
peek_for_resize();
#endif
pump_info info;
//used to keep track of double click events
@ -363,15 +350,11 @@ void pump()
std::vector< SDL_Event > events;
while(SDL_PollEvent(&temp_event)) {
++poll_count;
#if SDL_VERSION_ATLEAST(2, 0, 0)
peek_for_resize();
if(!begin_ignoring && temp_event.type == SDL_WINDOWEVENT
&& (temp_event.window.event == SDL_WINDOWEVENT_ENTER
|| temp_event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED))
#else
if(!begin_ignoring && temp_event.type == SDL_ACTIVEEVENT)
#endif
{
begin_ignoring = poll_count;
} else if(begin_ignoring > 0 && is_input(temp_event)) {
@ -392,7 +375,6 @@ void pump()
}
std::vector<SDL_Event>::iterator ev_end = events.end();
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool resize_found = false;
for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
SDL_Event &event = *ev_it;
@ -414,13 +396,11 @@ void pump()
}
ev_end = events.end();
#endif
for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){
SDL_Event &event = *ev_it;
switch(event.type) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_WINDOWEVENT:
switch(event.window.event) {
case SDL_WINDOWEVENT_ENTER:
@ -458,27 +438,6 @@ void pump()
//This event was just distributed, don't re-distribute.
continue;
#else
case SDL_ACTIVEEVENT: {
SDL_ActiveEvent& ae = reinterpret_cast<SDL_ActiveEvent&>(event);
if((ae.state & SDL_APPMOUSEFOCUS) != 0 || (ae.state & SDL_APPINPUTFOCUS) != 0) {
cursor::set_focus(ae.gain != 0);
}
break;
}
//if the window must be redrawn, update the entire screen
case SDL_VIDEOEXPOSE:
update_whole_screen();
break;
case SDL_VIDEORESIZE: {
const SDL_ResizeEvent* const resize = reinterpret_cast<SDL_ResizeEvent*>(&event);
info.resize_dimensions.first = resize->w;
info.resize_dimensions.second = resize->h;
break;
}
#endif
case SDL_MOUSEMOTION: {
//always make sure a cursor is displayed if the
@ -674,7 +633,6 @@ int pump_info::ticks(unsigned *refresh_counter, unsigned refresh_rate) {
return ticks_;
}
#if SDL_VERSION_ATLEAST(2,0,0)
/* The constants for the minimum and maximum are picked from the headers. */
#define INPUT_MIN 0x300
@ -703,54 +661,6 @@ void peek_for_resize()
}
}
#else
#define INPUT_MASK (SDL_EVENTMASK(SDL_KEYDOWN)|\
SDL_EVENTMASK(SDL_KEYUP)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONUP)|\
SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|\
SDL_EVENTMASK(SDL_JOYBUTTONUP))
bool is_input(const SDL_Event& event)
{
return (SDL_EVENTMASK(event.type) & INPUT_MASK) != 0;
}
static void discard(Uint32 event_mask)
{
SDL_Event temp_event;
std::vector< SDL_Event > keepers;
SDL_Delay(10);
while(SDL_PollEvent(&temp_event) > 0) {
if((SDL_EVENTMASK(temp_event.type) & event_mask) == 0) {
keepers.push_back( temp_event );
}
}
//FIXME: there is a chance new events are added before kept events are replaced
for (unsigned int i=0; i < keepers.size(); ++i)
{
if(SDL_PushEvent(&keepers[i]) != 0) {
ERR_GEN << "failed to return an event to the queue.";
}
}
}
void discard_input()
{
discard(INPUT_MASK);
}
#endif
} //end events namespace
#if !SDL_VERSION_ATLEAST(2,0,0)
void SDL_FlushEvent(Uint32 type)
{
events::discard(SDL_EVENTMASK(type));
}
#endif

View file

@ -42,9 +42,7 @@ class sdl_handler
{
public:
virtual void handle_event(const SDL_Event& event) = 0;
#if SDL_VERSION_ATLEAST(2, 0, 0)
virtual void handle_window_event(const SDL_Event& event) = 0;
#endif
virtual void process_event() {}
virtual void draw() {}
@ -71,9 +69,6 @@ protected:
}
private:
#if !SDL_VERSION_ATLEAST(2, 0, 0)
int unicode_;
#endif
bool has_joined_;
bool has_joined_global_;
};
@ -101,10 +96,8 @@ struct event_context
//causes events to be dispatched to all handler objects.
void pump();
#if SDL_VERSION_ATLEAST(2,0,0)
//look for resize events and update references to the screen area
void peek_for_resize();
#endif
struct pump_info {
pump_info() : resize_dimensions(), ticks_(0) {}
@ -145,17 +138,5 @@ void discard_input();
typedef std::vector<events::sdl_handler*> sdl_handler_vector;
#if ! SDL_VERSION_ATLEAST(2,0,0)
/**
* Removes events from the queue.
*
* This emulates the function available in SDL 2.0.
*
* @param type The type of event to flush.
*/
void SDL_FlushEvent(Uint32 type);
#endif
#endif

View file

@ -201,25 +201,16 @@ const file_tree_checksum& data_tree_checksum(bool reset)
return checksum;
}
#if SDL_VERSION_ATLEAST(2,0,0)
static Sint64 ifs_size (struct SDL_RWops * context);
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence);
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum);
static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num);
static int SDLCALL ifs_close(struct SDL_RWops *context);
#else
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence);
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum);
static int SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, int size, int num);
static int SDLCALL ifs_close(struct SDL_RWops *context);
#endif
SDL_RWops* load_RWops(const std::string &path) {
SDL_RWops *rw = SDL_AllocRW();
#if SDL_VERSION_ATLEAST(2,0,0)
rw->size = &ifs_size;
#endif
rw->seek = &ifs_seek;
rw->read = &ifs_read;
rw->write = &ifs_write;
@ -239,7 +230,6 @@ SDL_RWops* load_RWops(const std::string &path) {
}
#if SDL_VERSION_ATLEAST(2,0,0)
static Sint64 ifs_size (struct SDL_RWops * context) {
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
std::streampos orig = ifs->tellg();
@ -253,13 +243,8 @@ static Sint64 ifs_size (struct SDL_RWops * context) {
return len;
}
#endif
#if SDL_VERSION_ATLEAST(2,0,0)
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence) {
#else
static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
#endif
std::ios_base::seekdir seekdir;
switch(whence){
@ -294,11 +279,7 @@ static int SDLCALL ifs_seek(struct SDL_RWops *context, int offset, int whence) {
return static_cast<int>(pos);
}
#if SDL_VERSION_ATLEAST(2,0,0)
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum) {
#else
static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int maxnum) {
#endif
std::istream *ifs = static_cast<std::istream*>(context->hidden.unknown.data1);
// This seems overly simplistic, but it's the same as mem_read's implementation
@ -312,11 +293,7 @@ static int SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, int size, int
return static_cast<int>(num);
}
#if SDL_VERSION_ATLEAST(2,0,0)
static size_t SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, size_t /*size*/, size_t /*num*/) {
#else
static int SDLCALL ifs_write(struct SDL_RWops * /*context*/, const void * /*ptr*/, int /*size*/, int /*num*/) {
#endif
SDL_SetError("Writing not implemented");
return 0;
}

View file

@ -23,9 +23,7 @@
#include <set>
#include <stack>
#if SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/alpha.hpp"
#endif
static lg::log_domain log_font("font");
#define DBG_FT LOG_STREAM(debug, log_font)
@ -390,11 +388,7 @@ floating_label_context::floating_label_context()
#ifdef SDL_GPU
#else
#if SDL_VERSION_ATLEAST(2, 0, 0)
surface const screen = NULL;
#else
surface const screen = SDL_GetVideoSurface();
#endif
if(screen != NULL) {
draw_floating_labels(screen);
}
@ -415,11 +409,7 @@ floating_label_context::~floating_label_context()
#ifdef SDL_GPU
//TODO
#else
#if SDL_VERSION_ATLEAST(2, 0, 0)
surface const screen = NULL;
#else
surface const screen = SDL_GetVideoSurface();
#endif
if(screen != NULL) {
undraw_floating_labels(screen);
}

View file

@ -58,11 +58,7 @@ public:
void set_color(const SDL_Color& color) {color_ = color;}
void set_bg_color(const SDL_Color& bg_color) {
bgcolor_ = bg_color;
#if SDL_VERSION_ATLEAST(2,0,0)
bgalpha_ = bg_color.a;
#else
bgalpha_ = bg_color.unused;
#endif
}
void set_border_size(int border) {border_ = border;}
// set width for word wrapping (use -1 to disable it)

View file

@ -313,7 +313,6 @@ void ui::handle_event(const SDL_Event& event)
{
gui::widget::handle_event(event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Rect new_location;
new_location.x = 0;
@ -322,7 +321,6 @@ void ui::handle_event(const SDL_Event& event)
new_location.h = event.window.data2;
set_location(new_location);
}
#endif
if(event.type == SDL_KEYDOWN) {
handle_key_event(event.key);

View file

@ -365,7 +365,6 @@ bool game_launcher::init_language()
return true;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool game_launcher::init_video()
{
// Handle special commandline launch flags
@ -394,66 +393,6 @@ bool game_launcher::init_video()
#endif
return true;
}
#else
bool game_launcher::init_video()
{
if(cmdline_opts_.nogui || cmdline_opts_.headless_unit_test) {
if( !(cmdline_opts_.multiplayer || cmdline_opts_.screenshot || cmdline_opts_.plugin_file || cmdline_opts_.headless_unit_test) ) {
std::cerr << "--nogui flag is only valid with --multiplayer or --screenshot or --plugin flags\n";
return false;
}
video().make_fake();
game_config::no_delay = true;
return true;
}
SDL_WM_SetCaption(game_config::get_default_title_string().c_str(), NULL);
#if !(defined(__APPLE__))
surface icon(image::get_image("icons/icon-game.png", image::UNSCALED));
if(icon != NULL) {
///must be called after SDL_Init() and before setting video mode
SDL_WM_SetIcon(icon,NULL);
}
#endif
std::pair<int,int> resolution;
int bpp = 0;
int video_flags = 0;
bool found_matching = video().detect_video_settings(resolution, bpp, video_flags);
if (cmdline_opts_.screenshot) {
bpp = CVideo::DefaultBpp;
}
if(!found_matching && (video_flags & SDL_FULLSCREEN)) {
video_flags ^= SDL_FULLSCREEN;
found_matching = video().detect_video_settings(resolution, bpp, video_flags);
if (found_matching) {
std::cerr << "Failed to set " << resolution.first << 'x' << resolution.second << 'x' << bpp << " in fullscreen mode. Using windowed instead.\n";
}
}
if(!found_matching) {
std::cerr << "Video mode " << resolution.first << 'x'
<< resolution.second << 'x' << bpp
<< " is not supported.\n";
return false;
}
std::cerr << "Setting mode to " << resolution.first << "x" << resolution.second << "x" << bpp << "\n";
const int res = video().setMode(resolution.first,resolution.second,bpp,video_flags);
video().setBpp(bpp);
if(res == 0) {
std::cerr << "Required video mode, " << resolution.first << "x"
<< resolution.second << "x" << bpp << " is not supported\n";
return false;
}
return true;
}
#endif
bool game_launcher::init_lua_script()
{
@ -1053,11 +992,7 @@ bool game_launcher::change_language()
if (dlg.get_retval() != gui2::twindow::OK) return false;
if (!(cmdline_opts_.nogui || cmdline_opts_.headless_unit_test)) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
video().set_window_title(game_config::get_default_title_string());
#else
SDL_WM_SetCaption(game_config::get_default_title_string().c_str(), NULL);
#endif
}
return true;

View file

@ -275,9 +275,7 @@ private:
{
public:
virtual void handle_event(const SDL_Event& ) {}
#if SDL_VERSION_ATLEAST(2, 0, 0)
virtual void handle_window_event(const SDL_Event& ) {}
#endif
layer() : video2::draw_layering(false) { }
};

View file

@ -133,10 +133,8 @@ public:
/** Inherited from events::sdl_handler. */
void handle_event(const SDL_Event& event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
/** Inherited from events::sdl_handler. */
void handle_window_event(const SDL_Event& event);
#endif
/**
* Connects a dispatcher.
@ -344,11 +342,9 @@ void thandler::handle_event(const SDL_Event& event)
event.button.button);
break;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL:
mouse_wheel(get_mouse_position(), event.wheel.x, event.wheel.y);
break;
#endif
case SHOW_HELPTIP_EVENT:
mouse(SHOW_HELPTIP, get_mouse_position());
@ -397,7 +393,6 @@ void thandler::handle_event(const SDL_Event& event)
key_down(event);
break;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_WINDOWEVENT:
switch(event.window.event) {
case SDL_WINDOWEVENT_EXPOSED:
@ -420,19 +415,6 @@ void thandler::handle_event(const SDL_Event& event)
case SDL_TEXTINPUT:
text_input(event.text.text);
break;
#else
case SDL_VIDEOEXPOSE:
draw(true);
break;
case SDL_VIDEORESIZE:
video_resize(tpoint(event.resize.w, event.resize.h));
break;
case SDL_ACTIVEEVENT:
activate();
break;
#endif
#if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
case SDL_SYSWMEVENT:
@ -452,12 +434,10 @@ void thandler::handle_event(const SDL_Event& event)
}
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void thandler::handle_window_event(const SDL_Event& event)
{
handle_event(event);
}
#endif
void thandler::connect(tdispatcher* dispatcher)
{
@ -554,14 +534,7 @@ void thandler::draw(const bool force)
if(!dispatchers_.empty()) {
CVideo& video = dynamic_cast<twindow&>(*dispatchers_.back()).video();
#if !SDL_VERSION_ATLEAST(2,0,0)
surface& frame_buffer = video.getSurface();
cursor::draw(frame_buffer);
#endif
video.flip();
#if !SDL_VERSION_ATLEAST(2,0,0)
cursor::undraw(frame_buffer);
#endif
}
}
@ -621,20 +594,6 @@ void thandler::mouse_button_up(const tpoint& position, const Uint8 button)
mouse(SDL_RIGHT_BUTTON_UP, position);
break;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_BUTTON_WHEELLEFT:
mouse(SDL_WHEEL_LEFT, get_mouse_position());
break;
case SDL_BUTTON_WHEELRIGHT:
mouse(SDL_WHEEL_RIGHT, get_mouse_position());
break;
case SDL_BUTTON_WHEELUP:
mouse(SDL_WHEEL_UP, get_mouse_position());
break;
case SDL_BUTTON_WHEELDOWN:
mouse(SDL_WHEEL_DOWN, get_mouse_position());
break;
#endif
default:
WRN_GUI_E << "Unhandled 'mouse button up' event for button "
@ -671,7 +630,6 @@ void thandler::mouse_button_down(const tpoint& position, const Uint8 button)
}
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void thandler::mouse_wheel(const tpoint& position, int x, int y)
{
if(x > 0) {
@ -686,7 +644,6 @@ void thandler::mouse_wheel(const tpoint& position, int x, int y)
mouse(SDL_WHEEL_UP, position);
}
}
#endif
tdispatcher* thandler::keyboard_dispatcher()
{
@ -741,15 +698,9 @@ void thandler::key_down(const SDL_Event& event)
done = hotkey_pressed(hk);
}
if(!done) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
key_down(event.key.keysym.sym,
static_cast<const SDL_Keymod>(event.key.keysym.mod),
"");
#else
key_down(event.key.keysym.sym,
event.key.keysym.mod,
unicode_cast<std::string>(static_cast<ucs4::char_t>(event.key.keysym.unicode)));
#endif
}
}

View file

@ -408,18 +408,6 @@ static bool fullscreen(CVideo& video)
{
video.set_fullscreen(!preferences::fullscreen());
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Setting to fullscreen doesn't seem to generate a resize event.
const SDL_Rect& rect = screen_area();
SDL_Event event;
event.type = SDL_VIDEORESIZE;
event.resize.type = SDL_VIDEORESIZE;
event.resize.w = rect.w;
event.resize.h = rect.h;
SDL_PushEvent(&event);
#endif
return true;
}

View file

@ -145,18 +145,6 @@ static bool fullscreen(CVideo& video)
{
video.set_fullscreen(!preferences::fullscreen());
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Setting to fullscreen doesn't seem to generate a resize event.
const SDL_Rect& rect = screen_area();
SDL_Event event;
event.type = SDL_VIDEORESIZE;
event.resize.type = SDL_VIDEORESIZE;
event.resize.w = rect.w;
event.resize.h = rect.h;
SDL_PushEvent(&event);
#endif
return true;
}

View file

@ -917,9 +917,6 @@ void tgrid::impl_draw_children(surface& frame_buffer, int x_offset, int y_offset
* Without the call when resizing larger a black area of remains, this is
* the area not used for resizing the screen, this call `fixes' that.
*/
#if !SDL_VERSION_ATLEAST(2,0,0)
SDL_PumpEvents();
#endif
assert(get_visible() == twidget::tvisible::visible);
set_is_dirty(false);

View file

@ -1420,24 +1420,6 @@ void twindow::signal_handler_sdl_video_resize(const event::tevent event,
const tpoint& new_size)
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(new_size.x < preferences::min_allowed_width()
|| new_size.y < preferences::min_allowed_height()) {
DBG_GUI_E << LOG_HEADER << " resize aborted, too small.\n";
return;
}
if(new_size.x == static_cast<int>(settings::screen_width)
&& new_size.y == static_cast<int>(settings::screen_height)) {
DBG_GUI_E << LOG_HEADER << " resize not needed.\n";
handled = true;
return;
}
video_.set_resolution(new_size.x, new_size.y);
#endif
settings::gamemap_width += new_size.x - settings::screen_width;
settings::gamemap_height += new_size.y - settings::screen_height;

View file

@ -172,9 +172,7 @@ public:
basic_handler(command_executor* exec);
void handle_event(const SDL_Event& event);
#if SDL_VERSION_ATLEAST(2, 0, 0)
void handle_window_event(const SDL_Event&) {}
#endif
private:
command_executor* exec_;

View file

@ -34,9 +34,6 @@
#include "SDL.h"
#if !SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/keyboard.hpp"
#endif
static lg::log_domain log_config("config");
#define ERR_G LOG_STREAM(err, lg::general)
@ -68,13 +65,8 @@ static unsigned int sdl_get_mods()
if (mods & KMOD_ALT)
mods |= KMOD_ALT;
#if SDL_VERSION_ATLEAST(2,0,0)
if (mods & KMOD_GUI)
mods |= KMOD_GUI;
#else
if (mods & KMOD_META)
mods |= KMOD_META;
#endif
return mods;
}
@ -101,11 +93,7 @@ const std::string hotkey_base::get_name() const
ret +=
(!ret.empty() && !boost::algorithm::ends_with(ret, "+") ?
"+" : "");
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (mod_ & KMOD_GUI)
#else
if (mod_ & KMOD_META)
#endif
#ifdef __APPLE__
ret += "cmd";
#else
@ -162,11 +150,7 @@ void hotkey_base::save(config& item) const
item["shift"] = !!(mod_ & KMOD_SHIFT);
item["ctrl"] = !!(mod_ & KMOD_CTRL);
#if SDL_VERSION_ATLEAST(2, 0, 0)
item["cmd"] = !!(mod_ & KMOD_GUI);
#else
item["cmd"] = !!(mod_ & KMOD_META);
#endif
item["alt"] = !!(mod_ & KMOD_ALT);
save_helper(item);
@ -182,11 +166,7 @@ hotkey_ptr create_hotkey(const std::string &id, SDL_Event &event)
hotkey_keyboard_ptr keyboard(new hotkey_keyboard());
base = boost::dynamic_pointer_cast<hotkey_base>(keyboard);
SDL_Scancode code;
#if SDL_VERSION_ATLEAST(2, 0, 0)
code = event.key.keysym.scancode;
#else
code = SDL_GetScancodeFromKey(event.key.keysym.sym);
#endif
keyboard->set_scancode(code);
break;
}
@ -260,11 +240,7 @@ hotkey_ptr load_from_config(const config& cfg)
if (cfg["ctrl"].to_bool())
mods |= KMOD_CTRL;
if (cfg["cmd"].to_bool())
#if SDL_VERSION_ATLEAST(2, 0, 0)
mods |= KMOD_GUI;
#else
mods |= KMOD_META;
#endif
if (cfg["alt"].to_bool())
mods |= KMOD_ALT;
@ -320,11 +296,7 @@ bool hotkey_keyboard::matches_helper(const SDL_Event &event) const
}
SDL_Scancode code;
#if SDL_VERSION_ATLEAST(2, 0, 0)
code = event.key.keysym.scancode;
#else
code = SDL_GetScancodeFromKey(event.key.keysym.sym);
#endif
if (code != scancode_) {
return false;

View file

@ -21,9 +21,6 @@
#include <boost/shared_ptr.hpp>
#include <vector>
#if !SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl/keyboard.hpp"
#endif
class config;
class CVideo;

View file

@ -69,9 +69,7 @@ hotkey::hotkey_ptr show_binding_dialog(CVideo& video, const std::string& id)
}
SDL_PollEvent(&event);
#if SDL_VERSION_ATLEAST(2,0,0)
events::peek_for_resize();
#endif
} while (event.type != SDL_KEYUP && event.type != SDL_JOYBUTTONUP
&& event.type != SDL_JOYHATMOTION

View file

@ -688,10 +688,6 @@ void set_pixel_format(SDL_PixelFormat* format)
|| f.Gshift != l.Gshift
|| f.Bshift != l.Bshift
// || f.Ashift != l.Ashift This field in not checked, not sure why.
#if !SDL_VERSION_ATLEAST(2,0,0)
|| f.colorkey != l.colorkey
|| f.alpha != l.alpha
#endif
)
{
LOG_DP << "detected a new display format\n";

View file

@ -526,13 +526,8 @@ surface darken_modification::operator()(const surface &src) const
surface background_modification::operator()(const surface &src) const
{
surface ret = make_neutral_surface(src);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_FillRect(ret, NULL, SDL_MapRGBA(ret->format, color_.r, color_.g,
color_.b, color_.a));
#else
SDL_FillRect(ret, NULL, SDL_MapRGBA(ret->format, color_.r, color_.g,
color_.b, color_.unused));
#endif
SDL_SetAlpha(src, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
blit_surface(src, NULL, ret, NULL);
return ret;

View file

@ -35,7 +35,6 @@ joystick_manager::~joystick_manager() {
close();
}
#if SDL_VERSION_ATLEAST(2,0,0)
static bool attached(
const std::vector<SDL_Joystick*>& joysticks
@ -51,19 +50,6 @@ static const char* name(
return SDL_JoystickName(joysticks[index]);
}
#else
static bool attached(const std::vector<SDL_Joystick*>&, const size_t index)
{
return SDL_JoystickOpened(index) == 1;
}
static const char* name(const std::vector<SDL_Joystick*>&, const size_t index)
{
return SDL_JoystickName(index);
}
#endif
bool joystick_manager::close() {
if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)

View file

@ -26,9 +26,5 @@ CKey::CKey() :
bool CKey::operator[](int k) const
{
#if SDL_VERSION_ATLEAST(2,0,0)
return key_list[SDL_GetScancodeFromKey(k)] > 0;
#else
return key_list[k] > 0;
#endif
}

View file

@ -206,7 +206,6 @@ void loadscreen::draw_screen(const std::string &text)
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
SDL_Event ev;
while(SDL_PollEvent(&ev)) {
#if SDL_VERSION_ATLEAST(2,0,0)
if (ev.type == SDL_WINDOWEVENT &&
ev.window.event == SDL_WINDOWEVENT_RESIZED) {
screen_.update_framebuffer();
@ -214,9 +213,6 @@ void loadscreen::draw_screen(const std::string &text)
if (ev.type == SDL_WINDOWEVENT &&
(ev.window.event == SDL_WINDOWEVENT_RESIZED ||
ev.window.event == SDL_WINDOWEVENT_EXPOSED))
#else
if(ev.type == SDL_VIDEORESIZE || ev.type == SDL_VIDEOEXPOSE)
#endif
{
logo_drawn_ = false;
}

View file

@ -30,9 +30,6 @@
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
*/
#if 0 && !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
#define LUA_ANSI
#endif
#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)

View file

@ -474,11 +474,7 @@ std::string terrain_label::cfg_color() const
const unsigned int red = static_cast<unsigned int>(color_.r);
const unsigned int green = static_cast<unsigned int>(color_.g);
const unsigned int blue = static_cast<unsigned int>(color_.b);
#if SDL_VERSION_ATLEAST(2,0,0)
const unsigned int alpha = static_cast<unsigned int>(color_.a);
#else
const unsigned int alpha = static_cast<unsigned int>(color_.unused);
#endif
buf << red << "," << green << "," << blue << "," << alpha;
return buf.str();
}

View file

@ -136,10 +136,6 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
show_menu_ = false;
map_location loc = gui().hex_clicked_on(event.x,event.y);
mouse_update(browse, loc);
#if !SDL_VERSION_ATLEAST(2,0,0)
int scrollx = 0;
int scrolly = 0;
#endif
if (is_left_click(event)) {
if (event.state == SDL_PRESSED) {
@ -187,38 +183,6 @@ void mouse_handler_base::mouse_press(const SDL_MouseButtonEvent& event, const bo
scroll_started_ = false;
}
}
#if !SDL_VERSION_ATLEAST(2,0,0)
else if (allow_mouse_wheel_scroll(event.x, event.y)) {
if (event.button == SDL_BUTTON_WHEELUP) {
scrolly = - preferences::scroll_speed();
mouse_wheel_up(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELDOWN) {
scrolly = preferences::scroll_speed();
mouse_wheel_down(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELLEFT) {
scrollx = - preferences::scroll_speed();
mouse_wheel_left(event.x, event.y, browse);
} else if (event.button == SDL_BUTTON_WHEELRIGHT) {
scrollx = preferences::scroll_speed();
mouse_wheel_right(event.x, event.y, browse);
}
// Don't scroll map and map zoom slider at same time
gui::slider* s = gui().find_slider("map-zoom-slider");
if (s && sdl::point_in_rect(event.x, event.y, s->location())) {
scrollx = 0; scrolly = 0;
}
}
if (scrollx != 0 || scrolly != 0) {
CKey pressed;
// Alt + mousewheel do an 90° rotation on the scroll direction
if (pressed[SDLK_LALT] || pressed[SDLK_RALT])
gui().scroll(scrolly,scrollx);
else
gui().scroll(scrollx,scrolly);
}
#endif
if (!dragging_left_ && !dragging_right_ && dragging_started_) {
dragging_started_ = false;
cursor::set_dragging(false);
@ -286,7 +250,6 @@ void mouse_handler_base::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse
{
}
#if SDL_VERSION_ATLEAST(2,0,0)
void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
{
int x, y;
@ -323,7 +286,6 @@ void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
mouse_wheel_up(x, y, browse);
}
}
#endif
void mouse_handler_base::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
{

View file

@ -81,12 +81,10 @@ public:
bool is_middle_click(const SDL_MouseButtonEvent& event) const;
bool is_right_click(const SDL_MouseButtonEvent& event) const;
#if SDL_VERSION_ATLEAST(2,0,0)
/**
* Called when scrolling with the mouse wheel.
*/
virtual void mouse_wheel(int xscroll, int yscroll, bool browse);
#endif
/**
* Derived classes can override this to disable mousewheel scrolling under

View file

@ -60,9 +60,7 @@ namespace preferences {
class prefs_event_handler : public events::sdl_handler {
public:
virtual void handle_event(const SDL_Event &) {}
#if SDL_VERSION_ATLEAST(2, 0, 0)
virtual void handle_window_event(const SDL_Event &event);
#endif
prefs_event_handler() : sdl_handler(false) {}
};
@ -105,7 +103,6 @@ base_manager::~base_manager()
} catch (...) {}
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
/*
* Hook for setting window state variables on window resize and maximize
* events. Since there is no fullscreen window event, that setter is called
@ -134,7 +131,6 @@ void prefs_event_handler::handle_window_event(const SDL_Event& event)
break;
}
}
#endif
void write_preferences()
{
@ -959,11 +955,7 @@ void set_draw_delay(int value)
bool use_color_cursors()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
return get("color_cursors", true);
#else
return get("color_cursors", false);
#endif
}
void _set_color_cursors(bool value)

View file

@ -14,7 +14,6 @@
#include "sdl/alpha.hpp"
#if SDL_VERSION_ATLEAST(2, 0, 0)
int SDL_SetAlpha(SDL_Surface* surface, Uint32 flag, Uint8 alpha)
{
@ -30,4 +29,3 @@ int SDL_SetAlpha(SDL_Surface* surface, Uint32 flag, Uint8 alpha)
}
}
#endif

View file

@ -24,12 +24,10 @@
#include <SDL.h>
#if SDL_VERSION_ATLEAST(2, 0, 0)
#define SDL_SRCALPHA 0x00010000
int SDL_SetAlpha(SDL_Surface* surface, Uint32 flag, Uint8 alpha);
#endif
#endif

View file

@ -25,7 +25,6 @@
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST(2, 0, 0)
#define SDLKey SDL_Keycode
#define SDLMod SDL_Keymod
@ -40,6 +39,5 @@
#define SDL_EVENTMASK(EVENT) EVENT, EVENT
#define SDL_GetAppState CVideo::get_singleton().window_state
#endif
#endif

View file

@ -21,621 +21,5 @@
#include "SDL.h"
#if !SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl/keyboard.hpp"
#define SDLK_SCANCODE_MASK (1<<30)
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
static const int SDL_default_keymap[SDL_NUM_SCANCODES] = {
0, 0, 0, 0,
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
SDLK_RETURN,
SDLK_ESCAPE,
SDLK_BACKSPACE,
SDLK_TAB,
SDLK_SPACE,
'-',
'=',
'[',
']',
'\\',
'#',
';',
'\'',
'`',
',',
'.',
'/',
SDLK_CAPSLOCK,
SDLK_F1,
SDLK_F2,
SDLK_F3,
SDLK_F4,
SDLK_F5,
SDLK_F6,
SDLK_F7,
SDLK_F8,
SDLK_F9,
SDLK_F10,
SDLK_F11,
SDLK_F12,
SDLK_PRINT,
SDLK_SCROLLOCK,
SDLK_PAUSE,
SDLK_INSERT,
SDLK_HOME,
SDLK_PAGEUP,
SDLK_DELETE,
SDLK_END,
SDLK_PAGEDOWN,
SDLK_RIGHT,
SDLK_LEFT,
SDLK_DOWN,
SDLK_UP,
0,
SDLK_KP_DIVIDE,
SDLK_KP_MULTIPLY,
SDLK_KP_MINUS,
SDLK_KP_PLUS,
SDLK_KP_ENTER,
SDLK_KP1,
SDLK_KP2,
SDLK_KP3,
SDLK_KP4,
SDLK_KP5,
SDLK_KP6,
SDLK_KP7,
SDLK_KP8,
SDLK_KP9,
SDLK_KP0,
SDLK_KP_PERIOD,
0,
0,
SDLK_POWER,
SDLK_KP_EQUALS,
SDLK_F13,
SDLK_F14,
SDLK_F15,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
SDLK_HELP,
SDLK_MENU,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, 0, 0,
0,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
SDLK_SYSREQ,
0,
SDLK_CLEAR,
0,
0,
0,
0,
0,
0,
0,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, 0,
SDLK_LCTRL,
SDLK_LSHIFT,
SDLK_LALT,
SDLK_LMETA,
SDLK_RCTRL,
SDLK_RSHIFT,
SDLK_RALT,
SDLK_RMETA,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
SDLK_MODE,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};
static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
NULL, NULL, NULL, NULL,
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
"Return",
"Escape",
"Backspace",
"Tab",
"Space",
"-",
"=",
"[",
"]",
"\\",
"#",
";",
"'",
"`",
",",
".",
"/",
"CapsLock",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"PrintScreen",
"ScrollLock",
"Pause",
"Insert",
"Home",
"PageUp",
"Delete",
"End",
"PageDown",
"Right",
"Left",
"Down",
"Up",
"Numlock",
"Keypad /",
"Keypad *",
"Keypad -",
"Keypad +",
"Keypad Enter",
"Keypad 1",
"Keypad 2",
"Keypad 3",
"Keypad 4",
"Keypad 5",
"Keypad 6",
"Keypad 7",
"Keypad 8",
"Keypad 9",
"Keypad 0",
"Keypad .",
NULL,
"Application",
"Power",
"Keypad =",
"F13",
"F14",
"F15",
"F16",
"F17",
"F18",
"F19",
"F20",
"F21",
"F22",
"F23",
"F24",
"Execute",
"Help",
"Menu",
"Select",
"Stop",
"Again",
"Undo",
"Cut",
"Copy",
"Paste",
"Find",
"Mute",
"VolumeUp",
"VolumeDown",
NULL, NULL, NULL,
"Keypad ,",
"Keypad = (AS400)",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
"AltErase",
"SysReq",
"Cancel",
"Clear",
"Prior",
"Return",
"Separator",
"Out",
"Oper",
"Clear / Again",
"CrSel",
"ExSel",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
"Keypad 00",
"Keypad 000",
"ThousandsSeparator",
"DecimalSeparator",
"CurrencyUnit",
"CurrencySubUnit",
"Keypad (",
"Keypad )",
"Keypad {",
"Keypad }",
"Keypad Tab",
"Keypad Backspace",
"Keypad A",
"Keypad B",
"Keypad C",
"Keypad D",
"Keypad E",
"Keypad F",
"Keypad XOR",
"Keypad ^",
"Keypad %",
"Keypad <",
"Keypad >",
"Keypad &",
"Keypad &&",
"Keypad |",
"Keypad ||",
"Keypad :",
"Keypad #",
"Keypad Space",
"Keypad @",
"Keypad !",
"Keypad MemStore",
"Keypad MemRecall",
"Keypad MemClear",
"Keypad MemAdd",
"Keypad MemSubtract",
"Keypad MemMultiply",
"Keypad MemDivide",
"Keypad +/-",
"Keypad Clear",
"Keypad ClearEntry",
"Keypad Binary",
"Keypad Octal",
"Keypad Decimal",
"Keypad Hexadecimal",
NULL, NULL,
"Left Ctrl",
"Left Shift",
"Left Alt",
"Left GUI",
"Right Ctrl",
"Right Shift",
"Right Alt",
"Right GUI",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL,
"ModeSwitch",
"AudioNext",
"AudioPrev",
"AudioStop",
"AudioPlay",
"AudioMute",
"MediaSelect",
"WWW",
"Mail",
"Calculator",
"Computer",
"AC Search",
"AC Home",
"AC Back",
"AC Forward",
"AC Stop",
"AC Refresh",
"AC Bookmarks",
"BrightnessDown",
"BrightnessUp",
"DisplaySwitch",
"KBDIllumToggle",
"KBDIllumDown",
"KBDIllumUp",
"Eject",
"Sleep",
};
/**
* \brief Get the key code corresponding to the given scancode according
* to the current keyboard layout.
*
* See ::SDL_Keycode for details.
*
* \sa SDL_GetKeyName()
*/
SDLKey SDL_GetKeyFromScancode(SDL_Scancode scancode);
/**
* \brief Get the scancode corresponding to the given key code according to the
* current keyboard layout.
*
* See ::SDL_Scancode for details.
*
* \sa SDL_GetScancodeName()
*/
SDL_Scancode SDL_GetScancodeFromKey(SDLKey key);
/**
* \brief Get a human-readable name for a scancode.
*
* \return A pointer to the name for the scancode.
* If the scancode doesn't have a name, this function returns
* an empty string ("").
*
* \sa SDL_Scancode
*/
const char * SDL_GetScancodeName(SDL_Scancode scancode);
/**
* \brief Get a scancode from a human-readable name
*
* \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
*
* \sa SDL_Scancode
*/
SDL_Scancode SDL_GetScancodeFromName(const char *name);
SDLKey
SDL_GetKeyFromScancode(SDL_Scancode scancode)
{
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
return SDLK_UNKNOWN;
}
return static_cast<SDLKey>(SDL_default_keymap[scancode]);
}
SDL_Scancode
SDL_GetScancodeFromKey(SDLKey key)
{
for (int scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
++scancode) {
if (SDL_default_keymap[scancode] == key) {
return static_cast<SDL_Scancode>(scancode);
}
}
return SDL_SCANCODE_UNKNOWN;
}
const char *
SDL_GetScancodeName(SDL_Scancode scancode)
{
const char *name;
if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) {
return "";
}
name = SDL_scancode_names[scancode];
if (name)
return name;
else
return "";
}
SDL_Scancode SDL_GetScancodeFromName(const char *name)
{
unsigned int i;
if (!name || !*name) {
return SDL_SCANCODE_UNKNOWN;
}
for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
if (!SDL_scancode_names[i]) {
continue;
}
if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
return static_cast<SDL_Scancode>(i);
}
}
return SDL_SCANCODE_UNKNOWN;
}
SDLKey
SDL_GetKeyFromName(const char *name)
{
int key;
/* Check input */
if (name == NULL) return SDLK_UNKNOWN;
/* If it's a single UTF-8 character, then that's the keycode itself */
key = *reinterpret_cast<const unsigned char *>(name);
if (key >= 0xF0) {
if (SDL_strlen(name) == 4) {
int i = 0;
key = static_cast<Uint16>((name[i]&0x07) << 18);
key |= static_cast<Uint16>((name[++i]&0x3F) << 12);
key |= static_cast<Uint16>((name[++i]&0x3F) << 6);
key |= static_cast<Uint16>((name[++i]&0x3F));
return static_cast<SDLKey>(key);
}
return SDLK_UNKNOWN;
} else if (key >= 0xE0) {
if (SDL_strlen(name) == 3) {
int i = 0;
key = static_cast<Uint16>((name[i]&0x0F) << 12);
key |= static_cast<Uint16>((name[++i]&0x3F) << 6);
key |= static_cast<Uint16>((name[++i]&0x3F));
return static_cast<SDLKey>(key);
}
return SDLK_UNKNOWN;
} else if (key >= 0xC0) {
if (SDL_strlen(name) == 2) {
int i = 0;
key = static_cast<Uint16>((name[i]&0x1F) << 6);
key |= static_cast<Uint16>((name[++i]&0x3F));
return static_cast<SDLKey>(key);
}
return SDLK_UNKNOWN;
} else {
if (SDL_strlen(name) == 1) {
if (key >= 'A' && key <= 'Z') {
key += 32;
}
return static_cast<SDLKey>(key);
}
/* Get the scancode for this name, and the associated keycode */
return static_cast<SDLKey>(SDL_default_keymap[SDL_GetScancodeFromName(name)]);
}
}
#endif
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -22,401 +22,5 @@
#ifndef SDL_KEYBOARD_HPP_INCLUDED
#define SDL_KEYBOARD_HPP_INCLUDED
#if !SDL_VERSION_ATLEAST(2, 0, 0)
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief The SDL keyboard scancode representation.
*
* Values of this type are used to represent keyboard keys, among other places
* in the \link SDL_Keysym::scancode key.keysym.scancode \endlink field of the
* SDL_Event structure.
*
* The values in this enumeration are based on the USB usage page standard:
* http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf
*/
typedef enum
{
SDL_SCANCODE_UNKNOWN = 0,
/**
* \name Usage page 0x07
*
* These values are from usage page 0x07 (USB keyboard page).
*/
/* @{ */
SDL_SCANCODE_A = 4,
SDL_SCANCODE_B = 5,
SDL_SCANCODE_C = 6,
SDL_SCANCODE_D = 7,
SDL_SCANCODE_E = 8,
SDL_SCANCODE_F = 9,
SDL_SCANCODE_G = 10,
SDL_SCANCODE_H = 11,
SDL_SCANCODE_I = 12,
SDL_SCANCODE_J = 13,
SDL_SCANCODE_K = 14,
SDL_SCANCODE_L = 15,
SDL_SCANCODE_M = 16,
SDL_SCANCODE_N = 17,
SDL_SCANCODE_O = 18,
SDL_SCANCODE_P = 19,
SDL_SCANCODE_Q = 20,
SDL_SCANCODE_R = 21,
SDL_SCANCODE_S = 22,
SDL_SCANCODE_T = 23,
SDL_SCANCODE_U = 24,
SDL_SCANCODE_V = 25,
SDL_SCANCODE_W = 26,
SDL_SCANCODE_X = 27,
SDL_SCANCODE_Y = 28,
SDL_SCANCODE_Z = 29,
SDL_SCANCODE_1 = 30,
SDL_SCANCODE_2 = 31,
SDL_SCANCODE_3 = 32,
SDL_SCANCODE_4 = 33,
SDL_SCANCODE_5 = 34,
SDL_SCANCODE_6 = 35,
SDL_SCANCODE_7 = 36,
SDL_SCANCODE_8 = 37,
SDL_SCANCODE_9 = 38,
SDL_SCANCODE_0 = 39,
SDL_SCANCODE_RETURN = 40,
SDL_SCANCODE_ESCAPE = 41,
SDL_SCANCODE_BACKSPACE = 42,
SDL_SCANCODE_TAB = 43,
SDL_SCANCODE_SPACE = 44,
SDL_SCANCODE_MINUS = 45,
SDL_SCANCODE_EQUALS = 46,
SDL_SCANCODE_LEFTBRACKET = 47,
SDL_SCANCODE_RIGHTBRACKET = 48,
SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
* key on ISO keyboards and at the right end
* of the QWERTY row on ANSI keyboards.
* Produces REVERSE SOLIDUS (backslash) and
* VERTICAL LINE in a US layout, REVERSE
* SOLIDUS and VERTICAL LINE in a UK Mac
* layout, NUMBER SIGN and TILDE in a UK
* Windows layout, DOLLAR SIGN and POUND SIGN
* in a Swiss German layout, NUMBER SIGN and
* APOSTROPHE in a German layout, GRAVE
* ACCENT and POUND SIGN in a French Mac
* layout, and ASTERISK and MICRO SIGN in a
* French Windows layout.
*/
SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
* instead of 49 for the same key, but all
* OSes I've seen treat the two codes
* identically. So, as an implementor, unless
* your keyboard generates both of those
* codes and your OS treats them differently,
* you should generate SDL_SCANCODE_BACKSLASH
* instead of this code. As a user, you
* should not rely on this code because SDL
* will never generate it with most (all?)
* keyboards.
*/
SDL_SCANCODE_SEMICOLON = 51,
SDL_SCANCODE_APOSTROPHE = 52,
SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
* and ISO keyboards). Produces GRAVE ACCENT and
* TILDE in a US Windows layout and in US and UK
* Mac layouts on ANSI keyboards, GRAVE ACCENT
* and NOT SIGN in a UK Windows layout, SECTION
* SIGN and PLUS-MINUS SIGN in US and UK Mac
* layouts on ISO keyboards, SECTION SIGN and
* DEGREE SIGN in a Swiss German layout (Mac:
* only on ISO keyboards), CIRCUMFLEX ACCENT and
* DEGREE SIGN in a German layout (Mac: only on
* ISO keyboards), SUPERSCRIPT TWO and TILDE in a
* French Windows layout, COMMERCIAL AT and
* NUMBER SIGN in a French Mac layout on ISO
* keyboards, and LESS-THAN SIGN and GREATER-THAN
* SIGN in a Swiss German, German, or French Mac
* layout on ANSI keyboards.
*/
SDL_SCANCODE_COMMA = 54,
SDL_SCANCODE_PERIOD = 55,
SDL_SCANCODE_SLASH = 56,
SDL_SCANCODE_CAPSLOCK = 57,
SDL_SCANCODE_F1 = 58,
SDL_SCANCODE_F2 = 59,
SDL_SCANCODE_F3 = 60,
SDL_SCANCODE_F4 = 61,
SDL_SCANCODE_F5 = 62,
SDL_SCANCODE_F6 = 63,
SDL_SCANCODE_F7 = 64,
SDL_SCANCODE_F8 = 65,
SDL_SCANCODE_F9 = 66,
SDL_SCANCODE_F10 = 67,
SDL_SCANCODE_F11 = 68,
SDL_SCANCODE_F12 = 69,
SDL_SCANCODE_PRINTSCREEN = 70,
SDL_SCANCODE_SCROLLLOCK = 71,
SDL_SCANCODE_PAUSE = 72,
SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
does send code 73, not 117) */
SDL_SCANCODE_HOME = 74,
SDL_SCANCODE_PAGEUP = 75,
SDL_SCANCODE_DELETE = 76,
SDL_SCANCODE_END = 77,
SDL_SCANCODE_PAGEDOWN = 78,
SDL_SCANCODE_RIGHT = 79,
SDL_SCANCODE_LEFT = 80,
SDL_SCANCODE_DOWN = 81,
SDL_SCANCODE_UP = 82,
SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
*/
SDL_SCANCODE_KP_DIVIDE = 84,
SDL_SCANCODE_KP_MULTIPLY = 85,
SDL_SCANCODE_KP_MINUS = 86,
SDL_SCANCODE_KP_PLUS = 87,
SDL_SCANCODE_KP_ENTER = 88,
SDL_SCANCODE_KP_1 = 89,
SDL_SCANCODE_KP_2 = 90,
SDL_SCANCODE_KP_3 = 91,
SDL_SCANCODE_KP_4 = 92,
SDL_SCANCODE_KP_5 = 93,
SDL_SCANCODE_KP_6 = 94,
SDL_SCANCODE_KP_7 = 95,
SDL_SCANCODE_KP_8 = 96,
SDL_SCANCODE_KP_9 = 97,
SDL_SCANCODE_KP_0 = 98,
SDL_SCANCODE_KP_PERIOD = 99,
SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
* keyboards have over ANSI ones,
* located between left shift and Y.
* Produces GRAVE ACCENT and TILDE in a
* US or UK Mac layout, REVERSE SOLIDUS
* (backslash) and VERTICAL LINE in a
* US or UK Windows layout, and
* LESS-THAN SIGN and GREATER-THAN SIGN
* in a Swiss German, German, or French
* layout. */
SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
* not a physical key - but some Mac keyboards
* do have a power key. */
SDL_SCANCODE_KP_EQUALS = 103,
SDL_SCANCODE_F13 = 104,
SDL_SCANCODE_F14 = 105,
SDL_SCANCODE_F15 = 106,
SDL_SCANCODE_F16 = 107,
SDL_SCANCODE_F17 = 108,
SDL_SCANCODE_F18 = 109,
SDL_SCANCODE_F19 = 110,
SDL_SCANCODE_F20 = 111,
SDL_SCANCODE_F21 = 112,
SDL_SCANCODE_F22 = 113,
SDL_SCANCODE_F23 = 114,
SDL_SCANCODE_F24 = 115,
SDL_SCANCODE_EXECUTE = 116,
SDL_SCANCODE_HELP = 117,
SDL_SCANCODE_MENU = 118,
SDL_SCANCODE_SELECT = 119,
SDL_SCANCODE_STOP = 120,
SDL_SCANCODE_AGAIN = 121, /**< redo */
SDL_SCANCODE_UNDO = 122,
SDL_SCANCODE_CUT = 123,
SDL_SCANCODE_COPY = 124,
SDL_SCANCODE_PASTE = 125,
SDL_SCANCODE_FIND = 126,
SDL_SCANCODE_MUTE = 127,
SDL_SCANCODE_VOLUMEUP = 128,
SDL_SCANCODE_VOLUMEDOWN = 129,
/* not sure whether there's a reason to enable these */
/* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
/* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
/* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
SDL_SCANCODE_KP_COMMA = 133,
SDL_SCANCODE_KP_EQUALSAS400 = 134,
SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
footnotes in USB doc */
SDL_SCANCODE_INTERNATIONAL2 = 136,
SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
SDL_SCANCODE_INTERNATIONAL4 = 138,
SDL_SCANCODE_INTERNATIONAL5 = 139,
SDL_SCANCODE_INTERNATIONAL6 = 140,
SDL_SCANCODE_INTERNATIONAL7 = 141,
SDL_SCANCODE_INTERNATIONAL8 = 142,
SDL_SCANCODE_INTERNATIONAL9 = 143,
SDL_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
SDL_SCANCODE_LANG2 = 145, /**< Hanja conversion */
SDL_SCANCODE_LANG3 = 146, /**< Katakana */
SDL_SCANCODE_LANG4 = 147, /**< Hiragana */
SDL_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
SDL_SCANCODE_LANG6 = 149, /**< reserved */
SDL_SCANCODE_LANG7 = 150, /**< reserved */
SDL_SCANCODE_LANG8 = 151, /**< reserved */
SDL_SCANCODE_LANG9 = 152, /**< reserved */
SDL_SCANCODE_ALTERASE = 153, /**< Erase-Eaze */
SDL_SCANCODE_SYSREQ = 154,
SDL_SCANCODE_CANCEL = 155,
SDL_SCANCODE_CLEAR = 156,
SDL_SCANCODE_PRIOR = 157,
SDL_SCANCODE_RETURN2 = 158,
SDL_SCANCODE_SEPARATOR = 159,
SDL_SCANCODE_OUT = 160,
SDL_SCANCODE_OPER = 161,
SDL_SCANCODE_CLEARAGAIN = 162,
SDL_SCANCODE_CRSEL = 163,
SDL_SCANCODE_EXSEL = 164,
SDL_SCANCODE_KP_00 = 176,
SDL_SCANCODE_KP_000 = 177,
SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
SDL_SCANCODE_DECIMALSEPARATOR = 179,
SDL_SCANCODE_CURRENCYUNIT = 180,
SDL_SCANCODE_CURRENCYSUBUNIT = 181,
SDL_SCANCODE_KP_LEFTPAREN = 182,
SDL_SCANCODE_KP_RIGHTPAREN = 183,
SDL_SCANCODE_KP_LEFTBRACE = 184,
SDL_SCANCODE_KP_RIGHTBRACE = 185,
SDL_SCANCODE_KP_TAB = 186,
SDL_SCANCODE_KP_BACKSPACE = 187,
SDL_SCANCODE_KP_A = 188,
SDL_SCANCODE_KP_B = 189,
SDL_SCANCODE_KP_C = 190,
SDL_SCANCODE_KP_D = 191,
SDL_SCANCODE_KP_E = 192,
SDL_SCANCODE_KP_F = 193,
SDL_SCANCODE_KP_XOR = 194,
SDL_SCANCODE_KP_POWER = 195,
SDL_SCANCODE_KP_PERCENT = 196,
SDL_SCANCODE_KP_LESS = 197,
SDL_SCANCODE_KP_GREATER = 198,
SDL_SCANCODE_KP_AMPERSAND = 199,
SDL_SCANCODE_KP_DBLAMPERSAND = 200,
SDL_SCANCODE_KP_VERTICALBAR = 201,
SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
SDL_SCANCODE_KP_COLON = 203,
SDL_SCANCODE_KP_HASH = 204,
SDL_SCANCODE_KP_SPACE = 205,
SDL_SCANCODE_KP_AT = 206,
SDL_SCANCODE_KP_EXCLAM = 207,
SDL_SCANCODE_KP_MEMSTORE = 208,
SDL_SCANCODE_KP_MEMRECALL = 209,
SDL_SCANCODE_KP_MEMCLEAR = 210,
SDL_SCANCODE_KP_MEMADD = 211,
SDL_SCANCODE_KP_MEMSUBTRACT = 212,
SDL_SCANCODE_KP_MEMMULTIPLY = 213,
SDL_SCANCODE_KP_MEMDIVIDE = 214,
SDL_SCANCODE_KP_PLUSMINUS = 215,
SDL_SCANCODE_KP_CLEAR = 216,
SDL_SCANCODE_KP_CLEARENTRY = 217,
SDL_SCANCODE_KP_BINARY = 218,
SDL_SCANCODE_KP_OCTAL = 219,
SDL_SCANCODE_KP_DECIMAL = 220,
SDL_SCANCODE_KP_HEXADECIMAL = 221,
SDL_SCANCODE_LCTRL = 224,
SDL_SCANCODE_LSHIFT = 225,
SDL_SCANCODE_LALT = 226, /**< alt, option */
SDL_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
SDL_SCANCODE_RCTRL = 228,
SDL_SCANCODE_RSHIFT = 229,
SDL_SCANCODE_RALT = 230, /**< alt gr, option */
SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
SDL_SCANCODE_MODE = 257, /**< I'm not sure if this is really not covered
* by any of the above, but since there's a
* special KMOD_MODE for it I'm adding it here
*/
/* @} *//* Usage page 0x07 */
/**
* \name Usage page 0x0C
*
* These values are mapped from usage page 0x0C (USB consumer page).
*/
/* @{ */
SDL_SCANCODE_AUDIONEXT = 258,
SDL_SCANCODE_AUDIOPREV = 259,
SDL_SCANCODE_AUDIOSTOP = 260,
SDL_SCANCODE_AUDIOPLAY = 261,
SDL_SCANCODE_AUDIOMUTE = 262,
SDL_SCANCODE_MEDIASELECT = 263,
SDL_SCANCODE_WWW = 264,
SDL_SCANCODE_MAIL = 265,
SDL_SCANCODE_CALCULATOR = 266,
SDL_SCANCODE_COMPUTER = 267,
SDL_SCANCODE_AC_SEARCH = 268,
SDL_SCANCODE_AC_HOME = 269,
SDL_SCANCODE_AC_BACK = 270,
SDL_SCANCODE_AC_FORWARD = 271,
SDL_SCANCODE_AC_STOP = 272,
SDL_SCANCODE_AC_REFRESH = 273,
SDL_SCANCODE_AC_BOOKMARKS = 274,
/* @} *//* Usage page 0x0C */
/**
* \name Walther keys
*
* These are values that Christian Walther added (for mac keyboard?).
*/
/* @{ */
SDL_SCANCODE_BRIGHTNESSDOWN = 275,
SDL_SCANCODE_BRIGHTNESSUP = 276,
SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
switch, video mode switch */
SDL_SCANCODE_KBDILLUMTOGGLE = 278,
SDL_SCANCODE_KBDILLUMDOWN = 279,
SDL_SCANCODE_KBDILLUMUP = 280,
SDL_SCANCODE_EJECT = 281,
SDL_SCANCODE_SLEEP = 282,
SDL_SCANCODE_APP1 = 283,
SDL_SCANCODE_APP2 = 284,
/* @} *//* Walther keys */
/* Add any other keys here. */
SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
for array bounds */
} SDL_Scancode;
extern SDL_Scancode SDL_GetScancodeFromKey(SDLKey key);
extern SDL_Scancode SDL_GetScancodeFromName(const char *name);
extern const char *
SDL_GetScancodeName(SDL_Scancode scancode);
/**
* \brief Get a key code from a human-readable name
*
* \return key code, or SDLK_UNKNOWN if the name wasn't recognized
*
* \sa SDL_Keycode
*/
extern SDLKey SDL_GetKeyFromName(const char *name);
extern SDLKey SDL_GetKeyFromScancode(SDL_Scancode scancode);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif
#endif /* SDL_KEYBOARD_HPP_INCLUDED */

View file

@ -23,11 +23,7 @@
#include <SDL_version.h>
#include "utils.hpp"
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include <SDL_rect.h>
#else
#include <SDL_video.h>
#endif
#ifdef SDL_GPU
#include "gpu.hpp"

View file

@ -68,10 +68,8 @@ SDL_Color int_to_color(const Uint32 rgb)
result.b = (0x000000FF & rgb);
#ifdef SDL_GPU
result.unused = SDL_ALPHA_OPAQUE;
#elif SDL_VERSION_ATLEAST(2,0,0)
result.a = SDL_ALPHA_OPAQUE;
#else
result.unused = SDL_ALPHA_OPAQUE;
result.a = SDL_ALPHA_OPAQUE;
#endif
return result;
}
@ -97,39 +95,14 @@ SDL_Color create_color(const unsigned char red
result.r = red;
result.g = green;
result.b = blue;
#if SDL_VERSION_ATLEAST(2,0,0)
result.a = alpha;
#else
result.unused = alpha;
#endif
return result;
}
SDLKey sdl_keysym_from_name(std::string const &keyname)
{
#if SDL_VERSION_ATLEAST(2,0,0)
return SDL_GetKeyFromName(keyname.c_str());
#else
static bool initialized = false;
typedef std::map<std::string const, SDLKey> keysym_map_t;
static keysym_map_t keysym_map;
if (!initialized) {
for(SDLKey i = SDLK_FIRST; i < SDLK_LAST; i = SDLKey(int(i) + 1)) {
std::string name = SDL_GetKeyName(i);
if (!name.empty())
keysym_map[name] = i;
}
initialized = true;
}
keysym_map_t::const_iterator it = keysym_map.find(keyname);
if (it != keysym_map.end())
return it->second;
else
return SDLK_UNKNOWN;
#endif
}
bool operator<(const surface& a, const surface& b)
@ -2211,11 +2184,7 @@ surface create_compatible_surface(const surface &surf, int width, int height)
surface s = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, surf->format->BitsPerPixel,
surf->format->Rmask, surf->format->Gmask, surf->format->Bmask, surf->format->Amask);
if (surf->format->palette) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetPaletteColors(s->format->palette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
#else
SDL_SetPalette(s, SDL_LOGPAL, surf->format->palette->colors, 0, surf->format->palette->ncolors);
#endif
}
return s;
}
@ -2498,11 +2467,7 @@ SDL_Color inverse(const SDL_Color& color) {
inverse.r = 255 - color.r;
inverse.g = 255 - color.g;
inverse.b = 255 - color.b;
#if SDL_VERSION_ATLEAST(2,0,0)
inverse.a = 0;
#else
inverse.unused = 0;
#endif
return inverse;
}
@ -2561,11 +2526,7 @@ void draw_centered_on_background(surface surf, const SDL_Rect& rect, const SDL_C
{
clip_rect_setter clip_setter(target, &rect);
#if SDL_VERSION_ATLEAST(2,0,0)
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.a);
#else
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.unused);
#endif
//TODO: only draw background outside the image
SDL_Rect r = rect;
sdl::fill_rect(target, &r, col);

View file

@ -114,14 +114,10 @@ inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_R
}
inline void sdl_copy_portion(const surface& screen, SDL_Rect* screen_rect, surface& dst, SDL_Rect* dst_rect){
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_NONE);
SDL_SetSurfaceBlendMode(dst, SDL_BLENDMODE_NONE);
#endif
SDL_BlitSurface(screen, screen_rect, dst, dst_rect);
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_BLEND);
#endif
}
/**

View file

@ -14,7 +14,6 @@
#include "sdl/window.hpp"
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl/exception.hpp"
#include "sdl/image.hpp"
@ -141,4 +140,3 @@ twindow::operator SDL_Renderer*()
} // namespace sdl
#endif

View file

@ -22,7 +22,6 @@
#include <SDL_version.h>
#if SDL_VERSION_ATLEAST(2, 0, 0)
#include "sdl/utils.hpp"
@ -183,6 +182,5 @@ private:
} // namespace sdl
#endif
#endif

View file

@ -149,7 +149,6 @@ void dialog_frame::set_dirty(bool dirty) {
dirty_ = dirty;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void dialog_frame::handle_window_event(const SDL_Event& event) {
if (event.type == SDL_WINDOWEVENT) {
@ -162,7 +161,6 @@ void dialog_frame::handle_window_event(const SDL_Event& event) {
}
}
}
#endif
void dialog_frame::handle_event(const SDL_Event& event) {

View file

@ -98,9 +98,7 @@ public:
void set_dirty(bool dirty = true);
virtual void handle_event(const SDL_Event&);
#if SDL_VERSION_ATLEAST(2, 0, 0)
void handle_window_event(const SDL_Event& event);
#endif
private:
void clear_background();

View file

@ -314,30 +314,11 @@ void part_ui::prepare_floating_images()
void part_ui::render_background()
{
#if SDL_VERSION_ATLEAST(2,0,0)
sdl::draw_solid_tinted_rectangle(
0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0,
video_.getSurface()
);
sdl_blit(background_, NULL, video_.getSurface(), NULL);
#else
#ifdef SDL_GPU
GPU_Target *target = get_render_target();
GPU_Clear(target);
for (size_t i = 0; i<background_images_.size(); i++) {
const int x = background_positions_[i].first;
const int y = background_positions_[i].second;
background_images_[i].draw(video_, x, y);
}
#else
sdl::draw_solid_tinted_rectangle(
0, 0, video_.getx(), video_.gety(), 0, 0, 0, 1.0,
video_.getSurface()
);
sdl_blit(background_, NULL, video_.getSurface(), NULL);
#endif
#endif
}
bool part_ui::render_floating_images()
@ -1014,7 +995,6 @@ void part_ui::handle_event(const SDL_Event &event)
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void part_ui::handle_window_event(const SDL_Event &event)
{
@ -1032,7 +1012,6 @@ void part_ui::handle_window_event(const SDL_Event &event)
dirty_ = true;
}
}
#endif
} // end namespace storyscreen

View file

@ -67,9 +67,7 @@ public:
virtual void handle_event(const SDL_Event&);
#if SDL_VERSION_ATLEAST(2,0,0)
virtual void handle_window_event(const SDL_Event& event);
#endif
private:
part& p_;

View file

@ -35,97 +35,3 @@
// Linker workarounds end here
#if !SDL_VERSION_ATLEAST(2, 0, 0)
namespace test {
struct save_dialog_fixture {
save_dialog_fixture()
: source()
{
}
test_utils::fake_event_source source;
};
BOOST_FIXTURE_TEST_SUITE( save_dialog , save_dialog_fixture)
SDLKey fake_input_keys[] = {SDLK_KP_ENTER, SDLK_RETURN, SDLK_ESCAPE, SDLK_a};
WESNOTH_PARAMETERIZED_TEST_CASE( test_fake_input, SDLKey,fake_input_keys, keyid)
{
test_utils::event_node_ptr new_keypress = source.press_key(2, keyid);
test_utils::event_node_ptr new_keyrelease = source.release_key(4,keyid);
// Protection against forever loop
source.press_key(6, keyid);
source.release_key(8,keyid);
CKey key;
while(true)
{
events::pump();
BOOST_CHECK_EQUAL(key[keyid], new_keypress->is_fired());
if (key[keyid])
break;
}
while(true)
{
events::pump();
BOOST_CHECK_EQUAL(key[keyid], !new_keyrelease->is_fired());
if (!key[keyid])
break;
}
}
SDLKey dialog_get_save_name_enter_pressed[] = {SDLK_KP_ENTER, SDLK_RETURN};
WESNOTH_PARAMETERIZED_TEST_CASE( test_dialog_get_save_name_enter_pressed, SDLKey, dialog_get_save_name_enter_pressed, keyid )
{
// fill in events to be used in test
test_utils::event_node_ptr press_return_before = source.press_key(0, keyid);
test_utils::event_node_ptr release_return_before = source.release_key(3, keyid);
test_utils::event_node_ptr press_return_after = source.press_key(5, keyid);
test_utils::event_node_ptr release_return_after = source.release_key(7, keyid);
// Protection agains for ever loop
source.press_key(10, keyid);
source.release_key(13, keyid);
std::string fname("test_save");
filesystem::write_file(filesystem::get_saves_dir() + "/" + fname +".gz", "böö");
// Start test (set ticks start time)
// Activated enter press
events::pump();
BOOST_CHECK_MESSAGE(press_return_before->is_fired(), "Enter wasn't activated");
BOOST_CHECK_MESSAGE(!release_return_before->is_fired(), "Enter was released before test");
/*
After moving the savegame code to savegame.cpp, there need to be a lot more parameters to pass to the
savegame class, that are not available here. Just to give an impression, this could be the code to call
the dialog:
game_savegame save(gamestate, level, gui, teams, units, gamestatus, map, game_preferences::compress_saves());
save.save_game_interactive(gui, "Save game", gui::OK_CANCEL, false, false);
This code however does not compile anymore:
BOOST_CHECK_EQUAL(dialogs::get_save_name_oos(test_utils::get_fake_display(1024, 768),
"Save game?", "file", &fname,gui::OK_CANCEL, "Save game"), 0);
Not sure how to fix it best.
BOOST_CHECK_MESSAGE(release_return_before->is_fired(), "get_save_name returned before releasing first enter.");
BOOST_CHECK_MESSAGE(press_return_after->is_fired(), "get_save_name returned before 2nd enter event was sent");
BOOST_CHECK_MESSAGE(!release_return_after->is_fired(), "get_save_name returned after 2nd release event was sent");
*/
filesystem::delete_file(filesystem::get_saves_dir() + "/" + fname + ".gz");
}
BOOST_AUTO_TEST_SUITE_END()
}
#endif

View file

@ -898,11 +898,7 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_no_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 0);
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
#endif
delete mod;
}
@ -924,11 +920,7 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_1_arg)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
#endif
delete mod;
}
@ -950,11 +942,7 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_2_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
#endif
delete mod;
}
@ -976,11 +964,7 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_3_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 3);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, SDL_ALPHA_OPAQUE);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, SDL_ALPHA_OPAQUE);
#endif
delete mod;
}
@ -1002,11 +986,7 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_4_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 3);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 4);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 4);
#endif
delete mod;
}

View file

@ -18,212 +18,3 @@
#include "mouse_handler_base.hpp"
#if !SDL_VERSION_ATLEAST(2, 0, 0)
namespace test_utils {
/**
* Base class for all event nodes to be used to fire fake input events
**/
event_node::event_node(const size_t time, const SDL_Event& event) : time_(time), fired_(false), event_(event)
{}
event_node::~event_node()
{ }
void event_node::fire_event()
{
const int number_of_events = 1;
const Uint32 mask = 0;
SDL_PeepEvents(&event_, number_of_events, SDL_ADDEVENT, mask);
fired_ = true;
}
/**
* @return true if this should stop firing events
**/
bool event_node::test_if_should_fire(const size_t frame_count) const
{
return frame_count >= time_;
}
bool event_node::is_fired() const
{
return fired_;
}
/**
* We want the smallestat the top
**/
bool event_node::operator<(const event_node& o) const
{ return time_ > o.time_; }
event_node_keyboard::event_node_keyboard(size_t time, SDL_Event& event) : event_node(time,event)
{}
void event_node_keyboard::fire_event()
{
event_node::fire_event();
static int num_keys = 300;
Uint8* key_list = SDL_GetKeyState( &num_keys );
if (event_.type == SDL_KEYDOWN)
{
key_list[event_.key.keysym.sym] = 1;
}
else
key_list[event_.key.keysym.sym] = 0;
}
event_node_mouse_motion::event_node_mouse_motion(size_t time, SDL_Event& event) : event_node(time,event)
{}
void event_node_mouse_motion::fire_event()
{
SDL_WarpMouse(event_.motion.x,event_.motion.y);
}
event_node_mouse_click::event_node_mouse_click(size_t time, SDL_Event& event) : event_node(time,event)
{}
void event_node_mouse_click::fire_event()
{
// We have to use temporaries because of difference
// in types for mouse position.
int x, y;
SDL_GetMouseState(&x, &y);
event_.button.x = static_cast<Uint16>(x);
event_.button.y = static_cast<Uint16>(y);
event_node::fire_event();
}
fake_event_source::fake_event_source()
: frame_count_(0)
, queue_()
{
}
fake_event_source::~fake_event_source()
{
// send all still queued events
// so keyboard/mouse state is restored
while(!queue_.empty())
{
queue_.top()->fire_event();
queue_.pop();
}
events::pump();
}
void fake_event_source::add_event(const size_t time, const SDL_Event& event)
{
event_node_ptr new_node(new event_node(time,event));
queue_.push(new_node);
}
void fake_event_source::add_event(event_node_ptr new_node)
{
queue_.push(new_node);
}
void fake_event_source::start()
{
frame_count_ = 0;
}
SDL_Event fake_event_source::make_key_event(Uint8 type, const SDLKey key, const SDLMod mod)
{
SDL_Event event;
event.type = type;
if (type == SDL_KEYDOWN)
event.key.state = SDL_PRESSED;
else
event.key.state = SDL_RELEASED;
event.key.keysym.sym = key;
event.key.keysym.scancode = static_cast<Uint8>(key); //
event.key.keysym.mod = mod;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
event.key.keysym.unicode = static_cast<Uint16>(key); //
#endif
return event;
}
event_node_ptr fake_event_source::move_mouse(const size_t time, const int x, const int y)
{
SDL_Event event;
event.type = SDL_MOUSEMOTION;
event.motion.x = static_cast<Uint16>(x);
event.motion.y = static_cast<Uint16>(y);
event_node_ptr new_move(new event_node_mouse_motion(time, event));
add_event(new_move);
return new_move;
}
SDL_Event fake_event_source::make_mouse_click_event(const Uint8 type, const Uint8 button)
{
SDL_Event event;
event.type = type;
if (type == SDL_MOUSEBUTTONDOWN)
event.button.state = SDL_PRESSED;
else
event.button.state = SDL_RELEASED;
event.button.button = button;
return event;
}
event_node_ptr fake_event_source::mouse_press(const size_t time, const Uint8 button)
{
SDL_Event event = make_mouse_click_event(SDL_MOUSEBUTTONDOWN, button);
event_node_ptr new_click(new event_node_mouse_click(time, event));
add_event(new_click);
return new_click;
}
event_node_ptr fake_event_source::mouse_release(const size_t time, const Uint8 button)
{
SDL_Event event = make_mouse_click_event(SDL_MOUSEBUTTONDOWN, button);
event_node_ptr new_click(new event_node_mouse_click(time, event));
add_event(new_click);
return new_click;
}
event_node_ptr fake_event_source::mouse_click(const size_t time, const Uint8 button)
{
mouse_press(time, button);
return mouse_release(time+1,button);
}
event_node_ptr fake_event_source::press_key(const size_t time, const SDLKey key, const SDLMod mod)
{
SDL_Event event = make_key_event(SDL_KEYDOWN, key, mod);
event_node_ptr new_key(new event_node_keyboard(time, event));
add_event(new_key);
return new_key;
}
event_node_ptr fake_event_source::release_key(const size_t time, const SDLKey key, const SDLMod mod)
{
SDL_Event event = make_key_event(SDL_KEYUP, key, mod);
event_node_ptr new_key(new event_node_keyboard(time, event));
add_event(new_key);
return new_key;
}
event_node_ptr fake_event_source::type_key(const size_t time, const SDLKey key, const SDLMod mod)
{
press_key(time,key,mod);
return release_key(time+1,key,mod);
}
void fake_event_source::process(events::pump_info& /*info*/)
{
if (events::commands_disabled > 0)
return;
++frame_count_;
if (queue_.empty())
return;
while (!queue_.empty()
&& queue_.top()->test_if_should_fire(frame_count_))
{
queue_.top()->fire_event();
queue_.pop();
}
}
}
#endif

View file

@ -23,161 +23,4 @@
#include "events.hpp"
#include "sdl/compat.hpp"
#if !SDL_VERSION_ATLEAST(2, 0, 0)
namespace test_utils {
template<class T>
struct less_ptr {
bool operator()(const T& a, const T& b) const
{
return (*a) < (*b);
}
};
/**
* Base class for all event nodes to be used to fire fake input events
**/
class event_node :
public boost::noncopyable
{
size_t time_;
bool fired_;
protected:
SDL_Event event_;
public:
event_node(const size_t time, const SDL_Event& event);
virtual ~event_node();
/**
* Used to fire sdl event stored in this object.
* Child class may extend or override functionality
**/
virtual void fire_event();
/**
* Test if this event should fire now
**/
bool test_if_should_fire(const size_t frame_count ) const;
/**
* @return true if this event has fired
**/
bool is_fired() const;
/**
* We want the smallestat the top
**/
bool operator<(const event_node& o) const;
};
/**
* modifies SDL_GetKeyState table to have
* correct state.
**/
class event_node_keyboard : public event_node {
public:
event_node_keyboard(size_t time, SDL_Event& event);
virtual void fire_event();
};
/**
* Uses special SDL_WarpMouse function to
* generate mouse move events
**/
class event_node_mouse_motion : public event_node {
public:
event_node_mouse_motion(size_t time, SDL_Event& event);
virtual void fire_event();
};
/**
* Used to create SDL_MOUSEBUTTONDOWN/UP events
* with correct x,y values
**/
class event_node_mouse_click : public event_node {
public:
event_node_mouse_click(size_t time, SDL_Event& event);
virtual void fire_event();
};
typedef boost::shared_ptr<event_node> event_node_ptr;
/**
* fake_event_source is used to generate new events in
* events::pump()
* Timing used in function is loop counter incremented
* everytime events::pump() is called.
**/
class fake_event_source
: public events::pump_monitor,
public boost::noncopyable
{
size_t frame_count_;
typedef std::priority_queue<event_node_ptr,std::vector<event_node_ptr>,less_ptr<event_node_ptr> > event_queue;
event_queue queue_;
SDL_Event make_key_event(Uint8 type, const SDLKey key, const SDLMod mod);
SDL_Event make_mouse_click_event(const Uint8 type, const Uint8 button);
public:
fake_event_source();
~fake_event_source();
/**
* adds a generic event to queue
**/
void add_event(const size_t time, const SDL_Event& event);
/**
* adds any type of event to queue
**/
void add_event(event_node_ptr new_node);
/**
* Sets event time source back to zero
**/
void start();
/**
* adds keyboard press event to queue
**/
event_node_ptr press_key(const size_t time, const SDLKey key, const SDLMod mod = KMOD_NONE);
/**
* adds keyboard release event to queue
**/
event_node_ptr release_key(const size_t time, const SDLKey key, const SDLMod mod =KMOD_NONE);
/**
* Just push and release a key
* release is done in time+1
* @return release event only
**/
event_node_ptr type_key(const size_t time, const SDLKey key, const SDLMod mod =KMOD_NONE);
/**
* Adds mouse motion event to queue
**/
event_node_ptr move_mouse(const size_t time, const int x, const int y);
/**
* adds mouse button click event to queue
**/
event_node_ptr mouse_press(const size_t time, const Uint8 button);
/**
* adds mouse button realease event to queue
**/
event_node_ptr mouse_release(const size_t time, const Uint8 button);
/**
* Make mouse click that equals to press and release
* relase is done in time+1
* @return release event only
**/
event_node_ptr mouse_click(const size_t time, const Uint8 button);
/**
* Called by events::pump() to fire events
**/
void process(events::pump_info& /*info*/);
};
}
#endif
#endif

View file

@ -28,113 +28,3 @@
#include <boost/make_shared.hpp>
#if !SDL_VERSION_ATLEAST(2, 0, 0)
namespace test_utils {
play_scenario::play_scenario(const std::string& id) :
id_(id),
source_(),
game_config_(get_test_config_ref()),
tdata_(boost::make_shared<terrain_type_data>(game_config_)),
current_time_(80),
end_pos_()
{
add_initial_signals();
}
void play_scenario::add_initial_signals()
{
source_.type_key(current_time_++, SDLK_RETURN);
current_time_+= 100;
}
struct add_key_type_to_source {
add_key_type_to_source(fake_event_source& source, timing& time) :
source_(source),
time_(time)
{}
void operator()(const std::string::value_type& c)
{
source_.type_key(time_++, static_cast<SDLKey>(c));
}
private:
fake_event_source& source_;
timing& time_;
};
void play_scenario::add_formula_command(const std::string& command)
{
// Activate command line;
source_.type_key(current_time_++, SDLK_f);
std::for_each(command.begin(), command.end(),
add_key_type_to_source(source_, current_time_));
source_.type_key(current_time_++, SDLK_RETURN);
}
class end_position_collector : public event_node {
saved_game state_;
unit_map units_;
public:
end_position_collector(const size_t time) :
event_node(time, SDL_Event()),
state_(),
units_()
{
}
virtual void fire_event()
{
// Now collect data and quit the game
units_ = game_display::get_singleton()->get_units();
}
saved_game& get_state()
{
return state_;
}
unit_map& get_units()
{
return units_;
}
};
void play_scenario::play()
{
// We have to first append a "event" that collects end poisition
end_pos_.reset(new end_position_collector(current_time_++));
end_position_collector* end = static_cast<end_position_collector*>(end_pos_.get());
source_.add_event(end_pos_);
source_.type_key(current_time_++, SDLK_COLON, SDLMod(KMOD_LSHIFT | KMOD_SHIFT) );
source_.type_key(current_time_++, SDLK_q);
source_.type_key(current_time_++, SDLK_EXCLAIM);
source_.type_key(current_time_++, SDLK_RETURN);
saved_game& state = end->get_state();
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
state.set_carryover_sides_start(
config_of("next_scenario", id_)
);
campaign_controller controller(get_fake_display(1024, 768).video(), state, game_config_, tdata_);
controller.play_game();
}
std::string play_scenario::get_unit_id(const map_location &loc)
{
if (!end_pos_)
return std::string();
end_position_collector* end = static_cast<end_position_collector*>(end_pos_.get());
unit_map::iterator it = end->get_units().find(loc);
if (it == end->get_units().end())
return std::string();
return it->id();
}
}
#endif

View file

@ -25,73 +25,4 @@
class config;
class terrain_type_data;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
namespace test_utils {
class end_position_collector;
class timing {
static const size_t step_size = 2;
size_t time_;
public:
timing() : time_(0) {}
timing(const size_t& t) : time_(t) {}
timing operator++()
{
return time_ += step_size;
}
timing operator++(int)
{
timing ret(*this);
operator++();
return ret;
}
operator size_t&()
{ return time_;}
timing operator+(const size_t& t) const
{ return timing(time_ + t*step_size);}
timing operator+(const int& t) const
{ return *this + size_t(t);}
timing& operator+=(const size_t& t)
{ time_ += t*step_size;
return *this;}
timing& operator+=(const int& t)
{ return *this+= size_t(t);}
};
/**
* simple abstaction to settup scenario playing test case
**/
class play_scenario {
const std::string id_;
fake_event_source source_;
const config& game_config_;
const boost::shared_ptr<terrain_type_data> tdata_;
timing current_time_;
event_node_ptr end_pos_;
/**
* We have to add automatically one enter press
* for objectives view
**/
void add_initial_signals();
public:
play_scenario(const std::string& id);
void play();
void add_formula_command(const std::string& command);
std::string get_unit_id(const map_location &loc);
};
}
#endif
#endif

View file

@ -31,9 +31,7 @@
#include <cassert>
#include <cstring>
#if SDL_VERSION_ATLEAST(2,0,0)
#include "video.hpp"
#endif
namespace font {

View file

@ -26,9 +26,7 @@
#include <string>
#if SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/image.hpp"
#endif
#ifdef SDL_GPU
#include "sdl/gpu.hpp"

View file

@ -56,11 +56,7 @@ manager::~manager()
}
thread::thread(int (*f)(void*), void* data)
#if SDL_VERSION_ATLEAST(2,0,0)
: thread_(SDL_CreateThread(f, "", data))
#else
: thread_(SDL_CreateThread(f, data))
#endif
{
}

View file

@ -46,42 +46,22 @@ static lg::log_domain log_display("display");
CVideo* CVideo::singleton_ = NULL;
namespace {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
bool is_fullscreen = false;
int disallow_resize = 0;
#endif
#ifdef SDL_GPU
GPU_Target *render_target_;
#endif
}
void resize_monitor::process(events::pump_info &info) {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(info.resize_dimensions.first >= preferences::min_allowed_width()
&& info.resize_dimensions.second >= preferences::min_allowed_height()
&& disallow_resize == 0) {
if (display::get_singleton()) {
display::get_singleton()->video().set_resolution(info.resize_dimensions);
}
}
#else
UNUSED(info);
#endif
}
resize_lock::resize_lock()
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
++disallow_resize;
#endif
}
resize_lock::~resize_lock()
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
--disallow_resize;
#endif
}
static unsigned int get_flags(unsigned int flags)
@ -90,158 +70,12 @@ static unsigned int get_flags(unsigned int flags)
#ifdef SDL_GPU
flags |= SDL_OPENGLBLIT;
#endif
#if !SDL_VERSION_ATLEAST(2, 0, 0)
// SDL under Windows doesn't seem to like hardware surfaces
// for some reason.
#if !(defined(_WIN32) || defined(__APPLE__))
flags |= SDL_HWSURFACE;
#endif
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
flags |= SDL_WINDOW_RESIZABLE;
#else
if((flags&SDL_FULLSCREEN) == 0) {
flags |= SDL_RESIZABLE;
}
#endif
return flags;
}
#if !SDL_GPU && !SDL_VERSION_ATLEAST(2, 0, 0)
namespace {
struct event {
int x, y, w, h;
bool in;
event(const SDL_Rect& rect, bool i) : x(i ? rect.x : rect.x + rect.w), y(rect.y), w(rect.w), h(rect.h), in(i) { }
};
bool operator<(const event& a, const event& b) {
if (a.x != b.x) return a.x < b.x;
if (a.in != b.in) return a.in;
if (a.y != b.y) return a.y < b.y;
if (a.h != b.h) return a.h < b.h;
if (a.w != b.w) return a.w < b.w;
return false;
}
bool operator==(const event& a, const event& b) {
return a.x == b.x && a.y == b.y && a.w == b.w && a.h == b.h && a.in == b.in;
}
std::vector<event> events;
struct segment {
int x, count;
segment() : x(0), count(0) { }
segment(int x, int count) : x(x), count(count) { }
};
std::vector<SDL_Rect> update_rects;
std::map<int, segment> segments;
static void calc_rects()
{
events.clear();
BOOST_FOREACH(SDL_Rect const &rect, update_rects) {
events.push_back(event(rect, true));
events.push_back(event(rect, false));
}
std::sort(events.begin(), events.end());
std::vector<event>::iterator events_end = std::unique(events.begin(), events.end());
segments.clear();
update_rects.clear();
for (std::vector<event>::iterator iter = events.begin(); iter != events_end; ++iter) {
std::map<int, segment>::iterator lower = segments.find(iter->y);
if (lower == segments.end()) {
lower = segments.insert(std::make_pair(iter->y, segment())).first;
if (lower != segments.begin()) {
std::map<int, segment>::iterator prev = lower;
--prev;
lower->second = prev->second;
}
}
if (lower->second.count == 0) {
lower->second.x = iter->x;
}
std::map<int, segment>::iterator upper = segments.find(iter->y + iter->h);
if (upper == segments.end()) {
upper = segments.insert(std::make_pair(iter->y + iter->h, segment())).first;
std::map<int, segment>::iterator prev = upper;
--prev;
upper->second = prev->second;
}
if (iter->in) {
while (lower != upper) {
++lower->second.count;
++lower;
}
} else {
while (lower != upper) {
lower->second.count--;
if (lower->second.count == 0) {
std::map<int, segment>::iterator next = lower;
++next;
int x = lower->second.x, y = lower->first;
unsigned w = iter->x - x;
unsigned h = next->first - y;
SDL_Rect a = sdl::create_rect(x, y, w, h);
if (update_rects.empty()) {
update_rects.push_back(a);
} else {
SDL_Rect& p = update_rects.back(), n;
int pa = p.w * p.h, aa = w * h, s = pa + aa;
int thresh = 51;
n.w = std::max<int>(x + w, p.x + p.w);
n.x = std::min<int>(p.x, x);
n.w -= n.x;
n.h = std::max<int>(y + h, p.y + p.h);
n.y = std::min<int>(p.y, y);
n.h -= n.y;
if (s * 100 < thresh * n.w * n.h) {
update_rects.push_back(a);
} else {
p = n;
}
}
if (lower == segments.begin()) {
segments.erase(lower);
} else {
std::map<int, segment>::iterator prev = lower;
--prev;
if (prev->second.count == 0) segments.erase(lower);
}
lower = next;
} else {
++lower;
}
}
}
}
}
bool update_all = false;
}
static void clear_updates()
{
update_all = false;
update_rects.clear();
}
#endif
namespace {
@ -267,7 +101,6 @@ draw_layering::~draw_layering()
}
void trigger_full_redraw() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Event event;
event.type = SDL_WINDOWEVENT;
event.window.event = SDL_WINDOWEVENT_RESIZED;
@ -277,7 +110,6 @@ void trigger_full_redraw() {
for(std::list<events::sdl_handler*>::iterator it = draw_layers.begin(); it != draw_layers.end(); ++it) {
(*it)->handle_window_event(event);
}
#endif
SDL_Event drawEvent;
SDL_UserEvent data;
@ -299,11 +131,7 @@ bool CVideo::non_interactive()
{
if (fake_interactive)
return false;
#if SDL_VERSION_ATLEAST(2, 0, 0)
return window == NULL;
#else
return SDL_GetVideoSurface() == NULL;
#endif
}
@ -316,15 +144,7 @@ GPU_Target *get_render_target()
surface display_format_alpha(surface surf)
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(SDL_GetVideoSurface() != NULL)
return SDL_DisplayFormatAlpha(surf);
else if(frameBuffer != NULL)
return SDL_ConvertSurface(surf,frameBuffer->format,0);
else
#else
UNUSED(surf);
#endif
return NULL;
}
@ -345,18 +165,10 @@ void update_rect(size_t x, size_t y, size_t w, size_t h)
void update_rect(const SDL_Rect& rect_value)
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(update_all)
return;
#endif
SDL_Rect rect = rect_value;
#if SDL_VERSION_ATLEAST(2, 0, 0)
surface const fb = NULL;
#else
surface const fb = SDL_GetVideoSurface();
#endif
if(fb != NULL) {
if(rect.x < 0) {
if(rect.x*-1 >= int(rect.w))
@ -390,22 +202,15 @@ void update_rect(const SDL_Rect& rect_value)
return;
}
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
update_rects.push_back(rect);
#endif
}
void update_whole_screen()
{
#if !SDL_VERSION_ATLEAST(2, 0, 0)
update_all = true;
#endif
}
void CVideo::video_event_handler::handle_window_event(const SDL_Event &event)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (event.type == SDL_WINDOWEVENT) {
switch (event.window.event) {
case SDL_WINDOWEVENT_RESIZED:
@ -430,23 +235,15 @@ void CVideo::video_event_handler::handle_window_event(const SDL_Event &event)
break;
}
}
#else
UNUSED(event);
#endif
}
CVideo::CVideo(FAKE_TYPES type) :
#if SDL_VERSION_ATLEAST(2, 0, 0)
window(),
#endif
#ifdef SDL_GPU
shader_(),
#endif
mode_changed_(false),
#if !SDL_VERSION_ATLEAST(2, 0, 0)
bpp_(0),
#endif
fake_screen_(false),
help_string_(0),
updatesLocked_(0)
@ -599,38 +396,7 @@ void CVideo::make_test_fake(const unsigned width,
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
int CVideo::bppForMode( int x, int y, int flags)
{
int test_values[3] = {getBpp(), 32, 16};
BOOST_FOREACH(int &bpp, test_values) {
if(modePossible(x, y, bpp, flags) > 0) {
return bpp;
}
}
return 0;
}
int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags, bool current_screen_optimal )
{
int bpp = SDL_VideoModeOK( x, y, bits_per_pixel, get_flags(flags) );
if(current_screen_optimal)
{
const SDL_VideoInfo* const video_info = SDL_GetVideoInfo();
/* if current video_info is smaller than the mode checking and the checked mode is supported
(meaning that probably the video card supports higher resolutions than the monitor)
that means that we just need to adjust the resolution and the bpp is ok
*/
if(bpp==0 && video_info->current_h<y && video_info->current_w<x){
return bits_per_pixel;
}
}
return bpp;
}
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
void CVideo::update_framebuffer()
{
@ -721,49 +487,6 @@ void CVideo::setMode(int x, int y, const MODE_EVENT mode)
image::set_pixel_format(frameBuffer->format);
}
}
#else
int CVideo::setMode( int x, int y, int bits_per_pixel, int flags )
{
update_rects.clear();
if (fake_screen_) return 0;
mode_changed_ = true;
flags = get_flags(flags);
const int res = SDL_VideoModeOK( x, y, bits_per_pixel, flags );
#ifdef SDL_GPU
const bool toggle_fullscreen = ((flags & SDL_FULLSCREEN) != 0) != is_fullscreen;
#endif
if( res == 0 )
return 0;
is_fullscreen = (flags & SDL_FULLSCREEN) != 0;
#ifdef SDL_GPU
//NOTE: this surface is in fact unused now. Can be removed when possible.
frameBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, x, y, 32,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000);
overlay_ = SDL_CreateRGBSurface(SDL_SWSURFACE, x, y, 32,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000);
GPU_SetWindowResolution(x, y);
if (toggle_fullscreen) {
GPU_ToggleFullscreen(1);
}
#else
frameBuffer = SDL_SetVideoMode( x, y, bits_per_pixel, flags );
#endif
if( frameBuffer != NULL ) {
image::set_pixel_format(frameBuffer->format);
return bits_per_pixel;
} else return 0;
}
#endif
bool CVideo::modeChanged()
{
@ -803,23 +526,10 @@ void CVideo::flip()
#ifdef SDL_GPU
assert(render_target_);
GPU_Flip(render_target_);
#else
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(update_all) {
::SDL_Flip(frameBuffer);
} else if(update_rects.empty() == false) {
calc_rects();
if(!update_rects.empty()) {
SDL_UpdateRects(frameBuffer, update_rects.size(), &update_rects[0]);
}
}
clear_updates();
#else
if (window)
window->render();
#endif
#endif
}
void CVideo::lock_updates(bool value)
@ -835,7 +545,6 @@ bool CVideo::update_locked() const
return updatesLocked_ > 0;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
Uint8 CVideo::window_state()
{
Uint8 state = 0;
@ -881,9 +590,7 @@ sdl::twindow *CVideo::get_window()
return window.get();
}
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
static int sdl_display_index(sdl::twindow* window)
{
if(window) {
@ -891,9 +598,7 @@ static int sdl_display_index(sdl::twindow* window)
}
return 0;
}
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
std::vector<std::pair<int, int> > CVideo::get_available_resolutions(const bool include_current)
{
std::vector<std::pair<int, int> > result;
@ -927,62 +632,6 @@ std::vector<std::pair<int, int> > CVideo::get_available_resolutions(const bool i
return result;
}
#else
std::vector<std::pair<int, int> > CVideo::get_available_resolutions(const bool include_current)
{
UNUSED(include_current);
std::vector<std::pair<int, int> > result;
const SDL_Rect* const * modes;
if (const surface& surf = getSurface()) {
SDL_PixelFormat format = *surf->format;
format.BitsPerPixel = getBpp();
modes = SDL_ListModes(&format, SDL_FULLSCREEN);
} else
modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
// The SDL documentation says that a return value of -1
// means that all dimensions are supported/possible.
if(modes == reinterpret_cast<SDL_Rect**>(-1)) {
// SDL says that all modes are possible, so it's OK to use a
// hardcoded list here. Include tiny and small gui since they
// will be filtered out later if not needed.
result.push_back(std::make_pair(800, 480)); // EeePC resolution
result.push_back(std::make_pair(800, 600));
result.push_back(std::make_pair(1024, 600)); // used on many netbooks
result.push_back(std::make_pair(1024, 768));
result.push_back(std::make_pair(1280, 960));
result.push_back(std::make_pair(1280, 1024));
result.push_back(std::make_pair(1366, 768)); // 16:9 notebooks
result.push_back(std::make_pair(1440, 900));
result.push_back(std::make_pair(1440, 1200));
result.push_back(std::make_pair(1600, 1200));
result.push_back(std::make_pair(1680, 1050));
result.push_back(std::make_pair(1920, 1080));
result.push_back(std::make_pair(1920, 1200));
result.push_back(std::make_pair(2560, 1600));
return result;
} else if(modes == NULL) {
std::cerr << "No modes supported\n";
return result;
}
const std::pair<int,int> min_res = std::make_pair(preferences::min_allowed_width(),preferences::min_allowed_height());
if (getSurface() && getSurface()->w >= min_res.first && getSurface()->h >= min_res.second)
result.push_back(current_resolution());
for(int i = 0; modes[i] != NULL; ++i) {
if (modes[i]->w >= min_res.first && modes[i]->h >= min_res.second)
result.push_back(std::make_pair(modes[i]->w,modes[i]->h));
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
return result;
}
#endif
surface& CVideo::getSurface()
{
@ -994,25 +643,10 @@ std::pair<int,int> CVideo::current_resolution()
return std::make_pair(getSurface()->w, getSurface()->h);
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool CVideo::isFullScreen() const {
return (window->get_flags() & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
}
#else
bool CVideo::isFullScreen() const { return is_fullscreen; }
#endif
#if !SDL_VERSION_ATLEAST(2, 0, 0)
void CVideo::setBpp( int bpp )
{
bpp_ = bpp;
}
int CVideo::getBpp()
{
return bpp_;
}
#endif
int CVideo::set_help_string(const std::string& str)
{
@ -1058,66 +692,14 @@ void CVideo::clear_all_help_strings()
clear_help_string(help_string_);
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
bool CVideo::detect_video_settings(std::pair<int,int>& resolution, int& bpp, int& video_flags)
{
video_flags = preferences::fullscreen() ? SDL_FULLSCREEN : 0;
resolution = preferences::resolution();
int DefaultBPP = DefaultBpp;
/* This needs to be fixed properly. */
const SDL_VideoInfo* const video_info = SDL_GetVideoInfo();
if(video_info != NULL && video_info->vfmt != NULL) {
DefaultBPP = video_info->vfmt->BitsPerPixel;
}
std::cerr << "Checking video mode: " << resolution.first << 'x'
<< resolution.second << 'x' << DefaultBPP << "...\n";
typedef std::pair<int, int> res_t;
std::vector<res_t> res_list = get_available_resolutions();
if (res_list.empty()) {
res_list.push_back(res_t(800, 480));
res_list.push_back(res_t(800, 600));
res_list.push_back(res_t(1024, 600));
res_list.push_back(res_t(1024, 768));
res_list.push_back(res_t(1920, 1080));
}
bpp = modePossible(resolution.first, resolution.second,
DefaultBPP, video_flags, true);
BOOST_REVERSE_FOREACH(const res_t &res, res_list)
{
if (bpp != 0) break;
std::cerr << "Video mode " << resolution.first << 'x'
<< resolution.second << 'x' << DefaultBPP
<< " is not supported; attempting " << res.first
<< 'x' << res.second << 'x' << DefaultBPP << "...\n";
resolution = res;
bpp = modePossible(resolution.first, resolution.second,
DefaultBPP, video_flags);
}
return bpp != 0;
}
#endif
void CVideo::set_fullscreen(bool ison)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (window && isFullScreen() != ison) {
#else
if (frameBuffer && isFullScreen() != ison) {
#endif
const std::pair<int,int>& res = preferences::resolution();
#if SDL_VERSION_ATLEAST(2, 0, 0)
MODE_EVENT mode;
if (ison) {
@ -1127,12 +709,6 @@ void CVideo::set_fullscreen(bool ison)
}
setMode(res.first, res.second, mode);
#else
const int flags = ison ? SDL_FULLSCREEN : 0;
int bpp = bppForMode(res.first, res.second, flags);
setMode(res.first, res.second, bpp, flags);
#endif
if (display::get_singleton()) {
display::get_singleton()->redraw_everything();
@ -1156,16 +732,7 @@ void CVideo::set_resolution(const unsigned width, const unsigned height)
return;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
setMode(width, height, TO_RES);
#else
const int flags = preferences::fullscreen() ? SDL_FULLSCREEN : 0;
int bpp = bppForMode(width, height, flags);
if(bpp != 0) {
setMode(width, height, bpp, flags);
}
#endif
if(display::get_singleton()) {
display::get_singleton()->redraw_everything();

View file

@ -21,9 +21,7 @@
#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>
#if SDL_VERSION_ATLEAST(2,0,0)
#include "sdl/window.hpp"
#endif
struct surface;
#ifdef SDL_GPU
@ -37,11 +35,9 @@ class timage;
#endif
//possible flags when setting video modes
#if SDL_VERSION_ATLEAST(2, 0, 0)
#define SDL_APPMOUSEFOCUS 0x01 /**< The app has mouse coverage */
#define SDL_APPINPUTFOCUS 0x02 /**< The app has input focus */
#define SDL_APPACTIVE 0x04 /**< The application is active */
#endif
#ifdef SDL_GPU
struct GPU_Target;
@ -84,35 +80,14 @@ public:
const static int DefaultBpp = 32;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
int bppForMode( int x, int y, int flags);
int modePossible( int x, int y, int bits_per_pixel, int flags, bool current_screen_optimal=false);
#endif
/**
* Initializes a new window, taking into account any preiously saved states.
*/
bool init_window();
#if SDL_VERSION_ATLEAST(2, 0, 0)
void setMode( int x, int y, const MODE_EVENT mode );
#else
int setMode( int x, int y, int bits_per_pixel, int flags );
#endif
#if !SDL_VERSION_ATLEAST(2, 0, 0)
/**
* Detect a good resolution.
*
* @param video The video 'holding' the framebuffer.
* @param resolution Any good resolution is returned through this reference.
* @param bpp A reference through which the best bpp is returned.
* @param video_flags A reference through which the video flags for setting the video mode are returned.
*
* @returns Whether valid video settings were found.
*/
bool detect_video_settings(std::pair<int,int>& resolution, int& bpp, int& video_flags);
#endif
void set_fullscreen(bool ison);
@ -179,10 +154,6 @@ public:
};
//functions to allow changing video modes when 16BPP is emulated
#if !SDL_VERSION_ATLEAST(2, 0, 0)
void setBpp( int bpp );
int getBpp();
#endif
void make_fake();
/**
@ -211,7 +182,6 @@ public:
void lock_updates(bool value);
bool update_locked() const;
#if SDL_VERSION_ATLEAST(2, 0, 0)
//this needs to be invoked immediately after a resize event or the game will crash.
void update_framebuffer();
@ -235,7 +205,6 @@ public:
void set_window_icon(surface& icon);
sdl::twindow *get_window();
#endif
/**
* Returns the list of available screen resolutions.
@ -245,9 +214,7 @@ public:
private:
static CVideo* singleton_;
#if SDL_VERSION_ATLEAST(2, 0, 0)
boost::scoped_ptr<sdl::twindow> window;
#endif
class video_event_handler : public events::sdl_handler {
public:
virtual void handle_event(const SDL_Event &) {}
@ -267,9 +234,6 @@ private:
bool mode_changed_;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
int bpp_; // Store real bits per pixel
#endif
//if there is no display at all, but we 'fake' it for clients
bool fake_screen_;

View file

@ -439,12 +439,7 @@ static int process_command_args(const commandline_options& cmdline_opts) {
srand(*cmdline_opts.rng_seed);
}
if(cmdline_opts.screenshot || cmdline_opts.render_image) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_setenv("SDL_VIDEODRIVER", "dummy", 1);
#else
static char opt[] = "SDL_VIDEODRIVER=dummy";
SDL_putenv(opt);
#endif
}
if(cmdline_opts.strict_validation) {
strict_validation_enabled = true;
@ -960,7 +955,7 @@ static void restart_process(const std::vector<std::string>& commandline)
}
#endif
#if defined(__native_client__) || (defined(__APPLE__) && SDL_VERSION_ATLEAST(2, 0, 0))
#if defined(__native_client__) || defined(__APPLE__)
extern "C" int wesnoth_main(int argc, char** argv);
int wesnoth_main(int argc, char** argv)
#else

View file

@ -155,19 +155,6 @@ void scrollarea::handle_event(const SDL_Event& event)
if (mouse_locked() || hidden())
return;
#if !SDL_VERSION_ATLEAST(2,0,0)
if (event.type != SDL_MOUSEBUTTONDOWN)
return;
SDL_MouseButtonEvent const &e = event.button;
if (sdl::point_in_rect(e.x, e.y, inner_location())) {
if (e.button == SDL_BUTTON_WHEELDOWN) {
scrollbar_.scroll_down();
} else if (e.button == SDL_BUTTON_WHEELUP) {
scrollbar_.scroll_up();
}
}
#else
if (event.type != SDL_MOUSEWHEEL)
return;
@ -181,7 +168,6 @@ void scrollarea::handle_event(const SDL_Event& event)
scrollbar_.scroll_down();
}
}
#endif
}
} // end namespace gui

View file

@ -344,13 +344,6 @@ void scrollbar::handle_event(const SDL_Event& event)
SDL_MouseButtonEvent const &e = event.button;
bool on_grip = sdl::point_in_rect(e.x, e.y, grip);
bool on_groove = sdl::point_in_rect(e.x, e.y, groove);
#if !SDL_VERSION_ATLEAST(2,0,0)
if (on_groove && e.button == SDL_BUTTON_WHEELDOWN) {
move_position(scroll_rate_);
} else if (on_groove && e.button == SDL_BUTTON_WHEELUP) {
move_position(-scroll_rate_);
} else
#endif
if (on_grip && e.button == SDL_BUTTON_LEFT) {
mousey_on_grip_ = e.y - grip.y;
new_state = DRAGGED;
@ -379,7 +372,6 @@ void scrollbar::handle_event(const SDL_Event& event)
}
break;
}
#if SDL_VERSION_ATLEAST(2,0,0)
case SDL_MOUSEWHEEL:
{
const SDL_MouseWheelEvent& e = event.wheel;
@ -393,7 +385,6 @@ void scrollbar::handle_event(const SDL_Event& event)
}
break;
}
#endif
default:
break;
}

View file

@ -218,28 +218,6 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
if (!sdl::point_in_rect(event.x, event.y, location()))
return;
#if !SDL_VERSION_ATLEAST(2,0,0)
if (event.button == SDL_BUTTON_WHEELUP || event.button == SDL_BUTTON_WHEELRIGHT) {
value_change_ = false;
set_focus(true);
set_value(value_ + increment_);
if(value_change_) {
sound::play_UI_sound(game_config::sounds::slider_adjust);
} else {
value_change_ = prev_change;
}
}
if (event.button == SDL_BUTTON_WHEELDOWN || event.button == SDL_BUTTON_WHEELLEFT) {
value_change_ = false;
set_focus(true);
set_value(value_ - increment_);
if(value_change_) {
sound::play_UI_sound(game_config::sounds::slider_adjust);
} else {
value_change_ = prev_change;
}
}
#endif
if (event.button != SDL_BUTTON_LEFT)
return;
@ -259,7 +237,6 @@ void slider::mouse_down(const SDL_MouseButtonEvent& event)
}
}
#if SDL_VERSION_ATLEAST(2,0,0)
void slider::mouse_wheel(const SDL_MouseWheelEvent& event) {
bool prev_change = value_change_;
int x, y;
@ -289,7 +266,6 @@ void slider::mouse_wheel(const SDL_MouseWheelEvent& event) {
}
}
}
#endif
bool slider::requires_event_focus(const SDL_Event* event) const
{
@ -352,12 +328,10 @@ void slider::handle_event(const SDL_Event& event)
}
}
break;
#if SDL_VERSION_ATLEAST(2,0,0)
case SDL_MOUSEWHEEL:
if (!mouse_locked())
mouse_wheel(event.wheel);
break;
#endif
default:
return;
}

View file

@ -56,9 +56,7 @@ protected:
private:
void mouse_motion(const SDL_MouseMotionEvent& event);
void mouse_down(const SDL_MouseButtonEvent& event);
#if SDL_VERSION_ATLEAST(2,0,0)
void mouse_wheel(const SDL_MouseWheelEvent& event);
#endif
void set_slider_position(int x);
SDL_Rect slider_area() const;
surface image_, pressedImage_, activeImage_, disabledImage_;

View file

@ -38,9 +38,7 @@ textbox::textbox(CVideo &video, int width, const std::string& text, bool editabl
wrap_(false), line_height_(0), yscroll_(0), alpha_(alpha),
alpha_focus_(alpha_focus),
edit_target_(NULL)
#if SDL_VERSION_ATLEAST(2, 0, 0)
,listening_(false)
#endif
{
// static const SDL_Rect area = d.screen_area();
// const int height = font::draw_text(NULL,area,font_size,font::NORMAL_COLOR,"ABCD",0,0).h;
@ -106,21 +104,15 @@ void textbox::append_text(const std::string& text, bool auto_scroll, const SDL_C
SDL_SetAlpha(new_text.get(),0,0);
SDL_SetAlpha(text_image_.get(),0,0);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_SetSurfaceBlendMode(text_image_, SDL_BLENDMODE_NONE);
#endif
sdl_blit(text_image_,NULL,new_surface,NULL);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_SetSurfaceBlendMode(text_image_, SDL_BLENDMODE_BLEND);
#endif
SDL_Rect target = sdl::create_rect(0
, text_image_->h
, new_text->w
, new_text->h);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_SetSurfaceBlendMode(new_text, SDL_BLENDMODE_NONE);
#endif
sdl_blit(new_text,NULL,new_surface,&target);
text_image_.assign(new_surface);
@ -451,7 +443,6 @@ void textbox::handle_event(const SDL_Event& event)
handle_event(event, false);
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool textbox::handle_text_input(const SDL_Event& event)
{
bool changed = false;
@ -475,7 +466,6 @@ bool textbox::handle_text_input(const SDL_Event& event)
}
return changed;
}
#endif
bool textbox::handle_key_down(const SDL_Event &event)
{
@ -487,9 +477,7 @@ bool textbox::handle_key_down(const SDL_Event &event)
const int c = key.sym;
const int old_cursor = cursor_;
#if SDL_VERSION_ATLEAST(2, 0, 0)
listening_ = true;
#endif
if(editable_) {
if(c == SDLK_LEFT && cursor_ > 0)
@ -545,19 +533,11 @@ bool textbox::handle_key_down(const SDL_Event &event)
pass_event_to_target(event);
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
ucs4::char_t character = key.unicode;
#endif
//movement characters may have a "Unicode" field on some platforms, so ignore it.
if(!(c == SDLK_UP || c == SDLK_DOWN || c == SDLK_LEFT || c == SDLK_RIGHT ||
c == SDLK_DELETE || c == SDLK_BACKSPACE || c == SDLK_END || c == SDLK_HOME ||
c == SDLK_PAGEUP || c == SDLK_PAGEDOWN)) {
#if !SDL_VERSION_ATLEAST(2, 0, 0)
if(character != 0) {
DBG_G << "Char: " << character << ", c = " << c << "\n";
}
#endif
if((event.key.keysym.mod & copypaste_modifier)
//on windows SDL fires for AltGr lctrl+ralt (needed to access @ etc on certain keyboards)
#ifdef _WIN32
@ -610,20 +590,6 @@ bool textbox::handle_key_down(const SDL_Event &event)
break;
}
}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
else if(editable_) {
if(character >= 32 && character != 127) {
changed = true;
if(is_selection())
erase_selection();
if(text_.size() + 1 <= max_size_) {
text_.insert(text_.begin()+cursor_,character);
++cursor_;
}
}
}
#endif
else {
pass_event_to_target(event);
}
@ -713,11 +679,9 @@ void textbox::handle_event(const SDL_Event& event, bool was_forwarded)
const int old_cursor = cursor_;
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (event.type == SDL_TEXTINPUT && listening_) {
changed = handle_text_input(event);
} else
#endif
if (event.type == SDL_KEYDOWN) {
changed = handle_key_down(event);
}

View file

@ -92,13 +92,11 @@ private:
textbox* edit_target_;
#if SDL_VERSION_ATLEAST(2, 0, 0)
/* This boolean is used to filter out any TextInput events that are received without
* the corresponding KeyPress events. This is needed to avoid a bug when creating a
* textbox using a hotkey.
* */
bool listening_;
#endif
void handle_event(const SDL_Event& event, bool was_forwarded);
@ -117,9 +115,7 @@ private:
bool requires_event_focus(const SDL_Event *event=NULL) const;
bool show_scrollbar() const;
#if SDL_VERSION_ATLEAST(2, 0, 0)
bool handle_text_input(const SDL_Event& event);
#endif
bool handle_key_down(const SDL_Event &event);
};

View file

@ -349,7 +349,6 @@ void widget::handle_event(SDL_Event const &event) {
}
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
void widget::handle_window_event(SDL_Event const &event) {
if (event.type == SDL_WINDOWEVENT) {
switch (event.window.event) {
@ -361,7 +360,6 @@ void widget::handle_window_event(SDL_Event const &event) {
}
}
}
#endif
}

View file

@ -91,9 +91,7 @@ protected:
virtual sdl_handler_vector member_handlers() { return sdl_handler::handler_members(); }
virtual void handle_event(SDL_Event const &);
#if SDL_VERSION_ATLEAST(2, 0, 0)
virtual void handle_window_event(SDL_Event const &event);
#endif
bool focus_; // Should user input be ignored?
bool mouse_locked() const;