conv to SDL2, except video; all untested yet

This commit is contained in:
Christopher Mosher 2013-10-08 10:29:28 -04:00
parent b3f1e6b23d
commit 6a2b84794c
11 changed files with 40 additions and 228 deletions

View File

@ -23,7 +23,7 @@ AM_PROG_CC_C_O
# Checks for libraries.
AC_CHECK_LIB([SDL],[SDL_Init],,[AC_MSG_ERROR([cannot find libsdl])])
AC_CHECK_LIB([SDL2],[SDL_Init],,[AC_MSG_ERROR([cannot find libsdl])])
AC_CHECK_LIB([X11],[XOpenDisplay])

View File

@ -17,214 +17,22 @@
*/
#include "clipboardhandler.h"
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <SDL2/SDL.h>
#include <limits.h>
// taken from: http://www.libsdl.org/projects/scrap (original author: Sam Lantinga)
/* Determine what type of clipboard we are using */
#if defined(__WIN32__) || defined(__CYGWIN__)
#define WIN_SCRAP
#elif defined(__unix__)
#define X11_SCRAP
#else
#error Unknown window manager for clipboard handling
#endif /* scrap type */
/* System dependent variables */
#if defined(X11_SCRAP)
static Display *SDL_Display;
static Window SDL_Window;
static void (*Lock_Display)();
static void (*Unlock_Display)();
#elif defined(WIN_SCRAP)
static HWND SDL_Window;
#endif /* scrap type */
static bool initialized(false);
static bool have(false);
#ifdef X11_SCRAP
static int clipboard_filter(const SDL_Event *event)
{
/* Post all non-window manager specific events */
if ( event->type != SDL_SYSWMEVENT ) {
return(1);
}
/* Handle window-manager specific clipboard events */
switch (event->syswm.msg->event.xevent.type) {
/* Copy the selection from XA_CUT_BUFFER0 to the requested property */
case SelectionRequest: {
XSelectionRequestEvent *req;
XEvent sevent;
int seln_format;
unsigned long nbytes;
unsigned long overflow;
unsigned char *seln_data;
req = &event->syswm.msg->event.xevent.xselectionrequest;
sevent.xselection.type = SelectionNotify;
sevent.xselection.display = req->display;
sevent.xselection.selection = req->selection;
sevent.xselection.target = None;
sevent.xselection.property = None;
sevent.xselection.requestor = req->requestor;
sevent.xselection.time = req->time;
if ( XGetWindowProperty(SDL_Display, DefaultRootWindow(SDL_Display),
XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
&sevent.xselection.target, &seln_format,
&nbytes, &overflow, &seln_data) == Success )
{
if ( sevent.xselection.target == req->target )
{
if ( sevent.xselection.target == XA_STRING )
{
if ( seln_data[nbytes-1] == '\0' )
--nbytes;
}
XChangeProperty(SDL_Display, req->requestor, req->property,
sevent.xselection.target, seln_format, PropModeReplace,
seln_data, nbytes);
sevent.xselection.property = req->property;
}
XFree(seln_data);
}
XSendEvent(SDL_Display,req->requestor,False,0,&sevent);
XSync(SDL_Display, False);
}
break;
}
/* Post the event for X11 clipboard reading above */
return(1);
}
#endif /* X11_SCRAP */
ClipboardHandler::ClipboardHandler()
{
if (initialized)
return;
initialized = true;
SDL_SetError("SDL is not running on known window manager");
/* Grab the window manager specific information */
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWMInfo(&info))
{
/* Save the information for later use */
#if defined(X11_SCRAP)
if (info.subsystem == SDL_SYSWM_X11)
{
SDL_Display = info.info.x11.display;
SDL_Window = info.info.x11.window;
Lock_Display = info.info.x11.lock_func;
Unlock_Display = info.info.x11.unlock_func;
/* Enable the special window hook events */
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
SDL_SetEventFilter(clipboard_filter);
have = true;
}
else
{
SDL_SetError("SDL is not running on X11");
}
#elif defined(WIN_SCRAP)
SDL_Window = info.window;
have = true;
#endif /* scrap type */
}
}
ClipboardHandler::~ClipboardHandler()
{
}
std::string ClipboardHandler::getText()
{
std::string ret;
if (!have)
return ret;
#if defined(X11_SCRAP)
const Atom format(XA_STRING);
Atom selection;
Lock_Display();
Window owner = XGetSelectionOwner(SDL_Display, XA_PRIMARY);
Unlock_Display();
if (owner == None || owner == SDL_Window)
{
owner = DefaultRootWindow(SDL_Display);
selection = XA_CUT_BUFFER0;
}
else
{
int selection_response = 0;
SDL_Event event;
owner = SDL_Window;
Lock_Display();
selection = XInternAtom(SDL_Display, "SDL_SELECTION", False);
XConvertSelection(SDL_Display, XA_PRIMARY, format, selection, owner, CurrentTime);
Unlock_Display();
while (!selection_response)
{
SDL_WaitEvent(&event);
if (event.type == SDL_SYSWMEVENT)
{
XEvent xevent = event.syswm.msg->event.xevent;
if (xevent.type == SelectionNotify && xevent.xselection.requestor == owner)
selection_response = 1;
}
}
}
Lock_Display();
Atom seln_type;
int seln_format;
unsigned long nbytes;
unsigned long overflow;
char *src;
if (XGetWindowProperty(SDL_Display, owner, selection, 0, INT_MAX/4, False, format, &seln_type, &seln_format, &nbytes, &overflow, (unsigned char **)&src) == Success)
{
if (seln_type == format)
{
ret.assign(src,nbytes);
}
XFree(src);
}
Unlock_Display();
#elif defined(WIN_SCRAP)
const UINT format(CF_TEXT);
if (IsClipboardFormatAvailable(format) && OpenClipboard(SDL_Window))
{
const HANDLE hMem = GetClipboardData(format);
if (hMem)
{
char *src = (char*)GlobalLock(hMem);
ret.assign(src);
GlobalUnlock(hMem);
}
CloseClipboard();
}
#endif /* scrap type */
char* sdlAllocatedText = SDL_GetClipboardText();
ret.assign(sdlAllocatedText);
SDL_free(sdlAllocatedText);
return ret;
}

View File

@ -19,7 +19,7 @@
#include "configep2.h"
#include "e2const.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <ctime>
@ -205,11 +205,11 @@ int Emulator::run()
void Emulator::dispatchKeyUp(const SDL_KeyboardEvent& keyEvent)
{
unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F);
SDLKey sym = keyEvent.keysym.sym;
SDLMod mod = keyEvent.keysym.mod;
unsigned char scancode = keyEvent.keysym.scancode;
// printf("key UP: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode);
SDL_Keycode sym = keyEvent.keysym.sym;
SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod;
unsigned char key = (unsigned char)(sym & 0x7F);
// printf("key UP: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode);
if ((sym < 0x7F || sym == SDLK_LEFT || sym == SDLK_RIGHT) &&
!(sym == SDLK_TAB || sym == SDLK_BACKQUOTE || sym == '[' || sym == '\\' || sym == SDLK_DELETE) &&
@ -230,10 +230,14 @@ void Emulator::dispatchKeyUp(const SDL_KeyboardEvent& keyEvent)
// Apple ][ or Apple ][ plus keyboard
void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent)
{
unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F);
SDLKey sym = keyEvent.keysym.sym;
SDLMod mod = keyEvent.keysym.mod;
unsigned char scancode = keyEvent.keysym.scancode;
if (keyEvent.repeat)
{
return;
}
SDL_Keycode sym = keyEvent.keysym.sym;
SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod;
unsigned char key = (unsigned char)(sym & 0x7F);
// printf("key DN: %d sym: %d mod: %04X scn: %d\n",key,sym,mod,scancode);
@ -339,7 +343,7 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent)
return;
}
// ...else save a screen shot
else if (sym == SDLK_PRINT)
else if (sym == SDLK_PRINTSCREEN)
{
this->screenImage.saveBMP();
}
@ -360,10 +364,10 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent)
// Ctrl-Shift-Space is the same as Space
key = ' ';
}
else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && SDLK_KP0 <= sym && sym <= SDLK_KP9)
else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && SDLK_KP_0 <= sym && sym <= SDLK_KP_9)
{
// Control-only numeric keypad keys are converted to regular digit keys
key = sym-SDLK_KP0+'0';
key = sym-SDLK_KP_0+'0';
}
else if ((mod&KMOD_CTRL) && !(mod&KMOD_SHIFT) && (('0' <= sym && sym <= '9') || sym == '/' || sym == ' '))
{
@ -401,8 +405,10 @@ void Emulator::dispatchKeypress(const SDL_KeyboardEvent& keyEvent)
// window
void Emulator::cmdKey(const SDL_KeyboardEvent& keyEvent)
{
unsigned char key = (unsigned char)(keyEvent.keysym.unicode & 0x7F);
SDLKey sym = keyEvent.keysym.sym;
SDL_Keycode sym = keyEvent.keysym.sym;
SDL_Keymod mod = (SDL_Keymod)keyEvent.keysym.mod;
unsigned char key = (unsigned char)(sym & 0x7F);
if (sym == SDLK_RETURN)
{
processCommand();

View File

@ -27,7 +27,7 @@
#include "keyboardbuffermode.h"
#include "hypermode.h"
#include "clipboardhandler.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
class Timable;
class Config;

View File

@ -20,7 +20,7 @@
#endif
#include "gui.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
// Create, initialize, and cable together the UI objects to serve this
// program
@ -33,9 +33,7 @@ GUI::GUI()
throw GUI::NotInitException();
}
SDL_EnableUNICODE(1);
SDL_ShowCursor(0);
SDL_EnableKeyRepeat(0,0);
}
GUI::~GUI()

View File

@ -18,7 +18,7 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <queue>
typedef std::queue<unsigned char> KeypressQueue;

View File

@ -17,7 +17,7 @@
*/
#include "paddlebuttonstates.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
const int PaddleButtonStates::PADDLE_COUNT(3);

View File

@ -17,7 +17,7 @@
*/
#include "e2const.h"
#include "paddles.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <iostream>
#include <ostream>

View File

@ -20,7 +20,7 @@
#include "applentsc.h"
#include "card.h"
#include "util.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <ctime>
#include <sstream>
@ -67,7 +67,7 @@ void ScreenImage::toggleFullScreen()
void ScreenImage::createScreen()
{
this->screen = SDL_SetVideoMode(SCRW,SCRH,32,SDL_HWSURFACE|SDL_HWPALETTE|(this->fullscreen?SDL_FULLSCREEN:0));
// TODO this->screen = SDL_SetVideoMode(SCRW,SCRH,32,SDL_HWSURFACE|SDL_HWPALETTE|(this->fullscreen?SDL_FULLSCREEN:0));
if (this->screen == NULL)
{
printf("Unable to set video mode: %s\n",SDL_GetError());
@ -248,7 +248,7 @@ void ScreenImage::drawChar(const char ch, int row, int col, int color, int bgcol
pn -= FONTW;
pn += SCRW;
}
SDL_UpdateRect(this->screen,col*FONTW,row*FONTH,(col+1)*FONTW,(row+1)*FONTH);
// TODO SDL_UpdateRect(this->screen,col*FONTW,row*FONTH,(col+1)*FONTW,(row+1)*FONTH);
}
void ScreenImage::displayHz(int hz)
@ -296,7 +296,7 @@ void ScreenImage::drawPower(bool on)
pn -= POWERD;
pn += this->screen->pitch/4;
}
SDL_UpdateRect(this->screen,0,HEIGHT,POWERD,HEIGHT+POWERD);
// TODO SDL_UpdateRect(this->screen,0,HEIGHT,POWERD,HEIGHT+POWERD);
}
ScreenImage::~ScreenImage()
@ -305,7 +305,7 @@ ScreenImage::~ScreenImage()
void ScreenImage::notifyObservers()
{
SDL_UpdateRect(this->screen,0,0,SCRW,SCRH);
// TODO SDL_UpdateRect(this->screen,0,0,SCRW,SCRH);
}
void ScreenImage::setElem(unsigned int i, const unsigned int val)

View File

@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "speakerclicker.h"
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <iostream>
#include <ostream>
#include <deque>

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "standardinproducer.h"
#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_thread.h>
#include <iostream>
#define CR '\r'
@ -92,7 +92,7 @@ static int readInput(void *voidkeys)
StandardInProducer::StandardInProducer()
{
SDL_CreateThread(readInput,&this->keys);
SDL_CreateThread(readInput,"stdin",&this->keys);
}
StandardInProducer::~StandardInProducer()