Merge branch 'sdl_android' of github.com:pelya/commandergenius into sdl_android

This commit is contained in:
Gerhard Stein
2013-12-07 14:11:34 +01:00
9 changed files with 1649 additions and 1233 deletions

View File

@@ -109,13 +109,18 @@ abstract class DifferentTouchInput
multiTouchAvailable2 = true;
}
try {
Log.i("SDL", "Device: " + android.os.Build.DEVICE);
Log.i("SDL", "Device name: " + android.os.Build.DISPLAY);
Log.i("SDL", "Device model: " + android.os.Build.MODEL);
Log.i("SDL", "Device board: " + android.os.Build.BOARD);
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH )
{
if ( Globals.GenerateSubframeTouchEvents )
return IcsTouchInputWithHistory.Holder.sInstance;
if( DetectCrappyDragonRiseDatexGamepad() )
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance;
if( android.os.Build.BOARD.contains("bird") )
return CrappyMtkTabletWithBrokenTouchDrivers.Holder.sInstance;
return IcsTouchInput.Holder.sInstance;
}
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD )
@@ -468,6 +473,23 @@ abstract class DifferentTouchInput
return false;
}
}
private static class CrappyMtkTabletWithBrokenTouchDrivers extends IcsTouchInput
{
private static class Holder
{
private static final CrappyMtkTabletWithBrokenTouchDrivers sInstance = new CrappyMtkTabletWithBrokenTouchDrivers();
}
public void process(final MotionEvent event)
{
if( event.getX() != 0.0f && event.getY() != 0.0f ) // Ignore event when it has zero coordinates
super.process(event);
}
public void processGenericEvent(final MotionEvent event)
{
if( event.getX() != 0.0f && event.getY() != 0.0f ) // Ignore event when it has zero coordinates
super.processGenericEvent(event);
}
}
}

View File

@@ -75,6 +75,10 @@ CompatibilityHacksSlowCompatibleEventQueue=n
# Save and restore OpenGL state when drawing on-screen keyboard for apps that use SDL_OPENGL
CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState=
# Application uses SDL_UpdateRects() properly, and does not draw in any region outside those rects.
# This improves drawing speed, but I know only one application that does that, and it's written by me (y)/(n)
CompatibilityHacksProperUsageOfSDL_UpdateRects=
# Application uses mouse (y) or (n), this will show mouse emulation dialog to the user
AppUsesMouse=y
@@ -82,10 +86,13 @@ AppUsesMouse=y
AppNeedsTwoButtonMouse=y
# Show SDL mouse cursor, for applications that do not draw cursor at all (y) or (n)
ShowMouseCursor=n
ShowMouseCursor=y
# Generate more touch events, by default SDL generates one event per one video frame, this is useful for drawing apps (y) or (n)
GenerateSubframeTouchEvents=
# Force relative (laptop) mouse movement mode, useful when both on-screen keyboard and mouse are needed (y) or (n)
ForceRelativeMouseMode=n
ForceRelativeMouseMode=y
# Application needs arrow keys (y) or (n), will show on-screen dpad/joystick (y) or (n)
AppNeedsArrowKeys=n
@@ -106,7 +113,7 @@ AppUsesAccelerometer=n
AppUsesGyroscope=n
# Application uses multitouch (y) or (n), multitouch events are passed as SDL_JOYBALLMOTION events for the joystick 0
AppUsesMultitouch=n
AppUsesMultitouch=y
# Application records audio (it will use any available source, such a s microphone)
# API is defined in file SDL_android.h: int SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec); void SDL_ANDROID_CloseAudioRecording(void);
@@ -179,7 +186,7 @@ AppVersionName="1.01"
ResetSdlConfigForThisVersion=n
# Delete application data files when upgrading (specify file/dir paths separated by spaces)
DeleteFilesOnUpgrade=""
DeleteFilesOnUpgrade="%"
# Optional shared libraries to compile - removing some of them will save space
# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed

View File

@@ -1,208 +1,268 @@
/**
* SDL Hello World example for Guichan.
*/
// Include all necessary headers.
#include <iostream>
#include <guichan.hpp>
#include <guichan/sdl.hpp>
#include <SDL/SDL.h>
#include "xmlgui.h"
/*
* Common stuff we need
*/
bool running = true;
/*
* SDL Stuff we need
*/
SDL_Surface* screen;
SDL_Event event;
/*
* Guichan SDL stuff we need
*/
gcn::SDLInput* input; // Input driver
gcn::SDLGraphics* graphics; // Graphics driver
gcn::SDLImageLoader* imageLoader; // For loading images
/*
* Guichan stuff we need
*/
gcn::Gui* gui; // A Gui object - binds it all together
gcn::Container* top; // A top container
gcn::ImageFont* font; // A font
//XmlGui stuff
XmlGui *xmlgui = new XmlGui();
/**
* Initializes the Hello World
*/
void init()
{
/*
* Here we initialize SDL as we would do with any SDL application.
*/
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
// We want unicode
SDL_EnableUNICODE(1);
// We want to enable key repeat
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
/*
* Now it's time for Guichan SDL stuff
*/
imageLoader = new gcn::SDLImageLoader();
// The ImageLoader in use is static and must be set to be
// able to load images
gcn::Image::setImageLoader(imageLoader);
graphics = new gcn::SDLGraphics();
// Set the target for the graphics object to be the screen.
// In other words, we will draw to the screen.
// Note, any surface will do, it doesn't have to be the screen.
graphics->setTarget(screen);
input = new gcn::SDLInput();
/*
* Last but not least it's time to initialize and create the gui
* with Guichan stuff.
*/
gui = new gcn::Gui();
// Set gui to use the SDLGraphics object.
gui->setGraphics(graphics);
// Set gui to use the SDLInput object
gui->setInput(input);
// Set the top container
gui->setTop(top);
// Load the image font.
font = new gcn::ImageFont("fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
// The global font is static and must be set.
gcn::Widget::setGlobalFont(font);
xmlgui = new XmlGui();
xmlgui->parse("gui.xml");
gui->setTop(xmlgui->getWidget("top"));
}
/**
* Halts the application
*/
void halt()
{
/*
* Destroy Guichan stuff
*/
delete xmlgui;
delete font;
delete top;
delete gui;
/*
* Destroy Guichan SDL stuff
*/
delete input;
delete graphics;
delete imageLoader;
/*
* Destroy SDL stuff
*/
SDL_Quit();
}
/**
* Checks input. On escape halt the application.
*/
void checkInput()
{
/*
* Poll SDL events
*/
while(SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
if (event.key.keysym.sym == SDLK_f)
{
if (event.key.keysym.mod & KMOD_CTRL)
{
// Works with X11 only
SDL_WM_ToggleFullScreen(screen);
}
}
}
else if(event.type == SDL_QUIT)
{
running = false;
}
/*
* Now that we are done polling and using SDL events we pass
* the leftovers to the SDLInput object to later be handled by
* the Gui. (This example doesn't require us to do this 'cause a
* label doesn't use input. But will do it anyway to show how to
* set up an SDL application with Guichan.)
*/
input->pushInput(event);
}
}
/**
* Runs the application
*/
void run()
{
while(running)
{
// Poll input
checkInput();
// Let the gui perform it's logic (like handle input)
gui->logic();
// Draw the gui
gui->draw();
// Update the screen
SDL_Flip(screen);
}
}
int main(int argc, char **argv)
{
try
{
init();
run();
halt();
}
/*
* Catch all Guichan exceptions
*/
catch (gcn::Exception e)
{
std::cerr << e.getMessage() << std::endl;
return 1;
}
/*
* Catch all Std exceptions
*/
catch (std::exception e)
{
std::cerr << "Std exception: " << e.what() << std::endl;
return 1;
}
/*
* Catch all Unknown exceptions
*/
catch (...)
{
std::cerr << "Unknown exception" << std::endl;
return 1;
}
return 0;
}
/**
* SDL Hello World example for Guichan.
*/
// Include all necessary headers.
#include <iostream>
#include <guichan.hpp>
#include <guichan/sdl.hpp>
#include <SDL/SDL.h>
//#include <android/log.h>
#include "xmlgui.h"
/*
* Common stuff we need
*/
bool running = true;
/*
* SDL Stuff we need
*/
SDL_Surface* screen;
SDL_Event event;
/*
* Guichan SDL stuff we need
*/
gcn::SDLInput* input; // Input driver
gcn::SDLGraphics* graphics; // Graphics driver
gcn::SDLImageLoader* imageLoader; // For loading images
/*
* Guichan stuff we need
*/
gcn::Gui* gui; // A Gui object - binds it all together
gcn::Container* top; // A top container
gcn::ImageFont* font; // A font
//XmlGui stuff
XmlGui *xmlgui = new XmlGui();
/**
* Initializes the Hello World
*/
void init()
{
/*
* Here we initialize SDL as we would do with any SDL application.
*/
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
// We want unicode
SDL_EnableUNICODE(1);
// We want to enable key repeat
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
// Enable Android multitouch
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDL_JoystickOpen(0);
/*
* Now it's time for Guichan SDL stuff
*/
imageLoader = new gcn::SDLImageLoader();
// The ImageLoader in use is static and must be set to be
// able to load images
gcn::Image::setImageLoader(imageLoader);
graphics = new gcn::SDLGraphics();
// Set the target for the graphics object to be the screen.
// In other words, we will draw to the screen.
// Note, any surface will do, it doesn't have to be the screen.
graphics->setTarget(screen);
input = new gcn::SDLInput();
/*
* Last but not least it's time to initialize and create the gui
* with Guichan stuff.
*/
gui = new gcn::Gui();
// Set gui to use the SDLGraphics object.
gui->setGraphics(graphics);
// Set gui to use the SDLInput object
gui->setInput(input);
// Set the top container
gui->setTop(top);
// Load the image font.
font = new gcn::ImageFont("fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
// The global font is static and must be set.
gcn::Widget::setGlobalFont(font);
xmlgui = new XmlGui();
xmlgui->parse("gui.xml");
gui->setTop(xmlgui->getWidget("top"));
}
/**
* Halts the application
*/
void halt()
{
/*
* Destroy Guichan stuff
*/
delete xmlgui;
delete font;
delete top;
delete gui;
/*
* Destroy Guichan SDL stuff
*/
delete input;
delete graphics;
delete imageLoader;
/*
* Destroy SDL stuff
*/
SDL_Quit();
}
/**
* Checks input. On escape halt the application.
*/
void checkInput()
{
/*
* Poll SDL events
*/
while(SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
if (event.key.keysym.sym == SDLK_f)
{
if (event.key.keysym.mod & KMOD_CTRL)
{
// Works with X11 only
SDL_WM_ToggleFullScreen(screen);
}
}
}
else if(event.type == SDL_QUIT)
{
running = false;
}
/*
* Now that we are done polling and using SDL events we pass
* the leftovers to the SDLInput object to later be handled by
* the Gui. (This example doesn't require us to do this 'cause a
* label doesn't use input. But will do it anyway to show how to
* set up an SDL application with Guichan.)
*/
if (event.type == SDL_MOUSEMOTION ||
event.type == SDL_MOUSEBUTTONDOWN ||
event.type == SDL_MOUSEBUTTONUP)
{
// Filter emulated mouse events for Guichan, we wand absolute input
}
else
{
// Convert multitouch event to SDL mouse event
static int x = 0, y = 0, buttons = 0;
SDL_Event event2;
memcpy(&event2, &event, sizeof(event));
if (event.type == SDL_JOYBALLMOTION &&
event.jball.which == 0 &&
event.jball.ball == 0)
{
event2.type = SDL_MOUSEMOTION;
event2.motion.which = 0;
event2.motion.state = buttons;
event2.motion.xrel = event.jball.xrel - x;
event2.motion.yrel = event.jball.yrel - y;
x = event.jball.xrel;
y = event.jball.yrel;
event2.motion.x = x;
event2.motion.y = y;
//__android_log_print(ANDROID_LOG_INFO, "GUICHAN","Mouse motion %d %d btns %d", x, y, buttons);
if (buttons == 0)
{
// Push mouse motion event first, then button down event
input->pushInput(event2);
buttons = SDL_BUTTON_LMASK;
event2.type = SDL_MOUSEBUTTONDOWN;
event2.button.which = 0;
event2.button.button = SDL_BUTTON_LEFT;
event2.button.state = SDL_PRESSED;
event2.button.x = x;
event2.button.y = y;
//__android_log_print(ANDROID_LOG_INFO, "GUICHAN","Mouse button %d coords %d %d", buttons, x, y);
}
}
if (event.type == SDL_JOYBUTTONUP &&
event.jbutton.which == 0 &&
event.jbutton.button == 0)
{
// Do not push button down event here, because we need mouse motion event first
buttons = 0;
event2.type = SDL_MOUSEBUTTONUP;
event2.button.which = 0;
event2.button.button = SDL_BUTTON_LEFT;
event2.button.state = SDL_RELEASED;
event2.button.x = x;
event2.button.y = y;
//__android_log_print(ANDROID_LOG_INFO, "GUICHAN","Mouse button %d coords %d %d", buttons, x, y);
}
input->pushInput(event2);
}
}
}
/**
* Runs the application
*/
void run()
{
while(running)
{
// Poll input
checkInput();
// Let the gui perform it's logic (like handle input)
gui->logic();
// Draw the gui
gui->draw();
// Update the screen
SDL_Flip(screen);
}
}
int main(int argc, char **argv)
{
try
{
init();
run();
halt();
}
/*
* Catch all Guichan exceptions
*/
catch (gcn::Exception e)
{
std::cerr << e.getMessage() << std::endl;
return 1;
}
/*
* Catch all Std exceptions
*/
catch (std::exception e)
{
std::cerr << "Std exception: " << e.what() << std::endl;
return 1;
}
/*
* Catch all Unknown exceptions
*/
catch (...)
{
std::cerr << "Unknown exception" << std::endl;
return 1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,155 +1,155 @@
/* XmlGui - xml parsing class for guichan (http://guichan.sourceforge.net)
* author - quard (quard8@gmail.com)
* Changes:
* v. 0.4 - fixed bug in Visual Studio .NET 2003, when compiler option /GR is not enabled;
fixed widget allocation, when attribute "name" is't exists
deleted all "return false" after GCN_EXCEPTION, because they not used ever
* v. 0.3.5 - fixed stupid bug, when widgets not parsed if parent widget is NULL
* v. 0.3 - added parsing method for widget,
* now checking widget node is in one function
* v. 0.2 - small bug fix
* - added parsing widgets under 'container'
* - changed sscanf to atoi
* v. 0.1 - first public release
*/
#ifndef XML_GUI_H
#define XML_GUI_H
#include <guichan.hpp>
#include "tinyxml.h"
#include <map>
//!XmlGui class for loading gui widget from xml file
class XmlGui
{
public:
//!constructor
XmlGui();
//!parse xml file
//@param filename the file name to parse
//@return true if loaded ok
bool parse(const std::string &filename);
//@param name th widget name
//@return widget by name
gcn::Widget *getWidget(const std::string &name);
//!parse default parameters for all widgets
//@param element the xml element
//@param widget the current widget
void parseDefaults(TiXmlElement *element, gcn::Widget *widget);
//!parse container widget
//@param element the xml element
//@param widget the current widget
void parseContainer(TiXmlElement *element, gcn::Widget *parent);
//!parse label widget
//@param element the xml element
//@param widget the current widget
void parseLabel(TiXmlElement *element, gcn::Widget *parent);
//!parse button widget
//@param element the xml element
//@param widget the current widget
void parseButton(TiXmlElement *element, gcn::Widget *parent);
//!parse checkbox widget
//@param element the xml element
//@param widget the current widget
void parseCheckBox(TiXmlElement *element, gcn::Widget *parent);
//!parse radiobutton widget
//@param element the xml element
//@param widget the current widget
void parseRadioButton(TiXmlElement *element, gcn::Widget *parent);
//!parse icon widget
//@param element the xml element
//@param widget the current widget
void parseIcon(TiXmlElement *element, gcn::Widget *parent);
//!parse textbox widget
//@param element the xml element
//@param widget the current widget
void parseTextBox(TiXmlElement *element, gcn::Widget *parent);
//!parse textfield widget
//@param element the xml element
//@param widget the current widget
void parseTextField(TiXmlElement *element, gcn::Widget *parent);
//!parse slider widget
//@param element the xml element
//@param widget the current widget
void parseSlider(TiXmlElement *element, gcn::Widget *parent);
//!parse window widget
//@param element the xml element
//@param widget the current widget
void parseWindow(TiXmlElement *element, gcn::Widget *parent);
//!parse scrollarea widget
//@param element the xml element
//@param widget the current widget
void parseScrollArea(TiXmlElement *element,gcn::Widget *parent);
//!parse dropdown widget
//@param element the xml element
//@param widget the current widget
void parseDropdown(TiXmlElement *element,gcn::Widget *parent);
//!parse listbox widget
//@param element the xml element
//@param widget the current widget
void parseListbox(TiXmlElement *element,gcn::Widget *parent);
//!add actionlistener to array
//@param name the actionlistener name
//@param al the pointer to actionlistener class
void addActionListener(const std::string &name,gcn::ActionListener *al);
//!add font
//@param name the font name
//@param al the pointer to font class
void addFont(const std::string &name,gcn::Font *font);
private:
//!parse xml node
//@param element - xml element
//@param parent - the parent widget
void parseWidgets(TiXmlElement *element, gcn::Widget *parent);
//!adding widget to parent
//!parent widget can be Container,ScrollArea,Window. this function get class and set widget or add widget (for Container)
//@param widget our widget
//@param parent the parent widget
void addToParent(gcn::Widget *widget, gcn::Widget *parent);
//!check string value for boolean value
//@param value the string value
//@return true if value are "1" or "true"
bool checkBool(const std::string &value);
std::map<std::string,gcn::Widget*> widgets;
std::map<std::string,gcn::ActionListener*> actions;
std::map<std::string,gcn::Font*> fonts;
//temporary xml document (need by some functions)
TiXmlDocument *doc;
};
class XmlListModel : public gcn::ListModel
{
public:
virtual int getNumberOfElements();
virtual std::string getElementAt(int i);
std::vector<std::string> items;
};
/* XmlGui - xml parsing class for guichan (http://guichan.sourceforge.net)
* author - quard (quard8@gmail.com)
* Changes:
* v. 0.4 - fixed bug in Visual Studio .NET 2003, when compiler option /GR is not enabled;
fixed widget allocation, when attribute "name" is't exists
deleted all "return false" after GCN_EXCEPTION, because they not used ever
* v. 0.3.5 - fixed stupid bug, when widgets not parsed if parent widget is NULL
* v. 0.3 - added parsing method for widget,
* now checking widget node is in one function
* v. 0.2 - small bug fix
* - added parsing widgets under 'container'
* - changed sscanf to atoi
* v. 0.1 - first public release
*/
#ifndef XML_GUI_H
#define XML_GUI_H
#include <guichan.hpp>
#include "tinyxml.h"
#include <map>
//!XmlGui class for loading gui widget from xml file
class XmlGui
{
public:
//!constructor
XmlGui();
//!parse xml file
//@param filename the file name to parse
//@return true if loaded ok
bool parse(const std::string &filename);
//@param name th widget name
//@return widget by name
gcn::Widget *getWidget(const std::string &name);
//!parse default parameters for all widgets
//@param element the xml element
//@param widget the current widget
void parseDefaults(TiXmlElement *element, gcn::Widget *widget);
//!parse container widget
//@param element the xml element
//@param widget the current widget
void parseContainer(TiXmlElement *element, gcn::Widget *parent);
//!parse label widget
//@param element the xml element
//@param widget the current widget
void parseLabel(TiXmlElement *element, gcn::Widget *parent);
//!parse button widget
//@param element the xml element
//@param widget the current widget
void parseButton(TiXmlElement *element, gcn::Widget *parent);
//!parse checkbox widget
//@param element the xml element
//@param widget the current widget
void parseCheckBox(TiXmlElement *element, gcn::Widget *parent);
//!parse radiobutton widget
//@param element the xml element
//@param widget the current widget
void parseRadioButton(TiXmlElement *element, gcn::Widget *parent);
//!parse icon widget
//@param element the xml element
//@param widget the current widget
void parseIcon(TiXmlElement *element, gcn::Widget *parent);
//!parse textbox widget
//@param element the xml element
//@param widget the current widget
void parseTextBox(TiXmlElement *element, gcn::Widget *parent);
//!parse textfield widget
//@param element the xml element
//@param widget the current widget
void parseTextField(TiXmlElement *element, gcn::Widget *parent);
//!parse slider widget
//@param element the xml element
//@param widget the current widget
void parseSlider(TiXmlElement *element, gcn::Widget *parent);
//!parse window widget
//@param element the xml element
//@param widget the current widget
void parseWindow(TiXmlElement *element, gcn::Widget *parent);
//!parse scrollarea widget
//@param element the xml element
//@param widget the current widget
void parseScrollArea(TiXmlElement *element,gcn::Widget *parent);
//!parse dropdown widget
//@param element the xml element
//@param widget the current widget
void parseDropdown(TiXmlElement *element,gcn::Widget *parent);
//!parse listbox widget
//@param element the xml element
//@param widget the current widget
void parseListbox(TiXmlElement *element,gcn::Widget *parent);
//!add actionlistener to array
//@param name the actionlistener name
//@param al the pointer to actionlistener class
void addActionListener(const std::string &name,gcn::ActionListener *al);
//!add font
//@param name the font name
//@param al the pointer to font class
void addFont(const std::string &name,gcn::Font *font);
private:
//!parse xml node
//@param element - xml element
//@param parent - the parent widget
void parseWidgets(TiXmlElement *element, gcn::Widget *parent);
//!adding widget to parent
//!parent widget can be Container,ScrollArea,Window. this function get class and set widget or add widget (for Container)
//@param widget our widget
//@param parent the parent widget
void addToParent(gcn::Widget *widget, gcn::Widget *parent);
//!check string value for boolean value
//@param value the string value
//@return true if value are "1" or "true"
bool checkBool(const std::string &value);
std::map<std::string,gcn::Widget*> widgets;
std::map<std::string,gcn::ActionListener*> actions;
std::map<std::string,gcn::Font*> fonts;
//temporary xml document (need by some functions)
TiXmlDocument *doc;
};
class XmlListModel : public gcn::ListModel
{
public:
virtual int getNumberOfElements();
virtual std::string getElementAt(int i);
std::vector<std::string> items;
};
#endif

View File

@@ -7,7 +7,7 @@ LOCAL_MODULE := guichan
APP_SUBDIRS := $(patsubst $(LOCAL_PATH)/%, %, $(shell find $(LOCAL_PATH)/src -type d))
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include $(LOCAL_PATH)/include \
$(LOCAL_PATH)/../sdl_image/include
$(LOCAL_PATH)/../sdl_image/include $(LOCAL_PATH)/../sdl_ttf/include
LOCAL_CFLAGS := -DHAVE_CONFIG_H -D_GNU_SOURCE=1 -D_REENTRANT -fexceptions -frtti
LOCAL_CPP_EXTENSION := .cpp
@@ -16,7 +16,7 @@ LOCAL_SRC_FILES := $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wil
LOCAL_SRC_FILES += $(foreach F, $(APP_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
LOCAL_SHARED_LIBRARIES := sdl-$(SDL_VERSION)
LOCAL_SHARED_LIBRARIES += sdl_image
LOCAL_SHARED_LIBRARIES += sdl_image sdl_ttf
LOCAL_STATIC_LIBRARIES :=

View File

@@ -0,0 +1,156 @@
/* _______ __ __ __ ______ __ __ _______ __ __
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
*
* Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
*
*
* Per Larsson a.k.a finalman
* Olof Naessén a.k.a jansem/yakslem
*
* Visit: http://guichan.sourceforge.net
*
* License: (BSD)
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Guichan nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GCN_CONTRIB_SDLTRUETYPEFONT_HPP
#define GCN_CONTRIB_SDLTRUETYPEFONT_HPP
#include <map>
#include <string>
#include <SDL/SDL_ttf.h>
#include "guichan/font.hpp"
#include "guichan/platform.hpp"
namespace gcn
{
class Graphics;
namespace contrib
{
/**
* SDL True Type Font implementation of Font. It uses the SDL_ttf library
* to display True Type Fonts with SDL.
*
* NOTE: You must initialize the SDL_ttf library before using this
* class. Also, remember to call the SDL_ttf libraries quit
* function.
*
* @author Walluce Pinkham
* @author Olof Naessén
*/
class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font
{
public:
/**
* Constructor.
*
* @param filename the filename of the True Type Font.
* @param size the size the font should be in.
*/
SDLTrueTypeFont (const std::string& filename, int size);
/**
* Destructor.
*/
virtual ~SDLTrueTypeFont();
/**
* Sets the spacing between rows in pixels. Default is 0 pixels.
* The spacing can be negative.
*
* @param spacing the spacing in pixels.
*/
virtual void setRowSpacing (int spacing);
/**
* Gets the spacing between rows in pixels.
*
* @return the spacing.
*/
virtual int getRowSpacing();
/**
* Sets the spacing between letters in pixels. Default is 0 pixels.
* The spacing can be negative.
*
* @param spacing the spacing in pixels.
*/
virtual void setGlyphSpacing(int spacing);
/**
* Gets the spacing between letters in pixels.
*
* @return the spacing.
*/
virtual int getGlyphSpacing();
/**
* Sets the use of anti aliasing..
*
* @param antaAlias true for use of antia aliasing.
*/
virtual void setAntiAlias(bool antiAlias);
/**
* Checks if anti aliasing is used.
*
* @return true if anti aliasing is used.
*/
virtual bool isAntiAlias();
// Inherited from Font
virtual int getWidth(const std::string& text) const;
virtual int getHeight() const;
virtual void drawString(Graphics* graphics, const std::string& text, int x, int y);
protected:
TTF_Font *mFont;
int mHeight;
int mGlyphSpacing;
int mRowSpacing;
std::string mFilename;
bool mAntiAlias;
};
}
}
#endif

View File

@@ -0,0 +1,171 @@
/* _______ __ __ __ ______ __ __ _______ __ __
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
*
* Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
*
*
* Per Larsson a.k.a finalman
* Olof Naessén a.k.a jansem/yakslem
*
* Visit: http://guichan.sourceforge.net
*
* License: (BSD)
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Guichan nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* For comments regarding functions please see the header file.
*/
#include "guichan/contrib/sdl/sdltruetypefont.hpp"
#include "guichan/exception.hpp"
#include "guichan/image.hpp"
#include "guichan/graphics.hpp"
#include "guichan/sdl/sdlgraphics.hpp"
namespace gcn
{
namespace contrib
{
SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size)
{
mRowSpacing = 0;
mGlyphSpacing = 0;
mAntiAlias = true;
mFilename = filename;
mFont = NULL;
mFont = TTF_OpenFont(filename.c_str(), size);
if (mFont == NULL)
{
throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError()));
}
}
SDLTrueTypeFont::~SDLTrueTypeFont()
{
TTF_CloseFont(mFont);
}
int SDLTrueTypeFont::getWidth(const std::string& text) const
{
int w, h;
TTF_SizeText(mFont, text.c_str(), &w, &h);
return w;
}
int SDLTrueTypeFont::getHeight() const
{
return TTF_FontHeight(mFont) + mRowSpacing;
}
void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y)
{
if (text == "")
{
return;
}
gcn::SDLGraphics *sdlGraphics = dynamic_cast<gcn::SDLGraphics *>(graphics);
if (sdlGraphics == NULL)
{
throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!");
return;
}
// This is needed for drawing the Glyph in the middle if we have spacing
int yoffset = getRowSpacing() / 2;
Color col = sdlGraphics->getColor();
SDL_Color sdlCol;
sdlCol.b = col.b;
sdlCol.r = col.r;
sdlCol.g = col.g;
SDL_Surface *textSurface;
if (mAntiAlias)
{
textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol);
}
else
{
textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol);
}
SDL_Rect dst, src;
dst.x = x;
dst.y = y + yoffset;
src.w = textSurface->w;
src.h = textSurface->h;
src.x = 0;
src.y = 0;
sdlGraphics->drawSDLSurface(textSurface, src, dst);
SDL_FreeSurface(textSurface);
}
void SDLTrueTypeFont::setRowSpacing(int spacing)
{
mRowSpacing = spacing;
}
int SDLTrueTypeFont::getRowSpacing()
{
return mRowSpacing;
}
void SDLTrueTypeFont::setGlyphSpacing(int spacing)
{
mGlyphSpacing = spacing;
}
int SDLTrueTypeFont::getGlyphSpacing()
{
return mGlyphSpacing;
}
void SDLTrueTypeFont::setAntiAlias(bool antiAlias)
{
mAntiAlias = antiAlias;
}
bool SDLTrueTypeFont::isAntiAlias()
{
return mAntiAlias;
}
}
}