Moved all files one dir upwards (should've done that long ago)
This commit is contained in:
141
project/jni/application/jooleem_0.1.4/src/UI/aboutwindow.cpp
Normal file
141
project/jni/application/jooleem_0.1.4/src/UI/aboutwindow.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/aboutwindow.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
#include "../common/common.h"
|
||||
|
||||
#include "../common/surfacemanager.h"
|
||||
#include "../common/fontmanager.h"
|
||||
#include "../common/soundmanager.h"
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
#include "../UI/uitextbox.h"
|
||||
|
||||
|
||||
AboutWindow::AboutWindow(SDL_Surface *background):
|
||||
UIWindow(background)
|
||||
{
|
||||
InitControls();
|
||||
}
|
||||
|
||||
AboutWindow::~AboutWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Initializes the window's controls, and adds them to the
|
||||
// control collection
|
||||
void AboutWindow::InitControls()
|
||||
{
|
||||
SurfaceManager *surfaceMgr = SurfaceManager::GetInstance();
|
||||
FontManager *fontMgr = FontManager::GetInstance();
|
||||
SoundManager *sndMgr = SoundManager::GetInstance();
|
||||
|
||||
{
|
||||
/////// Buttons ///////
|
||||
SDL_Color buttonTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Link:
|
||||
// This is an unusual button. To simulate the graphical beahvior of a HTML link
|
||||
// as viewed in a web broweser, the text is rendered several times (normal, hover,
|
||||
// click) and these surfaces are passed to the button *as surfaces*. The button
|
||||
// itself has no text.
|
||||
SDL_Color linkNormalColor = {66, 128, 221, 0};
|
||||
SDL_Color linkHoverColor = {75, 147, 255, 0};
|
||||
SDL_Color linkClickColor = {131, 194, 255, 0};
|
||||
Font *linkFont = fontMgr->GetFont("LinkFont");
|
||||
linkFont->SetStyle(Font::STYLE_UNDERLINE); // Make the font underline
|
||||
SDL_Surface *linkNormalSurface = surfaceMgr->AddSurface("LinkNormal",
|
||||
linkFont->RenderPlain(Font::ALN_LEFT, linkNormalColor, APP_URL));
|
||||
SDL_Surface *linkHoverSurface = surfaceMgr->AddSurface("LinkHover",
|
||||
linkFont->RenderPlain(Font::ALN_LEFT, linkHoverColor, APP_URL));
|
||||
SDL_Surface *linkClickSurface = surfaceMgr->AddSurface("LinkClick",
|
||||
linkFont->RenderPlain(Font::ALN_LEFT, linkClickColor, APP_URL));
|
||||
|
||||
UIButton *linkButton = new UIButton();
|
||||
linkButton->Set(0, 0, "ButtonClick",
|
||||
linkNormalSurface, linkNormalSurface, linkHoverSurface, linkClickSurface,
|
||||
linkNormalSurface, NULL);
|
||||
linkButton->AddState(EVENT_WEBSITE, fontMgr->GetFont("MediumButtonFont"), " ", buttonTextColor);
|
||||
linkButton->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 241);
|
||||
linkButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_LINK, linkButton);
|
||||
|
||||
// Close:
|
||||
UIButton *closeButton = new UIButton();
|
||||
closeButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
closeButton->AddState(EVENT_CLOSE, fontMgr->GetFont("MediumButtonFont"), "Close", buttonTextColor);
|
||||
closeButton->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 355);
|
||||
closeButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_CLOSE, closeButton);
|
||||
|
||||
/////// Labels ///////
|
||||
SDL_Color titleColor = {64, 64, 64, 0};
|
||||
SDL_Color labelTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Title:
|
||||
UILabel *titleLabel = new UILabel();
|
||||
titleLabel->Set(0, 0, NULL, fontMgr->GetFont("WindowTitleFont"), titleColor);
|
||||
titleLabel->SetText(UIControl::HALN_LEFT, "About");
|
||||
titleLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_TOP, 320, 125);
|
||||
AddControl(LBL_TITLE, titleLabel);
|
||||
|
||||
// Logo:
|
||||
UILabel *logoLabel = new UILabel();
|
||||
logoLabel->Set(0, 0, surfaceMgr->GetSurface("Logo"), NULL, labelTextColor);
|
||||
logoLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_TOP, 320, 153);
|
||||
AddControl(LBL_LOGO, logoLabel);
|
||||
|
||||
// Application name and version:
|
||||
UILabel *appVersionLabel = new UILabel();
|
||||
appVersionLabel->Set(0, 0, NULL, fontMgr->GetFont("AppVersionFont"), labelTextColor);
|
||||
appVersionLabel->SetText(UIControl::HALN_LEFT, "%s %s", APP_NAME.c_str(), APP_VERSION.c_str());
|
||||
appVersionLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 219);
|
||||
AddControl(LBL_APP, appVersionLabel);
|
||||
|
||||
// Credits:
|
||||
UILabel *creditsLabel = new UILabel();
|
||||
creditsLabel->Set(0, 0, NULL, fontMgr->GetFont("CreditsFont"), labelTextColor);
|
||||
creditsLabel->SetText( UIControl::HALN_CENTER,
|
||||
"Developed by Chai Braudo\n"
|
||||
"Music by Ryan Reilly\n"
|
||||
"Sound design by Dale North");
|
||||
creditsLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 289);
|
||||
AddControl(LBL_CREDITS, creditsLabel);
|
||||
|
||||
// License:
|
||||
UILabel *licenseLabel = new UILabel();
|
||||
licenseLabel->Set(0, 0, NULL, fontMgr->GetFont("LicenseFont"), labelTextColor);
|
||||
licenseLabel->SetText( UIControl::HALN_LEFT,
|
||||
"This program is free, open source software\n"
|
||||
"released under the GNU General Public License.");
|
||||
licenseLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 318);
|
||||
AddControl(LBL_LICENSE, licenseLabel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
55
project/jni/application/jooleem_0.1.4/src/UI/aboutwindow.h
Normal file
55
project/jni/application/jooleem_0.1.4/src/UI/aboutwindow.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _ABOUTWINDOW_H_
|
||||
#define _ABOUTWINDOW_H_
|
||||
|
||||
// The about window.
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class AboutWindow: public UIWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Controls {
|
||||
// Buttons:
|
||||
BTN_LINK, // Website link
|
||||
BTN_CLOSE, // Close
|
||||
|
||||
// Labels:
|
||||
LBL_TITLE, // Window title
|
||||
LBL_LOGO, // Logo
|
||||
LBL_APP, // Application name and version
|
||||
LBL_CREDITS, // Game credits
|
||||
LBL_LICENSE, // License info
|
||||
};
|
||||
|
||||
// Constructor / destructor:
|
||||
AboutWindow(SDL_Surface *background);
|
||||
~AboutWindow();
|
||||
|
||||
private:
|
||||
void InitControls(); // Initializes the window's controls, and adds them to the control collection
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
152
project/jni/application/jooleem_0.1.4/src/UI/gameoverwindow.cpp
Normal file
152
project/jni/application/jooleem_0.1.4/src/UI/gameoverwindow.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/gameoverwindow.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
#include "../common/surfacemanager.h"
|
||||
#include "../common/fontmanager.h"
|
||||
#include "../common/soundmanager.h"
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
#include "../UI/uitextbox.h"
|
||||
|
||||
#include "../game/highscores.h"
|
||||
|
||||
|
||||
GameOverWindow::GameOverWindow(SDL_Surface *background):
|
||||
UIWindow(background)
|
||||
{
|
||||
InitControls();
|
||||
}
|
||||
|
||||
GameOverWindow::~GameOverWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Initializes the window's controls, and adds them to the
|
||||
// control collection
|
||||
void GameOverWindow::InitControls()
|
||||
{
|
||||
SurfaceManager *surfaceMgr = SurfaceManager::GetInstance();
|
||||
FontManager *fontMgr = FontManager::GetInstance();
|
||||
SoundManager *sndMgr = SoundManager::GetInstance();
|
||||
|
||||
{
|
||||
/////// Buttons ///////
|
||||
SDL_Color buttonTextColor = {0, 0, 0, 0};
|
||||
|
||||
// OK:
|
||||
UIButton *okButton = new UIButton();
|
||||
okButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
okButton->AddState(EVENT_CLOSE, fontMgr->GetFont("MediumButtonFont"), "OK", buttonTextColor);
|
||||
okButton->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 373);
|
||||
okButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_OK, okButton);
|
||||
|
||||
// Quit:
|
||||
UIButton *quitButton = new UIButton();
|
||||
quitButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
quitButton->AddState(event, fontMgr->GetFont("MediumButtonFont"), "Quit", buttonTextColor);
|
||||
quitButton->Align(UIControl::HALN_RIGHT, UIControl::VALN_BOTTOM, 435, 373);
|
||||
quitButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_QUIT, quitButton);
|
||||
|
||||
// Restart:
|
||||
UIButton *restartButton = new UIButton();
|
||||
restartButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
restartButton->AddState(EVENT_RESTART, fontMgr->GetFont("MediumButtonFont"), "Restart", buttonTextColor);
|
||||
restartButton->Align(UIControl::HALN_LEFT, UIControl::VALN_BOTTOM, 205, 373);
|
||||
restartButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_RESTART, restartButton);
|
||||
|
||||
/////// Labels ///////
|
||||
SDL_Color titleColor = {64, 64, 64, 0};
|
||||
SDL_Color labelTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Title:
|
||||
UILabel *titleLabel = new UILabel();
|
||||
titleLabel->Set(0, 0, NULL, fontMgr->GetFont("WindowTitleFont"), titleColor);
|
||||
titleLabel->SetText(UIControl::HALN_LEFT, "Game Over");
|
||||
titleLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_TOP, 320, 108);
|
||||
AddControl(LBL_TITLE, titleLabel);
|
||||
|
||||
// Congratulations message:
|
||||
UILabel *congratsLabel = new UILabel();
|
||||
congratsLabel->Set(0, 0, NULL, fontMgr->GetFont("GameOverCongratsFont"), labelTextColor);
|
||||
congratsLabel->SetText(UIControl::HALN_LEFT,
|
||||
"Congratulations, you got a\n"
|
||||
"high score!\n"
|
||||
"Please enter your name.");
|
||||
congratsLabel->Align(UIControl::HALN_LEFT, UIControl::VALN_TOP, 204, 133);
|
||||
AddControl(LBL_CONGRATS, congratsLabel);
|
||||
|
||||
// Final score:
|
||||
UILabel *scoreLabel = new UILabel();
|
||||
scoreLabel->Set(0, 0, NULL, fontMgr->GetFont("GameOverScoreFont"), labelTextColor);
|
||||
AddControl(LBL_SCORE, scoreLabel);
|
||||
|
||||
// Statistics description:
|
||||
UILabel *statsDescLabel = new UILabel();
|
||||
statsDescLabel->Set(0, 0, NULL, fontMgr->GetFont("GameOverStatsFont"), labelTextColor);
|
||||
statsDescLabel->SetText(UIControl::HALN_LEFT,
|
||||
"Level reached:\n"
|
||||
"Total game time:\n"
|
||||
"Marbles cleared:\n"
|
||||
"Rectangles cleared:\n"
|
||||
"Avg. rectangle size:\n"
|
||||
"Best move:\n"
|
||||
"Perfect moves:");
|
||||
statsDescLabel->Align(UIControl::HALN_LEFT, UIControl::VALN_BOTTOM,
|
||||
203, 337);
|
||||
AddControl(LBL_STATS_DESC, statsDescLabel);
|
||||
|
||||
// Statistics values:
|
||||
UILabel *statsValLabel = new UILabel();
|
||||
statsValLabel->Set(0, 0, NULL, fontMgr->GetFont("GameOverStatsFont"), labelTextColor);
|
||||
AddControl(LBL_STATS_VAL, statsValLabel);
|
||||
|
||||
// Text box:
|
||||
UITextBox *textBox = new UITextBox();
|
||||
textBox->Set(205, 188,
|
||||
16, 6,
|
||||
surfaceMgr->GetSurface("TextBoxBackground"),
|
||||
surfaceMgr->GetSurface("TextBoxCursor"),
|
||||
fontMgr->GetFont("TextBoxFont"),
|
||||
titleColor);
|
||||
AddControl(TXT_NAME, textBox);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _GAMEOVERWINDOW_H_
|
||||
#define _GAMEOVERWINDOW_H_
|
||||
|
||||
// This window is displayed when the game is over.
|
||||
// It shows the final score and various game statitics.
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class GameOverWindow: public UIWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Controls {
|
||||
// Buttons:
|
||||
BTN_OK, // OK
|
||||
BTN_QUIT, // Quit
|
||||
BTN_RESTART, // Restart
|
||||
|
||||
// Labels:
|
||||
LBL_TITLE, // Window title
|
||||
LBL_CONGRATS, // Congratulations message
|
||||
LBL_SCORE, // Final score
|
||||
LBL_STATS_DESC, // Statistics description
|
||||
LBL_STATS_VAL, // Statistics values
|
||||
|
||||
// Text box:
|
||||
TXT_NAME, // Enter the player's name
|
||||
};
|
||||
|
||||
// Constructor / destructor:
|
||||
GameOverWindow(SDL_Surface *background);
|
||||
~GameOverWindow();
|
||||
|
||||
private:
|
||||
void InitControls(); // Initializes the window's controls, and adds them to the control collection
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/highscoreswindow.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
#include "../common/surfacemanager.h"
|
||||
#include "../common/fontmanager.h"
|
||||
#include "../common/soundmanager.h"
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
|
||||
#include "../game/highscores.h"
|
||||
|
||||
|
||||
HighScoresWindow::HighScoresWindow(SDL_Surface *background):
|
||||
UIWindow(background)
|
||||
{
|
||||
InitControls();
|
||||
}
|
||||
|
||||
HighScoresWindow::~HighScoresWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Initializes the window's controls, and adds them to the
|
||||
// control collection
|
||||
void HighScoresWindow::InitControls()
|
||||
{
|
||||
SurfaceManager *surfaceMgr = SurfaceManager::GetInstance();
|
||||
FontManager *fontMgr = FontManager::GetInstance();
|
||||
SoundManager *sndMgr = SoundManager::GetInstance();
|
||||
|
||||
{
|
||||
/////// Buttons ///////
|
||||
SDL_Color buttonTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Close:
|
||||
UIButton *closeButton = new UIButton();
|
||||
closeButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
closeButton->AddState(EVENT_CLOSE, fontMgr->GetFont("MediumButtonFont"), "Close", buttonTextColor);
|
||||
closeButton->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 375);
|
||||
closeButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_CLOSE, closeButton);
|
||||
|
||||
// Restart:
|
||||
UIButton *restartButton = new UIButton();
|
||||
restartButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
restartButton->AddState(EVENT_RESTART, fontMgr->GetFont("MediumButtonFont"), "Restart", buttonTextColor);
|
||||
restartButton->Align(UIControl::HALN_LEFT, UIControl::VALN_BOTTOM,
|
||||
m_x + 29, m_y + m_h - 34);
|
||||
restartButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_RESTART, restartButton);
|
||||
|
||||
// Quit:
|
||||
UIButton *quitButton = new UIButton();
|
||||
quitButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
quitButton->AddState(event, fontMgr->GetFont("MediumButtonFont"), "Quit", buttonTextColor);
|
||||
quitButton->Align(UIControl::HALN_RIGHT, UIControl::VALN_BOTTOM,
|
||||
m_x + m_w - 40 + 13, m_y + m_h - 34);
|
||||
quitButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_QUIT, quitButton);
|
||||
|
||||
|
||||
/////// Vectors ///////
|
||||
SDL_Color tableTextColor = {0, 0, 0, 0};
|
||||
|
||||
vector<UIControl *> indexVec; // Index
|
||||
vector<UIControl *> namesVec; // Names
|
||||
vector<UIControl *> scoresVec; // Scores
|
||||
|
||||
for (Uint16 i = 0 ; i < NUM_OF_HIGH_SCORES ; ++i)
|
||||
{
|
||||
// Index:
|
||||
UILabel *index = new UILabel();
|
||||
|
||||
index->Set(0, 0, NULL, fontMgr->GetFont("HighScoresFont"), tableTextColor);
|
||||
index->SetText(UIControl::HALN_LEFT, "%d", i + 1);
|
||||
index->Align(UIControl::HALN_LEFT, UIControl::VALN_TOP, 207, 136 + 20 * i);
|
||||
|
||||
indexVec.push_back(index);
|
||||
|
||||
|
||||
// Names:
|
||||
UILabel *name = new UILabel();
|
||||
|
||||
name->Set(0, 0, NULL, fontMgr->GetFont("HighScoresFont"), tableTextColor);
|
||||
name->SetText(UIControl::HALN_LEFT, "-");
|
||||
name->Align(UIControl::HALN_LEFT, UIControl::VALN_TOP, 233, 136 + 20 * i);
|
||||
|
||||
namesVec.push_back(name);
|
||||
|
||||
|
||||
// Scores:
|
||||
UILabel *score = new UILabel();
|
||||
|
||||
score->Set(0, 0, NULL, fontMgr->GetFont("HighScoresFont"), tableTextColor);
|
||||
score->SetText(UIControl::HALN_LEFT, "-");
|
||||
score->Align(UIControl::HALN_RIGHT, UIControl::VALN_TOP, 435, 136 + 20 * i);
|
||||
|
||||
scoresVec.push_back(score);
|
||||
}
|
||||
|
||||
AddControlVector(VEC_INDEX, indexVec);
|
||||
AddControlVector(VEC_NAMES, namesVec);
|
||||
AddControlVector(VEC_SCORES, scoresVec);
|
||||
|
||||
/////// Labels ///////
|
||||
SDL_Color titleColor = {64, 64, 64, 0};
|
||||
|
||||
// Title:
|
||||
UILabel *titleLabel = new UILabel();
|
||||
titleLabel->Set(0, 0, NULL, fontMgr->GetFont("WindowTitleFont"), titleColor);
|
||||
titleLabel->SetText(UIControl::HALN_LEFT, "High Scores");
|
||||
titleLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_TOP, 320, 106);
|
||||
AddControl(LBL_TITLE, titleLabel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _HIGHSCORESWINDOW_H_
|
||||
#define _HIGHSCORESWINDOW_H_
|
||||
|
||||
// The high scores window.
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class HighScoresWindow: public UIWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Controls {
|
||||
// Buttons:
|
||||
BTN_CLOSE, // Close
|
||||
BTN_RESTART, // Restart
|
||||
BTN_QUIT, // Quit
|
||||
|
||||
// Vectors (the names and scores are a vector of labels):
|
||||
VEC_INDEX, // Scores index (1st place, 2nd...)
|
||||
VEC_NAMES, // Player names
|
||||
VEC_SCORES, // Scores
|
||||
|
||||
// Labels:
|
||||
LBL_TITLE, // Window title
|
||||
};
|
||||
|
||||
// Constructor / destructor:
|
||||
HighScoresWindow(SDL_Surface *background);
|
||||
~HighScoresWindow();
|
||||
|
||||
private:
|
||||
void InitControls(); // Initializes the window's controls, and adds them to the control collection
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
172
project/jni/application/jooleem_0.1.4/src/UI/mainwindow.cpp
Normal file
172
project/jni/application/jooleem_0.1.4/src/UI/mainwindow.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/mainwindow.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
#include "../common/surfacemanager.h"
|
||||
#include "../common/fontmanager.h"
|
||||
#include "../common/soundmanager.h"
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
#include "../UI/uiprogress.h"
|
||||
|
||||
|
||||
MainWindow::MainWindow(SDL_Surface *background):
|
||||
UIWindow(background)
|
||||
{
|
||||
InitControls();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Initializes the window's controls, and adds them to the
|
||||
// control collection
|
||||
void MainWindow::InitControls()
|
||||
{
|
||||
SurfaceManager *surfaceMgr = SurfaceManager::GetInstance();
|
||||
FontManager *fontMgr = FontManager::GetInstance();
|
||||
SoundManager *sndMgr = SoundManager::GetInstance();
|
||||
|
||||
{
|
||||
/////// Buttons ///////
|
||||
SDL_Color buttonTextColor = {0, 0, 0, 0};
|
||||
SDL_Event event;
|
||||
|
||||
// Start / restart:
|
||||
UIButton *startButton = new UIButton();
|
||||
startButton->Set(20, 344, "ButtonClick",
|
||||
surfaceMgr->GetSurface("LargeButtonNormal"), surfaceMgr->GetSurface("LargeButtonDisabled"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonClicked"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonMask"));
|
||||
startButton->AddState(EVENT_START, fontMgr->GetFont("LargeButtonFont"), "Start", buttonTextColor);
|
||||
startButton->AddState(EVENT_RESTART, fontMgr->GetFont("LargeButtonFont"), "Restart", buttonTextColor);
|
||||
startButton->SetState(EVENT_START);
|
||||
startButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_START, startButton);
|
||||
|
||||
// Pause / resume:
|
||||
UIButton *pauseButton = new UIButton();
|
||||
pauseButton->Set(20, 276, "ButtonClick",
|
||||
surfaceMgr->GetSurface("LargeButtonNormal"), surfaceMgr->GetSurface("LargeButtonDisabled"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonClicked"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonMask"));
|
||||
pauseButton->AddState(EVENT_PAUSE, fontMgr->GetFont("LargeButtonFont"), "Pause", buttonTextColor);
|
||||
pauseButton->AddState(EVENT_RESUME, fontMgr->GetFont("LargeButtonFont"), "Resume", buttonTextColor);
|
||||
pauseButton->SetState(EVENT_PAUSE);
|
||||
pauseButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_PAUSE, pauseButton);
|
||||
|
||||
// Quit:
|
||||
UIButton *quitButton = new UIButton();
|
||||
quitButton->Set(20, 412, "ButtonClick",
|
||||
surfaceMgr->GetSurface("LargeButtonNormal"), surfaceMgr->GetSurface("LargeButtonDisabled"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonClicked"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonMask"));
|
||||
event.type = SDL_QUIT;
|
||||
quitButton->AddState(event, fontMgr->GetFont("LargeButtonFont"), "Quit", buttonTextColor);
|
||||
quitButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_QUIT, quitButton);
|
||||
|
||||
// Hint:
|
||||
UIButton *hintButton = new UIButton();
|
||||
hintButton->Set(20, 208, "ButtonClick",
|
||||
surfaceMgr->GetSurface("LargeButtonNormal"), surfaceMgr->GetSurface("LargeButtonDisabled"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonClicked"),
|
||||
surfaceMgr->GetSurface("LargeButtonHover"), surfaceMgr->GetSurface("LargeButtonMask"));
|
||||
hintButton->AddState(EVENT_HINT, fontMgr->GetFont("LargeButtonFont"), "Hint", buttonTextColor);
|
||||
hintButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_HINT, hintButton);
|
||||
|
||||
|
||||
// Mute / unmute:
|
||||
UIButton *muteButton = new UIButton();
|
||||
muteButton->Set(20, 140, "ButtonClick",
|
||||
surfaceMgr->GetSurface("SmallButtonNormal"), surfaceMgr->GetSurface("SmallButtonDisabled"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonClicked"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonMask"));
|
||||
muteButton->AddState(EVENT_MUTE, surfaceMgr->GetSurface("MuteButton"),
|
||||
fontMgr->GetFont("TooltipFont"), "Mute");
|
||||
muteButton->AddState(EVENT_UNMUTE, surfaceMgr->GetSurface("UnmuteButton"),
|
||||
fontMgr->GetFont("TooltipFont"), "Unmute");
|
||||
muteButton->SetState(EVENT_MUTE);
|
||||
muteButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_MUTE, muteButton);
|
||||
|
||||
// About:
|
||||
UIButton *aboutButton = new UIButton();
|
||||
aboutButton->Set(120, 140, "ButtonClick",
|
||||
surfaceMgr->GetSurface("SmallButtonNormal"), surfaceMgr->GetSurface("SmallButtonDisabled"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonClicked"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonMask"));
|
||||
aboutButton->AddState(EVENT_ABOUT, surfaceMgr->GetSurface("AboutButton"),
|
||||
fontMgr->GetFont("TooltipFont"), "About");
|
||||
aboutButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_ABOUT, aboutButton);
|
||||
|
||||
// High scores:
|
||||
UIButton *hiscoreButton = new UIButton();
|
||||
hiscoreButton->Set(70, 140, "ButtonClick",
|
||||
surfaceMgr->GetSurface("SmallButtonNormal"), surfaceMgr->GetSurface("SmallButtonDisabled"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonClicked"),
|
||||
surfaceMgr->GetSurface("SmallButtonHover"), surfaceMgr->GetSurface("SmallButtonMask"));
|
||||
hiscoreButton->AddState(EVENT_HIGH_SCORES, surfaceMgr->GetSurface("HighScoresButton"),
|
||||
fontMgr->GetFont("TooltipFont"), "High Scores");
|
||||
hiscoreButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_HISCORES, hiscoreButton);
|
||||
|
||||
|
||||
/////// Labels ///////
|
||||
SDL_Color scoreTextColor = {64, 64, 64, 0};
|
||||
|
||||
// Score:
|
||||
UILabel *scoreLabel = new UILabel();
|
||||
scoreLabel->Set(20, 70, surfaceMgr->GetSurface("ScoreLabel"), fontMgr->GetFont("ScoreFont"),
|
||||
scoreTextColor);
|
||||
AddControl(LBL_SCORE, scoreLabel);
|
||||
|
||||
// Level:
|
||||
UILabel *levelLabel = new UILabel();
|
||||
levelLabel->Set(20, 55, NULL, fontMgr->GetFont("LevelFont"),
|
||||
scoreTextColor);
|
||||
AddControl(LBL_LEVEL, levelLabel);
|
||||
|
||||
/*
|
||||
// Time bar:
|
||||
UILabel *timeBarLabel = new UILabel();
|
||||
timeBarLabel->Set(192, 454, surfaceMgr->GetSurface("TimeBar"), NULL, scoreTextColor);
|
||||
AddControl(LBL_TIMEBAR, timeBarLabel);
|
||||
*/
|
||||
|
||||
/////// Progress bar ///////
|
||||
UIProgressBar *timeBar = new UIProgressBar();
|
||||
timeBar->Set(192, 454, NULL, surfaceMgr->GetSurface("TimeBar"), surfaceMgr->GetSurface("TimeBarFlash"),
|
||||
surfaceMgr->GetSurface("TimeBarPaused"));
|
||||
AddControl(PRG_TIMEBAR, timeBar);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
65
project/jni/application/jooleem_0.1.4/src/UI/mainwindow.h
Normal file
65
project/jni/application/jooleem_0.1.4/src/UI/mainwindow.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _MAINWINDOW_H_
|
||||
#define _MAINWINDOW_H_
|
||||
|
||||
// The main window.
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class MainWindow: public UIWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Controls {
|
||||
// Buttons:
|
||||
BTN_START, // Start / restart
|
||||
BTN_PAUSE, // Pause / resume
|
||||
BTN_QUIT, // Quit
|
||||
BTN_HINT, // Hint
|
||||
BTN_MUTE, // Mute
|
||||
BTN_ABOUT, // About
|
||||
BTN_HISCORES, // High scores
|
||||
|
||||
// Labels:
|
||||
LBL_SCORE, // Game score
|
||||
LBL_LEVEL, // Game level
|
||||
//LBL_TIMEBAR, // The time bar
|
||||
|
||||
// Windows:
|
||||
WND_ABOUT, // About window
|
||||
WND_HISCORES, // High scores window
|
||||
|
||||
// Progress bar:
|
||||
PRG_TIMEBAR, // Time bar
|
||||
};
|
||||
|
||||
// Constructor / destructor:
|
||||
MainWindow(SDL_Surface *background);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
void InitControls(); // Initializes the window's controls, and adds them to the control collection
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
103
project/jni/application/jooleem_0.1.4/src/UI/quitwindow.cpp
Normal file
103
project/jni/application/jooleem_0.1.4/src/UI/quitwindow.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/quitwindow.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
#include "../common/surfacemanager.h"
|
||||
#include "../common/fontmanager.h"
|
||||
#include "../common/soundmanager.h"
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
|
||||
|
||||
QuitWindow::QuitWindow(SDL_Surface *background):
|
||||
UIWindow(background)
|
||||
{
|
||||
InitControls();
|
||||
}
|
||||
|
||||
QuitWindow::~QuitWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Initializes the window's controls, and adds them to the
|
||||
// control collection
|
||||
void QuitWindow::InitControls()
|
||||
{
|
||||
SurfaceManager *surfaceMgr = SurfaceManager::GetInstance();
|
||||
FontManager *fontMgr = FontManager::GetInstance();
|
||||
SoundManager *sndMgr = SoundManager::GetInstance();
|
||||
|
||||
{
|
||||
/////// Buttons ///////
|
||||
SDL_Color buttonTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Close:
|
||||
UIButton *quitButton = new UIButton();
|
||||
quitButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
SDL_Event event;
|
||||
event.type = SDL_QUIT;
|
||||
quitButton->AddState(event, fontMgr->GetFont("MediumButtonFont"), "Quit", buttonTextColor);
|
||||
quitButton->Align(UIControl::HALN_LEFT, UIControl::VALN_BOTTOM, 328, 290);
|
||||
quitButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_QUIT, quitButton);
|
||||
|
||||
// Play:
|
||||
UIButton *playButton = new UIButton();
|
||||
playButton->Set(0, 0, "ButtonClick",
|
||||
surfaceMgr->GetSurface("MediumButtonNormal"), surfaceMgr->GetSurface("MediumButtonDisabled"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonClicked"),
|
||||
surfaceMgr->GetSurface("MediumButtonHover"), surfaceMgr->GetSurface("MediumButtonMask"));
|
||||
playButton->AddState(EVENT_CLOSE, fontMgr->GetFont("MediumButtonFont"), "Play", buttonTextColor);
|
||||
playButton->Align(UIControl::HALN_RIGHT, UIControl::VALN_BOTTOM, 312, 290);
|
||||
playButton->SetMode(UIButton::MODE_NORMAL);
|
||||
AddControl(BTN_PLAY, playButton);
|
||||
|
||||
/////// Labels ///////
|
||||
SDL_Color titleColor = {64, 64, 64, 0};
|
||||
SDL_Color labelTextColor = {0, 0, 0, 0};
|
||||
|
||||
// Title:
|
||||
UILabel *titleLabel = new UILabel();
|
||||
titleLabel->Set(0, 0, NULL, fontMgr->GetFont("WindowTitleFont"), titleColor);
|
||||
titleLabel->SetText(UIControl::HALN_LEFT, "Quit");
|
||||
titleLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_TOP, 320, 191);
|
||||
AddControl(LBL_TITLE, titleLabel);
|
||||
|
||||
// Dialog text:
|
||||
UILabel *textLabel = new UILabel();
|
||||
textLabel->Set(0, 0, NULL, fontMgr->GetFont("DialogTextFont"), labelTextColor);
|
||||
textLabel->SetText( UIControl::HALN_LEFT,
|
||||
"Are you sure you want to\n"
|
||||
"quit Jooleem?");
|
||||
textLabel->Align(UIControl::HALN_CENTER, UIControl::VALN_BOTTOM, 320, 252);
|
||||
AddControl(LBL_TEXT, textLabel);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
53
project/jni/application/jooleem_0.1.4/src/UI/quitwindow.h
Normal file
53
project/jni/application/jooleem_0.1.4/src/UI/quitwindow.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _QUITWINDOW_H_
|
||||
#define _QUITWINDOW_H_
|
||||
|
||||
// The quit dialog window.
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class QuitWindow: public UIWindow
|
||||
{
|
||||
public:
|
||||
|
||||
enum Controls {
|
||||
// Buttons:
|
||||
BTN_QUIT, // Close
|
||||
BTN_PLAY, // Play
|
||||
|
||||
// Labels:
|
||||
LBL_TITLE, // Window title
|
||||
LBL_TEXT, // Dialog text
|
||||
};
|
||||
|
||||
// Constructor / destructor:
|
||||
QuitWindow(SDL_Surface *background);
|
||||
~QuitWindow();
|
||||
|
||||
private:
|
||||
void InitControls(); // Initializes the window's controls, and adds them to the control collection
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
559
project/jni/application/jooleem_0.1.4/src/UI/uibutton.cpp
Normal file
559
project/jni/application/jooleem_0.1.4/src/UI/uibutton.cpp
Normal file
@@ -0,0 +1,559 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
#include "../common/soundmanager.h"
|
||||
#include "SDL_image.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// Constructor - initialize the data members:
|
||||
UIButton::UIButton()
|
||||
{
|
||||
m_maskW = m_maskH = 0;
|
||||
m_clickSoundID = "";
|
||||
for (int i = 0 ; i < MODE_MAX ; ++i)
|
||||
m_surfaces[i] = NULL;
|
||||
m_currentMode = MODE_DISABLED;
|
||||
m_enabled = true;
|
||||
m_visible = true;
|
||||
m_mask = NULL;
|
||||
m_showTooltip = false;
|
||||
m_isFlashing = false;
|
||||
|
||||
// Populate the tooltip callback timer parameter struct:
|
||||
m_tooltipParam.currentMode = &m_currentMode;
|
||||
m_tooltipParam.showTooltip = &m_showTooltip;
|
||||
}
|
||||
|
||||
|
||||
// Destructor - Free the tooltip surfaces memory for all the states:
|
||||
UIButton::~UIButton()
|
||||
{
|
||||
SDL_RemoveTimer(m_timerID);
|
||||
|
||||
map<int, State>::iterator itr;
|
||||
for (itr = m_states.begin() ; itr != m_states.end() ; itr++)
|
||||
{
|
||||
if ((itr->second).toolTipSurface != NULL)
|
||||
SDL_FreeSurface((itr->second).toolTipSurface);
|
||||
}
|
||||
|
||||
delete []m_mask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Set the button's location, click sounds, surfaces and mask:
|
||||
void UIButton::Set(Uint16 x, Uint16 y, string clickSoundID, SDL_Surface* normal,
|
||||
SDL_Surface* disabled, SDL_Surface* hover, SDL_Surface* clicked,
|
||||
SDL_Surface* flash, SDL_Surface* mask)
|
||||
{
|
||||
SetLocation(x, y);
|
||||
|
||||
m_clickSoundID = clickSoundID;
|
||||
|
||||
m_surfaces[MODE_NORMAL] = normal;
|
||||
m_surfaces[MODE_DISABLED] = disabled;
|
||||
m_surfaces[MODE_HOVER] = hover;
|
||||
m_surfaces[MODE_CLICKED] = clicked;
|
||||
m_surfaces[MODE_FLASH] = flash;
|
||||
|
||||
if (mask != NULL)
|
||||
{
|
||||
m_w = (Sint16) mask->w;
|
||||
m_h = (Sint16) mask->h;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_w = (Sint16) normal->w;
|
||||
m_h = (Sint16) normal->h;
|
||||
}
|
||||
|
||||
MakeMask(mask);
|
||||
}
|
||||
|
||||
|
||||
// Handle a mouse down event:
|
||||
bool UIButton::MouseDown(Uint16 x, Uint16 y)
|
||||
{
|
||||
if (m_states.size() == 0 || m_visible == false || m_currentMode == MODE_DISABLED ||
|
||||
m_currentMode == MODE_CLICKED)
|
||||
return false;
|
||||
|
||||
if (IsInButton(x, y))
|
||||
{
|
||||
m_currentMode = MODE_CLICKED;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Handle a mouse down event:
|
||||
bool UIButton::MouseUp(Uint16 x, Uint16 y)
|
||||
{
|
||||
if (m_states.size() == 0 || m_visible == false || m_currentMode == MODE_DISABLED
|
||||
|| m_currentMode != MODE_CLICKED)
|
||||
return false;
|
||||
|
||||
if (IsInButton(x, y))
|
||||
return Click();
|
||||
else
|
||||
{
|
||||
m_currentMode = MODE_NORMAL;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Are the coordinates inside the button (use mask)?
|
||||
bool UIButton::IsInButton(Uint16 x, Uint16 y)
|
||||
{
|
||||
Sint32 X = x - m_x;
|
||||
Sint32 Y = y - m_y;
|
||||
|
||||
// If no mask is defined, do a simple boundry check:
|
||||
if (m_mask == NULL)
|
||||
return (X > 0 && Y > 0 && X <= m_surfaces[m_currentMode]->w && Y <= m_surfaces[m_currentMode]->h);
|
||||
|
||||
// Otherwise, check the mask:
|
||||
if (X < 0 || Y < 0 || X >= m_maskW || Y >= m_maskH)
|
||||
return false;
|
||||
|
||||
return ((m_mask[Y * m_maskW + X] == 0)? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Are the coordinates inside the button?
|
||||
bool UIButton::IsInRect(Uint16 x, Uint16 y)
|
||||
{
|
||||
return (m_x <= x && m_x + m_w >= x && m_y <= y && m_w + m_h >= y);
|
||||
}
|
||||
|
||||
|
||||
// An unconditional click:
|
||||
bool UIButton::Click()
|
||||
{
|
||||
if (m_states.size() == 0 || m_visible == false || m_currentMode == MODE_DISABLED)
|
||||
return false;
|
||||
|
||||
// Play the sound:
|
||||
if (m_clickSoundID != "")
|
||||
SoundManager::GetInstance()->PlaySound(m_clickSoundID);
|
||||
|
||||
// Push the event into the even queue:
|
||||
SDL_PushEvent(&m_currentState.event);
|
||||
|
||||
// Switch to clicked mode:
|
||||
m_currentMode = MODE_NORMAL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Clicks the button if the coords are valid:
|
||||
bool UIButton::Click(Uint16 x, Uint16 y)
|
||||
{
|
||||
if (IsInButton(x, y))
|
||||
return Click();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Switch to hover mode.
|
||||
bool UIButton::Hover()
|
||||
{
|
||||
m_currentMode = MODE_HOVER;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Switch to hover mode, if the cursor is over the button.
|
||||
bool UIButton::Hover(Uint16 x, Uint16 y)
|
||||
{
|
||||
if (m_states.size() == 0 || m_visible == false || m_currentMode == MODE_DISABLED
|
||||
|| m_currentMode == MODE_CLICKED || m_currentMode == MODE_FLASH)
|
||||
return false;
|
||||
|
||||
if (IsInButton(x, y))
|
||||
{
|
||||
if (m_currentMode != MODE_HOVER) // We just started hovering
|
||||
{
|
||||
m_currentMode = MODE_HOVER;
|
||||
|
||||
// Set the tooltip callback timer:
|
||||
m_timerID = SDL_AddTimer(TOOLTIP_DELAY, TriggerTooltip, &m_tooltipParam);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (m_currentMode == MODE_HOVER) // Restore to normal when no longer over button
|
||||
{
|
||||
m_currentMode = MODE_NORMAL;
|
||||
m_showTooltip = false;
|
||||
SDL_RemoveTimer(m_timerID);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Switch to disabled mode.
|
||||
// Clicks on the button will be ignored.
|
||||
void UIButton::Disable()
|
||||
{
|
||||
m_enabled = false;
|
||||
m_currentMode = MODE_DISABLED;
|
||||
m_showTooltip = false;
|
||||
}
|
||||
|
||||
|
||||
// Sets the button's enabled / disabled state.
|
||||
// Overrides the base class' method, to make it is compatible
|
||||
// with the button states.
|
||||
void UIButton::SetEnabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
m_showTooltip = false;
|
||||
|
||||
if (enabled)
|
||||
m_currentMode = MODE_NORMAL;
|
||||
else
|
||||
m_currentMode = MODE_DISABLED;
|
||||
}
|
||||
|
||||
|
||||
// Switch to flash mode.
|
||||
// Set the button to flash every a_iInterval ms.
|
||||
void UIButton::Flash(Uint32 interval)
|
||||
{
|
||||
m_flashStart = SDL_GetTicks();
|
||||
m_flashInterval = interval;
|
||||
m_isFlashing = true;
|
||||
m_currentMode = MODE_FLASH;
|
||||
}
|
||||
|
||||
|
||||
// Switch to normal (enabled) mode.
|
||||
void UIButton::Normal()
|
||||
{
|
||||
m_currentMode = MODE_NORMAL;
|
||||
m_showTooltip = false;
|
||||
}
|
||||
|
||||
|
||||
// Adds a state - User event / Text:
|
||||
void UIButton::AddState(int eventCode, Font *font, string text, SDL_Color color,
|
||||
Font *tooltipFont, string tooltipText)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = eventCode;
|
||||
|
||||
AddState(event, font, text, color, tooltipFont, tooltipText);
|
||||
}
|
||||
|
||||
|
||||
// Adds a state - SDL event / Text.
|
||||
void UIButton::AddState(SDL_Event event, Font *font, string text, SDL_Color color,
|
||||
Font *tooltipFont, string tooltipText)
|
||||
{
|
||||
State state;
|
||||
|
||||
// Render the text surface:
|
||||
if (font != NULL && text != "")
|
||||
state.textSurface = font->RenderPlain(Font::ALN_LEFT, color, text);
|
||||
|
||||
// Create the tooltip:
|
||||
if (tooltipFont != NULL && tooltipText != "")
|
||||
state.toolTipSurface = CreateTooltip(tooltipFont, tooltipText);
|
||||
else
|
||||
state.toolTipSurface = NULL;
|
||||
|
||||
// Set the event:
|
||||
state.event = event;
|
||||
|
||||
// Add the state to the map. The name is the event type. For user events,
|
||||
// the name is the event code.
|
||||
if (event.type == SDL_USEREVENT)
|
||||
m_states.insert(pair<int, State>(event.user.code, state));
|
||||
else
|
||||
m_states.insert(pair<int, State>(event.type, state));
|
||||
|
||||
m_currentState = state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Adds a state - User event / Image:
|
||||
void UIButton::AddState(int eventCode, SDL_Surface *surface, Font *tooltipFont, string tooltipText)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = eventCode;
|
||||
|
||||
AddState(event, surface, tooltipFont, tooltipText);
|
||||
}
|
||||
|
||||
|
||||
// Adds a state - SDL event / Image:
|
||||
void UIButton::AddState(SDL_Event event, SDL_Surface *surface, Font *tooltipFont, string tooltipText)
|
||||
{
|
||||
State state;
|
||||
|
||||
state.textSurface = surface;
|
||||
|
||||
// Set the event:
|
||||
state.event = event;
|
||||
|
||||
// Create the tooltip:
|
||||
if (tooltipFont != NULL && tooltipText != "")
|
||||
state.toolTipSurface = CreateTooltip(tooltipFont, tooltipText);
|
||||
else
|
||||
state.toolTipSurface = NULL;
|
||||
|
||||
// Add the state to the map. The name is the event type. For user events,
|
||||
// the name is the event code.
|
||||
if (event.type == SDL_USEREVENT)
|
||||
m_states.insert(pair<int, State>(event.user.code, state));
|
||||
else
|
||||
m_states.insert(pair<int, State>(event.type, state));
|
||||
|
||||
m_currentState = state;
|
||||
}
|
||||
|
||||
|
||||
// Sets the button's state.
|
||||
void UIButton::SetState(int state)
|
||||
{
|
||||
map<int, State>::iterator itr = m_states.find(state);
|
||||
if (itr != m_states.end())
|
||||
m_currentState = itr->second;
|
||||
}
|
||||
|
||||
|
||||
// Sets the button's mode:
|
||||
void UIButton::SetMode(ButtonMode mode)
|
||||
{
|
||||
m_currentMode = mode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Updates the button.
|
||||
// Needed for flashing buttons.
|
||||
// Return true if a redraw is needed.
|
||||
bool UIButton::Update()
|
||||
{
|
||||
if (m_enabled != true || m_currentMode != MODE_FLASH)
|
||||
return false;
|
||||
|
||||
bool redraw = false;
|
||||
|
||||
if (((SDL_GetTicks() - m_flashStart) / m_flashInterval) % 2) // Flashing
|
||||
{
|
||||
if (!m_isFlashing) // ... but was not flashing before
|
||||
redraw = true;
|
||||
m_isFlashing = true;
|
||||
}
|
||||
else // Not flashing
|
||||
{
|
||||
if (m_isFlashing) // ... but was flashing before
|
||||
redraw = true;
|
||||
|
||||
m_isFlashing = false;
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
// Draws the button:
|
||||
void UIButton::Draw(SDL_Surface *screen)
|
||||
{
|
||||
if (!m_visible)
|
||||
return;
|
||||
|
||||
// Draw button:
|
||||
SDL_Rect rect = {m_x, m_y, 0, 0};
|
||||
|
||||
// Draw the basic surface:
|
||||
if (m_currentMode == MODE_FLASH && m_isFlashing)
|
||||
SDL_BlitSurface(m_surfaces[MODE_NORMAL], NULL, screen, &rect);
|
||||
else // Not flashing or between flashes
|
||||
SDL_BlitSurface(m_surfaces[m_currentMode], NULL, screen, &rect);
|
||||
|
||||
// Draw text, centered horizontally and vertically:
|
||||
rect.x = (Sint16) (m_x + (m_surfaces[m_currentMode]->w - m_currentState.textSurface->w) / 2);
|
||||
rect.y = (Sint16) (m_y + (m_surfaces[m_currentMode]->h - m_currentState.textSurface->h) / 2);
|
||||
SDL_BlitSurface(m_currentState.textSurface, NULL, screen, &rect);
|
||||
|
||||
// Draws the tooltip:
|
||||
if (m_showTooltip && m_currentState.toolTipSurface != NULL && m_currentMode != MODE_DISABLED)
|
||||
{
|
||||
rect.x = (Sint16)(m_x + m_w / 2 - m_currentState.toolTipSurface->w / 2);
|
||||
rect.y = (Sint16)(m_y + m_h);
|
||||
|
||||
SDL_BlitSurface(m_currentState.toolTipSurface, NULL, screen, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Creates a mask from a surface.
|
||||
// http://sdldoc.csn.ul.ie/guidevideo.php#AEN112
|
||||
void UIButton::MakeMask(SDL_Surface* maskSurface)
|
||||
{
|
||||
if (maskSurface == NULL)
|
||||
return;
|
||||
|
||||
m_maskW = (Uint16) maskSurface->w;
|
||||
m_maskH = (Uint16) maskSurface->h;
|
||||
|
||||
{
|
||||
m_mask = new Uint8[m_maskW * m_maskH];
|
||||
}
|
||||
|
||||
// Lock the surface:
|
||||
if(SDL_MUSTLOCK(maskSurface)) {
|
||||
if(SDL_LockSurface(maskSurface) < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy each pixel from the alpha or red channels to the mask:
|
||||
Uint32 pixel; // Value of the current pixel
|
||||
Uint8 *pPixel; // Pointer to the current pixel
|
||||
Uint8 g,b;
|
||||
for (Uint16 i = 0 ; i < m_maskW ; ++i)
|
||||
for (Uint16 j = 0 ; j < m_maskH ; ++j)
|
||||
{
|
||||
// 32 bit images - the mask is based on the alpha channel:
|
||||
if (maskSurface->format->BytesPerPixel == 4)
|
||||
{
|
||||
pPixel = (Uint8 *) maskSurface->pixels + j * maskSurface->pitch +
|
||||
i * maskSurface->format->BytesPerPixel;
|
||||
|
||||
SDL_PixelFormat *fmt = maskSurface->format;
|
||||
pixel = *(Uint32 *)pPixel & fmt->Amask; // Isolate alpha component
|
||||
pixel = pixel >> fmt->Ashift; // Shift it down to 8-bit
|
||||
pixel = pixel << fmt->Aloss; // Expand to a full 8-bit number
|
||||
m_mask[j * m_maskW + i] = (Uint8) pixel;
|
||||
}
|
||||
|
||||
// 24 bit images - the mask is based on the red channel:
|
||||
else if (maskSurface->format->BytesPerPixel == 3)
|
||||
{
|
||||
pPixel = (Uint8 *) maskSurface->pixels + j * maskSurface->pitch +
|
||||
i * maskSurface->format->BytesPerPixel;
|
||||
|
||||
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
pixel = pPixel[0] << 16 | pPixel[1] << 8 | pPixel[2];
|
||||
else
|
||||
pixel = pPixel[0] | pPixel[1] << 8 | pPixel[2] << 16;
|
||||
|
||||
SDL_GetRGB(pixel, maskSurface->format, &m_mask[j * m_maskW + i],
|
||||
&g, &b);
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock:
|
||||
if(SDL_MUSTLOCK(maskSurface))
|
||||
SDL_UnlockSurface(maskSurface);
|
||||
}
|
||||
|
||||
|
||||
// Creates a tooltip.
|
||||
SDL_Surface* UIButton::CreateTooltip(Font *tooltipFont, string tooltipText)
|
||||
{
|
||||
// Render the text on a colored background:
|
||||
SDL_Surface *shadedText =
|
||||
tooltipFont->RenderShaded(Font::ALN_LEFT, TOOLTIP_FG, TOOLTIP_BG, tooltipText);
|
||||
|
||||
// Get a pointer to the screen, so we can create surfaces with
|
||||
// the same pixel format:
|
||||
SDL_Surface* screen = SDL_GetVideoSurface();
|
||||
|
||||
// Create a surface the will form the tooltip's background:
|
||||
SDL_Surface *background = SDL_CreateRGBSurface(screen->flags,
|
||||
shadedText->w + 8, shadedText->h + 4, // Add some spacing
|
||||
screen->format->BitsPerPixel,
|
||||
screen->format->Rmask,
|
||||
screen->format->Gmask,
|
||||
screen->format->Bmask, 0);
|
||||
|
||||
TRAP(background == NULL, "UIButton::MakeTooltip - SDL_CreateRGBSurface failed");
|
||||
|
||||
// Fill the surface with the background color:
|
||||
SDL_FillRect(background, NULL, SDL_MapRGB(background->format, TOOLTIP_BG.r, TOOLTIP_BG.g, TOOLTIP_BG.b));
|
||||
|
||||
// Create a surface that will form the tooltip's border.
|
||||
SDL_Surface *border = SDL_CreateRGBSurface(screen->flags,
|
||||
background->w + 2, background->h + 2, // Add a 1px border
|
||||
screen->format->BitsPerPixel,
|
||||
screen->format->Rmask,
|
||||
screen->format->Gmask,
|
||||
screen->format->Bmask, 0);
|
||||
|
||||
TRAP(border == NULL, "UIButton::MakeTooltip - SDL_CreateRGBSurface failed");
|
||||
|
||||
// Fill the surface with the foreground color:
|
||||
SDL_FillRect(border, NULL, SDL_MapRGB(border->format, TOOLTIP_FG.r, TOOLTIP_FG.g, TOOLTIP_FG.b));
|
||||
|
||||
// Blit the text on to the background surface:
|
||||
SDL_Rect rect = {4, 2, 0, 0};
|
||||
SDL_BlitSurface(shadedText, NULL, background, &rect);
|
||||
|
||||
// Blit the background + text on the border surface:
|
||||
rect.x = rect.y = 1;
|
||||
SDL_BlitSurface(background, NULL, border, &rect);
|
||||
|
||||
// The text surface is no longer needed:
|
||||
SDL_FreeSurface(shadedText);
|
||||
SDL_FreeSurface(background);
|
||||
|
||||
return border;
|
||||
}
|
||||
|
||||
|
||||
// Trigger tooltip timer callback function.
|
||||
// If by the time this is called the button is still in hover mode,
|
||||
// then the tooltip should be shown.
|
||||
Uint32 UIButton::TriggerTooltip(Uint32 interval, void* param)
|
||||
{
|
||||
TooltipParam *tooltipParam = (TooltipParam *) param;
|
||||
|
||||
if (tooltipParam == NULL)
|
||||
return 0;
|
||||
|
||||
if (*(tooltipParam->currentMode) == UIButton::MODE_HOVER)
|
||||
*(tooltipParam->showTooltip) = true;
|
||||
|
||||
// Force a redraw:
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
166
project/jni/application/jooleem_0.1.4/src/UI/uibutton.h
Normal file
166
project/jni/application/jooleem_0.1.4/src/UI/uibutton.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UIBUTTON_H_
|
||||
#define _UIBUTTON_H_
|
||||
|
||||
// User interface button class.
|
||||
// A button has several modes (normal, hover etc.), and one
|
||||
// or more user defined states.
|
||||
// Once a button is clicked, it pushes an event defined by
|
||||
// its current state.
|
||||
// The class also supports tooltips.
|
||||
|
||||
#include "../UI/uicontrol.h"
|
||||
#include "../common/font.h"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Tooltip related:
|
||||
static const SDL_Color TOOLTIP_FG = {0, 0, 0, 0}; // Foreground color (text and border)
|
||||
static const SDL_Color TOOLTIP_BG = {250, 250, 150, 0}; // Background color
|
||||
static const Uint32 TOOLTIP_DELAY = 750; // Time, in ms, until tooltip is shown
|
||||
|
||||
class UIButton: public UIControl
|
||||
{
|
||||
public:
|
||||
// Button modes:
|
||||
enum ButtonMode { MODE_NORMAL,
|
||||
MODE_DISABLED,
|
||||
MODE_HOVER,
|
||||
MODE_CLICKED,
|
||||
MODE_FLASH,
|
||||
MODE_MASK,
|
||||
MODE_MAX};
|
||||
|
||||
// The button's state:
|
||||
typedef struct
|
||||
{
|
||||
SDL_Event event; // The event to raise once clicked
|
||||
SDL_Surface *textSurface; // Button text's surface
|
||||
SDL_Surface *toolTipSurface; // Button's tooltip surface
|
||||
} State;
|
||||
|
||||
private:
|
||||
string m_clickSoundID; // Click sound ID
|
||||
|
||||
// Modes:
|
||||
SDL_Surface *m_surfaces[MODE_MAX]; // A surface for every one of the modes
|
||||
ButtonMode m_currentMode; // Current mode
|
||||
ButtonMode m_prevMode; // Previous mode (to return to from hover)
|
||||
|
||||
// Flash:
|
||||
bool m_isFlashing; // Are we currently flashing?
|
||||
Uint32 m_flashStart; // Time flashing has started
|
||||
Uint32 m_flashInterval; // Flash interval
|
||||
|
||||
// States:
|
||||
map<int, State> m_states; // Map states to their names
|
||||
State m_currentState; // Current state
|
||||
|
||||
// Mask:
|
||||
Uint8* m_mask; // Masks the button's clickable area
|
||||
Uint16 m_maskW, m_maskH; // Mask's dimensions
|
||||
|
||||
// Tooltip:
|
||||
bool m_showTooltip; // Should the tooltip be shown?
|
||||
SDL_TimerID m_timerID; // Tooltip timer ID
|
||||
typedef struct // Passed to the timer callback fucntion
|
||||
{
|
||||
ButtonMode *currentMode; // Current button mode
|
||||
bool *showTooltip; // Should the tooltip be shown?
|
||||
} TooltipParam;
|
||||
TooltipParam m_tooltipParam;
|
||||
|
||||
public:
|
||||
UIButton();
|
||||
~UIButton();
|
||||
|
||||
// Set all of the button's properties:
|
||||
void Set(Uint16 x, Uint16 y, string clickSoundID, SDL_Surface* normal,
|
||||
SDL_Surface* disabled = NULL, SDL_Surface* hover = NULL,
|
||||
SDL_Surface* clicked = NULL, SDL_Surface* flash = NULL,
|
||||
SDL_Surface* mask = NULL);
|
||||
|
||||
bool IsInButton(Uint16 x, Uint16 y); // Are the coordinates inside the button (use mask)?
|
||||
bool IsInRect(Uint16 x, Uint16 y); // Are the coordinates inside the button?
|
||||
|
||||
// Handle mouse down and up events:
|
||||
bool MouseDown(Uint16 x, Uint16 y);
|
||||
bool MouseUp(Uint16 x, Uint16 y);
|
||||
|
||||
// Click the button:
|
||||
bool Click(); // Click the button
|
||||
bool Click(Uint16 x, Uint16 y); // Click the button if the coords are valid
|
||||
|
||||
// Hover over the button:
|
||||
bool Hover();
|
||||
bool Hover(Uint16 x, Uint16 y);
|
||||
|
||||
// Disable the button:
|
||||
void Disable();
|
||||
void SetEnabled(bool enabled); // Override the base class' method
|
||||
|
||||
// Set the button to normal (enabled) mode:
|
||||
void Normal();
|
||||
|
||||
// Set the button to flash mode:
|
||||
void Flash(Uint32 interval);
|
||||
|
||||
// Add a state to the button:
|
||||
void AddState(int eventCode, Font *font, string text, SDL_Color color,
|
||||
Font *tooltipFont = NULL, string tooltipText = "");
|
||||
void AddState(SDL_Event event, Font *font, string text, SDL_Color color,
|
||||
Font *tooltipFont = NULL, string tooltipText = "");
|
||||
void AddState(int eventCode, SDL_Surface *surface, Font *tooltipFont = NULL, string tooltipText = "");
|
||||
void AddState(SDL_Event event, SDL_Surface *surface, Font *tooltipFont = NULL, string tooltipText = "");
|
||||
|
||||
// Set the button's state:
|
||||
void SetState(int state);
|
||||
|
||||
// Set/Get the button's mode:
|
||||
void SetMode(ButtonMode mode);
|
||||
ButtonMode GetMode(){return m_currentMode;}
|
||||
|
||||
// Update the button:
|
||||
bool Update();
|
||||
|
||||
// Draw the button:
|
||||
void Draw(SDL_Surface *screen);
|
||||
|
||||
// Key down, unimplemented:
|
||||
virtual bool KeyDown(SDL_KeyboardEvent *event){return false;}
|
||||
|
||||
// Button flash interval:
|
||||
static const int FLASH_INTERVAL = 500;
|
||||
|
||||
protected:
|
||||
void MakeMask(SDL_Surface* maskSurface); // Creates a mask from a surface
|
||||
SDL_Surface* CreateTooltip(Font *tooltipFont, string tooltipText); // Creates a tooltip
|
||||
static Uint32 TriggerTooltip(Uint32 interval, void* param); // Trigger tooltip timer callback func.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
59
project/jni/application/jooleem_0.1.4/src/UI/uicontrol.cpp
Normal file
59
project/jni/application/jooleem_0.1.4/src/UI/uicontrol.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "uicontrol.h"
|
||||
|
||||
void UIControl::Align(HAlign hAlign, VAlign vAlign, Uint16 x, Uint16 y)
|
||||
{
|
||||
switch (hAlign)
|
||||
{
|
||||
case HALN_LEFT:
|
||||
m_x = x;
|
||||
break;
|
||||
|
||||
case HALN_CENTER:
|
||||
if (x >= m_w / 2)
|
||||
m_x = x - m_w / 2;
|
||||
break;
|
||||
|
||||
case HALN_RIGHT:
|
||||
if (x >= m_w)
|
||||
m_x = x - m_w;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (vAlign)
|
||||
{
|
||||
case VALN_TOP:
|
||||
m_y = y;
|
||||
break;
|
||||
|
||||
case VALN_MIDDLE:
|
||||
if (y >= m_h / 2)
|
||||
m_y = y - m_h / 2;
|
||||
break;
|
||||
|
||||
case VALN_BOTTOM:
|
||||
if (y >= m_h)
|
||||
m_y = y - m_h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
79
project/jni/application/jooleem_0.1.4/src/UI/uicontrol.h
Normal file
79
project/jni/application/jooleem_0.1.4/src/UI/uicontrol.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UICONTROL_H_
|
||||
#define _UICONTROL_H_
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
// Abstract base class for user interface controls (buttons, labels, text boxes)
|
||||
class UIControl
|
||||
{
|
||||
protected:
|
||||
Uint16 m_x, m_y; // Location
|
||||
Uint16 m_w, m_h; // Dimensions
|
||||
bool m_visible; // Visibility flag
|
||||
bool m_enabled; // Enabled flag
|
||||
|
||||
public:
|
||||
UIControl():m_x(0), m_y(0), m_w(0), m_h(0), m_visible(true), m_enabled(true){};
|
||||
virtual ~UIControl(){};
|
||||
|
||||
// Set the control's location:
|
||||
void SetLocation(Uint16 x, Uint16 y){m_x = x; m_y = y;}
|
||||
|
||||
// Align the control, vertically and horizontally:
|
||||
enum HAlign { HALN_LEFT, HALN_CENTER, HALN_RIGHT};
|
||||
enum VAlign { VALN_TOP, VALN_MIDDLE, VALN_BOTTOM};
|
||||
void Align(HAlign hAlign, VAlign vAlign, Uint16 x, Uint16 y);
|
||||
|
||||
// Visibility:
|
||||
void SetVisible(bool visible){m_visible = visible;}
|
||||
bool GetVisible(){return m_visible;}
|
||||
|
||||
// Enable / disable:
|
||||
virtual void SetEnabled(bool enabled){m_enabled = enabled;}
|
||||
bool GetEnabled(){return m_enabled;}
|
||||
|
||||
// Accessors:
|
||||
Uint16 GetX(){return m_x;}
|
||||
Uint16 GetY(){return m_y;}
|
||||
Uint16 GetWidth(){return m_w;}
|
||||
Uint16 GetHeight(){return m_h;}
|
||||
|
||||
// Mouse events:
|
||||
virtual bool MouseDown(Uint16 x, Uint16 y) = 0; // Process mouse up events
|
||||
virtual bool MouseUp(Uint16 x, Uint16 y) = 0; // Process mouse up events
|
||||
virtual bool Click(Uint16 x, Uint16 y) = 0; // Process user clicks
|
||||
virtual bool Hover(Uint16 x, Uint16 y) = 0; // Process user mouse hover
|
||||
|
||||
// Kyboard events:
|
||||
virtual bool KeyDown(SDL_KeyboardEvent *event) = 0;
|
||||
|
||||
// Update:
|
||||
virtual bool Update() = 0;
|
||||
|
||||
// Draw the control:
|
||||
virtual void Draw(SDL_Surface *screen) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
205
project/jni/application/jooleem_0.1.4/src/UI/uilabel.cpp
Normal file
205
project/jni/application/jooleem_0.1.4/src/UI/uilabel.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "uilabel.h"
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
// Constructor
|
||||
UILabel::UILabel():
|
||||
m_BGSurface(NULL), m_TextSurface(NULL), m_CompSurface(NULL), m_font(NULL), m_Text("")
|
||||
{
|
||||
m_clipRect.x = m_clipRect.y = m_clipRect.w = m_clipRect.h = 0;
|
||||
}
|
||||
|
||||
|
||||
// Destructor - free the SDL surfaces we created.
|
||||
// Note that the background surface is not freed, since it was
|
||||
// supplied to the object by the caller.
|
||||
UILabel::~UILabel()
|
||||
{
|
||||
if (m_TextSurface)
|
||||
SDL_FreeSurface(m_TextSurface);
|
||||
|
||||
if (m_CompSurface)
|
||||
SDL_FreeSurface(m_CompSurface);
|
||||
|
||||
SDL_RemoveTimer(m_timerID);
|
||||
}
|
||||
|
||||
// Sets the label's location and background.
|
||||
void UILabel::Set(Uint16 x, Uint16 y, SDL_Surface* background, Font* font, SDL_Color textColor, float alpha)
|
||||
{
|
||||
UIControl::SetLocation(x, y);
|
||||
m_BGSurface = background;
|
||||
m_textColor = textColor;
|
||||
m_alpha = alpha;
|
||||
|
||||
if (font != NULL)
|
||||
m_font = font;
|
||||
|
||||
if (m_BGSurface != NULL)
|
||||
{
|
||||
m_w = m_clipRect.w = (Uint16) m_BGSurface->w;
|
||||
m_h = m_clipRect.h = (Uint16) m_BGSurface->h;
|
||||
}
|
||||
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
}
|
||||
|
||||
|
||||
// Returns the label's text.
|
||||
std::string UILabel::GetText() const
|
||||
{
|
||||
return m_Text;
|
||||
}
|
||||
|
||||
|
||||
// Sets the label's text, using printf-like formatting.
|
||||
// The alignment is only relevant to multi-line strings.
|
||||
// The text surface itself is always centered in the
|
||||
// background surface, if once exists.
|
||||
void UILabel::SetText(HAlign hAlign, const char *format, ...)
|
||||
{
|
||||
// Format the text:
|
||||
char formatted[4096]; // Holds the text after formatting
|
||||
va_list listOfArgs; // Pointer to the list of arguments
|
||||
|
||||
if (format == NULL) // If there's no text, do nothing
|
||||
{
|
||||
*formatted = 0;
|
||||
}
|
||||
else // Handle the variable-argument list
|
||||
{
|
||||
va_start(listOfArgs, format);
|
||||
vsprintf(formatted, format, listOfArgs);
|
||||
va_end(listOfArgs);
|
||||
}
|
||||
|
||||
|
||||
SetText(hAlign, std::string(formatted));
|
||||
}
|
||||
|
||||
// Sets the lable's text.
|
||||
void UILabel::SetText(HAlign hAlign, const std::string& text)
|
||||
{
|
||||
m_Text = text;
|
||||
|
||||
if (m_TextSurface != NULL)
|
||||
SDL_FreeSurface(m_TextSurface);
|
||||
|
||||
if (m_Text == "" && m_font == NULL)
|
||||
return;
|
||||
|
||||
if (hAlign == HALN_LEFT)
|
||||
m_TextSurface = m_font->RenderTransparent(Font::ALN_LEFT, m_textColor, m_alpha, text);
|
||||
else if (hAlign == HALN_CENTER)
|
||||
m_TextSurface = m_font->RenderTransparent(Font::ALN_CENTER, m_textColor, m_alpha, text);
|
||||
else
|
||||
m_TextSurface = m_font->RenderTransparent(Font::ALN_RIGHT, m_textColor, m_alpha, text);
|
||||
|
||||
// If no background surface is defined, the label's dimensions are those of the text surface:
|
||||
if (m_BGSurface == NULL)
|
||||
{
|
||||
m_w = m_clipRect.w = (Uint16) m_TextSurface->w;
|
||||
m_h = m_clipRect.h = (Uint16) m_TextSurface->h;
|
||||
}
|
||||
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
}
|
||||
|
||||
|
||||
// Sets the background surface.
|
||||
void UILabel::SetBackground(SDL_Surface *background)
|
||||
{
|
||||
m_BGSurface = background;
|
||||
|
||||
if (m_BGSurface != NULL)
|
||||
{
|
||||
m_w = (Uint16) m_BGSurface->w;
|
||||
m_h = (Uint16) m_BGSurface->h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sets the clipping rectangle.
|
||||
// Setting either dimension to a negative number cancels
|
||||
// clipping of that dimension.
|
||||
void UILabel::SetClipping(Sint16 w, Sint16 h)
|
||||
{
|
||||
m_clipRect.w = (w < 0) ? m_w : w;
|
||||
m_clipRect.h = (h < 0) ? m_h : h;
|
||||
}
|
||||
|
||||
// Show the label for a set amount of time.
|
||||
void UILabel::ShowTimed(Uint32 time)
|
||||
{
|
||||
m_visible = true;
|
||||
|
||||
// Remove any existing timers:
|
||||
SDL_RemoveTimer(m_timerID);
|
||||
|
||||
// Set the tooltip callback timer:
|
||||
m_timerID = SDL_AddTimer(time, HideLabel, &m_visible);
|
||||
}
|
||||
|
||||
|
||||
// Draws the label.
|
||||
// The method can use a clipping rectangle to clip the surface.
|
||||
void UILabel::Draw(SDL_Surface *screen)
|
||||
{
|
||||
if (m_visible == false)
|
||||
return;
|
||||
|
||||
SDL_Rect rect = {0, 0, 0, 0};
|
||||
|
||||
if (m_BGSurface != NULL)
|
||||
{
|
||||
rect.x = m_x;
|
||||
rect.y = m_y;
|
||||
|
||||
SDL_BlitSurface(m_BGSurface, &m_clipRect, screen, &rect);
|
||||
}
|
||||
|
||||
if (m_TextSurface != NULL)
|
||||
{
|
||||
rect.x = (Sint16) (m_x + (m_w - m_TextSurface->w) / 2);
|
||||
rect.y = (Sint16) (m_y + (m_h - m_TextSurface->h) / 2);
|
||||
|
||||
SDL_BlitSurface(m_TextSurface, &m_clipRect, screen, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Hides the label.
|
||||
// This is an SDL_timer callback function.
|
||||
Uint32 UILabel::HideLabel(Uint32 interval, void* param)
|
||||
{
|
||||
bool *visible = (bool *) param;
|
||||
*visible = false;
|
||||
|
||||
// Force a redraw:
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
83
project/jni/application/jooleem_0.1.4/src/UI/uilabel.h
Normal file
83
project/jni/application/jooleem_0.1.4/src/UI/uilabel.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UILABEL_H_
|
||||
#define _UILABEL_H_
|
||||
|
||||
// UI label control
|
||||
// May contain text and/or a background image.
|
||||
// The text is always centered in both dimensions.
|
||||
|
||||
#include "../UI/uicontrol.h"
|
||||
#include "../common/font.h"
|
||||
#include <string>
|
||||
#include "SDL.h"
|
||||
|
||||
class UILabel: public UIControl
|
||||
{
|
||||
private:
|
||||
SDL_Surface *m_BGSurface; // Background surface
|
||||
SDL_Surface *m_TextSurface; // Text surface
|
||||
SDL_Surface *m_CompSurface; // The text composited onto the the background
|
||||
|
||||
Font *m_font; // Font used to render the label's text
|
||||
std::string m_Text; // Label's text
|
||||
SDL_Color m_textColor; // Label's Text color
|
||||
float m_alpha; // Text's alpha value (0.0-1.0)
|
||||
|
||||
SDL_Rect m_clipRect; // Clipping rectangle for the label's surface
|
||||
|
||||
public:
|
||||
UILabel();
|
||||
~UILabel();
|
||||
|
||||
void Set(Uint16 x, Uint16 y, SDL_Surface* background, // Set location, background, font & color
|
||||
Font *font, SDL_Color textColor, float alpha = 1.0f);
|
||||
|
||||
void SetEnabled(bool enabled){};
|
||||
|
||||
std::string GetText() const; // Get the label's text
|
||||
void SetText(HAlign hAlign, const char *format, ...); // Set the label's text (printf-like formatting)
|
||||
void SetText(HAlign hAlign, const std::string& text); // Set the label's text
|
||||
|
||||
void SetClipping(Sint16 w, Sint16 h); // Sets the clipping rectangle
|
||||
|
||||
void SetBackground(SDL_Surface *background);// Sets the background surface
|
||||
|
||||
void ShowTimed(Uint32 time); // Show the label for a set amount of time
|
||||
|
||||
bool Update(){return false;} // Update
|
||||
|
||||
void Draw(SDL_Surface *screen); // Draw the label
|
||||
|
||||
// Mouse and keyboard events are irrelevant to a label, but required for polymorphism:
|
||||
bool MouseDown(Uint16 x, Uint16 y){return false;} // Process mouse up events
|
||||
bool MouseUp(Uint16 x, Uint16 y){return false;} // Process mouse up events
|
||||
bool Click(Uint16 x, Uint16 y){return false;} // Process user clicks
|
||||
bool Hover(Uint16 x, Uint16 y){return false;} // Process user mouse hover
|
||||
bool KeyDown(SDL_KeyboardEvent *event){return false;}
|
||||
|
||||
private:
|
||||
SDL_TimerID m_timerID; // Hide timer ID
|
||||
static Uint32 HideLabel(Uint32 interval, void* param); // Hide label timer callback func.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
141
project/jni/application/jooleem_0.1.4/src/UI/uiprogress.cpp
Normal file
141
project/jni/application/jooleem_0.1.4/src/UI/uiprogress.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/uiprogress.h"
|
||||
#include "../common/trap.h"
|
||||
#include "../common/events.h"
|
||||
|
||||
// Constructor
|
||||
UIProgressBar::UIProgressBar():
|
||||
m_BGSurface(NULL), m_normalSurface(NULL), m_flashingSurface(NULL), m_disabledSurface(NULL)
|
||||
{
|
||||
m_flashingMode = false;
|
||||
m_isFlashing = false;
|
||||
m_x = m_y = 0;
|
||||
m_progress = 0;
|
||||
m_clipRect.x = m_clipRect.y = m_clipRect.w = m_clipRect.h = 0;
|
||||
}
|
||||
|
||||
|
||||
// Sets location and surfaces
|
||||
void UIProgressBar::Set(Uint16 x, Uint16 y, SDL_Surface* BGSurface,
|
||||
SDL_Surface *normalSurface, SDL_Surface *flashingSurface, SDL_Surface *disabledSurface)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
|
||||
m_BGSurface = BGSurface;
|
||||
m_normalSurface = normalSurface;
|
||||
m_flashingSurface = flashingSurface;
|
||||
m_disabledSurface = disabledSurface;
|
||||
|
||||
if (normalSurface != NULL)
|
||||
{
|
||||
m_w = m_clipRect.w = (Uint16) normalSurface->w;
|
||||
m_h = m_clipRect.h = (Uint16) normalSurface->h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sets the bar's progress. Valid range is 0.0f - 1.0f.
|
||||
void UIProgressBar::SetProgress(float progress)
|
||||
{
|
||||
if (progress < 0.0f)
|
||||
m_progress = 0.0f;
|
||||
else if (progress > 1.0f)
|
||||
m_progress = 1.0f;
|
||||
else
|
||||
m_progress = progress;
|
||||
|
||||
|
||||
// Calculate the progress value in pixels:
|
||||
Uint16 progressInPixels = (Uint16) (m_progress * m_w);
|
||||
|
||||
// If the pixel value has changed, the bar needs to be redrawn:
|
||||
if (progressInPixels != m_clipRect.w)
|
||||
{
|
||||
m_clipRect.w = progressInPixels;
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Starts or stops the bar's flashing
|
||||
void UIProgressBar::Flash(bool flag)
|
||||
{
|
||||
// Ignore requests to start flashing while already flashing.
|
||||
if (flag == true && m_flashingMode == true)
|
||||
return;
|
||||
|
||||
m_flashingMode = m_isFlashing = flag;
|
||||
m_flashStart = SDL_GetTicks();
|
||||
|
||||
// Force redraw:
|
||||
PushUserEvent(EVENT_REDRAW);
|
||||
}
|
||||
|
||||
|
||||
// Updates the progress bar.
|
||||
bool UIProgressBar::Update()
|
||||
{
|
||||
if (m_enabled != true || m_flashingMode == false)
|
||||
return false;
|
||||
|
||||
bool redraw = false;
|
||||
|
||||
if (((SDL_GetTicks() - m_flashStart) / FLASH_INTERVAL) % 2) // Flashing
|
||||
{
|
||||
if (!m_isFlashing) // ... but was not flashing before
|
||||
redraw = true;
|
||||
m_isFlashing = true;
|
||||
}
|
||||
else // Not flashing
|
||||
{
|
||||
if (m_isFlashing) // ... but was flashing before
|
||||
redraw = true;
|
||||
|
||||
m_isFlashing = false;
|
||||
}
|
||||
|
||||
return redraw;
|
||||
|
||||
}
|
||||
|
||||
// Draws the progress bar.
|
||||
void UIProgressBar::Draw(SDL_Surface *screen)
|
||||
{
|
||||
if (!m_visible || screen == NULL || m_normalSurface == NULL || m_flashingSurface == NULL)
|
||||
return;
|
||||
|
||||
|
||||
SDL_Rect rect = {m_x, m_y, 0, 0};
|
||||
|
||||
// Blit background:
|
||||
if (m_BGSurface)
|
||||
SDL_BlitSurface(m_BGSurface, NULL, screen, &rect);
|
||||
|
||||
// Blit foreground:
|
||||
if (!m_enabled)
|
||||
SDL_BlitSurface(m_disabledSurface, &m_clipRect, screen, &rect);
|
||||
else if (m_isFlashing)
|
||||
SDL_BlitSurface(m_flashingSurface, &m_clipRect, screen, &rect);
|
||||
else
|
||||
SDL_BlitSurface(m_normalSurface, &m_clipRect, screen, &rect);
|
||||
}
|
||||
76
project/jni/application/jooleem_0.1.4/src/UI/uiprogress.h
Normal file
76
project/jni/application/jooleem_0.1.4/src/UI/uiprogress.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UIPROGRESS_H_
|
||||
#define _UIPROGRESS_H_
|
||||
|
||||
// UI progress bar control.
|
||||
|
||||
#include "../UI/uicontrol.h"
|
||||
#include "SDL.h"
|
||||
|
||||
class UIProgressBar: public UIControl
|
||||
{
|
||||
private:
|
||||
// Surfaces:
|
||||
SDL_Surface *m_BGSurface; // Background surface
|
||||
SDL_Surface *m_normalSurface; // Normal foreground surface
|
||||
SDL_Surface *m_flashingSurface; // Flashing foreground surface
|
||||
SDL_Surface *m_disabledSurface; // Disabled foreground surface
|
||||
|
||||
SDL_Rect m_clipRect; // Clipping rectangle for the foreground surface
|
||||
|
||||
float m_progress; // Bar's progress, between 0.0f and 1.0f
|
||||
|
||||
// Flash:
|
||||
bool m_flashingMode; // Are we in flashing mode?
|
||||
bool m_isFlashing; // Are we currently flashing?
|
||||
Uint32 m_flashStart; // Time flashing has started
|
||||
|
||||
// Button flash interval:
|
||||
static const int FLASH_INTERVAL = 500;
|
||||
|
||||
public:
|
||||
UIProgressBar();
|
||||
~UIProgressBar(){};
|
||||
|
||||
void Set(Uint16 x, Uint16 y, SDL_Surface* BGSurface, // Sets location and surfaces
|
||||
SDL_Surface *normalSurface, SDL_Surface *flashingSurface, SDL_Surface *disabledSurface);
|
||||
|
||||
// Set and get the bar's progress:
|
||||
void SetProgress(float progress);
|
||||
float GetProgress(){return m_progress;}
|
||||
|
||||
void Flash(bool flag); // Starts or stops the bar's flashing
|
||||
|
||||
bool Update(); // Updates the progress bar
|
||||
|
||||
void Draw(SDL_Surface *screen); // Draws the progress bar
|
||||
|
||||
// Mouse and keyboard events are irrelevant to a progress bar, but required for polymorphism:
|
||||
bool MouseDown(Uint16 x, Uint16 y){return false;} // Process mouse up events
|
||||
bool MouseUp(Uint16 x, Uint16 y){return false;} // Process mouse up events
|
||||
bool Click(Uint16 x, Uint16 y){return false;} // Process user clicks
|
||||
bool Hover(Uint16 x, Uint16 y){return false;} // Process user mouse hover
|
||||
bool KeyDown(SDL_KeyboardEvent *event){return false;} // Process key down events
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
282
project/jni/application/jooleem_0.1.4/src/UI/uitextbox.cpp
Normal file
282
project/jni/application/jooleem_0.1.4/src/UI/uitextbox.cpp
Normal file
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/uitextbox.h"
|
||||
#include "../common/trap.h"
|
||||
|
||||
// Constructor
|
||||
UITextBox::UITextBox():
|
||||
m_BGSurface(NULL), m_textSurface(NULL), m_cursorSurface(NULL), m_font(NULL), m_text("")
|
||||
{
|
||||
m_cursorIndex = 0;
|
||||
m_blinking = true;
|
||||
}
|
||||
|
||||
|
||||
// Destructor - free the SDL surfaces we created.
|
||||
// Note that the background and cursor surfaces are not freed,
|
||||
// since they were supplied to the object by the caller.
|
||||
UITextBox::~UITextBox()
|
||||
{
|
||||
if (m_textSurface)
|
||||
SDL_FreeSurface(m_textSurface);
|
||||
}
|
||||
|
||||
|
||||
// Sets the label's location and background.
|
||||
void UITextBox::Set(Uint16 x, Uint16 y, // Box location
|
||||
Uint16 textX, Uint16 textY, // Text location relative to the box
|
||||
SDL_Surface* background, SDL_Surface *cursorSurface, // background and cursor surfaces
|
||||
Font *font, SDL_Color textColor) // Font and text color
|
||||
{
|
||||
UIControl::SetLocation(x, y);
|
||||
m_textX = textX;
|
||||
m_textY = textY;
|
||||
|
||||
m_BGSurface = background;
|
||||
m_cursorSurface = cursorSurface;
|
||||
m_textColor = textColor;
|
||||
|
||||
m_font = font;
|
||||
}
|
||||
|
||||
|
||||
// Clears the text.
|
||||
void UITextBox::Clear()
|
||||
{
|
||||
SetText("");
|
||||
}
|
||||
|
||||
|
||||
// Returns the label's text.
|
||||
std::string UITextBox::GetText() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
|
||||
// Sets the box's text.
|
||||
void UITextBox::SetText(string text)
|
||||
{
|
||||
m_text = text;
|
||||
m_cursorIndex = (Uint16) m_text.length();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
// Update the cursor blink.
|
||||
bool UITextBox::Update()
|
||||
{
|
||||
if (m_enabled != true)
|
||||
return false;
|
||||
|
||||
bool redraw = false;
|
||||
|
||||
if (SDL_GetTicks() % (CURSOR_BLINK * 2) < CURSOR_BLINK) // Blink on
|
||||
{
|
||||
if (!m_blinking) // ... but was not flashing before
|
||||
redraw = true;
|
||||
m_blinking = true;
|
||||
}
|
||||
else // Not flashing
|
||||
{
|
||||
if (m_blinking) // ... but was flashing before
|
||||
redraw = true;
|
||||
m_blinking = false;
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
// Draws the text box.
|
||||
void UITextBox::Draw(SDL_Surface *screen)
|
||||
{
|
||||
if (m_visible == false)
|
||||
return;
|
||||
|
||||
SDL_Rect rect = {0, 0, 0, 0};
|
||||
|
||||
// Background:
|
||||
if (m_BGSurface != NULL)
|
||||
{
|
||||
rect.x = m_x;
|
||||
rect.y = m_y;
|
||||
|
||||
SDL_BlitSurface(m_BGSurface, NULL, screen, &rect);
|
||||
}
|
||||
|
||||
// Text:
|
||||
if (m_textSurface != NULL)
|
||||
{
|
||||
rect.x = m_textX + m_x;
|
||||
rect.y = m_textY + m_y;
|
||||
|
||||
SDL_BlitSurface(m_textSurface, NULL, screen, &rect);
|
||||
}
|
||||
|
||||
// Cursor:
|
||||
if (m_cursorSurface != NULL && m_blinking)
|
||||
//SDL_GetTicks() % (CURSOR_BLINK * 2) < CURSOR_BLINK)
|
||||
{
|
||||
rect.x = m_x + m_textX + (m_charOffset.empty() ? 0 : m_charOffset[m_cursorIndex]);
|
||||
rect.y = m_y + m_textY + 1;
|
||||
|
||||
SDL_BlitSurface(m_cursorSurface, NULL, screen, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Process mouse down events.
|
||||
// A click sets the cursor position.
|
||||
bool UITextBox::MouseDown(Uint16 x, Uint16 y)
|
||||
{
|
||||
// Check if the click in inside the text area:
|
||||
if (m_textSurface == NULL || x < m_x + m_textX || x > m_x + m_textX + m_textSurface->w
|
||||
|| y < m_y + m_textY || y > m_y + m_textY + m_textSurface->h)
|
||||
return false;
|
||||
|
||||
// Scan the offset vector to see where to place the cursor:
|
||||
Uint16 A, B;
|
||||
|
||||
for (Uint16 i = 0 ; i < (Uint16) m_charOffset.size() ; ++i)
|
||||
{
|
||||
if (i == 0)
|
||||
A = m_x + m_textX + m_charOffset[i];
|
||||
else
|
||||
A = (m_x + m_textX + m_charOffset[i - 1] + m_x + m_textX + m_charOffset[i]) / 2;
|
||||
|
||||
if (i == (Uint16) m_charOffset.size())
|
||||
B = m_x + m_textX + m_charOffset[i];
|
||||
else
|
||||
B = (m_x + m_textX + m_charOffset[i] + m_x + m_textX + m_charOffset[i + 1]) / 2;
|
||||
|
||||
if (x >= A && x < B)
|
||||
m_cursorIndex = i;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Handle key down events.
|
||||
bool UITextBox::KeyDown(SDL_KeyboardEvent *event)
|
||||
{
|
||||
switch (event->keysym.sym) // Get the key symbol
|
||||
{
|
||||
// Left arrow:
|
||||
case SDLK_LEFT:
|
||||
if (m_cursorIndex > 0)
|
||||
m_cursorIndex--;
|
||||
break;
|
||||
|
||||
// Right arrow:
|
||||
case SDLK_RIGHT:
|
||||
if (m_cursorIndex < m_text.length())
|
||||
m_cursorIndex++;
|
||||
break;
|
||||
|
||||
// Home:
|
||||
case SDLK_HOME:
|
||||
m_cursorIndex = 0;
|
||||
break;
|
||||
|
||||
// End:
|
||||
case SDLK_END:
|
||||
m_cursorIndex = (Uint16) m_text.length();
|
||||
break;
|
||||
|
||||
// Backspace:
|
||||
case SDLK_BACKSPACE:
|
||||
if (m_cursorIndex > 0)
|
||||
{
|
||||
m_text.erase(m_cursorIndex - 1, 1);
|
||||
m_cursorIndex--;
|
||||
Refresh();
|
||||
}
|
||||
break;
|
||||
|
||||
// Delete:
|
||||
case SDLK_DELETE:
|
||||
if (m_cursorIndex < m_text.length())
|
||||
{
|
||||
m_text.erase(m_cursorIndex, 1);
|
||||
Refresh();
|
||||
}
|
||||
break;
|
||||
|
||||
// Characters:
|
||||
default:
|
||||
{
|
||||
// Make sure text doesn't graphically overflow the background image:
|
||||
if (m_textSurface != NULL &&
|
||||
m_textSurface->w >= (m_BGSurface->w - 3 * m_textX))
|
||||
break;
|
||||
|
||||
char c = 0;
|
||||
|
||||
// Convert the unicode value into ASCII:
|
||||
if ((event->keysym.unicode & 0xFF80) == 0)
|
||||
{
|
||||
c = (char)(event->keysym.unicode & 0x7F);
|
||||
|
||||
if (c >= ' ' && c <= '~') // Add only displayable chars
|
||||
{
|
||||
// Insert the character to the string at the current cursor position:
|
||||
m_text.insert(m_cursorIndex, string(1,c));
|
||||
m_cursorIndex++;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
else // International char - ignore
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Refreshes the text box when changed.
|
||||
void UITextBox::Refresh()
|
||||
{
|
||||
MeasureOffsets();
|
||||
|
||||
SDL_FreeSurface(m_textSurface);
|
||||
m_textSurface = m_font->RenderPlain(Font::ALN_LEFT, m_textColor, m_text);
|
||||
}
|
||||
|
||||
|
||||
// Measure the characters' offset.
|
||||
// The method populates the offset vector with the offsets
|
||||
// of the string characters, in pixels, when rendered with
|
||||
// the object's font.
|
||||
void UITextBox::MeasureOffsets()
|
||||
{
|
||||
m_charOffset.clear();
|
||||
|
||||
m_charOffset.push_back(0);
|
||||
for (size_t i = 0 ; i < m_text.length() ; ++i)
|
||||
{
|
||||
Uint16 temp = m_font->GetGlyphAdvance((Uint16) m_text[i]);
|
||||
m_charOffset.push_back(temp + m_charOffset[i]);
|
||||
}
|
||||
}
|
||||
|
||||
99
project/jni/application/jooleem_0.1.4/src/UI/uitextbox.h
Normal file
99
project/jni/application/jooleem_0.1.4/src/UI/uitextbox.h
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UITEXTBOX_H_
|
||||
#define _UITEXTBOX_H_
|
||||
|
||||
// UI text box control
|
||||
|
||||
#include "../UI/uicontrol.h"
|
||||
#include "../common/font.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "SDL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class UITextBox: public UIControl
|
||||
{
|
||||
private:
|
||||
SDL_Surface *m_BGSurface; // Background surface
|
||||
SDL_Surface *m_textSurface; // Text surface
|
||||
SDL_Surface *m_cursorSurface; // Cursor surface
|
||||
|
||||
string m_text; // The box's text
|
||||
Font *m_font; // Font used to render the text
|
||||
SDL_Color m_textColor; // Text color
|
||||
|
||||
Uint16 m_cursorIndex; // Cursor position - as the index of the
|
||||
// character in the string. The cursor
|
||||
// is drawn BEFORE the character with
|
||||
// the same index.
|
||||
// Use n+1 to indicate the position after
|
||||
// the last character.
|
||||
|
||||
vector<Uint16> m_charOffset; // A vector of character advance offset.
|
||||
// E.g. For the string "Hello", the value
|
||||
// of the second element will be the distance,
|
||||
// in pixels, from the begining of the rendered
|
||||
// text until the end of the character 'e'
|
||||
|
||||
Uint16 m_textX, m_textY; // Location of text area within the control
|
||||
|
||||
bool m_blinking; // Current blinking status
|
||||
static const int CURSOR_BLINK = 500; // Cursor blink rate, in ms
|
||||
|
||||
|
||||
public:
|
||||
UITextBox();
|
||||
~UITextBox();
|
||||
|
||||
void Set(Uint16 x, Uint16 y, // Box location
|
||||
Uint16 textX, Uint16 textY, // Text location relative to the box
|
||||
SDL_Surface* background, SDL_Surface *cursorSurface, // Background and cursor surfaces
|
||||
Font *font, SDL_Color textColor); // Font and text color
|
||||
|
||||
void SetEnabled(bool enabled){};
|
||||
|
||||
void Clear(); // Clears the text
|
||||
|
||||
string GetText() const; // Gets the box's text
|
||||
void SetText(string text); // Sets the box's text
|
||||
|
||||
void SetBackground(SDL_Surface *background);// Sets the background surface
|
||||
|
||||
bool Update(); // Updates the text box
|
||||
|
||||
void Draw(SDL_Surface *screen); // Draws the text box
|
||||
|
||||
// Mouse and keyboard events:
|
||||
bool MouseDown(Uint16 x, Uint16 y); // Processes mouse down events
|
||||
bool MouseUp(Uint16 x, Uint16 y){return false;} // Processes mouse up events
|
||||
bool Click(Uint16 x, Uint16 y){return false;} // Processes user clicks
|
||||
bool Hover(Uint16 x, Uint16 y){return false;} // Processes user mouse hover
|
||||
bool KeyDown(SDL_KeyboardEvent *event); // Processes keyboard clicks
|
||||
|
||||
private:
|
||||
void Refresh(); // Refreshes the text box when changed
|
||||
void MeasureOffsets(); // Measure the characters' offset
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
307
project/jni/application/jooleem_0.1.4/src/UI/uiwindow.cpp
Normal file
307
project/jni/application/jooleem_0.1.4/src/UI/uiwindow.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../UI/uiwindow.h"
|
||||
#include "../common/common.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Constructor
|
||||
UIWindow::UIWindow(SDL_Surface *background)
|
||||
{
|
||||
m_visible = true;
|
||||
|
||||
m_background = background;
|
||||
|
||||
if (m_background != NULL)
|
||||
{
|
||||
m_w = (Uint16) m_background->w;
|
||||
m_h = (Uint16) m_background->h;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_w = m_h = 0;
|
||||
}
|
||||
|
||||
// Set the window to be centered relative to the screen:
|
||||
m_x = (SCREEN_WIDTH - m_w) / 2;
|
||||
m_y = (SCREEN_HEIGHT - m_h) / 2;
|
||||
}
|
||||
|
||||
// Destructor - delete the window's controls
|
||||
UIWindow::~UIWindow()
|
||||
{
|
||||
// Delete the individual controls:
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
delete (itr->second);
|
||||
|
||||
// Delete the controls within the vectors:
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
delete (*itrVec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Enables or disables all of the window's controls.
|
||||
void UIWindow::SetEnabled(bool enabled)
|
||||
{
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
itr->second->SetEnabled(enabled);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
(*itrVec)->SetEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Adds a control to the collection.
|
||||
void UIWindow::AddControl(int ID, UIControl *control)
|
||||
{
|
||||
map<int, UIControl*>::iterator itr = m_controls.find(ID);
|
||||
|
||||
if (itr == m_controls.end())
|
||||
m_controls[ID] = control;
|
||||
|
||||
}
|
||||
|
||||
// Adds a vector of controls to the collection.
|
||||
void UIWindow::AddControlVector(int ID, vector<UIControl *> vec)
|
||||
{
|
||||
map<int, vector<UIControl *> >::iterator itr = m_controlsVectors.find(ID);
|
||||
|
||||
if (itr == m_controlsVectors.end())
|
||||
m_controlsVectors[ID] = vec;
|
||||
}
|
||||
|
||||
|
||||
// Gets a UI control by its ID.
|
||||
UIControl *UIWindow::GetControl(int ID)
|
||||
{
|
||||
map<int, UIControl*>::iterator itr = m_controls.find(ID);
|
||||
|
||||
if (itr == m_controls.end())
|
||||
return NULL;
|
||||
else
|
||||
return m_controls[ID];
|
||||
}
|
||||
|
||||
// Gets a UI control vector by its ID.
|
||||
vector<UIControl *> UIWindow::GetControlVector(int ID)
|
||||
{
|
||||
return m_controlsVectors[ID];
|
||||
}
|
||||
|
||||
// Gets a UI control, cast to a button, by its ID.
|
||||
UIButton *UIWindow::GetButton(int ID)
|
||||
{
|
||||
return (static_cast<UIButton *>(GetControl(ID)));
|
||||
}
|
||||
|
||||
// Gets a UI control, cast to a label, by its ID.
|
||||
UILabel *UIWindow::GetLabel(int ID)
|
||||
{
|
||||
return (static_cast<UILabel *>(GetControl(ID)));
|
||||
}
|
||||
|
||||
|
||||
// Gets a UI control, cast to a progress bar, by its ID.
|
||||
UIProgressBar *UIWindow::GetProgressBar(int ID)
|
||||
{
|
||||
return (static_cast<UIProgressBar *>(GetControl(ID)));
|
||||
}
|
||||
|
||||
// Processes mouse down events.
|
||||
bool UIWindow::MouseDown(Uint16 x, Uint16 y)
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->MouseDown(x, y);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->MouseDown(x, y);
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
|
||||
// Processes mouse up events.
|
||||
bool UIWindow::MouseUp(Uint16 x, Uint16 y)
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->MouseUp(x, y);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->MouseUp(x, y);
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
// Processes user clicks.
|
||||
bool UIWindow::Click(Uint16 x, Uint16 y)
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->Click(x, y);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->Click(x, y);
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
|
||||
// Processes mouse hover.
|
||||
bool UIWindow::Hover(Uint16 x, Uint16 y)
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->Hover(x, y);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->Hover(x, y);
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
|
||||
// Proces key down events:
|
||||
bool UIWindow::KeyDown(SDL_KeyboardEvent *event)
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->KeyDown(event);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->KeyDown(event);
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
|
||||
// Update the window.
|
||||
bool UIWindow::Update()
|
||||
{
|
||||
bool redraw = false;
|
||||
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
redraw |= itr->second->Update();
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
redraw |= (*itrVec)->Update();
|
||||
}
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
|
||||
// Draws the window.
|
||||
void UIWindow::Draw(SDL_Surface *screen)
|
||||
{
|
||||
if (m_visible == false)
|
||||
return;
|
||||
|
||||
DrawBackground(screen);
|
||||
|
||||
DrawControls(screen);
|
||||
}
|
||||
|
||||
|
||||
// Draws the window's background.
|
||||
void UIWindow::DrawBackground(SDL_Surface *screen)
|
||||
{
|
||||
if (m_visible == false)
|
||||
return;
|
||||
|
||||
// Draw the background:
|
||||
SDL_Rect rect = {m_x, m_y, m_w, m_h};
|
||||
SDL_BlitSurface(m_background, NULL, screen, &rect);
|
||||
}
|
||||
|
||||
// Draws the window's controls.
|
||||
void UIWindow::DrawControls(SDL_Surface *screen)
|
||||
{
|
||||
if (m_visible == false)
|
||||
return;
|
||||
|
||||
// Draw the controls:
|
||||
map<int, UIControl*>::iterator itr;
|
||||
for (itr = m_controls.begin() ; itr != m_controls.end() ; itr++)
|
||||
itr->second->Draw(screen);
|
||||
|
||||
map<int, vector<UIControl *> >::iterator itrCtlVec;
|
||||
for (itrCtlVec = m_controlsVectors.begin() ; itrCtlVec != m_controlsVectors.end() ; itrCtlVec++)
|
||||
{
|
||||
vector<UIControl *>::iterator itrVec;
|
||||
for (itrVec = itrCtlVec->second.begin() ; itrVec != itrCtlVec->second.end() ; itrVec++)
|
||||
(*itrVec)->Draw(screen);
|
||||
}
|
||||
}
|
||||
|
||||
86
project/jni/application/jooleem_0.1.4/src/UI/uiwindow.h
Normal file
86
project/jni/application/jooleem_0.1.4/src/UI/uiwindow.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Chai Braudo (braudo@users.sourceforge.net)
|
||||
*
|
||||
* This file is part of Jooleem - http://sourceforge.net/projects/jooleem
|
||||
*
|
||||
* Jooleem is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Jooleem is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Jooleem; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _UIWINDOW_H_
|
||||
#define _UIWINDOW_H_
|
||||
|
||||
// A base class for windows.
|
||||
// The window is composed of a background and a collection of
|
||||
// controls - labels, buttons or other windows.
|
||||
// The class supports vectors of controls.
|
||||
|
||||
#include "../UI/uicontrol.h"
|
||||
#include "../UI/uibutton.h"
|
||||
#include "../UI/uilabel.h"
|
||||
#include "../UI/uiprogress.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "SDL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class UIWindow: public UIControl
|
||||
{
|
||||
protected:
|
||||
SDL_Surface *m_background; // Window background
|
||||
map<int, UIControl *> m_controls; // Window controls
|
||||
map<int, vector<UIControl *> > m_controlsVectors; // Window controls vectors
|
||||
|
||||
public:
|
||||
UIWindow(SDL_Surface *background);
|
||||
virtual ~UIWindow();
|
||||
|
||||
// Enable / Disbable the windows' controls:
|
||||
void SetEnabled(bool enabled);
|
||||
|
||||
// Add and get a control:
|
||||
void AddControl(int ID, UIControl *control);
|
||||
void AddControlVector(int ID, vector<UIControl *> vec);
|
||||
UIControl *GetControl(int ID);
|
||||
vector<UIControl *> GetControlVector(int ID);
|
||||
|
||||
// Accessors:
|
||||
UIButton *GetButton(int ID);
|
||||
UILabel *GetLabel(int ID);
|
||||
UIProgressBar *GetProgressBar(int ID);
|
||||
SDL_Surface *GetBackground(){return m_background;}
|
||||
|
||||
|
||||
// Mouse events:
|
||||
bool MouseDown(Uint16 x, Uint16 y); // Process mouse up events
|
||||
bool MouseUp(Uint16 x, Uint16 y); // Process mouse up events
|
||||
bool Click(Uint16 x, Uint16 y); // Process user clicks
|
||||
bool Hover(Uint16 x, Uint16 y); // Process user mouse hover
|
||||
|
||||
// Key down:
|
||||
bool KeyDown(SDL_KeyboardEvent *event);
|
||||
|
||||
// Update the window:
|
||||
bool Update();
|
||||
|
||||
// Draw the window:
|
||||
void Draw(SDL_Surface *screen);
|
||||
void DrawBackground(SDL_Surface *screen);
|
||||
void DrawControls(SDL_Surface *screen);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user