From: <shu...@us...> - 2006-11-28 20:33:56
|
Revision: 125 http://svn.sourceforge.net/dunelegacy/?rev=125&view=rev Author: shutdownrunner Date: 2006-11-28 12:33:50 -0800 (Tue, 28 Nov 2006) Log Message: ----------- - Added label(somehow didn't do it the previous time) Added Paths: ----------- branches/dunks/include/gui2/Label.h branches/dunks/src/gui2/Label.cpp Added: branches/dunks/include/gui2/Label.h =================================================================== --- branches/dunks/include/gui2/Label.h (rev 0) +++ branches/dunks/include/gui2/Label.h 2006-11-28 20:33:50 UTC (rev 125) @@ -0,0 +1,33 @@ +#ifndef DUNE_GUI2_LABEL_H +#define DUNE_GUI2_LABEL_H + +#include "gui2/Widget.h" +#include <string> + +/* Label widget using dune's fonts +*/ +class Label : public Widget +{ +public: + //! @name Constructors & Destructor + //@{ + + /*! + Caption of label should always be set when constructing label + @param caption std::string a caption of label + @param bgcolour sets background colour of label. 115(dune yellow) by default + */ + Label(std::string caption, int bgcolour = 115); + + ~Label(); + //@} + + virtual void draw(SDL_Surface* dest, SPoint off); + +protected: + + SDL_Surface * m_surface; + std::string m_caption; +}; + +#endif //DUNE_GUI2_LABEL_H Added: branches/dunks/src/gui2/Label.cpp =================================================================== --- branches/dunks/src/gui2/Label.cpp (rev 0) +++ branches/dunks/src/gui2/Label.cpp 2006-11-28 20:33:50 UTC (rev 125) @@ -0,0 +1,54 @@ +#include "gui2/Label.h" +#include <stdio.h> +#include "Colours.h" +#include "Font.h" +#include "Application.h" +#include "Gfx.h" + +Label::Label(std::string caption, int bgcolour) +{ + m_caption = caption; + Font* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); + + Uint16 textw, texth; + + font->extents(m_caption.c_str(), textw, texth); + + /*If surface width was not %4 == 0 then you'd get a text in italics */ + m_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, textw + 4-(textw%4) , texth, 8, + 0, 0, 0, 0); + + assert(m_surface != NULL); + + SDL_LockSurface(m_surface); + + SDL_Palette* pal = Application::Instance()->Screen()->format->palette; + + SDL_SetColors(m_surface, pal->colors, 0, pal->ncolors); + + SDL_FillRect(m_surface, NULL, bgcolour); + + font->render(m_caption.c_str(), m_surface, + m_surface->w/2 - textw/2, + m_surface->h/2 - texth/2, 49); + SDL_UnlockSurface(m_surface); + +// Is it needed in case of label. It's not clickable or anything. +// Widget::setSize(SPoint(textw, texth)); +}; + +Label::~Label() +{ + +}; + +void Label::draw(SDL_Surface* dest, SPoint off) +{ + if (!m_visible) return; + + Rect destrect (off.x + x, off.y + y, 0, 0); + + assert(m_surface != NULL); + SDL_BlitSurface(m_surface, NULL, dest, &destrect); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |