1
Feature requests / New class for SFML2: TextArea.
« on: December 22, 2009, 09:41:57 pm »
oh...I'm sorry...didn't realize it was polish. Anyways, keep up the good work
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
int main()
{
lua_State* settings = lua.initialize_script("resource/scripts/settings.lua");
Game.initialize_app(settings, "Stick War");
while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();
if(Input.keyboard.esc)
{
Game.exit();
}
std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;
Game.App.Clear();
Game.App.Display();
}
Game.exit();
}
class CGame: public CBase
{
public:
sf::RenderWindow App;
int game_state;
enum GameState{
Menu,
Setup,
Ingame
};
//create window
int initialize_app(lua_State* L, std::string app_name)
{
set_fullscreen(L);
if(fullscreen)
{
App.Create(sf::VideoMode(1024, 768, 32), app_name, sf::Style::Fullscreen);
}
else
{
App.Create(sf::VideoMode(1024, 768, 32), app_name);
}
return 0;
};
//call when app is closed
int exit(void)
{
App.Close();
return 0;
};
private:
int set_fullscreen(lua_State* L)
{
fullscreen = CScript::lua_retreive_boolean(L, "Fullscreen");
return 0;
};
bool fullscreen;
};
class CInput
{
public:
const sf::Input& user_input;
struct Mouse
{
int mouse_x;
int mouse_y;
bool lmb;
bool rmb;
} mouse;
struct Keyboard
{
bool esc;
} keyboard;
void update_keyboard(void)
{
keyboard.esc = user_input.IsKeyDown(sf::Key::Escape);
};
void update_mouse(void)
{
mouse.mouse_x = user_input.GetMouseX();
mouse.mouse_y = user_input.GetMouseY();
mouse.lmb = user_input.IsMouseButtonDown(sf::Mouse::Left);
mouse.rmb = user_input.IsMouseButtonDown(sf::Mouse::Right);
};
CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};
private:
};
CInput Input(Game.App);
while(Game.game_state == Game.Menu)
{
Input.update_mouse();
Input.update_keyboard();
if(Input.keyboard.esc)
{
Game.exit();
}
std::cout << Input.mouse.mouse_x << std::endl;
std::cout << Input.mouse.mouse_y << std::endl;
Game.App.Clear();
Game.App.Display();
}
Input.user_input = Game.App.GetInput();
class CInput
{
public:
const sf::Input& user_input;
CInput(sf::RenderWindow &app) : user_input(app.GetInput())
{
};
};
class TextEngine{
public:
sf::Font Font;
std::string GetFont();
int CreateFont(std::string FileDir);
sf::String CreateText(sf::String Text, std::string String, float Size, float X, float Y);
int DisplayText(sf::RenderWindow Window, sf::String FileToDisplay);
};
std::string TextEngine::GetFont(){
std::string FileName;
lua_getglobal(Menu,"Font");
FileName = (std::string)lua_tostring(Menu, -1);
lua_pop(Menu, 1);
return FileName;
};
int TextEngine::CreateFont(std::string FileDir)
{
Font.LoadFromFile(FileDir);
return 0;
}
sf::String TextEngine::CreateText(sf::String Text, std::string String, float Size, float X, float Y){
Text.SetText(String);
Text.SetFont(Font);
Text.SetSize(Size);
Text.SetX(X);
Text.SetY(Y);
return Text;
};
int TextEngine::DisplayText(sf::RenderWindow Window, sf::String FileToDisplay){
Window.Draw(FileToDisplay);
return 0;
};