From 3dd248156b28f7062ba5febf7e3ba0eac5cf1276 Mon Sep 17 00:00:00 2001 From: Tamir Atias Date: Wed, 18 Jan 2012 13:59:28 +0200 Subject: [PATCH] [Fix] Added EventHistory.cpp and EventHistory.h to VS project. -- What the hell happened to them?! [Add] Event history box is now translucent. --- Win32/Unuk/LibUnuk/LibUnuk.vcproj | 8 ++++++++ src/Unuk/Game.cpp | 2 ++ src/libUnuk/System/Rect.cpp | 17 +++++++++++++---- src/libUnuk/System/Rect.h | 2 ++ src/libUnuk/UI/EventHistory.cpp | 17 ++++++++++++----- src/libUnuk/UI/EventHistory.h | 3 +++ 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Win32/Unuk/LibUnuk/LibUnuk.vcproj b/Win32/Unuk/LibUnuk/LibUnuk.vcproj index 3263c2b..197f76f 100644 --- a/Win32/Unuk/LibUnuk/LibUnuk.vcproj +++ b/Win32/Unuk/LibUnuk/LibUnuk.vcproj @@ -360,6 +360,14 @@ RelativePath="..\..\..\src\libUnuk\Ui\ButtonToggle.h" > + + + + diff --git a/src/Unuk/Game.cpp b/src/Unuk/Game.cpp index 255bed6..79a8398 100644 --- a/src/Unuk/Game.cpp +++ b/src/Unuk/Game.cpp @@ -146,6 +146,8 @@ void Game::HandleInput(void) { _ingameMenu.SetStatus(true); if(event.key.keysym.sym == SDLK_p) debugEnabled = !debugEnabled; + if(event.key.keysym.sym == SDLK_0) + _eventHistory.LogEvent("Item gained."); } else if(event.type == SDL_QUIT) { _gameRunning = false; diff --git a/src/libUnuk/System/Rect.cpp b/src/libUnuk/System/Rect.cpp index d2b1d53..764013d 100644 --- a/src/libUnuk/System/Rect.cpp +++ b/src/libUnuk/System/Rect.cpp @@ -16,16 +16,25 @@ void Rect::SetWidthHeight(int wArg, int hArg) { rect.h = (Uint16)hArg; } +void Rect::SetRGBA(Uint8 rArg, Uint8 gArg, Uint8 bArg, Uint8 aArg) { + r = rArg; + g = gArg; + b = bArg; + a = aArg; +} + void Rect::SetRGB(Uint8 rArg, Uint8 gArg, Uint8 bArg) { r = rArg; g = gArg; b = bArg; + a = 255; } void Rect::SetRGB(SDL_Color colour) { r = colour.r; g = colour.g; b = colour.b; + a = 255; } void Rect::Draw(void) { @@ -36,7 +45,7 @@ void Rect::Draw(void) { offset.w = rect.w; offset.h = rect.h; - SDL_FillRect(screen, &offset, SDL_MapRGB(screen->format, r, g, b)); + SDL_FillRect(screen, &offset, SDL_MapRGBA(screen->format, r, g, b, a)); } void Rect::Draw(int xArg, int yArg) { @@ -47,11 +56,11 @@ void Rect::Draw(int xArg, int yArg) { offset.w = (Sint16)rect.w; offset.h = (Sint16)rect.h; - SDL_FillRect(screen, &offset, SDL_MapRGB(screen->format, r, g, b)); + SDL_FillRect(screen, &offset, SDL_MapRGBA(screen->format, r, g, b, a)); } void Rect::DrawLiteral(void) { - SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); + SDL_FillRect(screen, &rect, SDL_MapRGBA(screen->format, r, g, b, a)); } void Rect::DrawLiteral(int xArg, int yArg) { @@ -62,5 +71,5 @@ void Rect::DrawLiteral(int xArg, int yArg) { offset.w = rect.w; offset.h = rect.h; - SDL_FillRect(screen, &offset, SDL_MapRGB(screen->format, r, g, b)); + SDL_FillRect(screen, &offset, SDL_MapRGBA(screen->format, r, g, b, a)); } diff --git a/src/libUnuk/System/Rect.h b/src/libUnuk/System/Rect.h index 645f3d7..5d4d5bc 100644 --- a/src/libUnuk/System/Rect.h +++ b/src/libUnuk/System/Rect.h @@ -17,6 +17,7 @@ public: void SetXY(int xArg, int yArg); void SetWidthHeight(int wArg, int hArg); + void SetRGBA(Uint8 rArg, Uint8 gArg, Uint8 bArg, Uint8 aArg); void SetRGB(Uint8 rArg, Uint8 gArg, Uint8 bArg); void SetRGB(SDL_Color); @@ -29,6 +30,7 @@ protected: Uint8 r; Uint8 g; Uint8 b; + Uint8 a; private: SDL_Rect rect; diff --git a/src/libUnuk/UI/EventHistory.cpp b/src/libUnuk/UI/EventHistory.cpp index 0ced2df..2a7c6fc 100644 --- a/src/libUnuk/UI/EventHistory.cpp +++ b/src/libUnuk/UI/EventHistory.cpp @@ -1,15 +1,18 @@ +#include +#include + #include "EventHistory.h" #include "../../Unuk/Constants.h" +#include "../../Unuk/Globals.h" const int EventHistory::BOX_WIDTH = 350; const int EventHistory::BOX_HEIGHT = 130; EventHistory::EventHistory(void) { - _background.SetXY(SCREEN_WIDTH/2 - BOX_WIDTH/2, 10); - _background.SetWidthHeight(BOX_WIDTH, BOX_HEIGHT); - _background.SetRGB(0, 0, 0); + _bgx = SCREEN_WIDTH / 2 - BOX_WIDTH / 2; + _bgy = 10; - _text.SetXY(_background.GetX() + 5, _background.GetY() + 5); + _text.SetXY(_bgx + 5, _bgy + 5); _visible = false; } @@ -46,6 +49,10 @@ void EventHistory::Render(void) { return; } - _background.DrawLiteral(); + boxRGBA(screen, + _bgx, _bgy, + _bgx + BOX_WIDTH, _bgy + BOX_HEIGHT, + 0, 0, 0, 128); + _text.RenderLiteral(); } \ No newline at end of file diff --git a/src/libUnuk/UI/EventHistory.h b/src/libUnuk/UI/EventHistory.h index c237a95..6d8eea1 100644 --- a/src/libUnuk/UI/EventHistory.h +++ b/src/libUnuk/UI/EventHistory.h @@ -23,6 +23,9 @@ private: Timer _timeToVanish; bool _visible; + int _bgx; + int _bgy; + static const int BOX_WIDTH; static const int BOX_HEIGHT; }; \ No newline at end of file