2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2011-09-01 14:58:52 +00:00
|
|
|
* Copyright (c) 2005-2006, 2008-2009, 2011 Günther Brammer
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2005 Peter Wortmann
|
|
|
|
* Copyright (c) 2006 Armin Burgmeier
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2009 Nicolas Hake
|
2010-12-23 00:01:24 +00:00
|
|
|
* Copyright (c) 2010 Benjamin Herr
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* A wrapper class to OS dependent event and window interfaces, Text version */
|
|
|
|
|
2010-03-04 21:12:35 +00:00
|
|
|
#include <C4Include.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
#ifdef USE_CONSOLE
|
2011-10-03 15:19:24 +00:00
|
|
|
#include <C4Window.h>
|
2012-04-27 17:04:43 +00:00
|
|
|
#include <C4Draw.h>
|
2011-01-09 23:01:17 +00:00
|
|
|
#include <C4Application.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBREADLINE
|
|
|
|
# if defined(HAVE_READLINE_READLINE_H)
|
|
|
|
# include <readline/readline.h>
|
|
|
|
# elif defined(HAVE_READLINE_H)
|
|
|
|
# include <readline.h>
|
|
|
|
# endif
|
|
|
|
static void readline_callback (char *);
|
|
|
|
#endif /* HAVE_LIBREADLINE */
|
|
|
|
|
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
|
|
|
# if defined(HAVE_READLINE_HISTORY_H)
|
|
|
|
# include <readline/history.h>
|
|
|
|
# elif defined(HAVE_HISTORY_H)
|
|
|
|
# include <history.h>
|
|
|
|
# endif
|
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
/* C4AbstractApp */
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
C4AbstractApp::C4AbstractApp(): Active(false), fQuitMsgReceived(false),
|
2010-03-28 18:58:01 +00:00
|
|
|
// main thread
|
2009-05-08 13:28:41 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
2010-03-28 18:58:01 +00:00
|
|
|
MainThread (pthread_self()),
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|
2010-03-28 18:58:01 +00:00
|
|
|
fDspModeSet(false)
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
Add(&InProc);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
C4AbstractApp::~C4AbstractApp()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
Remove(&InProc);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
bool C4AbstractApp::Init(int argc, char * argv[])
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// Set locale
|
|
|
|
setlocale(LC_ALL,"");
|
|
|
|
|
|
|
|
// Custom initialization
|
2010-10-04 19:39:19 +00:00
|
|
|
return DoInit (argc, argv);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
void C4AbstractApp::Clear()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
void C4AbstractApp::Quit()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
fQuitMsgReceived = true;
|
|
|
|
}
|
2011-01-09 23:01:17 +00:00
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
bool C4AbstractApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32_t *piYRes, int32_t *piBitDepth, int32_t *piRefreshRate, uint32_t iMonitor)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
void C4AbstractApp::RestoreVideoMode() {}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2012-04-01 20:16:59 +00:00
|
|
|
bool C4AbstractApp::SetVideoMode(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, bool)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// Copy the text to the clipboard or the primary selection
|
2011-08-27 14:20:39 +00:00
|
|
|
bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
return false;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paste the text from the clipboard or the primary selection
|
2011-08-27 14:20:39 +00:00
|
|
|
StdStrBuf C4AbstractApp::Paste(bool fClipboard)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return StdStrBuf("");
|
|
|
|
}
|
|
|
|
// Is there something in the clipboard?
|
2011-08-27 14:20:39 +00:00
|
|
|
bool C4AbstractApp::IsClipboardFull(bool fClipboard)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-09 23:01:17 +00:00
|
|
|
|
|
|
|
CStdInProc::CStdInProc()
|
|
|
|
{
|
|
|
|
#if USE_CONSOLE && HAVE_LIBREADLINE
|
|
|
|
rl_callback_handler_install (">", readline_callback);
|
|
|
|
#endif
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
|
2011-01-09 23:01:17 +00:00
|
|
|
CStdInProc::~CStdInProc()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
#if USE_CONSOLE && HAVE_LIBREADLINE
|
|
|
|
rl_callback_handler_remove();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CStdInProc::Execute(int iTimeout, pollfd *)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
while (_kbhit())
|
|
|
|
{
|
|
|
|
// Surely not the most efficient way to do it, but we won't have to read much data anyway.
|
|
|
|
char c = getch();
|
|
|
|
if (c == '\r')
|
|
|
|
{
|
|
|
|
if (!CmdBuf.isNull())
|
|
|
|
{
|
2011-02-03 23:16:45 +00:00
|
|
|
Application.OnCommand(CmdBuf.getData());
|
2011-01-09 23:01:17 +00:00
|
|
|
CmdBuf.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isprint((unsigned char)c))
|
|
|
|
CmdBuf.AppendChar(c);
|
|
|
|
}
|
|
|
|
// FIXME: handle stdin-close
|
|
|
|
return true;
|
|
|
|
#elif defined(HAVE_LIBREADLINE)
|
2009-05-08 13:28:41 +00:00
|
|
|
rl_callback_read_char();
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
// Surely not the most efficient way to do it, but we won't have to read much data anyway.
|
|
|
|
char c;
|
2010-03-28 18:58:01 +00:00
|
|
|
if (read(0, &c, 1) != 1)
|
2011-01-09 23:01:17 +00:00
|
|
|
{
|
|
|
|
Application.Quit();
|
2009-05-08 13:28:41 +00:00
|
|
|
return false;
|
2011-01-09 23:01:17 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
if (!CmdBuf.isNull())
|
|
|
|
{
|
2011-02-03 23:16:45 +00:00
|
|
|
Application.OnCommand(CmdBuf.getData());
|
2011-01-09 23:01:17 +00:00
|
|
|
CmdBuf.Clear();
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
|
|
|
else if (isprint((unsigned char)c))
|
2009-05-08 13:28:41 +00:00
|
|
|
CmdBuf.AppendChar(c);
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
2011-01-09 23:01:17 +00:00
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
#if HAVE_LIBREADLINE
|
2010-03-28 18:58:01 +00:00
|
|
|
static void readline_callback (char * line)
|
|
|
|
{
|
|
|
|
if (!line)
|
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
Application.Quit();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
Application.OnCommand(line);
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
|
|
|
#if HAVE_READLINE_HISTORY
|
2010-03-28 18:58:01 +00:00
|
|
|
if (line && *line)
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
add_history (line);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-28 19:40:19 +00:00
|
|
|
bool C4AbstractApp::ApplyGammaRamp(_D3DGAMMARAMP&, bool) { return true; }
|
|
|
|
bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP&) { return true; }
|
|
|
|
void C4AbstractApp::MessageDialog(const char * message) {}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2011-08-27 14:20:39 +00:00
|
|
|
bool C4AbstractApp::FlushMessages()
|
2009-05-08 13:28:41 +00:00
|
|
|
{
|
2011-01-09 23:01:17 +00:00
|
|
|
// Always fail after quit message
|
|
|
|
if (fQuitMsgReceived)
|
|
|
|
return false;
|
|
|
|
return true;
|
2009-05-08 13:28:41 +00:00
|
|
|
}
|
2011-01-09 23:01:17 +00:00
|
|
|
|
2011-08-27 21:12:01 +00:00
|
|
|
void C4Window::Clear() {}
|
|
|
|
C4Window::C4Window() {}
|
|
|
|
C4Window::~C4Window() {}
|
|
|
|
void C4Window::EnumerateMultiSamples(std::vector<int, std::allocator<int> >&) const {}
|
|
|
|
void C4Window::FlashWindow() {}
|
|
|
|
bool C4Window::GetSize(C4Rect*) {return 0;}
|
2012-04-01 20:16:59 +00:00
|
|
|
C4Window* C4Window::Init(C4Window::WindowKind, C4AbstractApp*, char const*, const C4Rect *) {return this;}
|
2011-08-27 21:12:01 +00:00
|
|
|
bool C4Window::ReInit(C4AbstractApp*) {return 0;}
|
|
|
|
bool C4Window::RestorePosition(char const*, char const*, bool) {return 0;}
|
2012-03-25 00:54:07 +00:00
|
|
|
void C4Window::RequestUpdate() {}
|
2011-08-27 21:12:01 +00:00
|
|
|
void C4Window::SetSize(unsigned int, unsigned int) {}
|
|
|
|
void C4Window::SetTitle(char const*) {}
|
2011-01-09 23:01:17 +00:00
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif // USE_CONSOLE
|