From: <hik...@us...> - 2009-12-16 01:44:23
|
Revision: 4302 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4302&view=rev Author: hikerstk Date: 2009-12-16 01:44:16 +0000 (Wed, 16 Dec 2009) Log Message: ----------- Fixed compiler warnings. Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/widgets/ribbon_widget.cpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2009-12-16 01:00:15 UTC (rev 4301) +++ main/trunk/src/guiengine/skin.cpp 2009-12-16 01:44:16 UTC (rev 4302) @@ -1141,7 +1141,7 @@ const core::dimension2d<u32>& texture_size = texture->getSize(); const float aspectRatio = (float)texture_size.Width / (float)texture_size.Height; const int h = std::min( rect.getHeight()/2 , (int)(texture_size.Height) ); - int w = aspectRatio*h; + int w = (int)(aspectRatio*h); const core::rect<s32> source_area = core::rect<s32>(0, 0, texture_size.Width, texture_size.Height); Modified: main/trunk/src/guiengine/widgets/ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/ribbon_widget.cpp 2009-12-16 01:00:15 UTC (rev 4301) +++ main/trunk/src/guiengine/widgets/ribbon_widget.cpp 2009-12-16 01:44:16 UTC (rev 4302) @@ -162,8 +162,8 @@ // size of the image video::ITexture* image = GUIEngine::getDriver()->getTexture((file_manager->getDataDir() + "/" + m_children[i].m_properties[PROP_ICON]).c_str()); - float image_h = image->getSize().Height; - float image_w = image->getSize().Width; + float image_h = (float)image->getSize().Height; + float image_w = (float)image->getSize().Width; //float image_w = image_h*imageRatio; // if button too high to fit, scale down @@ -176,8 +176,8 @@ m_children[i].x = widget_x - (int)(image_w*zoom/2.0f); m_children[i].y = button_y; - m_children[i].w = image_w*zoom; - m_children[i].h = image_h*zoom; + m_children[i].w = (int)(image_w*zoom); + m_children[i].h = (int)(image_h*zoom); //std::wcout << L"Widget has text '" << m_children[i].m_text.c_str() << "'\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2009-12-22 20:54:51
|
Revision: 4341 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4341&view=rev Author: auria Date: 2009-12-22 20:54:43 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Fixed keyboard navigation bug when a dialog was shown Modified Paths: -------------- main/trunk/src/guiengine/event_handler.cpp main/trunk/src/guiengine/modaldialog.cpp main/trunk/src/guiengine/modaldialog.hpp Modified: main/trunk/src/guiengine/event_handler.cpp =================================================================== --- main/trunk/src/guiengine/event_handler.cpp 2009-12-22 20:25:08 UTC (rev 4340) +++ main/trunk/src/guiengine/event_handler.cpp 2009-12-22 20:54:43 UTC (rev 4341) @@ -381,6 +381,11 @@ } } + // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog + if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el)) + { + el = NULL; + } // find closest widget if (el != NULL && el->getTabGroup() != NULL && @@ -413,7 +418,7 @@ if (ModalDialog::isADialogActive()) { - // TODO : select last widget in modal dialogs + w = ModalDialog::getCurrent()->getLastWidget(); } else { @@ -487,6 +492,11 @@ } } + // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog + if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el)) + { + el = NULL; + } if (el != NULL && el->getTabGroup() != NULL && el->getTabGroup()->getNextElement(el->getTabOrder(), false, false, first, closest)) @@ -521,7 +531,8 @@ if (ModalDialog::isADialogActive()) { - // TODO : select first widget in modal dialogs + std::cout << "w = ModalDialog::getCurrent()->getFirstWidget();\n"; + w = ModalDialog::getCurrent()->getFirstWidget(); } else { Modified: main/trunk/src/guiengine/modaldialog.cpp =================================================================== --- main/trunk/src/guiengine/modaldialog.cpp 2009-12-22 20:25:08 UTC (rev 4340) +++ main/trunk/src/guiengine/modaldialog.cpp 2009-12-22 20:54:43 UTC (rev 4341) @@ -115,4 +115,36 @@ { } +Widget* ModalDialog::getLastWidget() +{ + const int childrenCount = m_children.size(); + + for (int i=childrenCount-1; i>=0; i--) + { + if (m_children[i].getIrrlichtElement() == NULL || m_children[i].getIrrlichtElement()->getTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + { + continue; + } + return m_children.get(i); + + } + return NULL; } +Widget* ModalDialog::getFirstWidget() +{ + const int childrenCount = m_children.size(); + + for (int i=0; i<childrenCount; i++) + { + if (m_children[i].getIrrlichtElement() == NULL || m_children[i].getIrrlichtElement()->getTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + { + continue; + } + return m_children.get(i); + } + return NULL; +} + +} Modified: main/trunk/src/guiengine/modaldialog.hpp =================================================================== --- main/trunk/src/guiengine/modaldialog.hpp 2009-12-22 20:25:08 UTC (rev 4340) +++ main/trunk/src/guiengine/modaldialog.hpp 2009-12-22 20:54:43 UTC (rev 4341) @@ -60,7 +60,11 @@ virtual EventPropagation processEvent(std::string& eventSource){ return EVENT_LET; } bool isMyChild(Widget* widget) const { return m_children.contains(widget); } - + bool isMyChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); } + + Widget* getFirstWidget(); + Widget* getLastWidget(); + irr::gui::IGUIWindow* getIrrlichtElement() { return m_irrlicht_window; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2009-12-27 16:53:15
|
Revision: 4352 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4352&view=rev Author: auria Date: 2009-12-27 16:52:56 +0000 (Sun, 27 Dec 2009) Log Message: ----------- Fixed a few text clipping issues Modified Paths: -------------- main/trunk/src/guiengine/engine.hpp main/trunk/src/guiengine/screen_loader.cpp main/trunk/src/guiengine/widget.hpp main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp main/trunk/src/guiengine/widgets/icon_button_widget.cpp main/trunk/src/guiengine/widgets/ribbon_widget.cpp Modified: main/trunk/src/guiengine/engine.hpp =================================================================== --- main/trunk/src/guiengine/engine.hpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/engine.hpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -179,6 +179,10 @@ Valid on Ribbons or RibbonGrids. Can be "true" (omitting it means "false"). Indicates whether the contents use rectangular icons (this will affect the type of focus/highlighting used) +PROP_EXTEND_LABEL "extend_label" +How many pixels the label is allowed to expand beyond the boundaries of the widget itself. Currently only +allowed on icon widgets, + +--------------------------+ + Using the Engine in Code + +--------------------------+ Modified: main/trunk/src/guiengine/screen_loader.cpp =================================================================== --- main/trunk/src/guiengine/screen_loader.cpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/screen_loader.cpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -183,6 +183,7 @@ READ_PROPERTY(max_width, PROP_MAX_WIDTH); READ_PROPERTY(max_height, PROP_MAX_HEIGHT); + READ_PROPERTY(extend_label, PROP_EXTEND_LABEL); #undef READ_PROPERTY const char* text = xml->getAttributeValue( "text" ); Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/widget.hpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -71,7 +71,8 @@ PROP_MAX_VALUE, PROP_MAX_WIDTH, PROP_MAX_HEIGHT, - PROP_SQUARE + PROP_SQUARE, + PROP_EXTEND_LABEL }; bool isWithinATextBox(); Modified: main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -175,11 +175,11 @@ // ajust column amount to not add more items slot than we actually need const int item_count = m_items.size(); - std::cout << "item_count=" << item_count << ", row_amount*m_col_amount=" << m_row_amount*m_col_amount << std::endl; + //std::cout << "item_count=" << item_count << ", row_amount*m_col_amount=" << m_row_amount*m_col_amount << std::endl; if (m_row_amount*m_col_amount > item_count) { m_col_amount = (int)ceil((float)item_count/(float)m_row_amount); - std::cout << "Adjusting m_col_amount to be " << m_col_amount << std::endl; + //std::cout << "Adjusting m_col_amount to be " << m_col_amount << std::endl; } Modified: main/trunk/src/guiengine/widgets/icon_button_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/icon_button_widget.cpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/widgets/icon_button_widget.cpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -65,7 +65,10 @@ stringw& message = m_text; if (message.size() > 0) { - widget_size = rect<s32>(x, y + h, x + w, y + h*2); + //std::cout << "Adding label of icon widget, m_properties[PROP_EXTEND_LABEL] = " << m_properties[PROP_EXTEND_LABEL] << std::endl; + const int label_extra_size = ( m_properties[PROP_EXTEND_LABEL].size() == 0 ? + 0 : atoi(m_properties[PROP_EXTEND_LABEL].c_str()) ); + widget_size = rect<s32>(x - label_extra_size/2, y + h, x + w + label_extra_size/2, y + h*2); m_label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), widget_size, false, false /* word wrap */, m_parent); m_label->setTextAlignment(EGUIA_CENTER, EGUIA_UPPERLEFT); Modified: main/trunk/src/guiengine/widgets/ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/ribbon_widget.cpp 2009-12-27 16:23:38 UTC (rev 4351) +++ main/trunk/src/guiengine/widgets/ribbon_widget.cpp 2009-12-27 16:52:56 UTC (rev 4352) @@ -20,6 +20,8 @@ #include "guiengine/engine.hpp" #include "input/input_manager.hpp" #include "io/file_manager.hpp" +#include "utils/string_utils.hpp" + using namespace GUIEngine; using namespace irr::core; using namespace irr::gui; @@ -72,7 +74,8 @@ // ribbon children must not be keyboard navigatable, the parent ribbon takes care of that if (m_children[i].m_type == WTYPE_ICON_BUTTON) { - ((IconButtonWidget*)m_children.get(i))->m_tab_stop = false; + IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i)); + icon->m_tab_stop = false; } total_needed_space += m_children[i].w; @@ -116,6 +119,7 @@ 0, subsize.getHeight()+15, subsize.getHeight()); + // label at the *right* of the icon (for tabs) rect<s32> label_part = rect<s32>(subsize.getHeight()+15, 0, subsize.getWidth()-15, @@ -184,10 +188,13 @@ m_children[i].y = button_y; m_children[i].w = (int)(image_w*zoom); m_children[i].h = (int)(image_h*zoom); - //std::wcout << L"Widget has text '" << m_children[i].m_text.c_str() << "'\n"; + IconButtonWidget* icon = ((IconButtonWidget*)m_children.get(i)); + //std::cout << "Setting PROP_EXTEND_LABEL to " << (one_button_space - icon->w) << std::endl; + icon->m_properties[PROP_EXTEND_LABEL] = StringUtils::toString(one_button_space - icon->w); + m_children.get(i)->m_parent = btn; m_children.get(i)->add(); //subbtn->setUseAlphaChannel(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-01-23 19:55:25
|
Revision: 4519 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4519&view=rev Author: auria Date: 2010-01-23 19:55:19 +0000 (Sat, 23 Jan 2010) Log Message: ----------- Implemented lazy font loading, so that if we add chinese characters they are not loaded unless needed Modified Paths: -------------- main/trunk/src/guiengine/CGUIFont.cpp main/trunk/src/guiengine/CGUIFont.h Modified: main/trunk/src/guiengine/CGUIFont.cpp =================================================================== --- main/trunk/src/guiengine/CGUIFont.cpp 2010-01-23 16:24:42 UTC (rev 4518) +++ main/trunk/src/guiengine/CGUIFont.cpp 2010-01-23 19:55:19 UTC (rev 4519) @@ -84,13 +84,23 @@ //std::cout << "---- Adding font texture " << fn.c_str() << "; alpha=" << alpha.c_str() << std::endl; + // make sure the sprite bank has enough textures in it while (i+1 > SpriteBank->getTextureCount()) - SpriteBank->addTexture(0); + { + SpriteBank->addTexture(NULL); + } + TextureInfo info; + info.m_file_name = fn; + info.m_has_alpha = (alpha == core::stringw("false")); + // disable mipmaps+filtering //bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); + m_texture_files[i] = info; + + /* // load texture SpriteBank->setTexture(i, Driver->getTexture(fn)); @@ -110,6 +120,7 @@ if (alpha == core::stringw("false")) Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0)); } + */ } else if (core::stringw(L"c") == xml->getNodeName()) { @@ -226,30 +237,25 @@ //! loads a font file, native file needed, for texture parsing bool ScalableFont::load(io::IReadFile* file) { - if (!Driver) - return false; + if (!Driver) return false; - return loadTexture(Driver->createImageFromFile(file), - file->getFileName()); + return loadTexture(Driver->createImageFromFile(file), file->getFileName()); } //! loads a font file, native file needed, for texture parsing bool ScalableFont::load(const io::path& filename) { - if (!Driver) - return false; + if (!Driver) return false; - return loadTexture(Driver->createImageFromFile( filename ), - filename); + return loadTexture(Driver->createImageFromFile( filename ), filename); } //! load & prepare font from ITexture bool ScalableFont::loadTexture(video::IImage* image, const io::path& name) { - if (!image) - return false; + if (!image) return false; s32 lowerRightPositions = 0; @@ -489,8 +495,7 @@ void ScalableFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip) { - if (!Driver) - return; + if (!Driver) return; if (m_shadow) { @@ -510,38 +515,37 @@ core::dimension2d<s32> textDimension; core::position2d<s32> offset = position.UpperLeftCorner; - if (hcenter || vcenter || clip) - textDimension = getDimension(text.c_str()); + if (hcenter || vcenter || clip) textDimension = getDimension(text.c_str()); if (hcenter) { - offset.X += (position.getWidth() - textDimension.Width) >> 1; + offset.X += (position.getWidth() - textDimension.Width) / 2; } if (vcenter) - offset.Y += (position.getHeight() - textDimension.Height) >> 1; + { + offset.Y += (position.getHeight() - textDimension.Height) / 2; + } if (clip) { core::rect<s32> clippedRect(offset, textDimension); clippedRect.clipAgainst(*clip); - if (!clippedRect.isValid()) - return; + if (!clippedRect.isValid()) return; } core::array<u32> indices(text.size()); core::array<core::position2di> offsets(text.size()); - for(u32 i = 0;i < text.size();i++) + for (u32 i = 0;i < text.size();i++) { wchar_t c = text[i]; bool lineBreak=false; - if ( c == L'\r') // Windows breaks + if (c == L'\r') // Windows breaks { lineBreak = true; - if ( text[i + 1] == L'\n') // Windows breaks - c = text[++i]; + if (text[i + 1] == L'\n') c = text[++i]; } else if ( c == L'\n') // Unix breaks { @@ -595,7 +599,7 @@ // offsets[n].X << ", " << offsets[n].Y << "; size = " << source.getWidth() << ", " << source.getHeight() << std::endl; core::dimension2d<s32> size = source.getSize(); - size.Width = (int)(size.Width * m_scale); + size.Width = (int)(size.Width * m_scale); size.Height = (int)(size.Height * m_scale); core::rect<s32> dest(offsets[n], size); //std::cout << "source size = " << source.getWidth() << ", " << source.getHeight() << ", dest size = " << dest.getWidth() << ", " << dest.getHeight() << "; m_scale=" << m_scale << std::endl; @@ -603,6 +607,14 @@ video::SColor colors[] = {color, color, color, color}; video::ITexture* texture = SpriteBank->getTexture(texID); + if (texture == NULL) + { + // perform lazy loading + lazyLoadTexture(texID); + texture = SpriteBank->getTexture(texID); + assert(texture != NULL); + } + driver->draw2DImage(texture, dest, source, @@ -612,6 +624,31 @@ } +void ScalableFont::lazyLoadTexture(int texID) +{ + // load texture + SpriteBank->setTexture(texID, Driver->getTexture( m_texture_files[texID].m_file_name )); + + // set previous mip-map+filter state + //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap); + + // couldn't load texture, abort. + if (!SpriteBank->getTexture(texID)) + { + std::cerr << "!!!!! Unable to load all textures in the font" << std::endl; + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return; + } + else + { + // colorkey texture rather than alpha channel? + if (! m_texture_files[texID].m_has_alpha) + { + Driver->makeColorKeyTexture(SpriteBank->getTexture(texID), core::position2di(0,0)); + } + } +} + //! Calculates the index of the character in the text which is on a specific position. s32 ScalableFont::getCharacterFromPos(const wchar_t* text, s32 pixel_x) const { Modified: main/trunk/src/guiengine/CGUIFont.h =================================================================== --- main/trunk/src/guiengine/CGUIFont.h 2010-01-23 16:24:42 UTC (rev 4518) +++ main/trunk/src/guiengine/CGUIFont.h 2010-01-23 19:55:19 UTC (rev 4519) @@ -13,6 +13,7 @@ #include "IXMLReader.h" #include "IReadFile.h" #include "irrArray.h" +#include <map> namespace irr { @@ -33,6 +34,16 @@ float m_scale; bool m_shadow; irr::video::SColor m_shadow_color; + + struct TextureInfo + { + irr::core::stringc m_file_name; + bool m_has_alpha; + }; + + std::map<int /* texture file ID */, TextureInfo> m_texture_files; + + void lazyLoadTexture(int texID); public: //! constructor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-01-24 16:26:38
|
Revision: 4530 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=4530&view=rev Author: auria Date: 2010-01-24 16:26:31 +0000 (Sun, 24 Jan 2010) Log Message: ----------- Added fallback mechanism to font, as well as some graphical effect, so that the orange title font can now be used with any language Modified Paths: -------------- main/trunk/src/guiengine/CGUIFont.cpp main/trunk/src/guiengine/CGUIFont.h main/trunk/src/guiengine/engine.cpp Modified: main/trunk/src/guiengine/CGUIFont.cpp =================================================================== --- main/trunk/src/guiengine/CGUIFont.cpp 2010-01-24 15:36:43 UTC (rev 4529) +++ main/trunk/src/guiengine/CGUIFont.cpp 2010-01-24 16:26:31 UTC (rev 4530) @@ -23,6 +23,10 @@ : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) { + m_fallback_font = NULL; + m_fallback_font_scale = 1.0f; + m_fallback_kerning_width = 0; + #ifdef _DEBUG setDebugName("ScalableFont"); #endif @@ -206,7 +210,7 @@ } // set bad character - WrongCharacter = getAreaFromCharacter(L' '); + WrongCharacter = getAreaFromCharacter(L' ', NULL); setMaxHeight(); @@ -279,7 +283,7 @@ }*/ readPositions(tmpImage, lowerRightPositions); - WrongCharacter = getAreaFromCharacter(L' '); + WrongCharacter = getAreaFromCharacter(L' ', NULL); // output warnings if (!lowerRightPositions || !SpriteBank->getSprites().size()) @@ -395,11 +399,11 @@ if (thisLetter) { - ret += Areas[getAreaFromCharacter(*thisLetter)].overhang; + ret += Areas[getAreaFromCharacter(*thisLetter, NULL)].overhang; if (previousLetter) { - ret += Areas[getAreaFromCharacter(*previousLetter)].underhang; + ret += Areas[getAreaFromCharacter(*previousLetter, NULL)].underhang; } } @@ -424,17 +428,30 @@ //! returns the sprite number from a given character u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const { - return Areas[getAreaFromCharacter(*c)].spriteno; + return Areas[getAreaFromCharacter(*c, NULL)].spriteno; } -s32 ScalableFont::getAreaFromCharacter(const wchar_t c) const +s32 ScalableFont::getAreaFromCharacter(const wchar_t c, bool* fallback_font) const { core::map<wchar_t, s32>::Node* n = CharacterMap.find(c); if (n) + { + if (fallback_font != NULL) *fallback_font = false; return n->getValue(); + } + else if (m_fallback_font != NULL && fallback_font != NULL) + { + //std::wcout << L"Font does not have this character : <" << c << L">, trying fallback font" << std::endl; + *fallback_font = true; + return m_fallback_font->getAreaFromCharacter(c, NULL); + } else + { + //std::wcout << L"This font does not have this character : <" << c << L">" << std::endl; + if (fallback_font != NULL) *fallback_font = false; return WrongCharacter; + } } void ScalableFont::setInvisibleCharacters( const wchar_t *s ) @@ -471,20 +488,23 @@ continue; } - const int areaID = getAreaFromCharacter(*p); - const SFontArea &area = Areas[areaID]; + bool fallback = false; + const int areaID = getAreaFromCharacter(*p, &fallback); + const SFontArea &area = (fallback ? m_fallback_font->Areas[areaID] : Areas[areaID]); thisLine.Width += area.underhang; - thisLine.Width += area.width + area.overhang + GlobalKerningWidth; + + + if (fallback) thisLine.Width += (area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width; + else thisLine.Width += area.width + area.overhang + GlobalKerningWidth; } dim.Height += thisLine.Height; - if (dim.Width < thisLine.Width) - dim.Width = thisLine.Width; + if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; // std::cout << "ScalableFont::getDimension returns : " << dim.Width << ", " << dim.Height << " --> "; - dim.Width = (int)(dim.Width * m_scale); + dim.Width = (int)(dim.Width * m_scale); dim.Height = (int)(dim.Height * m_scale); //std::cout << dim.Width << ", " << dim.Height << std::endl; @@ -535,10 +555,12 @@ if (!clippedRect.isValid()) return; } - core::array<u32> indices(text.size()); - core::array<core::position2di> offsets(text.size()); - - for (u32 i = 0;i < text.size();i++) + const unsigned int text_size = text.size(); + core::array<u32> indices(text_size); + core::array<core::position2di> offsets(text_size); + std::vector<bool> fallback(text_size); + + for (u32 i = 0;i < text_size;i++) { wchar_t c = text[i]; @@ -566,18 +588,21 @@ continue; } - const int areaID = getAreaFromCharacter(c); + bool fallback_font = false; + const int areaID = getAreaFromCharacter(c, &fallback_font); //std::cout << "Char " << c << " has area " << areaID << std::endl; - SFontArea& area = Areas[areaID]; + SFontArea& area = (fallback_font ? m_fallback_font->Areas[areaID] : Areas[areaID]); offset.X += area.underhang; if ( Invisible.findFirst ( c ) < 0 ) { indices.push_back(area.spriteno); offsets.push_back(offset); + fallback[i] = fallback_font; } - - offset.X += (int)((area.width + area.overhang + GlobalKerningWidth) * m_scale); + + if (fallback[i]) offset.X += (int)(((area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width) * m_scale); + else offset.X += (int)((area.width + area.overhang + GlobalKerningWidth) * m_scale); } //SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color); @@ -585,34 +610,66 @@ const int indiceAmount = indices.size(); core::array< SGUISprite >& sprites = SpriteBank->getSprites(); core::array< core::rect<s32> >& positions = SpriteBank->getPositions(); + + core::array< SGUISprite >* fallback_sprites = (m_fallback_font != NULL ? + &m_fallback_font->SpriteBank->getSprites() : + NULL); + core::array< core::rect<s32> >* fallback_positions = (m_fallback_font != NULL ? + &m_fallback_font->SpriteBank->getPositions() : + NULL); + video::IVideoDriver* driver = GUIEngine::getDriver(); const int spriteAmount = sprites.size(); for (int n=0; n<indiceAmount; n++) { const int spriteID = indices[n]; - if (spriteID < 0 || spriteID >= spriteAmount) continue; + if (!fallback[n] && (spriteID < 0 || spriteID >= spriteAmount)) continue; - assert(sprites[spriteID].Frames.size() > 0); - const int texID = sprites[spriteID].Frames[0].textureNumber; - core::rect<s32> source = positions[sprites[spriteID].Frames[0].rectNumber]; + //assert(sprites[spriteID].Frames.size() > 0); - //std::cout << "Rendering " << source.UpperLeftCorner.X << ", " << source.UpperLeftCorner.Y << " to " << - // offsets[n].X << ", " << offsets[n].Y << "; size = " << source.getWidth() << ", " << source.getHeight() << std::endl; + const int texID = (fallback[n] ? + (*fallback_sprites)[spriteID].Frames[0].textureNumber : + sprites[spriteID].Frames[0].textureNumber); + core::rect<s32> source = (fallback[n] ? + (*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] : + positions[sprites[spriteID].Frames[0].rectNumber]); + core::dimension2d<s32> size = source.getSize(); size.Width = (int)(size.Width * m_scale); size.Height = (int)(size.Height * m_scale); - core::rect<s32> dest(offsets[n], size); - //std::cout << "source size = " << source.getWidth() << ", " << source.getHeight() << ", dest size = " << dest.getWidth() << ", " << dest.getHeight() << "; m_scale=" << m_scale << std::endl; + core::rect<s32> dest(offsets[n], (fallback[n] ? size*m_fallback_font_scale : size)); video::SColor colors[] = {color, color, color, color}; + + video::ITexture* texture = (fallback[n] ? + m_fallback_font->SpriteBank->getTexture(texID) : + SpriteBank->getTexture(texID) ); - video::ITexture* texture = SpriteBank->getTexture(texID); + /* + if (fallback[n]) + { + std::cout << "USING fallback font " << core::stringc(texture->getName()).c_str() << + "; source area is " << source.UpperLeftCorner.X << ", " << source.UpperLeftCorner.Y << + ", size " << source.getWidth() << ", " << source.getHeight() << "; dest = " << + offsets[n].X << ", " << offsets[n].Y << std::endl; + }*/ + if (texture == NULL) { // perform lazy loading - lazyLoadTexture(texID); - texture = SpriteBank->getTexture(texID); + + if (fallback[n]) + { + m_fallback_font->lazyLoadTexture(texID); + texture = m_fallback_font->SpriteBank->getTexture(texID); + } + else + { + lazyLoadTexture(texID); + texture = SpriteBank->getTexture(texID); + } + if (texture == NULL) { std::cerr << "WARNING: character not found in current font\n"; @@ -620,11 +677,43 @@ } } - driver->draw2DImage(texture, - dest, - source, - clip, - colors, true); + if (fallback[n]) + { + // draw black border + static video::SColor black(255,0,0,0); + video::SColor black_colors[] = {black, black, black, black}; + + for (int x_delta=-2; x_delta<=2; x_delta++) + { + for (int y_delta=-2; y_delta<=2; y_delta++) + { + if (x_delta == 0 || y_delta == 0) continue; + driver->draw2DImage(texture, + dest + core::position2d<s32>(x_delta, y_delta), + source, + clip, + black_colors, true); + } + } + + // draw text over + static video::SColor orange(255, 255, 100, 0); + static video::SColor yellow(255, 255, 220, 15); + video::SColor title_colors[] = {yellow, orange, orange, yellow}; + driver->draw2DImage(texture, + dest, + source, + clip, + title_colors, true); + } + else + { + driver->draw2DImage(texture, + dest, + source, + clip, + colors, true); + } } } @@ -662,7 +751,7 @@ while (text[idx]) { - const SFontArea& a = Areas[getAreaFromCharacter(text[idx])]; + const SFontArea& a = Areas[getAreaFromCharacter(text[idx], NULL)]; x += a.width + a.overhang + a.underhang + GlobalKerningWidth; Modified: main/trunk/src/guiengine/CGUIFont.h =================================================================== --- main/trunk/src/guiengine/CGUIFont.h 2010-01-24 15:36:43 UTC (rev 4529) +++ main/trunk/src/guiengine/CGUIFont.h 2010-01-24 16:26:31 UTC (rev 4530) @@ -46,6 +46,10 @@ void lazyLoadTexture(int texID); public: + ScalableFont* m_fallback_font; + float m_fallback_font_scale; + int m_fallback_kerning_width; + //! constructor ScalableFont(IGUIEnvironment* env, const io::path& filename); @@ -112,7 +116,7 @@ void readPositions(video::IImage* texture, s32& lowerRightPositions); - s32 getAreaFromCharacter (const wchar_t c) const; + s32 getAreaFromCharacter (const wchar_t c, bool* fallback_font) const; void setMaxHeight(); core::array<SFontArea> Areas; Modified: main/trunk/src/guiengine/engine.cpp =================================================================== --- main/trunk/src/guiengine/engine.cpp 2010-01-24 15:36:43 UTC (rev 4529) +++ main/trunk/src/guiengine/engine.cpp 2010-01-24 16:26:31 UTC (rev 4530) @@ -211,6 +211,9 @@ g_font = sfont; ScalableFont* sfont2 = new ScalableFont(g_env, file_manager->getFontFile("title_font.xml").c_str() ); + sfont2->m_fallback_font = sfont; + sfont2->m_fallback_font_scale = 4.0f; // because the fallback font is much smaller than the title font + sfont2->m_fallback_kerning_width = 15; sfont2->setScale(title_text_scale); sfont2->setKerningWidth(-18); g_title_font = sfont2; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-03-27 18:49:41
|
Revision: 5083 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5083&view=rev Author: auria Date: 2010-03-27 18:49:35 +0000 (Sat, 27 Mar 2010) Log Message: ----------- Render scrollbar in some way (not skinnable yet) when the list of players is very long Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/skin.hpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2010-03-27 18:11:00 UTC (rev 5082) +++ main/trunk/src/guiengine/skin.cpp 2010-03-27 18:49:35 UTC (rev 5083) @@ -1089,6 +1089,27 @@ } +void Skin::drawScrollbarBackground(const irr::core::rect< irr::s32 > &rect) +{ + //TODO: allow skinning scrollbar + GUIEngine::getDriver()->draw2DRectangle( video::SColor(255,200,200,200), rect ); +} + +void Skin::drawScrollbarThumb(const irr::core::rect< irr::s32 > &rect) +{ + //TODO: allow skinning scrollbar + GUIEngine::getDriver()->draw2DRectangle( video::SColor(255,0,150,0), rect ); +} + +void Skin::drawScrollbarButton(const irr::core::rect< irr::s32 > &rect, const bool pressed) +{ + //TODO: allow skinning scrollbar + GUIEngine::getDriver()->draw2DRectangle( (pressed ? + video::SColor(255, 0, 175, 0) : + video::SColor(255, 150, 150, 150)), + rect ); +} + #if 0 #pragma mark - #pragma mark irrlicht skin functions @@ -1098,6 +1119,12 @@ { if (GUIEngine::getStateManager()->getGameState() == GUIEngine::GAME) return; // ignore in game mode + if (element->getType()==gui::EGUIET_SCROLL_BAR) + { + drawScrollbarBackground(rect); + return; + } + const int id = element->getID(); Widget* widget = GUIEngine::getWidget(id); @@ -1107,7 +1134,7 @@ const bool focused = GUIEngine::isFocusedForPlayer(widget, playerID); const WidgetType type = widget->m_type; - if(type == WTYPE_LIST) + if (type == WTYPE_LIST) { // list selection background drawListSelection(rect, widget, focused); @@ -1123,7 +1150,16 @@ Widget* widget = NULL; if (id != -1) widget = GUIEngine::getWidget(id); - if (widget == NULL) return; + if (widget == NULL) + { + if (element->getType() == gui::EGUIET_BUTTON && element->getParent() != NULL && + element->getParent()->getType() == EGUIET_SCROLL_BAR) + { + drawScrollbarButton(rect, pressed); + } + + return; + } const int playerID = 0; // FIXME: don't hardcode player 0? const bool focused = GUIEngine::isFocusedForPlayer(widget, playerID); @@ -1252,7 +1288,14 @@ void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip) { - process3DPane(element, rect, false /* pressed */ ); + if (element->getType()==gui::EGUIET_SCROLL_BAR) + { + drawScrollbarThumb(rect); + } + else + { + process3DPane(element, rect, false /* pressed */ ); + } } // ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/skin.hpp =================================================================== --- main/trunk/src/guiengine/skin.hpp 2010-03-27 18:11:00 UTC (rev 5082) +++ main/trunk/src/guiengine/skin.hpp 2010-03-27 18:49:35 UTC (rev 5083) @@ -233,7 +233,12 @@ void drawListSelection(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused); void drawIconButton(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused); + void drawScrollbarBackground(const irr::core::rect< irr::s32 > &rect); + void drawScrollbarThumb(const irr::core::rect< irr::s32 > &rect); + void drawScrollbarButton(const irr::core::rect< irr::s32 > &rect, const bool pressed); + public: + // dirty way to have dialogs that zoom in bool m_dialog; float m_dialog_size; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-08 20:51:50
|
Revision: 5135 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5135&view=rev Author: auria Date: 2010-04-08 20:51:44 +0000 (Thu, 08 Apr 2010) Log Message: ----------- Removed a couple hardcoded player IDs, improved documentation in skin Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2010-04-08 20:50:57 UTC (rev 5134) +++ main/trunk/src/guiengine/skin.cpp 2010-04-08 20:51:44 UTC (rev 5135) @@ -23,6 +23,7 @@ #include "guiengine/screen.hpp" #include "guiengine/widget.hpp" #include "io/file_manager.hpp" +#include "states_screens/state_manager.hpp" #include <cassert> #include <iostream> @@ -592,6 +593,9 @@ } +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawButton(Widget* w, const core::rect< s32 > &rect, const bool pressed, const bool focused) { // if within an appearing dialog, grow @@ -636,21 +640,24 @@ { } +/** + * @param focused whether this element is focus by the master player (whether the widget is + * focused for other players is automatically determined) + * FIXME: ugly to pass some focuses through parameter and others not xD + */ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused) { // for now, when this kind of widget is disabled, just hide it. we can change that behaviour if // we ever need to... if (widget->m_deactivated) return; - const int playerID = 0; // FIXME : don't hardcode player 0 ? - - bool mark_selected = widget->isSelected(playerID); + bool mark_selected = widget->isSelected(GUI_PLAYER_ID); bool always_show_selection = false; IGUIElement* focusedElem = NULL; - if (GUIEngine::getFocusForPlayer(playerID) != NULL) + if (GUIEngine::getFocusForPlayer(GUI_PLAYER_ID) != NULL) { - focusedElem = GUIEngine::getFocusForPlayer(playerID)->getIrrlichtElement(); + focusedElem = GUIEngine::getFocusForPlayer(GUI_PLAYER_ID)->getIrrlichtElement(); } const bool parent_focused = (focusedElem == widget->m_event_handler->m_element); @@ -832,6 +839,11 @@ } +/** + * @param focused whether this element is focus by the master player (whether the widget is + * focused for other players is automatically determined) + * FIXME: ugly to pass some focuses through parameter and others not xD + */ void Skin::drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused) { if (!focused) @@ -931,6 +943,9 @@ } +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawSpinnerChild(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused) { if (pressed) @@ -945,8 +960,8 @@ else return; core::rect< s32 > rect2 = core::rect< s32 >( spinner->x, spinner->y, - spinner->x + spinner->w, - spinner->y + spinner->h ); + spinner->x + spinner->w, + spinner->y + spinner->h ); BoxRenderParams& params = SkinConfig::m_render_params["spinner::down"]; params.areas = areas; @@ -955,6 +970,9 @@ } +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawIconButton(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused) { // for now, when this kind of widget is disabled, just hide it. we can change that behaviour if @@ -1023,6 +1041,9 @@ } +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawCheckBox(const core::rect< s32 > &rect, Widget* widget, bool focused) { // for now, when this kind of widget is disabled, just hide it. we can change that behaviour if @@ -1053,24 +1074,32 @@ 0 /* no clipping */, 0, true /* alpha */); } - +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawList(const core::rect< s32 > &rect, Widget* widget, bool focused) { drawBoxFromStretchableTexture(widget, rect, SkinConfig::m_render_params["list::neutral"]); } + +/** + * @param focused whether this element is focus by the master player (focus for other players is not supported) + */ void Skin::drawListSelection(const core::rect< s32 > &rect, Widget* widget, bool focused) { ListWidget* list = dynamic_cast<ListWidget*>(widget); assert(list != NULL); - if(focused) + if (focused) drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, SkinConfig::m_render_params["listitem::focused"]); else drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, SkinConfig::m_render_params["listitem::down"]); } -/** recusrive function to render all sections (recursion allows to easily travesre the tree of children and sub-children) */ +/** recusrive function to render all sections (recursion allows to easily travesre the tree of children + * and sub-children) + */ void Skin::renderSections(ptr_vector<Widget>* within_vector) { if (within_vector == NULL) within_vector = &getCurrentScreen()->m_widgets; @@ -1180,7 +1209,8 @@ #pragma mark irrlicht skin functions #endif -void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &rect, const core::rect< s32 > *clip) +void Skin::draw2DRectangle (IGUIElement *element, const video::SColor &color, const core::rect< s32 > &rect, + const core::rect< s32 > *clip) { if (GUIEngine::getStateManager()->getGameState() == GUIEngine::GAME) return; // ignore in game mode @@ -1194,14 +1224,13 @@ Widget* widget = GUIEngine::getWidget(id); if (widget == NULL) return; - - const int playerID = 0; // FIXME: don't hardcode player 0? - const bool focused = GUIEngine::isFocusedForPlayer(widget, playerID); - + const WidgetType type = widget->m_type; if (type == WTYPE_LIST) { - // list selection background + // lists not supported in multiplayer screens + const bool focused = GUIEngine::isFocusedForPlayer(widget, GUI_PLAYER_ID); + drawListSelection(rect, widget, focused); } } @@ -1231,11 +1260,11 @@ return; } - const int playerID = 0; // FIXME: don't hardcode player 0? - const bool focused = GUIEngine::isFocusedForPlayer(widget, playerID); + const bool focused = GUIEngine::isFocusedForPlayer(widget, GUI_PLAYER_ID); /* - std::cout << "Skin (3D Pane) : " << (widget == NULL ? "NULL!!" : widget->m_properties[PROP_ID].c_str()) << std::endl; + std::cout << "Skin (3D Pane) : " << (widget == NULL ? "NULL!!" : widget->m_properties[PROP_ID].c_str()) + << std::endl; if (widget == NULL) std::cout << "Null widget: ID=" << id << " type=" << element->getTypeName() << " x=" << rect.UpperLeftCorner.X << " y=" << rect.UpperLeftCorner.Y << @@ -1349,14 +1378,16 @@ } // ----------------------------------------------------------------------------- -void Skin::draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip) +void Skin::draw3DButtonPanePressed (IGUIElement *element, const core::rect< s32 > &rect, + const core::rect< s32 > *clip) { process3DPane(element, rect, true /* pressed */ ); } // ----------------------------------------------------------------------------- -void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip) +void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32 > &rect, + const core::rect< s32 > *clip) { if (element->getType()==gui::EGUIET_SCROLL_BAR) { @@ -1370,7 +1401,8 @@ // ----------------------------------------------------------------------------- -void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool flat, bool fillBackGround, const core::rect< s32 > &rect, const core::rect< s32 > *clip) +void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool flat, bool fillBackGround, + const core::rect< s32 > &rect, const core::rect< s32 > *clip) { const int id = element->getID(); Widget* widget = GUIEngine::getWidget(id); @@ -1378,13 +1410,11 @@ if (widget == NULL) return; const WidgetType type = widget->m_type; - - const int playerID = 0; // FIXME : don't hardcode player 0 ? - + IGUIElement* focusedElem = NULL; - if (GUIEngine::getFocusForPlayer(playerID) != NULL) + if (GUIEngine::getFocusForPlayer(GUI_PLAYER_ID) != NULL) { - focusedElem = GUIEngine::getFocusForPlayer(playerID)->getIrrlichtElement(); + focusedElem = GUIEngine::getFocusForPlayer(GUI_PLAYER_ID)->getIrrlichtElement(); } const bool focused = (focusedElem == element); @@ -1401,7 +1431,8 @@ borderArea.LowerRightCorner += position2d< s32 >( 2, 2 ); // if within an appearing dialog, grow - if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL && widget->m_parent->getType() == gui::EGUIET_WINDOW) + if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL && + widget->m_parent->getType() == gui::EGUIET_WINDOW) { core::position2d<u32> center = core::position2d<u32>(irr_driver->getFrameSize()/2); const float texture_size = sin(m_dialog_size*M_PI*0.5f); @@ -1421,7 +1452,8 @@ else { // if within an appearing dialog, grow - if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL && widget->m_parent->getType() == gui::EGUIET_WINDOW) + if (m_dialog && m_dialog_size < 1.0f && widget->m_parent != NULL && + widget->m_parent->getType() == gui::EGUIET_WINDOW) { core::position2d<u32> center = core::position2d<u32>(irr_driver->getFrameSize()/2); const float texture_size = sin(m_dialog_size*M_PI*0.5f); Modified: main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-04-08 20:50:57 UTC (rev 5134) +++ main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-04-08 20:51:44 UTC (rev 5135) @@ -18,6 +18,7 @@ #include "guiengine/engine.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" #include "io/file_manager.hpp" +#include "states_screens/state_manager.hpp" #include <sstream> @@ -629,8 +630,8 @@ { if (!m_has_label) return; - // FIXME? Don't hardcode player 0 (even though label can only work with a single player) - const int playerID = 0; + // only the master player can update the label + const int playerID = GUI_PLAYER_ID; RibbonWidget* row = from_this_ribbon ? from_this_ribbon : (RibbonWidget*)getSelectedRibbon(playerID); if (row == NULL) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-25 17:36:14
|
Revision: 5265 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5265&view=rev Author: auria Date: 2010-04-25 17:36:08 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Documentation improvements (some comment was misplaced and was attributed to the namespace and not the function inside the namespace where it belonged) Modified Paths: -------------- main/trunk/src/guiengine/screen.hpp main/trunk/src/guiengine/screen_loader.cpp Modified: main/trunk/src/guiengine/screen.hpp =================================================================== --- main/trunk/src/guiengine/screen.hpp 2010-04-25 17:21:51 UTC (rev 5264) +++ main/trunk/src/guiengine/screen.hpp 2010-04-25 17:36:08 UTC (rev 5265) @@ -71,6 +71,9 @@ /** * \ingroup guiengine + * \brief Loads a GUI screen from its XML file. + * Builds a hierarchy of Widget objects whose contents are a direct transcription of the XML file, + * with little analysis or layout performed on them. */ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to); Modified: main/trunk/src/guiengine/screen_loader.cpp =================================================================== --- main/trunk/src/guiengine/screen_loader.cpp 2010-04-25 17:21:51 UTC (rev 5264) +++ main/trunk/src/guiengine/screen_loader.cpp 2010-04-25 17:36:08 UTC (rev 5265) @@ -34,16 +34,8 @@ using namespace gui; using namespace GUIEngine; -/** - * Loads a GUI screen from its XML file. Builds a hierarchy of Widget objects whose - * contents are a direct transcription of the XML file, with little analysis or layout - * performed on them. - */ -namespace GUIEngine +void GUIEngine::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to) { - -void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to) -{ // parse XML file while(xml && xml->read()) { @@ -171,13 +163,13 @@ READ_PROPERTY(y, PROP_Y); READ_PROPERTY(layout, PROP_LAYOUT); READ_PROPERTY(align, PROP_ALIGN); - + READ_PROPERTY(icon, PROP_ICON); READ_PROPERTY(text_align, PROP_TEXT_ALIGN); READ_PROPERTY(min_value, PROP_MIN_VALUE); READ_PROPERTY(max_value, PROP_MAX_VALUE); READ_PROPERTY(square_items, PROP_SQUARE); - + READ_PROPERTY(max_width, PROP_MAX_WIDTH); READ_PROPERTY(max_height, PROP_MAX_HEIGHT); READ_PROPERTY(extend_label, PROP_EXTEND_LABEL); @@ -185,13 +177,13 @@ READ_PROPERTY(max_rows, PROP_MAX_ROWS); READ_PROPERTY(warp_around, PROP_WARP_AROUND); #undef READ_PROPERTY - + const char* text = xml->getAttributeValue( "text" ); if (text != NULL) { widget.m_text = _(text); } - + /* a new div starts here, continue parsing with this new div as new parent */ if (widget.getType() == WTYPE_DIV || widget.getType() == WTYPE_RIBBON) { @@ -222,5 +214,4 @@ }//end switch } // end while } // end function - -} // end namespace + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-25 17:58:28
|
Revision: 5266 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5266&view=rev Author: auria Date: 2010-04-25 17:58:22 +0000 (Sun, 25 Apr 2010) Log Message: ----------- More documentation improvements to GUI code. Fixed a couple old comments that were no longer valid and thus misleading. Modified Paths: -------------- main/trunk/src/guiengine/engine.cpp main/trunk/src/guiengine/engine.hpp main/trunk/src/guiengine/screen.hpp main/trunk/src/guiengine/widget.cpp Modified: main/trunk/src/guiengine/engine.cpp =================================================================== --- main/trunk/src/guiengine/engine.cpp 2010-04-25 17:36:08 UTC (rev 5265) +++ main/trunk/src/guiengine/engine.cpp 2010-04-25 17:58:22 UTC (rev 5266) @@ -363,10 +363,25 @@ Once you have instanciated your state manager class, call GUIEngine::init and pass it as argument. One of the most important callbacks is 'eventCallback', which will be called everytime sometimes happens. Events are generally a widget state change. In this case, a pointer to the said widget is passed along its - name, so you get its new state and/or act. There are two special events, passed with a NULL widget, and which - bear the names "init" and "tearDown", called respectively when a screen is being made visible and when it's - being left, allowing for setup/clean-up. + name, so you get its new state and/or act. + When you have described the general layout of a Screen in a XML file, as described above, you may use it + in the code by creating a class deriving from GUIEngine::Screen, passing the name of the XML file to the + constructor of the base class. The derived class will most notably be used for event callbacks, to allow + creating interactive menus. The derived class must also implement the GUIEngine::Screen::init and + GUIEngine::Screen::tearDown methods, that will be called, respectively, when a menu is entered/left. For + simple menus, it is not unexpected that those methods do nothing. + + Note that the same instance of your object may be entered/left more than once, so make sure that one instance + of your object can be used several times if the same screen is visited several times. + + You can also explore the various methods in GUIEngine::Screen to discover more optional callbacks you + can use. + + You can also create dialogs by deriving from GUIEngine::ModalDialog. Unfortunately, it is currently not + possible to specify modal dialogs through XML files (FIXME), so you will need to simulate the init + sequence of a GUI screen, which I admit is not too easy. This is to improve in the future. + */ #include "guiengine/engine.hpp" Modified: main/trunk/src/guiengine/engine.hpp =================================================================== --- main/trunk/src/guiengine/engine.hpp 2010-04-25 17:36:08 UTC (rev 5265) +++ main/trunk/src/guiengine/engine.hpp 2010-04-25 17:58:22 UTC (rev 5266) @@ -34,6 +34,8 @@ /** * \ingroup guiengine * \brief Contains all GUI engine related classes and functions + * + * See \ref gui_overview for more information. */ namespace GUIEngine { Modified: main/trunk/src/guiengine/screen.hpp =================================================================== --- main/trunk/src/guiengine/screen.hpp 2010-04-25 17:36:08 UTC (rev 5265) +++ main/trunk/src/guiengine/screen.hpp 2010-04-25 17:58:22 UTC (rev 5266) @@ -119,8 +119,16 @@ (useful e.g. on reschange, when sizes have changed and must be re-calculated) */ virtual void forgetWhatWasLoaded(); - Screen(); /**< creates a dummy incomplete object; only use to override behaviour in sub-class */ + /** \brief creates a dummy incomplete object; only use to override behaviour in sub-class */ + Screen(); + + /** + * \brief creates a screen populated by the widgets described in a STK GUI file + * \param filename name of the XML file describing the screen. this is NOT a path. + * The passed file name will be searched for in the STK data/gui directory + */ Screen(const char* filename); + virtual ~Screen(); bool operator ==(const char* filename) const { return m_filename == filename; } @@ -147,25 +155,58 @@ Widget* getFirstWidget(ptr_vector<Widget>* within_vector=NULL); Widget* getLastWidget(ptr_vector<Widget>* within_vector=NULL); - virtual void addWidgets(); - virtual void calculateLayout(); + /** \brief adds the irrLicht widgets corresponding to this screen to the IGUIEnvironment */ + void addWidgets(); + /** called after all widgets have been added. namely expands layouts into absolute positions */ + void calculateLayout(); + + /** \brief can be used for custom purposes for which the load-screen-from-XML code won't make it */ void manualAddWidget(Widget* w); + + /** \brief can be used for custom purposes for which the load-screen-from-XML code won't make it */ void manualRemoveWidget(Widget* w); + /** \return the name of this menu (which is the name of the file) */ const std::string& getName() const { return m_filename; } void elementsWereDeleted(ptr_vector<Widget>* within_vector = NULL); /** Will be called to determine if the 3D scene must be rendered when at this screen */ bool needs3D() { return m_render_3d; } + + /** \brief invoke this method for screens that use a 3D scene as background + * + * (if this method is not invoked with 'true' as parameter, the menu background will + * be rendered instead). + * + * \note to create the 3D background, use the facilities provided by the irrLicht scene + * manager, this class will not set up any 3D scene. + */ void setNeeds3D(bool needs3D) { m_render_3d = needs3D; } + /** + * \brief callback invoked when entering this menu + * + * @note the same instance of your object may be entered/left more than once, so make sure that + * one instance of your object can be used several times if the same screen is visited several + * times. + */ virtual void init() = 0; + + /** + * \brief callback invoked before leaving this menu + * + * @note the same instance of your object may be entered/left more than once, so make sure that + * one instance of your object can be used several times if the same screen is visited several + * times. + */ virtual void tearDown() = 0; - /** Called when escape is pressed. - * @return true if the screen should be closed, false if you handled the press another way */ + /** + * \brief Called when escape is pressed. + * \return true if the screen should be closed, false if you handled the press another way + */ virtual bool onEscapePressed() { return true; } /** Modified: main/trunk/src/guiengine/widget.cpp =================================================================== --- main/trunk/src/guiengine/widget.cpp 2010-04-25 17:36:08 UTC (rev 5265) +++ main/trunk/src/guiengine/widget.cpp 2010-04-25 17:58:22 UTC (rev 5266) @@ -135,9 +135,10 @@ namespace GUIEngine { // IDs must not start at 0, since it appears their GUI engine hardcodes some ID values... xD + /** Used to assign irrLicht IDs to widgets dynamically */ static unsigned int id_counter = 100; - /** // for items that can't be reached with keyboard navigation but can be clicked */ + /** for items that can't be reached with keyboard navigation but can be clicked */ static unsigned int id_counter_2 = 1000; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-25 18:23:00
|
Revision: 5268 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5268&view=rev Author: auria Date: 2010-04-25 18:22:53 +0000 (Sun, 25 Apr 2010) Log Message: ----------- Fixed skin glitch with list selection rendering : clip the selection image when drawing it very near the edge and half the image is outside the list Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/skin.hpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2010-04-25 18:11:36 UTC (rev 5267) +++ main/trunk/src/guiengine/skin.cpp 2010-04-25 18:22:53 UTC (rev 5268) @@ -326,7 +326,8 @@ } void Skin::drawBoxFromStretchableTexture(SkinWidgetContainer* w, const core::rect< s32 > &dest, - BoxRenderParams& params, bool deactivated) + BoxRenderParams& params, bool deactivated, + const core::rect<s32>* clipRect) { // check if widget moved. if so, recalculate coords if (w->x != dest.UpperLeftCorner.X || w->y != dest.UpperLeftCorner.Y || @@ -539,51 +540,51 @@ if ((areas & BoxRenderParams::LEFT) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_left, source_area_left, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ((areas & BoxRenderParams::BODY) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_center, source_area_center, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ((areas & BoxRenderParams::RIGHT) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_right, source_area_right, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ((areas & BoxRenderParams::TOP) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top, source_area_top, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ((areas & BoxRenderParams::BOTTOM) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom, source_area_bottom, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top_left, source_area_top_left, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top_right, source_area_top_right, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom_left, source_area_bottom_left, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if ( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom_right, source_area_bottom_right, - 0 /* no clipping */, colorptr, true /* alpha */); + clipRect, colorptr, true /* alpha */); } if (colorptr != NULL) @@ -1090,15 +1091,22 @@ /** * @param focused whether this element is focus by the master player (focus for other players is not supported) */ -void Skin::drawListSelection(const core::rect< s32 > &rect, Widget* widget, bool focused) +void Skin::drawListSelection(const core::rect< s32 > &rect, Widget* widget, bool focused, + const core::rect< s32 > *clip) { ListWidget* list = dynamic_cast<ListWidget*>(widget); assert(list != NULL); if (focused) - drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, SkinConfig::m_render_params["listitem::focused"]); + { + drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, + SkinConfig::m_render_params["listitem::focused"], false, clip); + } else - drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, SkinConfig::m_render_params["listitem::down"]); + { + drawBoxFromStretchableTexture(&list->m_selection_skin_info, rect, + SkinConfig::m_render_params["listitem::down"], false, clip); + } } /** recursive function to render all sections (recursion allows to easily traverse the tree of children @@ -1235,7 +1243,7 @@ // lists not supported in multiplayer screens const bool focused = GUIEngine::isFocusedForPlayer(widget, PLAYER_ID_GAME_MASTER); - drawListSelection(rect, widget, focused); + drawListSelection(rect, widget, focused, clip); } } Modified: main/trunk/src/guiengine/skin.hpp =================================================================== --- main/trunk/src/guiengine/skin.hpp 2010-04-25 18:11:36 UTC (rev 5267) +++ main/trunk/src/guiengine/skin.hpp 2010-04-25 18:22:53 UTC (rev 5268) @@ -172,6 +172,7 @@ /** * \brief class containing render params for the 'drawBoxFromStretchableTexture' function + * see \ref skin for more information about skinning in STK * \ingroup guiengine */ class BoxRenderParams @@ -231,6 +232,7 @@ /** * \brief Object used to render the GUI widgets + * see \ref skin for more information about skinning in STK * \ingroup guiengine */ class Skin : public irr::gui::IGUISkin @@ -242,7 +244,8 @@ void drawBoxFromStretchableTexture(SkinWidgetContainer* w, const irr::core::rect< irr::s32 > &dest, - BoxRenderParams& params, bool deactivated=false); + BoxRenderParams& params, bool deactivated=false, + const irr::core::rect<irr::s32>* clipRect=NULL); // my utility methods, to work around irrlicht's very Windows-95-like-look-enforcing skin system void process3DPane(irr::gui::IGUIElement *element, const irr::core::rect< irr::s32 > &rect, const bool pressed); @@ -255,7 +258,7 @@ void drawGaugeFill(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused); void drawCheckBox(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused); void drawList(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused); - void drawListSelection(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused); + void drawListSelection(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused, const irr::core::rect< irr::s32 > *clip); void drawIconButton(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused); void drawScrollbarBackground(const irr::core::rect< irr::s32 > &rect); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-26 23:15:05
|
Revision: 5282 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5282&view=rev Author: auria Date: 2010-04-26 23:14:59 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Some code cleanup, that might have fixed JoergH's build problem on the way Modified Paths: -------------- main/trunk/src/guiengine/screen.hpp main/trunk/src/guiengine/screen_loader.cpp main/trunk/src/guiengine/widget.hpp Modified: main/trunk/src/guiengine/screen.hpp =================================================================== --- main/trunk/src/guiengine/screen.hpp 2010-04-26 22:39:41 UTC (rev 5281) +++ main/trunk/src/guiengine/screen.hpp 2010-04-26 23:14:59 UTC (rev 5282) @@ -70,14 +70,6 @@ }; /** - * \ingroup guiengine - * \brief Loads a GUI screen from its XML file. - * Builds a hierarchy of Widget objects whose contents are a direct transcription of the XML file, - * with little analysis or layout performed on them. - */ - void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to); - - /** * \brief Represents a single GUI screen. * Mainly responsible of its children widgets; Screen lays them * out, asks them to add themselves, asks them to remove themselves, etc. @@ -109,6 +101,14 @@ bool m_throttle_FPS; + /** + * \ingroup guiengine + * \brief Loads a GUI screen from its XML file. + * Builds a hierarchy of Widget objects whose contents are a direct transcription of the XML file, + * with little analysis or layout performed on them. + */ + static void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to); + public: @@ -226,6 +226,8 @@ virtual void eventCallback(Widget* widget, const std::string& name, const int playerID) = 0; virtual void onUpdate(float dt, irr::video::IVideoDriver*) { }; + + }; } Modified: main/trunk/src/guiengine/screen_loader.cpp =================================================================== --- main/trunk/src/guiengine/screen_loader.cpp 2010-04-26 22:39:41 UTC (rev 5281) +++ main/trunk/src/guiengine/screen_loader.cpp 2010-04-26 23:14:59 UTC (rev 5282) @@ -34,7 +34,7 @@ using namespace gui; using namespace GUIEngine; -void GUIEngine::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to) +void Screen::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to) { // parse XML file while(xml && xml->read()) Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2010-04-26 22:39:41 UTC (rev 5281) +++ main/trunk/src/guiengine/widget.hpp 2010-04-26 23:14:59 UTC (rev 5282) @@ -111,9 +111,7 @@ */ class Widget : public SkinWidgetContainer { - protected: - friend void GUIEngine::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to); - + protected: unsigned int m_magic_number; friend class EventHandler; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-04-26 23:20:17
|
Revision: 5284 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5284&view=rev Author: auria Date: 2010-04-26 23:20:11 +0000 (Mon, 26 Apr 2010) Log Message: ----------- Sorry, I screwed up. Fixed previous commit Modified Paths: -------------- main/trunk/src/guiengine/widget.hpp main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2010-04-26 23:16:01 UTC (rev 5283) +++ main/trunk/src/guiengine/widget.hpp 2010-04-26 23:20:11 UTC (rev 5284) @@ -117,6 +117,9 @@ friend class EventHandler; friend class Screen; friend class Skin; + friend class RibbonWidget; + friend class SpinnerWidget; + friend class DynamicRibbonWidget; /** When true, this widget shall use a bigger and more colourful font */ bool m_title_font; @@ -285,6 +288,11 @@ m_badges = 0; } + int getBadges() const + { + return m_badges; + } + /** Set to false if widget is something that should not receieve focus */ bool m_focusable; Modified: main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-04-26 23:16:01 UTC (rev 5283) +++ main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-04-26 23:20:11 UTC (rev 5284) @@ -707,7 +707,7 @@ icon->m_properties[PROP_ID] = m_items[icon_id].m_code_name; icon->setLabel(m_items[icon_id].m_user_name); icon->m_text = m_items[icon_id].m_user_name; - icon->m_badges = m_items[icon_id].m_badges; + icon->m_badges = m_items[icon_id].getBadges(); //std::wcout << L"Setting widget text '" << icon->m_text.c_str() << L"'\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-05-02 17:27:24
|
Revision: 5345 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5345&view=rev Author: auria Date: 2010-05-02 17:27:17 +0000 (Sun, 02 May 2010) Log Message: ----------- Work around irrlicht list limitations with dark magic Modified Paths: -------------- main/trunk/src/guiengine/event_handler.cpp main/trunk/src/guiengine/widgets/list_widget.cpp main/trunk/src/guiengine/widgets/list_widget.hpp Modified: main/trunk/src/guiengine/event_handler.cpp =================================================================== --- main/trunk/src/guiengine/event_handler.cpp 2010-05-02 13:58:13 UTC (rev 5344) +++ main/trunk/src/guiengine/event_handler.cpp 2010-05-02 17:27:17 UTC (rev 5345) @@ -22,6 +22,7 @@ #include "guiengine/modaldialog.hpp" #include "guiengine/screen.hpp" #include "guiengine/widget.hpp" +#include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "input/input_manager.hpp" #include "states_screens/state_manager.hpp" @@ -389,19 +390,18 @@ // components if (w != NULL && w->m_type == WTYPE_LIST) { - IGUIListBox* list = (IGUIListBox*)(w->m_element); - assert(list != NULL); + ListWidget* list = (ListWidget*)w; - const bool stay_within_list = list->getSelected() > 0; + const bool stay_within_list = list->getSelectionID() > 0; if (stay_within_list) { - list->setSelected(list->getSelected()-1); + list->setSelectionID(list->getSelectionID()-1); return; } else { - list->setSelected(-1); + list->setSelectionID(-1); } } @@ -496,19 +496,18 @@ // components if (w != NULL && w->m_type == WTYPE_LIST) { - IGUIListBox* list = w->getIrrlichtElement<IGUIListBox>(); - assert(list != NULL); + ListWidget* list = (ListWidget*)w; - const bool stay_within_list = list->getSelected() < (int)list->getItemCount()-1; + const bool stay_within_list = list->getSelectionID() < list->getItemCount()-1; if (stay_within_list) { - list->setSelected(list->getSelected()+1); + list->setSelectionID(list->getSelectionID()+1); return; } else { - list->setSelected(-1); + list->setSelectionID(-1); } } Modified: main/trunk/src/guiengine/widgets/list_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/list_widget.cpp 2010-05-02 13:58:13 UTC (rev 5344) +++ main/trunk/src/guiengine/widgets/list_widget.cpp 2010-05-02 17:27:17 UTC (rev 5345) @@ -39,6 +39,7 @@ rect<s32> widget_size = rect<s32>(x, y, x + w, y + h); IGUIListBox* list = GUIEngine::getGUIEnv()->addListBox (widget_size, m_parent, getNewID()); + list->setAutoScrollEnabled(false); if (m_use_icons) { @@ -115,3 +116,37 @@ } // ----------------------------------------------------------------------------- + +int ListWidget::getSelectionID() const +{ + return getIrrlichtElement<IGUIListBox>()->getSelected(); +} + +// ----------------------------------------------------------------------------- + +void ListWidget::setSelectionID(const int index) +{ + IGUIListBox* irritem = getIrrlichtElement<IGUIListBox>(); + + // auto-scroll to item when selecting something, don't auto-scroll when selecting nothing + if (index != -1) + { + irritem->setAutoScrollEnabled(true); + } + + irritem->setSelected(index); + + if (index != -1) + { + irritem->setAutoScrollEnabled(false); + } +} + +// ----------------------------------------------------------------------------- + +int ListWidget::getItemCount() const +{ + return getIrrlichtElement<IGUIListBox>()->getItemCount(); +} + +// ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/widgets/list_widget.hpp =================================================================== --- main/trunk/src/guiengine/widgets/list_widget.hpp 2010-05-02 13:58:13 UTC (rev 5344) +++ main/trunk/src/guiengine/widgets/list_widget.hpp 2010-05-02 17:27:17 UTC (rev 5345) @@ -47,6 +47,18 @@ int getSelection() const; std::string getSelectionName() const; void clear(); + + /** \return the number of items in the list */ + int getItemCount() const; + + /** \return the index of the selected element within the list, or -1 if none */ + int getSelectionID() const; + + /** + * \brief change the selected item + * \param index the index of the element to select within the list, or -1 to select nothing + */ + void setSelectionID(const int index); }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-05-08 18:41:32
|
Revision: 5414 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5414&view=rev Author: auria Date: 2010-05-08 18:41:26 +0000 (Sat, 08 May 2010) Log Message: ----------- Fixed left/right ribbon arrows Modified Paths: -------------- main/trunk/src/guiengine/event_handler.cpp main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp Modified: main/trunk/src/guiengine/event_handler.cpp =================================================================== --- main/trunk/src/guiengine/event_handler.cpp 2010-05-08 18:24:26 UTC (rev 5413) +++ main/trunk/src/guiengine/event_handler.cpp 2010-05-08 18:41:26 UTC (rev 5414) @@ -480,8 +480,6 @@ Widget* w = GUIEngine::getWidget(id); if (w == NULL) break; - if (!w->m_focusable) return GUIEngine::EVENT_BLOCK; - // These events are only triggered by keyboard/mouse (or so I hope...) const int playerID = input_manager->getPlayerKeyboardID(); if (input_manager->masterPlayerOnly() && playerID != PLAYER_ID_GAME_MASTER) break; Modified: main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-05-08 18:24:26 UTC (rev 5413) +++ main/trunk/src/guiengine/widgets/dynamic_ribbon_widget.cpp 2010-05-08 18:41:26 UTC (rev 5414) @@ -504,7 +504,7 @@ EventPropagation DynamicRibbonWidget::transmitEvent(Widget* w, std::string& originator, const int playerID) { if (m_deactivated) return EVENT_LET; - + if (originator=="left") { scroll(-1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-07-19 03:37:06
|
Revision: 5697 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5697&view=rev Author: hikerstk Date: 2010-07-19 03:36:59 +0000 (Mon, 19 Jul 2010) Log Message: ----------- Replaced tabs with spaces. Modified Paths: -------------- main/trunk/src/guiengine/CGUIFont.cpp main/trunk/src/guiengine/CGUIFont.h main/trunk/src/guiengine/CGUISpriteBank.cpp main/trunk/src/guiengine/CGUISpriteBank.h Modified: main/trunk/src/guiengine/CGUIFont.cpp =================================================================== --- main/trunk/src/guiengine/CGUIFont.cpp 2010-07-19 00:14:06 UTC (rev 5696) +++ main/trunk/src/guiengine/CGUIFont.cpp 2010-07-19 03:36:59 UTC (rev 5697) @@ -22,7 +22,7 @@ //! constructor ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename) : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), - MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) + MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) { m_fallback_font = NULL; m_fallback_font_scale = 1.0f; @@ -32,27 +32,27 @@ m_black_border = false; - #ifdef _DEBUG - setDebugName("ScalableFont"); - #endif + #ifdef _DEBUG + setDebugName("ScalableFont"); + #endif m_scale = 1.0f; m_shadow = false; - if (Environment) - { - // don't grab environment, to avoid circular references - Driver = Environment->getVideoDriver(); + if (Environment) + { + // don't grab environment, to avoid circular references + Driver = Environment->getVideoDriver(); - SpriteBank = Environment->addEmptySpriteBank(filename); - if (SpriteBank) - SpriteBank->grab(); - } + SpriteBank = Environment->addEmptySpriteBank(filename); + if (SpriteBank) + SpriteBank->grab(); + } - if (Driver) - Driver->grab(); + if (Driver) + Driver->grab(); - setInvisibleCharacters ( L" " ); + setInvisibleCharacters ( L" " ); load( file_manager->createXMLReader(filename.c_str()) ); assert(Areas.size() > 0); @@ -78,33 +78,33 @@ //! loads a font file from xml bool ScalableFont::load(io::IXMLReader* xml) { - if (!SpriteBank) - return false; + if (!SpriteBank) + return false; - while (xml->read()) - { - if (io::EXN_ELEMENT == xml->getNodeType()) - { - if (core::stringw(L"Texture") == xml->getNodeName()) - { - // add a texture + while (xml->read()) + { + if (io::EXN_ELEMENT == xml->getNodeType()) + { + if (core::stringw(L"Texture") == xml->getNodeName()) + { + // add a texture core::stringc filename = xml->getAttributeValue(L"filename"); - core::stringc fn = file_manager->getFontFile(filename.c_str()).c_str(); - u32 i = (u32)xml->getAttributeValueAsInt(L"index"); + core::stringc fn = file_manager->getFontFile(filename.c_str()).c_str(); + u32 i = (u32)xml->getAttributeValueAsInt(L"index"); float scale = xml->getAttributeValueAsFloat(L"scale"); if (scale < 0.01f) scale = 1.0f; // FIXME: how do you check if some property exists in a cleaner way? //std::cout << "scale = " << scale << std::endl; - core::stringw alpha = xml->getAttributeValue(L"hasAlpha"); + core::stringw alpha = xml->getAttributeValue(L"hasAlpha"); //std::cout << "---- Adding font texture " << fn.c_str() << "; alpha=" << alpha.c_str() << std::endl; // make sure the sprite bank has enough textures in it - while (i+1 > SpriteBank->getTextureCount()) + while (i+1 > SpriteBank->getTextureCount()) { - SpriteBank->addTexture(NULL); + SpriteBank->addTexture(NULL); } TextureInfo info; @@ -112,123 +112,123 @@ info.m_has_alpha = (alpha == core::stringw("true")); info.m_scale = scale; - // disable mipmaps+filtering - //bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); - //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); + // disable mipmaps+filtering + //bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); + //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); m_texture_files[i] = info; /* - // load texture - SpriteBank->setTexture(i, Driver->getTexture(fn)); + // load texture + SpriteBank->setTexture(i, Driver->getTexture(fn)); - // set previous mip-map+filter state - //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap); + // set previous mip-map+filter state + //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap); - // couldn't load texture, abort. - if (!SpriteBank->getTexture(i)) - { + // couldn't load texture, abort. + if (!SpriteBank->getTexture(i)) + { std::cerr << "!!!!! Unable to load all textures in the font, aborting" << std::endl; - _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; - return false; - } - else - { - // colorkey texture rather than alpha channel? - if (alpha == core::stringw("false")) - Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0)); - } + _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; + return false; + } + else + { + // colorkey texture rather than alpha channel? + if (alpha == core::stringw("false")) + Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0)); + } */ - } - else if (core::stringw(L"c") == xml->getNodeName()) - { - // adding a character to this font - SFontArea a; - SGUISpriteFrame f; - SGUISprite s; - core::rect<s32> rectangle; + } + else if (core::stringw(L"c") == xml->getNodeName()) + { + // adding a character to this font + SFontArea a; + SGUISpriteFrame f; + SGUISprite s; + core::rect<s32> rectangle; - a.underhang = xml->getAttributeValueAsInt(L"u"); - a.overhang = xml->getAttributeValueAsInt(L"o"); - a.spriteno = SpriteBank->getSprites().size(); - s32 texno = xml->getAttributeValueAsInt(L"i"); + a.underhang = xml->getAttributeValueAsInt(L"u"); + a.overhang = xml->getAttributeValueAsInt(L"o"); + a.spriteno = SpriteBank->getSprites().size(); + s32 texno = xml->getAttributeValueAsInt(L"i"); - // parse rectangle - core::stringc rectstr = xml->getAttributeValue(L"r"); - wchar_t ch = xml->getAttributeValue(L"c")[0]; + // parse rectangle + core::stringc rectstr = xml->getAttributeValue(L"r"); + wchar_t ch = xml->getAttributeValue(L"c")[0]; - const c8 *c = rectstr.c_str(); - s32 val; - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.UpperLeftCorner.X = val; - while (*c == L' ' || *c == L',') c++; + const c8 *c = rectstr.c_str(); + s32 val; + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.UpperLeftCorner.X = val; + while (*c == L' ' || *c == L',') c++; - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.UpperLeftCorner.Y = val; - while (*c == L' ' || *c == L',') c++; + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.UpperLeftCorner.Y = val; + while (*c == L' ' || *c == L',') c++; - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.LowerRightCorner.X = val; - while (*c == L' ' || *c == L',') c++; + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.LowerRightCorner.X = val; + while (*c == L' ' || *c == L',') c++; - val = 0; - while (*c >= '0' && *c <= '9') - { - val *= 10; - val += *c - '0'; - c++; - } - rectangle.LowerRightCorner.Y = val; + val = 0; + while (*c >= '0' && *c <= '9') + { + val *= 10; + val += *c - '0'; + c++; + } + rectangle.LowerRightCorner.Y = val; - CharacterMap[ch] = Areas.size(); + CharacterMap[ch] = Areas.size(); //std::cout << "Inserting character '" << (int)ch << "' with area " << Areas.size() << std::endl; - // make frame - f.rectNumber = SpriteBank->getPositions().size(); - f.textureNumber = texno; + // make frame + f.rectNumber = SpriteBank->getPositions().size(); + f.textureNumber = texno; - // add frame to sprite - s.Frames.push_back(f); - s.frameTime = 0; + // add frame to sprite + s.Frames.push_back(f); + s.frameTime = 0; - // add rectangle to sprite bank - SpriteBank->getPositions().push_back(rectangle); - a.width = rectangle.getWidth(); + // add rectangle to sprite bank + SpriteBank->getPositions().push_back(rectangle); + a.width = rectangle.getWidth(); - // add sprite to sprite bank - SpriteBank->getSprites().push_back(s); + // add sprite to sprite bank + SpriteBank->getSprites().push_back(s); - // add character to font - Areas.push_back(a); - } - } - } + // add character to font + Areas.push_back(a); + } + } + } - // set bad character - WrongCharacter = getAreaFromCharacter(L' ', NULL); + // set bad character + WrongCharacter = getAreaFromCharacter(L' ', NULL); - setMaxHeight(); + setMaxHeight(); - return true; + return true; } void ScalableFont::setScale(const float scale) { @@ -238,17 +238,17 @@ void ScalableFont::setMaxHeight() { // FIXME: should consider per-texture scaling - MaxHeight = 0; - s32 t; + MaxHeight = 0; + s32 t; - core::array< core::rect<s32> >& p = SpriteBank->getPositions(); + core::array< core::rect<s32> >& p = SpriteBank->getPositions(); - for (u32 i=0; i<p.size(); ++i) - { - t = p[i].getHeight(); - if (t>MaxHeight) - MaxHeight = t; - } + for (u32 i=0; i<p.size(); ++i) + { + t = p[i].getHeight(); + if (t>MaxHeight) + MaxHeight = t; + } } @@ -258,9 +258,9 @@ /* bool ScalableFont::load(io::IReadFile* file) { - if (!Driver) return false; + if (!Driver) return false; - return loadTexture(Driver->createImageFromFile(file), file->getFileName()); + return loadTexture(Driver->createImageFromFile(file), file->getFileName()); } */ @@ -268,9 +268,9 @@ /* bool ScalableFont::load(const io::path& filename) { - if (!Driver) return false; + if (!Driver) return false; - return loadTexture(Driver->createImageFromFile( filename ), filename); + return loadTexture(Driver->createImageFromFile( filename ), filename); } */ @@ -278,186 +278,186 @@ #if 0 bool ScalableFont::loadTexture(video::IImage* image, const io::path& name) { - if (!image) return false; + if (!image) return false; - s32 lowerRightPositions = 0; + s32 lowerRightPositions = 0; - video::IImage* tmpImage=image; + video::IImage* tmpImage=image; /* - bool deleteTmpImage=false; - switch(image->getColorFormat()) - { - case video::ECF_R5G6B5: - tmpImage = new video::CImage(video::ECF_A1R5G5B5,image); - deleteTmpImage=true; - break; - case video::ECF_A1R5G5B5: - case video::ECF_A8R8G8B8: - break; - case video::ECF_R8G8B8: - tmpImage = new video::CImage(video::ECF_A8R8G8B8,image); - deleteTmpImage=true; - break; - }*/ - readPositions(tmpImage, lowerRightPositions); + bool deleteTmpImage=false; + switch(image->getColorFormat()) + { + case video::ECF_R5G6B5: + tmpImage = new video::CImage(video::ECF_A1R5G5B5,image); + deleteTmpImage=true; + break; + case video::ECF_A1R5G5B5: + case video::ECF_A8R8G8B8: + break; + case video::ECF_R8G8B8: + tmpImage = new video::CImage(video::ECF_A8R8G8B8,image); + deleteTmpImage=true; + break; + }*/ + readPositions(tmpImage, lowerRightPositions); - WrongCharacter = getAreaFromCharacter(L' ', NULL); + WrongCharacter = getAreaFromCharacter(L' ', NULL); - // output warnings - if (!lowerRightPositions || !SpriteBank->getSprites().size()) - std::cerr << "Either no upper or lower corner pixels in the font file. If this font was made using the new font tool, please load the XML file instead. If not, the font may be corrupted.\n"; - else - if (lowerRightPositions != (s32)SpriteBank->getPositions().size()) - std::cerr << "The amount of upper corner pixels and the lower corner pixels is not equal, font file may be corrupted.\n"; + // output warnings + if (!lowerRightPositions || !SpriteBank->getSprites().size()) + std::cerr << "Either no upper or lower corner pixels in the font file. If this font was made using the new font tool, please load the XML file instead. If not, the font may be corrupted.\n"; + else + if (lowerRightPositions != (s32)SpriteBank->getPositions().size()) + std::cerr << "The amount of upper corner pixels and the lower corner pixels is not equal, font file may be corrupted.\n"; - bool ret = ( !SpriteBank->getSprites().empty() && lowerRightPositions ); + bool ret = ( !SpriteBank->getSprites().empty() && lowerRightPositions ); - if ( ret ) - { - bool flag[2]; - flag[0] = Driver->getTextureCreationFlag ( video::ETCF_ALLOW_NON_POWER_2 ); - flag[1] = Driver->getTextureCreationFlag ( video::ETCF_CREATE_MIP_MAPS ); + if ( ret ) + { + bool flag[2]; + flag[0] = Driver->getTextureCreationFlag ( video::ETCF_ALLOW_NON_POWER_2 ); + flag[1] = Driver->getTextureCreationFlag ( video::ETCF_CREATE_MIP_MAPS ); - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true); - Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true ); + Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true); + Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true ); - SpriteBank->addTexture(Driver->addTexture(name, tmpImage)); + SpriteBank->addTexture(Driver->addTexture(name, tmpImage)); - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flag[0] ); - Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flag[1] ); - } - //if (deleteTmpImage) - // tmpImage->drop(); - image->drop(); + Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flag[0] ); + Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flag[1] ); + } + //if (deleteTmpImage) + // tmpImage->drop(); + image->drop(); - setMaxHeight(); + setMaxHeight(); - return ret; + return ret; } #endif /* void ScalableFont::readPositions(video::IImage* image, s32& spriteID) { - const core::dimension2d<u32> size = image->getDimension(); + const core::dimension2d<u32> size = image->getDimension(); - video::SColor colorTopLeft = image->getPixel(0,0); - colorTopLeft.setAlpha(255); - image->setPixel(0,0,colorTopLeft); - video::SColor colorLowerRight = image->getPixel(1,0); - video::SColor colorBackGround = image->getPixel(2,0); - video::SColor colorBackGroundTransparent = 0; + video::SColor colorTopLeft = image->getPixel(0,0); + colorTopLeft.setAlpha(255); + image->setPixel(0,0,colorTopLeft); + video::SColor colorLowerRight = image->getPixel(1,0); + video::SColor colorBackGround = image->getPixel(2,0); + video::SColor colorBackGroundTransparent = 0; - image->setPixel(1,0,colorBackGround); + image->setPixel(1,0,colorBackGround); - // start parsing + // start parsing - core::position2d<s32> pos(0,0); - for (pos.Y=0; pos.Y<(s32)size.Height; ++pos.Y) - { - for (pos.X=0; pos.X<(s32)size.Width; ++pos.X) - { - const video::SColor c = image->getPixel(pos.X, pos.Y); - if (c == colorTopLeft) - { - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - SpriteBank->getPositions().push_back(core::rect<s32>(pos, pos)); - } - else - if (c == colorLowerRight) - { - // too many lower right points - if (SpriteBank->getPositions().size()<=(u32)spriteID) - { - spriteID = 0; - return; - } + core::position2d<s32> pos(0,0); + for (pos.Y=0; pos.Y<(s32)size.Height; ++pos.Y) + { + for (pos.X=0; pos.X<(s32)size.Width; ++pos.X) + { + const video::SColor c = image->getPixel(pos.X, pos.Y); + if (c == colorTopLeft) + { + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + SpriteBank->getPositions().push_back(core::rect<s32>(pos, pos)); + } + else + if (c == colorLowerRight) + { + // too many lower right points + if (SpriteBank->getPositions().size()<=(u32)spriteID) + { + spriteID = 0; + return; + } - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - SpriteBank->getPositions()[spriteID].LowerRightCorner = pos; - // add frame to sprite bank - SGUISpriteFrame f; - f.rectNumber = spriteID; - f.textureNumber = 0; - SGUISprite s; - s.Frames.push_back(f); - s.frameTime = 0; - SpriteBank->getSprites().push_back(s); - // add character to font - SFontArea a; - a.overhang = 0; - a.underhang = 0; - a.spriteno = spriteID; - a.width = SpriteBank->getPositions()[spriteID].getWidth(); - Areas.push_back(a); - // map letter to character - wchar_t ch = (wchar_t)(spriteID + 32); - CharacterMap[ch] = spriteID; + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + SpriteBank->getPositions()[spriteID].LowerRightCorner = pos; + // add frame to sprite bank + SGUISpriteFrame f; + f.rectNumber = spriteID; + f.textureNumber = 0; + SGUISprite s; + s.Frames.push_back(f); + s.frameTime = 0; + SpriteBank->getSprites().push_back(s); + // add character to font + SFontArea a; + a.overhang = 0; + a.underhang = 0; + a.spriteno = spriteID; + a.width = SpriteBank->getPositions()[spriteID].getWidth(); + Areas.push_back(a); + // map letter to character + wchar_t ch = (wchar_t)(spriteID + 32); + CharacterMap[ch] = spriteID; - ++spriteID; - } - else - if (c == colorBackGround) - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - } - } + ++spriteID; + } + else + if (c == colorBackGround) + image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); + } + } } */ //! set an Pixel Offset on Drawing ( scale position on width ) void ScalableFont::setKerningWidth(s32 kerning) { - GlobalKerningWidth = kerning; + GlobalKerningWidth = kerning; } //! set an Pixel Offset on Drawing ( scale position on width ) s32 ScalableFont::getKerningWidth(const wchar_t* thisLetter, const wchar_t* previousLetter) const { - s32 ret = GlobalKerningWidth; + s32 ret = GlobalKerningWidth; - if (thisLetter) - { - ret += Areas[getAreaFromCharacter(*thisLetter, NULL)].overhang; + if (thisLetter) + { + ret += Areas[getAreaFromCharacter(*thisLetter, NULL)].overhang; - if (previousLetter) - { - ret += Areas[getAreaFromCharacter(*previousLetter, NULL)].underhang; - } - } + if (previousLetter) + { + ret += Areas[getAreaFromCharacter(*previousLetter, NULL)].underhang; + } + } - return ret; + return ret; } //! set an Pixel Offset on Drawing ( scale position on height ) void ScalableFont::setKerningHeight(s32 kerning) { - GlobalKerningHeight = kerning; + GlobalKerningHeight = kerning; } //! set an Pixel Offset on Drawing ( scale position on height ) s32 ScalableFont::getKerningHeight () const { - return GlobalKerningHeight; + return GlobalKerningHeight; } //! returns the sprite number from a given character u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const { - return Areas[getAreaFromCharacter(*c, NULL)].spriteno; + return Areas[getAreaFromCharacter(*c, NULL)].spriteno; } s32 ScalableFont::getAreaFromCharacter(const wchar_t c, bool* fallback_font) const { - std::map<wchar_t, s32>::const_iterator n = CharacterMap.find(c); - if (n != CharacterMap.end()) + std::map<wchar_t, s32>::const_iterator n = CharacterMap.find(c); + if (n != CharacterMap.end()) { if (fallback_font != NULL) *fallback_font = false; - return (*n).second; + return (*n).second; } else if (m_fallback_font != NULL && fallback_font != NULL) { @@ -465,17 +465,17 @@ *fallback_font = true; return m_fallback_font->getAreaFromCharacter(c, NULL); } - else + else { //std::cout << "The font does not have this character : <" << (int)c << ">" << std::endl; if (fallback_font != NULL) *fallback_font = false; - return WrongCharacter; + return WrongCharacter; } } void ScalableFont::setInvisibleCharacters( const wchar_t *s ) { - Invisible = s; + Invisible = s; } @@ -484,50 +484,50 @@ { assert(Areas.size() > 0); - core::dimension2d<u32> dim(0, 0); - core::dimension2d<u32> thisLine(0, (int)(MaxHeight*m_scale)); + core::dimension2d<u32> dim(0, 0); + core::dimension2d<u32> thisLine(0, (int)(MaxHeight*m_scale)); - for (const wchar_t* p = text; *p; ++p) - { - bool lineBreak=false; - if (*p == L'\r') // Windows breaks - { - lineBreak = true; - if (p[1] == L'\n') // Windows breaks - ++p; - } - else if (*p == L'\n') // Unix breaks - { - lineBreak = true; - } - if (lineBreak) - { - dim.Height += thisLine.Height; - if (dim.Width < thisLine.Width) - dim.Width = thisLine.Width; - thisLine.Width = 0; - continue; - } + for (const wchar_t* p = text; *p; ++p) + { + bool lineBreak=false; + if (*p == L'\r') // Windows breaks + { + lineBreak = true; + if (p[1] == L'\n') // Windows breaks + ++p; + } + else if (*p == L'\n') // Unix breaks + { + lineBreak = true; + } + if (lineBreak) + { + dim.Height += thisLine.Height; + if (dim.Width < thisLine.Width) + dim.Width = thisLine.Width; + thisLine.Width = 0; + continue; + } bool fallback = false; const int areaID = getAreaFromCharacter(*p, &fallback); assert(areaID < (int)Areas.size()); - const SFontArea &area = (fallback ? m_fallback_font->Areas[areaID] : Areas[areaID]); + const SFontArea &area = (fallback ? m_fallback_font->Areas[areaID] : Areas[areaID]); //const TextureInfo& info = (*(m_texture_files.find(area.spriteno))).second; //const float char_scale = info.m_scale; - thisLine.Width += area.underhang; + thisLine.Width += area.underhang; thisLine.Width += getCharWidth(area, fallback); //if (fallback) thisLine.Width += (area.width + area.overhang)*m_fallback_font_scale*char_scale*m_scale + m_fallback_kerning_width; - //else thisLine.Width += (area.width + area.overhang)*m_scale*char_scale + GlobalKerningWidth; - } + //else thisLine.Width += (area.width + area.overhang)*m_scale*char_scale + GlobalKerningWidth; + } - dim.Height += thisLine.Height; - if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; + dim.Height += thisLine.Height; + if (dim.Width < thisLine.Width) dim.Width = thisLine.Width; // std::cout << "ScalableFont::getDimension returns : " << dim.Width << ", " << dim.Height << " --> "; @@ -536,14 +536,14 @@ //std::cout << dim.Width << ", " << dim.Height << std::endl; - return dim; + return dim; } //! draws some text and clips it to the specified rectangle if wanted void ScalableFont::draw(const core::stringw& text, const core::rect<s32>& position, - video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip) + video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip) { - if (!Driver) return; + if (!Driver) return; if (m_shadow) { @@ -560,41 +560,41 @@ //color = video::SColor(255,255,255,255); - core::dimension2d<s32> textDimension; - core::position2d<s32> offset = position.UpperLeftCorner; + core::dimension2d<s32> textDimension; + core::position2d<s32> offset = position.UpperLeftCorner; - if (m_rtl || hcenter || vcenter || clip) textDimension = getDimension(text.c_str()); + if (m_rtl || hcenter || vcenter || clip) textDimension = getDimension(text.c_str()); - if (hcenter) + if (hcenter) { - offset.X += (position.getWidth() - textDimension.Width) / 2; + offset.X += (position.getWidth() - textDimension.Width) / 2; } else if (m_rtl) { offset.X += (position.getWidth() - textDimension.Width); } - if (vcenter) + if (vcenter) { - offset.Y += (position.getHeight() - textDimension.Height) / 2; + offset.Y += (position.getHeight() - textDimension.Height) / 2; } - if (clip) - { - core::rect<s32> clippedRect(offset, textDimension); - clippedRect.clipAgainst(*clip); - if (!clippedRect.isValid()) return; - } + if (clip) + { + core::rect<s32> clippedRect(offset, textDimension); + clippedRect.clipAgainst(*clip); + if (!clippedRect.isValid()) return; + } // ---- collect character locations const unsigned int text_size = text.size(); - core::array<s32> indices(text_size); - core::array<core::position2di> offsets(text_size); + core::array<s32> indices(text_size); + core::array<core::position2di> offsets(text_size); std::vector<bool> fallback(text_size); - for (u32 i = 0; i<text_size; i++) - { - wchar_t c = text[i]; + for (u32 i = 0; i<text_size; i++) + { + wchar_t c = text[i]; //hack: one tab character is supported, it moves the cursor to the middle of the area if (c == L'\t') @@ -603,45 +603,45 @@ continue; } - bool lineBreak=false; - if (c == L'\r') // Windows breaks - { - lineBreak = true; - if (text[i + 1] == L'\n') c = text[++i]; - } - else if ( c == L'\n') // Unix breaks - { - lineBreak = true; - } + bool lineBreak=false; + if (c == L'\r') // Windows breaks + { + lineBreak = true; + if (text[i + 1] == L'\n') c = text[++i]; + } + else if ( c == L'\n') // Unix breaks + { + lineBreak = true; + } - if (lineBreak) - { - offset.Y += MaxHeight; - offset.X = position.UpperLeftCorner.X; + if (lineBreak) + { + offset.Y += MaxHeight; + offset.X = position.UpperLeftCorner.X; - if ( hcenter ) - { - core::dimension2d<u32> lineDim = getDimension(text.c_str()); - offset.X += (position.getWidth() - lineDim.Width) >> 1; - } - continue; - } + if ( hcenter ) + { + core::dimension2d<u32> lineDim = getDimension(text.c_str()); + offset.X += (position.getWidth() - lineDim.Width) >> 1; + } + continue; + } bool fallback_font = false; const int areaID = getAreaFromCharacter(c, &fallback_font); //std::cout << "Char " << c << " has area " << areaID << std::endl; - SFontArea& area = (fallback_font ? m_fallback_font->Areas[areaID] : Areas[areaID]); + SFontArea& area = (fallback_font ? m_fallback_font->Areas[areaID] : Areas[areaID]); //float char_scale = m_texture_files[area.spriteno].m_scale; - offset.X += area.underhang; - if ( Invisible.findFirst ( c ) < 0 ) - { - indices.push_back(area.spriteno); - offsets.push_back(offset); + offset.X += area.underhang; + if ( Invisible.findFirst ( c ) < 0 ) + { + indices.push_back(area.spriteno); + offsets.push_back(offset); fallback[i] = fallback_font; - } + } else { // invisible character. add something to the array anyway so that indices from @@ -667,7 +667,7 @@ offset.X += getCharWidth(area, fallback[i]); } - //SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color); + //SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color); // ---- do the actual rendering const int indiceAmount = indices.size(); @@ -871,28 +871,28 @@ //! Calculates the index of the character in the text which is on a specific position. s32 ScalableFont::getCharacterFromPos(const wchar_t* text, s32 pixel_x) const { - s32 x = 0; - s32 idx = 0; + s32 x = 0; + s32 idx = 0; - while (text[idx]) - { - const SFontArea& a = Areas[getAreaFromCharacter(text[idx], NULL)]; + while (text[idx]) + { + const SFontArea& a = Areas[getAreaFromCharacter(text[idx], NULL)]; - x += a.width + a.overhang + a.underhang + GlobalKerningWidth; + x += a.width + a.overhang + a.underhang + GlobalKerningWidth; - if (x >= pixel_x) - return idx; + if (x >= pixel_x) + return idx; - ++idx; - } + ++idx; + } - return -1; + return -1; } IGUISpriteBank* ScalableFont::getSpriteBank() const { - return SpriteBank; + return SpriteBank; } } // end namespace gui Modified: main/trunk/src/guiengine/CGUIFont.h =================================================================== --- main/trunk/src/guiengine/CGUIFont.h 2010-07-19 00:14:06 UTC (rev 5696) +++ main/trunk/src/guiengine/CGUIFont.h 2010-07-19 03:36:59 UTC (rev 5697) @@ -21,14 +21,14 @@ namespace video { - class IVideoDriver; - class IImage; + class IVideoDriver; + class IImage; } namespace gui { - class IGUIEnvironment; + class IGUIEnvironment; class ScalableFont : public IGUIFontBitmap { @@ -63,8 +63,8 @@ float m_fallback_font_scale; int m_fallback_kerning_width; - //! constructor - ScalableFont(IGUIEnvironment* env, const io::path& filename); + //! constructor + ScalableFont(IGUIEnvironment* env, const io::path& filename); /** Creates a hollow copy of this font; i.e. the underlying font data is the *same* for * both fonts. The advantage of doing this is that you can change "view" parameters @@ -81,84 +81,84 @@ return out; } - //! destructor - virtual ~ScalableFont(); + //! destructor + virtual ~ScalableFont(); - //! loads a font from a texture file - //bool load(const io::path& filename); + //! loads a font from a texture file + //bool load(const io::path& filename); - //! loads a font from a texture file - //bool load(io::IReadFile* file); + //! loads a font from a texture file + //bool load(io::IReadFile* file); - //! loads a font from an XML file - bool load(io::IXMLReader* xml); + //! loads a font from an XML file + bool load(io::IXMLReader* xml); - //! draws an text and clips it to the specified rectangle if wanted - virtual void draw(const core::stringw& text, const core::rect<s32>& position, - video::SColor color, bool hcenter=false, - bool vcenter=false, const core::rect<s32>* clip=0); + //! draws an text and clips it to the specified rectangle if wanted + virtual void draw(const core::stringw& text, const core::rect<s32>& position, + video::SColor color, bool hcenter=false, + bool vcenter=false, const core::rect<s32>* clip=0); - //! returns the dimension of a text - virtual core::dimension2d<u32> getDimension(const wchar_t* text) const; + //! returns the dimension of a text + virtual core::dimension2d<u32> getDimension(const wchar_t* text) const; - //! Calculates the index of the character in the text which is on a specific position. - virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const; + //! Calculates the index of the character in the text which is on a specific position. + virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const; - //! Returns the type of this font - virtual EGUI_FONT_TYPE getType() const { return EGFT_BITMAP; } + //! Returns the type of this font + virtual EGUI_FONT_TYPE getType() const { return EGFT_BITMAP; } - //! set an Pixel Offset on Drawing ( scale position on width ) - virtual void setKerningWidth (s32 kerning); - virtual void setKerningHeight (s32 kerning); + //! set an Pixel Offset on Drawing ( scale position on width ) + virtual void setKerningWidth (s32 kerning); + virtual void setKerningHeight (s32 kerning); - //! set an Pixel Offset on Drawing ( scale position on width ) - virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const; - virtual s32 getKerningHeight() const; + //! set an Pixel Offset on Drawing ( scale position on width ) + virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const; + virtual s32 getKerningHeight() const; void setShadow(irr::video::SColor col); - //! gets the sprite bank - virtual IGUISpriteBank* getSpriteBank() const; + //! gets the sprite bank + virtual IGUISpriteBank* getSpriteBank() const; - //! returns the sprite number from a given character - virtual u32 getSpriteNoFromChar(const wchar_t *c) const; + //! returns the sprite number from a given character + virtual u32 getSpriteNoFromChar(const wchar_t *c) const; - virtual void setInvisibleCharacters( const wchar_t *s ); + virtual void setInvisibleCharacters( const wchar_t *s ); void setScale(const float scale); float getScale() const { return m_scale; } private: - struct SFontArea - { - SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {} - s32 underhang; - s32 overhang; - s32 width; - u32 spriteno; - }; + struct SFontArea + { + SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {} + s32 underhang; + s32 overhang; + s32 width; + u32 spriteno; + }; int getCharWidth(const SFontArea& area, const bool fallback) const; - //! load & prepare font from ITexture - //bool loadTexture(video::IImage * image, const io::path& name); + //! load & prepare font from ITexture + //bool loadTexture(video::IImage * image, const io::path& name); - //void readPositions(video::IImage* texture, s32& lowerRightPositions); + //void readPositions(video::IImage* texture, s32& lowerRightPositions); - s32 getAreaFromCharacter (const wchar_t c, bool* fallback_font) const; - void setMaxHeight(); + s32 getAreaFromCharacter (const wchar_t c, bool* fallback_font) const; + void setMaxHeight(); - core::array<SFontArea> Areas; - std::map<wchar_t, s32> CharacterMap; - video::IVideoDriver* Driver; - IGUISpriteBank* SpriteBank; - IGUIEnvironment* Environment; - u32 WrongCharacter; - s32 MaxHeight; - s32 GlobalKerningWidth, GlobalKerningHeight; + core::array<SFontArea> Areas; + std::map<wchar_t, s32> CharacterMap; + video::IVideoDriver* Driver; + IGUISpriteBank* SpriteBank; + IGUIEnvironment* Environment; + u32 WrongCharacter; + s32 MaxHeight; + s32 GlobalKerningWidth, GlobalKerningHeight; - core::stringw Invisible; + core::stringw Invisible; }; } // end namespace gui Modified: main/trunk/src/guiengine/CGUISpriteBank.cpp =================================================================== --- main/trunk/src/guiengine/CGUISpriteBank.cpp 2010-07-19 00:14:06 UTC (rev 5696) +++ main/trunk/src/guiengine/CGUISpriteBank.cpp 2010-07-19 03:36:59 UTC (rev 5697) @@ -16,35 +16,35 @@ { STKModifiedSpriteBank::STKModifiedSpriteBank(IGUIEnvironment* env) : - Environment(env), Driver(0) + Environment(env), Driver(0) { m_magic_number = 0xCAFEC001; - #ifdef _DEBUG - setDebugName("STKModifiedSpriteBank"); - #endif + #ifdef _DEBUG + setDebugName("STKModifiedSpriteBank"); + #endif m_scale = 1.0f; - if (Environment) - { - Driver = Environment->getVideoDriver(); - if (Driver) - Driver->grab(); - } + if (Environment) + { + Driver = Environment->getVideoDriver(); + if (Driver) + Driver->grab(); + } } STKModifiedSpriteBank::~STKModifiedSpriteBank() { - // drop textures - for (u32 i=0; i<Textures.size(); ++i) - if (Textures[i]) - Textures[i]->drop(); + // drop textures + for (u32 i=0; i<Textures.size(); ++i) + if (Textures[i]) + Textures[i]->drop(); - // drop video driver - if (Driver) - Driver->drop(); + // drop video driver + if (Driver) + Driver->drop(); m_magic_number = 0xDEADBEEF; } @@ -67,57 +67,57 @@ ); } - return copy; + return copy; } core::array< SGUISprite >& STKModifiedSpriteBank::getSprites() { assert( m_magic_number == 0xCAFEC001 ); - return Sprites; + return Sprites; } u32 STKModifiedSpriteBank::getTextureCount() const { assert( m_magic_number == 0xCAFEC001 ); - return Textures.size(); + return Textures.size(); } video::ITexture* STKModifiedSpriteBank::getTexture(u32 index) const { assert( m_magic_number == 0xCAFEC001 ); - if (index < Textures.size()) - return Textures[index]; - else - return 0; + if (index < Textures.size()) + return Textures[index]; + else + return 0; } void STKModifiedSpriteBank::addTexture(video::ITexture* texture) { assert( m_magic_number == 0xCAFEC001 ); - if (texture) - texture->grab(); + if (texture) + texture->grab(); - Textures.push_back(texture); + Textures.push_back(texture); } void STKModifiedSpriteBank::setTexture(u32 index, video::ITexture* texture) { assert( m_magic_number == 0xCAFEC001 ); - while (index >= Textures.size()) - Textures.push_back(0); + while (index >= Textures.size()) + Textures.push_back(0); - if (texture) - texture->grab(); + if (texture) + texture->grab(); - if (Textures[index]) - Textures[index]->drop(); + if (Textures[index]) + Textures[index]->drop(); - Textures[index] = texture; + Textures[index] = texture; } @@ -125,78 +125,78 @@ void STKModifiedSpriteBank::clear() { assert( m_magic_number == 0xCAFEC001 ); - // drop textures - for (u32 i=0; i<Textures.size(); ++i) - if (Textures[i]) - Textures[i]->drop(); - Textures.clear(); - Sprites.clear(); - Rectangles.clear(); + // drop textures + for (u32 i=0; i<Textures.size(); ++i) + if (Textures[i]) + Textures[i]->drop(); + Textures.clear(); + Sprites.clear(); + Rectangles.clear(); } //! Add the texture and use it for a single non-animated sprite. s32 STKModifiedSpriteBank::addTextureAsSprite(video::ITexture* texture) { assert( m_magic_number == 0xCAFEC001 ); - if ( !texture ) - return -1; + if ( !texture ) + return -1; - addTexture(texture); - u32 textureIndex = getTextureCount() - 1; + addTexture(texture); + u32 textureIndex = getTextureCount() - 1; - u32 rectangleIndex = Rectangles.size(); - Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) ); + u32 rectangleIndex = Rectangles.size(); + Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) ); - SGUISprite sprite; - sprite.frameTime = 0; + SGUISprite sprite; + sprite.frameTime = 0; - SGUISpriteFrame frame; - frame.textureNumber = textureIndex; - frame.rectNumber = rectangleIndex; - sprite.Frames.push_back( frame ); + SGUISpriteFrame frame; + frame.textureNumber = textureIndex; + frame.rectNumber = rectangleIndex; + sprite.Frames.push_back( frame ); - Sprites.push_back( sprite ); + Sprites.push_back( sprite ); - return Sprites.size() - 1; + return Sprites.size() - 1; } //! draws a sprite in 2d with scale and color void STKModifiedSpriteBank::draw2DSprite(u32 index, const core::position2di& pos, - const core::rect<s32>* clip, const video::SColor& color, - u32 starttime, u32 currenttime, bool loop, bool center) + const core::rect<s32>* clip, const video::SColor& color, + u32 starttime, u32 currenttime, bool loop, bool center) { assert( m_magic_number == 0xCAFEC001 ); - if (index >= Sprites.size() || Sprites[index].Frames.empty() ) - return; + if (index >= Sprites.size() || Sprites[index].Frames.empty() ) + return; - // work out frame number - u32 frame = 0; - if (Sprites[index].frameTime) - { - u32 f = ((currenttime - starttime) / Sprites[index].frameTime); - if (loop) - frame = f % Sprites[index].Frames.size(); - else - frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; - } + // work out frame number + u32 frame = 0; + if (Sprites[index].frameTime) + { + u32 f = ((currenttime - starttime) / Sprites[index].frameTime); + if (loop) + frame = f % Sprites[index].Frames.size(); + else + frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; + } - const video::ITexture* tex = Textures[Sprites[index].Frames[frame].textureNumber]; - if (!tex) - return; + const video::ITexture* tex = Textures[Sprites[index].Frames[frame].textureNumber]; + if (!tex) + return; - const u32 rn = Sprites[index].Frames[frame].rectNumber; - if (rn >= Rectangles.size()) - return; + const u32 rn = Sprites[index].Frames[frame].rectNumber; + if (rn >= Rectangles.size()) + return; - const core::rect<s32>& r = Rectangles[rn]; + const core::rect<s32>& r = Rectangles[rn]; const core::dimension2d<s32>& dim = r.getSize(); core::rect<s32> dest( pos, core::dimension2d<s32>((int)(dim.Width*m_scale), (int)(dim.Height*m_scale)) ); - if (center) - { - dest -= dest.getSize() / 2; + if (center) + { + dest -= dest.getSize() / 2; } /* @@ -209,73 +209,73 @@ } -void STKModifiedSpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, - const core::array<core::position2di>& pos, - const core::rect<s32>* clip, - const video::SColor& color, - u32 starttime, u32 currenttime, - bool loop, bool center) +void STKModifiedSpriteBank::draw2DSpriteBatch( const core::array<u32>& indices, + const core::array<core::position2di>& pos, + const core::rect<s32>* clip, + const video::SColor& color, + u32 starttime, u32 currenttime, + bool loop, bool center) { assert( m_magic_number == 0xCAFEC001 ); - const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size()); + const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size()); - core::array<SDrawBatch> drawBatches(Textures.size()); - for(u32 i = 0;i < Textures.size();i++) - { - drawBatches.push_back(SDrawBatch()); - drawBatches[i].positions.reallocate(drawCount); - drawBatches[i].sourceRects.reallocate(drawCount); - } + core::array<SDrawBatch> drawBatches(Textures.size()); + for(u32 i = 0;i < Textures.size();i++) + { + drawBatches.push_back(SDrawBatch()); + drawBatches[i].positions.reallocate(drawCount); + drawBatches[i].sourceRects.reallocate(drawCount); + } - for(u32 i = 0;i < drawCount;i++) - { - const u32 index = indices[i]; + for(u32 i = 0;i < drawCount;i++) + { + const u32 index = indices[i]; - if (index >= Sprites.size() || Sprites[index].Frames.empty() ) - continue; + if (index >= Sprites.size() || Sprites[index].Frames.empty() ) + continue; - // work out frame number - u32 frame = 0; - if (Sprites[index].frameTime) - { - u32 f = ((currenttime - starttime) / Sprites[index].frameTime); - if (loop) - frame = f % Sprites[index].Frames.size(); - else - frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; - } + // work out frame number + u32 frame = 0; + if (Sprites[index].frameTime) + { + u32 f = ((currenttime - starttime) / Sprites[index].frameTime); + if (loop) + frame = f % Sprites[index].Frames.size(); + else + frame = (f >= Sprites[index].Frames.size()) ? Sprites[index].Frames.size()-1 : f; + } - const u32 texNum = Sprites[index].Frames[frame].textureNumber; + const u32 texNum = Sprites[index].Frames[frame].textureNumber; - SDrawBatch& currentBatch = drawBatches[texNum]; + SDrawBatch& currentBatch = drawBatches[texNum]; - const u32 rn = Sprites[index].Frames[frame].rectNumber; - if (rn >= Rectangles.size()) - return; + const u32 rn = Sprites[index].Frames[frame].rectNumber; + if (rn >= Rectangles.size()) + return; - const core::rect<s32>& r = Rectangles[rn]; + const core::rect<s32>& r = Rectangles[rn]; - if (center) - { - core::position2di p = pos[i]; - p -= r.getSize() / 2; + if (center) + { + core::position2di p = pos[i]; + p -= r.getSize() / 2; - currentBatch.positions.push_back(p); - currentBatch.sourceRects.push_back(r); - } - else - { - currentBatch.positions.push_back(pos[i]); - currentBatch.sourceRects.push_back(r); - } - } + currentBatch.positions.push_back(p); + currentBatch.sourceRects.push_back(r); + } + else + { + currentBatch.positions.push_back(pos[i]); + currentBatch.sourceRects.push_back(r); + } + } - for(u32 i = 0;i < drawBatches.size();i++) - { - if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty()) - Driver->draw2DImageBatch(Textures[i], drawBatches[i].positions, - drawBatches[i].sourceRects, clip, color, true); - } + for(u32 i = 0;i < drawBatches.size();i++) + { + if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty()) + Driver->draw2DImageBatch(Textures[i], drawBatches[i].positions, + drawBatches[i].sourceRects, clip, color, true); + } } } // namespace gui Modified: main/trunk/src/guiengine/CGUISpriteBank.h =================================================================== --- main/trunk/src/guiengine/CGUISpriteBank.h 2010-07-19 00:14:06 UTC (rev 5696) +++ main/trunk/src/guiengine/CGUISpriteBank.h 2010-07-19 03:36:59 UTC (rev 5697) @@ -15,48 +15,48 @@ namespace video { - class IVideoDriver; - class ITexture; + class IVideoDriver; + class ITexture; } namespace gui { - class IGUIEnvironment; + class IGUIEnvironment; //! Sprite bank interface. class STKModifiedSpriteBank : public IGUISpriteBank { public: - STKModifiedSpriteBank(IGUIEnvironment* env); - virtual ~STKModifiedSpriteBank(); + STKModifiedSpriteBank(IGUIEnvironment* env); + virtual ~STKModifiedSpriteBank(); - virtual core::array< core::rect<s32> >& getPositions(); - virtual core::array< SGUISprite >& getSprites(); + virtual core::array< core::rect<s32> >& getPositions(); + virtual core::array< SGUISprite >& getSprites(); - virtual u32 getTextureCount() const; - virtual video::ITexture* getTexture(u32 index) const; - virtual void addTexture(video::ITexture* texture); - virtual void setTexture(u32 index, video::ITexture* texture); + virtual u32 getTextureCount() const; + virtual video::ITexture* getTexture(u32 index) const; + virtual void addTexture(video::ITexture* texture); + virtual void setTexture(u32 index, video::ITexture* texture); - //! Add the texture and use it for a single non-animated sprite. - virtual s32 addTextureAsSprite(video::ITexture* texture); + //! Add the texture and use it for a single non-animated sprite. + virtual s32 addTextureAsSprite(video::ITexture* texture); - //! clears sprites, rectangles and textures - virtual void clear(); + //! clears sprites, rectangles and textures + virtual void clear(); - //! Draws a sprite in 2d with position and color - virtual void draw2DSprite(u32 index, const core::position2di& pos, const core::rect<s32>* clip=0, - const video::SColor& color= video::SColor(255,255,255,255), - u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false); + //! Draws a sprite in 2d with position and color + virtual void draw2DSprite(u32 index, const core::position2di& pos, const core::rect<s32>* clip=0, + const video::SColor& color= video::SColor(255,255,255,255), + u32 starttime=0, u32 currenttime=0, bool loop=true, bool center=false); - //! Draws a sprite batch in 2d using an array of positions and a color - virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos, - const core::rect<s32>* clip=0, - const video::SColor& color= video::SColor(255,255,255,255), - u32 starttime=0, u32 currenttime=0, - bool loop=true, bool center=false); + //! Draws a sprite batch in 2d using an array of positions and a color + virtual void draw2DSpriteBatch(const core::array<u32>& indices, const core::array<core::position2di>& pos, + const core::rect<s32>* clip=0, + const video::SColor& color= video::SColor(255,255,255,255), + u32 starttime=0, u32 currenttime=0, + bool loop=true, bool center=false); void setScale(float scale) { @@ -71,22 +71,22 @@ float m_scale; - struct SDrawBatch - { - core::array<core::position2di> positions; - core::array<core::recti> sourceRects; - u32 textureNumber; - }; + struct SDrawBatch + { + core::array<core::position2di> positions; + core::array<core::recti> sourceRects; + u32 textureNumber; + }; //FIXME: ugly hack to work around irrLicht limitations, see STKModifiedSpriteBank::getPositions() // for all the gory details. core::array< core::rect<s32> > copy; - core::array<SGUISprite> Sprites; - core::array< core::rect<s32> > Rectangles; - core::array<video::ITexture*> Textures; - IGUIEnvironment* Environment; - video::IVideoDriver* Driver; + core::array<SGUISprite> Sprites; + core::array< core::rect<s32> > Rectangles; + core::array<video::ITexture*> Textures; + IGUIEnvironment* Environment; + video::IVideoDriver* Driver; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hik...@us...> - 2010-07-20 22:40:01
|
Revision: 5698 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5698&view=rev Author: hikerstk Date: 2010-07-20 22:39:54 +0000 (Tue, 20 Jul 2010) Log Message: ----------- Added support for mono-spaced digits (which makes tables with numbers look better): all digits and the space character have the same width. Modified Paths: -------------- main/trunk/src/guiengine/CGUIFont.cpp main/trunk/src/guiengine/CGUIFont.h Modified: main/trunk/src/guiengine/CGUIFont.cpp =================================================================== --- main/trunk/src/guiengine/CGUIFont.cpp 2010-07-19 03:36:59 UTC (rev 5697) +++ main/trunk/src/guiengine/CGUIFont.cpp 2010-07-20 22:39:54 UTC (rev 5698) @@ -24,20 +24,19 @@ : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0), MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0) { - m_fallback_font = NULL; - m_fallback_font_scale = 1.0f; - m_fallback_kerning_width = 0; - m_is_hollow_copy = false; - m_rtl = translations->isRTLLanguage(); - - m_black_border = false; - - #ifdef _DEBUG +#ifdef _DEBUG setDebugName("ScalableFont"); - #endif +#endif - m_scale = 1.0f; - m_shadow = false; + m_fallback_font = NULL; + m_fallback_kerning_width = 0; + m_fallback_font_scale = 1.0f; + m_scale = 1.0f; + m_is_hollow_copy = false; + m_black_border = false; + m_shadow = false; + m_mono_space_digits = false; + m_rtl = translations->isRTLLanguage(); if (Environment) { @@ -91,9 +90,10 @@ core::stringc filename = xml->getAttributeValue(L"filename"); core::stringc fn = file_manager->getFontFile(filename.c_str()).c_str(); u32 i = (u32)xml->getAttributeValueAsInt(L"index"); - - float scale = xml->getAttributeValueAsFloat(L"scale"); - if (scale < 0.01f) scale = 1.0f; // FIXME: how do you check if some property exists in a cleaner way? + + float scale=1.0f; + if(xml->getAttributeValue(L"scale")) + scale = xml->getAttributeValueAsFloat(L"scale"); //std::cout << "scale = " << scale << std::endl; core::stringw alpha = xml->getAttributeValue(L"hasAlpha"); @@ -108,37 +108,10 @@ } TextureInfo info; - info.m_file_name = fn; - info.m_has_alpha = (alpha == core::stringw("true")); - info.m_scale = scale; - - // disable mipmaps+filtering - //bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS); - //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); - - m_texture_files[i] = info; - - /* - // load texture - SpriteBank->setTexture(i, Driver->getTexture(fn)); - - // set previous mip-map+filter state - //Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap); - - // couldn't load texture, abort. - if (!SpriteBank->getTexture(i)) - { - std::cerr << "!!!!! Unable to load all textures in the font, aborting" << std::endl; - _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; - return false; - } - else - { - // colorkey texture rather than alpha channel? - if (alpha == core::stringw("false")) - Driver->makeColorKeyTexture(SpriteBank->getTexture(i), core::position2di(0,0)); - } - */ + info.m_file_name = fn; + info.m_has_alpha = (alpha == core::stringw("true")); + info.m_scale = scale; + m_texture_files[i] = info; } else if (core::stringw(L"c") == xml->getNodeName()) { @@ -224,10 +197,18 @@ } // set bad character - WrongCharacter = getAreaFromCharacter(L' ', NULL); + WrongCharacter = getAreaIDFromCharacter(L' ', NULL); setMaxHeight(); + for(wchar_t c='0'; c<='9'; c++) + { + SFontArea a = getAreaFromCharacter(c, NULL); + if(a.overhang > m_max_digit_area.overhang ) m_max_digit_area.overhang = a.overhang; + if(a.underhang > m_max_digit_area.underhang) m_max_digit_area.underhang = a.underhang; + if(a.width > m_max_digit_area.width ) m_max_digit_area.width = a.width; + } + m_max_digit_area.overhang = 0;m_max_digit_area.underhang=0; return true; } void ScalableFont::setScale(const float scale) @@ -250,160 +231,10 @@ MaxHeight = t; } - } -//! loads a font file, native file needed, for texture parsing - /* -bool ScalableFont::load(io::IReadFile* file) -{ - if (!Driver) return false; - return loadTexture(Driver->createImageFromFile(file), file->getFileName()); -} -*/ - -//! loads a font file, native file needed, for texture parsing - /* -bool ScalableFont::load(const io::path& filename) -{ - if (!Driver) return false; - - return loadTexture(Driver->createImageFromFile( filename ), filename); -} -*/ - -//! load & prepare font from ITexture -#if 0 -bool ScalableFont::loadTexture(video::IImage* image, const io::path& name) -{ - if (!image) return false; - - s32 lowerRightPositions = 0; - - video::IImage* tmpImage=image; - /* - bool deleteTmpImage=false; - switch(image->getColorFormat()) - { - case video::ECF_R5G6B5: - tmpImage = new video::CImage(video::ECF_A1R5G5B5,image); - deleteTmpImage=true; - break; - case video::ECF_A1R5G5B5: - case video::ECF_A8R8G8B8: - break; - case video::ECF_R8G8B8: - tmpImage = new video::CImage(video::ECF_A8R8G8B8,image); - deleteTmpImage=true; - break; - }*/ - readPositions(tmpImage, lowerRightPositions); - - WrongCharacter = getAreaFromCharacter(L' ', NULL); - - // output warnings - if (!lowerRightPositions || !SpriteBank->getSprites().size()) - std::cerr << "Either no upper or lower corner pixels in the font file. If this font was made using the new font tool, please load the XML file instead. If not, the font may be corrupted.\n"; - else - if (lowerRightPositions != (s32)SpriteBank->getPositions().size()) - std::cerr << "The amount of upper corner pixels and the lower corner pixels is not equal, font file may be corrupted.\n"; - - bool ret = ( !SpriteBank->getSprites().empty() && lowerRightPositions ); - - if ( ret ) - { - bool flag[2]; - flag[0] = Driver->getTextureCreationFlag ( video::ETCF_ALLOW_NON_POWER_2 ); - flag[1] = Driver->getTextureCreationFlag ( video::ETCF_CREATE_MIP_MAPS ); - - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, true); - Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true ); - - SpriteBank->addTexture(Driver->addTexture(name, tmpImage)); - - Driver->setTextureCreationFlag(video::ETCF_ALLOW_NON_POWER_2, flag[0] ); - Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flag[1] ); - } - //if (deleteTmpImage) - // tmpImage->drop(); - image->drop(); - - setMaxHeight(); - - return ret; -} -#endif - -/* -void ScalableFont::readPositions(video::IImage* image, s32& spriteID) -{ - const core::dimension2d<u32> size = image->getDimension(); - - video::SColor colorTopLeft = image->getPixel(0,0); - colorTopLeft.setAlpha(255); - image->setPixel(0,0,colorTopLeft); - video::SColor colorLowerRight = image->getPixel(1,0); - video::SColor colorBackGround = image->getPixel(2,0); - video::SColor colorBackGroundTransparent = 0; - - image->setPixel(1,0,colorBackGround); - - // start parsing - - core::position2d<s32> pos(0,0); - for (pos.Y=0; pos.Y<(s32)size.Height; ++pos.Y) - { - for (pos.X=0; pos.X<(s32)size.Width; ++pos.X) - { - const video::SColor c = image->getPixel(pos.X, pos.Y); - if (c == colorTopLeft) - { - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - SpriteBank->getPositions().push_back(core::rect<s32>(pos, pos)); - } - else - if (c == colorLowerRight) - { - // too many lower right points - if (SpriteBank->getPositions().size()<=(u32)spriteID) - { - spriteID = 0; - return; - } - - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - SpriteBank->getPositions()[spriteID].LowerRightCorner = pos; - // add frame to sprite bank - SGUISpriteFrame f; - f.rectNumber = spriteID; - f.textureNumber = 0; - SGUISprite s; - s.Frames.push_back(f); - s.frameTime = 0; - SpriteBank->getSprites().push_back(s); - // add character to font - SFontArea a; - a.overhang = 0; - a.underhang = 0; - a.spriteno = spriteID; - a.width = SpriteBank->getPositions()[spriteID].getWidth(); - Areas.push_back(a); - // map letter to character - wchar_t ch = (wchar_t)(spriteID + 32); - CharacterMap[ch] = spriteID; - - ++spriteID; - } - else - if (c == colorBackGround) - image->setPixel(pos.X, pos.Y, colorBackGroundTransparent); - } - } -} -*/ - //! set an Pixel Offset on Drawing ( scale position on width ) void ScalableFont::setKerningWidth(s32 kerning) { @@ -418,11 +249,11 @@ if (thisLetter) { - ret += Areas[getAreaFromCharacter(*thisLetter, NULL)].overhang; + ret += Areas[getAreaIDFromCharacter(*thisLetter, NULL)].overhang; if (previousLetter) { - ret += Areas[getAreaFromCharacter(*previousLetter, NULL)].underhang; + ret += Areas[getAreaIDFromCharacter(*previousLetter, NULL)].underhang; } } @@ -447,11 +278,11 @@ //! returns the sprite number from a given character u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const { - return Areas[getAreaFromCharacter(*c, NULL)].spriteno; + return Areas[getAreaIDFromCharacter(*c, NULL)].spriteno; } -s32 ScalableFont::getAreaFromCharacter(const wchar_t c, bool* fallback_font) const +s32 ScalableFont::getAreaIDFromCharacter(const wchar_t c, bool* fallback_font) const { std::map<wchar_t, s32>::const_iterator n = CharacterMap.find(c); if (n != CharacterMap.end()) @@ -463,7 +294,7 @@ { //std::wcout << L"Font does not have this character : <" << c << L">, trying fallback font" << std::endl; *fallback_font = true; - return m_fallback_font->getAreaFromCharacter(c, NULL); + return m_fallback_font->getAreaIDFromCharacter(c, NULL); } else { @@ -473,6 +304,26 @@ } } +const ScalableFont::SFontArea &ScalableFont::getAreaFromCharacter(const wchar_t c, + bool* fallback_font) const +{ + const int area_id = getAreaIDFromCharacter(c, fallback_font); + assert(area_id < (int)Areas.size()); + if(m_mono_space_digits && ( (c>=L'0' && c<=L'9') || c==L' ' ) ) + { + const SFontArea &area = (fallback_font && *fallback_font) + ? m_fallback_font->Areas[area_id] + : Areas[area_id]; + m_max_digit_area.spriteno = area.spriteno; + return m_max_digit_area; + } + + // Note: fallback_font can be NULL + return ( (fallback_font && *fallback_font) ? m_fallback_font->Areas[area_id] + : Areas[area_id]); +} // getAreaFromCharacter + + void ScalableFont::setInvisibleCharacters( const wchar_t *s ) { Invisible = s; @@ -510,20 +361,11 @@ } bool fallback = false; - const int areaID = getAreaFromCharacter(*p, &fallback); - assert(areaID < (int)Areas.size()); - const SFontArea &area = (fallback ? m_fallback_font->Areas[areaID] : Areas[areaID]); - - - //const TextureInfo& info = (*(m_texture_files.find(area.spriteno))).second; - //const float char_scale = info.m_scale; - + const SFontArea &area = getAreaFromCharacter(*p, &fallback); + thisLine.Width += area.underhang; thisLine.Width += getCharWidth(area, fallback); - - //if (fallback) thisLine.Width += (area.width + area.overhang)*m_fallback_font_scale*char_scale*m_scale + m_fallback_kerning_width; - //else thisLine.Width += (area.width + area.overhang)*m_scale*char_scale + GlobalKerningWidth; } dim.Height += thisLine.Height; @@ -540,8 +382,10 @@ } //! draws some text and clips it to the specified rectangle if wanted -void ScalableFont::draw(const core::stringw& text, const core::rect<s32>& position, - video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip) +void ScalableFont::draw(const core::stringw& text, + const core::rect<s32>& position, video::SColor color, + bool hcenter, bool vcenter, + const core::rect<s32>* clip) { if (!Driver) return; @@ -558,39 +402,29 @@ m_shadow = true; // set back } - //color = video::SColor(255,255,255,255); - - core::dimension2d<s32> textDimension; core::position2d<s32> offset = position.UpperLeftCorner; + core::dimension2d<s32> text_dimension; - if (m_rtl || hcenter || vcenter || clip) textDimension = getDimension(text.c_str()); - - if (hcenter) + if (m_rtl || hcenter || vcenter || clip) { - offset.X += (position.getWidth() - textDimension.Width) / 2; - } - else if (m_rtl) - { - offset.X += (position.getWidth() - textDimension.Width); - } + text_dimension = getDimension(text.c_str()); + if (hcenter) offset.X += (position.getWidth() - text_dimension.Width) / 2; + else if (m_rtl) offset.X += (position.getWidth() - text_dimension.Width); - if (vcenter) - { - offset.Y += (position.getHeight() - textDimension.Height) / 2; - } + if (vcenter) offset.Y += (position.getHeight() - text_dimension.Height) / 2; + if (clip) + { + core::rect<s32> clippedRect(offset, text_dimension); + clippedRect.clipAgainst(*clip); + if (!clippedRect.isValid()) return; + } + } // if rtl, centered, or clip - if (clip) - { - core::rect<s32> clippedRect(offset, textDimension); - clippedRect.clipAgainst(*clip); - if (!clippedRect.isValid()) return; - } - // ---- collect character locations const unsigned int text_size = text.size(); - core::array<s32> indices(text_size); + core::array<s32> indices(text_size); core::array<core::position2di> offsets(text_size); - std::vector<bool> fallback(text_size); + std::vector<bool> fallback(text_size); for (u32 i = 0; i<text_size; i++) { @@ -604,85 +438,48 @@ } bool lineBreak=false; - if (c == L'\r') // Windows breaks + if (c == L'\r' || // Windows breaks + c == L'\n' ) // Unix breaks { - lineBreak = true; - if (text[i + 1] == L'\n') c = text[++i]; - } - else if ( c == L'\n') // Unix breaks - { - lineBreak = true; - } - - if (lineBreak) - { + if(c==L'\r' && text[i+1]==L'\n') c = text[++i]; offset.Y += MaxHeight; - offset.X = position.UpperLeftCorner.X; - - if ( hcenter ) - { - core::dimension2d<u32> lineDim = getDimension(text.c_str()); - offset.X += (position.getWidth() - lineDim.Width) >> 1; - } + offset.X = position.UpperLeftCorner.X; + if (hcenter) + offset.X += (position.getWidth() - text_dimension.Width) >> 1; continue; - } + } // if lineBreak - - bool fallback_font = false; - const int areaID = getAreaFromCharacter(c, &fallback_font); - //std::cout << "Char " << c << " has area " << areaID << std::endl; - SFontArea& area = (fallback_font ? m_fallback_font->Areas[areaID] : Areas[areaID]); - - //float char_scale = m_texture_files[area.spriteno].m_scale; - - offset.X += area.underhang; - if ( Invisible.findFirst ( c ) < 0 ) - { - indices.push_back(area.spriteno); - offsets.push_back(offset); - fallback[i] = fallback_font; - } - else - { - // invisible character. add something to the array anyway so that indices from - // the various arrays remain in sync - indices.push_back(-1); - offsets.push_back(offset); - fallback[i] = fallback_font; - } - - /* - if (fallback_font) - { - std::cout << "Fallback : "; - std::cout << "Char " << (unsigned)((c >> 24) & 0xFF) << ", " << (unsigned)((c >> 16) & 0xFF) << ", " << - (unsigned)((c >> 8) & 0xFF) << ", " << (unsigned)(c & 0xFF) << std::endl; - std::cout << " w = " << getCharWidth(area, fallback[i]) << ", fallback[" << i << "]=" << fallback[i] << std::endl; - } - */ - - // std::cout << "Char " << (char)((c >> 24) & 0xFF) << ", " << (char)((c >> 16) & 0xFF) << ", " << - // (char)((c >> 8) & 0xFF) << ", " << (char)(c & 0xFF) << std::endl; - + bool use_fallback_font = false; + const SFontArea &area = getAreaFromCharacter(c, &use_fallback_font); + fallback[i] = use_fallback_font; + offset.X += area.underhang; + offsets.push_back(offset); + // Invisible character. add something to the array anyway so that + // indices from the various arrays remain in sync + indices.push_back( Invisible.findFirst(c) < 0 ? area.spriteno + : -1 ); offset.X += getCharWidth(area, fallback[i]); - } + } // for i<text_size - //SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color); - // ---- do the actual rendering - const int indiceAmount = indices.size(); - core::array< SGUISprite >& sprites = SpriteBank->getSprites(); - core::array< core::rect<s32> >& positions = SpriteBank->getPositions(); - - core::array< SGUISprite >* fallback_sprites = (m_fallback_font != NULL ? - &m_fallback_font->SpriteBank->getSprites() : - NULL); - core::array< core::rect<s32> >* fallback_positions = (m_fallback_font != NULL ? - &m_fallback_font->SpriteBank->getPositions() : - NULL); + const int indiceAmount = indices.size(); + core::array< SGUISprite >& sprites = SpriteBank->getSprites(); + core::array< core::rect<s32> >& positions = SpriteBank->getPositions(); + core::array< SGUISprite >* fallback_sprites; + core::array< core::rect<s32> >* fallback_positions; + if(m_fallback_font!=NULL) + { + fallback_sprites = &m_fallback_font->SpriteBank->getSprites(); + fallback_positions = &m_fallback_font->SpriteBank->getPositions(); + } + else + { + fallback_sprites = NULL; + fallback_positions = NULL; + } video::IVideoDriver* driver = GUIEngine::getDriver(); - const int spriteAmount = sprites.size(); + const int spriteAmount = sprites.size(); for (int n=0; n<indiceAmount; n++) { const int spriteID = indices[n]; @@ -876,7 +673,7 @@ while (text[idx]) { - const SFontArea& a = Areas[getAreaFromCharacter(text[idx], NULL)]; + const SFontArea& a = Areas[getAreaIDFromCharacter(text[idx], NULL)]; x += a.width + a.overhang + a.underhang + GlobalKerningWidth; Modified: main/trunk/src/guiengine/CGUIFont.h =================================================================== --- main/trunk/src/guiengine/CGUIFont.h 2010-07-19 03:36:59 UTC (rev 5697) +++ main/trunk/src/guiengine/CGUIFont.h 2010-07-20 22:39:54 UTC (rev 5698) @@ -34,6 +34,9 @@ { float m_scale; bool m_shadow; + /** True if digits should be mono spaced. */ + + bool m_mono_space_digits; irr::video::SColor m_shadow_color; struct TextureInfo @@ -84,12 +87,6 @@ //! destructor virtual ~ScalableFont(); - //! loads a font from a texture file - //bool load(const io::path& filename); - - //! loads a font from a texture file - //bool load(io::IReadFile* file); - //! loads a font from an XML file bool load(io::IXMLReader* xml); @@ -115,6 +112,9 @@ virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const; virtual s32 getKerningHeight() const; + /** Sets if digits are to be mono-spaced. */ + void setMonospaceDigits(bool mono) {m_mono_space_digits = mono; } + bool getMonospaceDigits() const { return m_mono_space_digits; } void setShadow(irr::video::SColor col); //! gets the sprite bank @@ -140,16 +140,13 @@ }; int getCharWidth(const SFontArea& area, const bool fallback) const; - - //! load & prepare font from ITexture - //bool loadTexture(video::IImage * image, const io::path& name); - - //void readPositions(video::IImage* texture, s32& lowerRightPositions); - - s32 getAreaFromCharacter (const wchar_t c, bool* fallback_font) const; + s32 getAreaIDFromCharacter(const wchar_t c, bool* fallback_font) const; + const SFontArea &getAreaFromCharacter(const wchar_t c, bool* fallback_font) const; void setMaxHeight(); core::array<SFontArea> Areas; + /** The maximum values of all digits, used in monospace_digits. */ + mutable SFontArea m_max_digit_area; std::map<wchar_t, s32> CharacterMap; video::IVideoDriver* Driver; IGUISpriteBank* SpriteBank; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-08-16 00:54:45
|
Revision: 5748 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5748&view=rev Author: auria Date: 2010-08-16 00:54:39 +0000 (Mon, 16 Aug 2010) Log Message: ----------- Added YET more files I forgot in earlier commits xD Added Paths: ----------- main/trunk/src/guiengine/abstract_top_level_container.cpp main/trunk/src/guiengine/abstract_top_level_container.hpp Added: main/trunk/src/guiengine/abstract_top_level_container.cpp =================================================================== --- main/trunk/src/guiengine/abstract_top_level_container.cpp (rev 0) +++ main/trunk/src/guiengine/abstract_top_level_container.cpp 2010-08-16 00:54:39 UTC (rev 5748) @@ -0,0 +1,228 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2010 Marianne Gagnon +// +// This program 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 3 +// of the License, or (at your option) any later version. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "graphics/irr_driver.hpp" +#include "guiengine/abstract_top_level_container.hpp" +#include "guiengine/engine.hpp" +#include "guiengine/scalable_font.hpp" +#include "guiengine/widget.hpp" +#include "io/file_manager.hpp" +#include "utils/ptr_vector.hpp" +#include <sstream> + +using namespace GUIEngine; + +#include "irrlicht.h" +using namespace irr; +using namespace core; +using namespace scene; +using namespace video; +using namespace io; +using namespace gui; + +void AbstractTopLevelContainer::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent) +{ + const unsigned short widgets_amount = widgets.size(); + + // ------- add widgets + for (int n=0; n<widgets_amount; n++) + { + if (widgets[n].getType() == WTYPE_DIV) + { + widgets[n].add(); // Will do nothing, but will maybe reserve an ID + addWidgetsRecursively(widgets[n].m_children, &widgets[n]); + } + else + { + // warn if widget has no dimensions (except for ribbons and icons, where it is normal since it + // adjusts to its contents) + if ((widgets[n].m_w < 1 || widgets[n].m_h < 1) && + widgets[n].getType() != WTYPE_RIBBON && + widgets[n].getType() != WTYPE_ICON_BUTTON) + { + std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no dimensions" << std::endl; + } + + if (widgets[n].m_x == -1 || widgets[n].m_y == -1) + { + std::cerr << "/!\\ Warning /!\\ : widget " << widgets[n].m_properties[PROP_ID].c_str() << " has no position" << std::endl; + } + + widgets[n].add(); + } + + } // next widget + +} // addWidgetsRecursively + +// ---------------------------------------------------------------------------- + +bool isMyChildHelperFunc(const ptr_vector<Widget>* within, const Widget* widget) +{ + if (within->size() == 0) return false; + + if (within->contains(widget)) + { + return true; + } + + const int count = within->size(); + for (int n=0; n<count; n++) + { + if (isMyChildHelperFunc(&within->getConst(n)->getChildren(), widget)) + { + return true; + } + } + + return false; +} + +bool AbstractTopLevelContainer::isMyChild(Widget* widget) const +{ + return isMyChildHelperFunc(&m_widgets, widget); +} + + + +Widget* AbstractTopLevelContainer::getWidget(const char* name) +{ + return getWidget(name, &m_widgets); +} // getWidget + +// ----------------------------------------------------------------------------- + +Widget* AbstractTopLevelContainer::getWidget(const int id) +{ + return getWidget(id, &m_widgets); +} // getWidget + +// ----------------------------------------------------------------------------- + +Widget* AbstractTopLevelContainer::getWidget(const char* name, ptr_vector<Widget>* within_vector) +{ + const unsigned short widgets_amount = within_vector->size(); + + for(int n=0; n<widgets_amount; n++) + { + Widget& widget = (*within_vector)[n]; + + if (widget.m_properties[PROP_ID] == name) return &widget; + + if (widget.searchInsideMe() && widget.m_children.size() > 0) + { + Widget* el = getWidget(name, &(widget.m_children)); + if(el != NULL) return el; + } + } // next + + return NULL; +} // getWidget + +// ----------------------------------------------------------------------------- + +Widget* AbstractTopLevelContainer::getWidget(const int id, ptr_vector<Widget>* within_vector) +{ + const unsigned short widgets_amount = within_vector->size(); + + for (int n=0; n<widgets_amount; n++) + { + Widget& widget = (*within_vector)[n]; + + if (widget.m_element != NULL && widget.getIrrlichtElement()->getID() == id) return &widget; + + if (widget.searchInsideMe() && widget.getChildren().size() > 0) + { + // std::cout << "widget = <" << widget.m_properties[PROP_ID].c_str() + // << "> widget.m_children.size()=" << widget.m_children.size() << std::endl; + Widget* el = getWidget(id, &(widget.m_children)); + if(el != NULL) return el; + } + } // next + + return NULL; +} // getWidget + +// ----------------------------------------------------------------------------- + +Widget* AbstractTopLevelContainer::getFirstWidget(ptr_vector<Widget>* within_vector) +{ + if (m_first_widget != NULL) return m_first_widget; + if (within_vector == NULL) within_vector = &m_widgets; + + for (int i = 0; i < within_vector->size(); i++) + { + if (!within_vector->get(i)->m_focusable) continue; + + // if container, also checks children (FIXME: don't hardcode which types to avoid descending into) + if (within_vector->get(i)->m_children.size() > 0 && + within_vector->get(i)->getType() != WTYPE_RIBBON && + within_vector->get(i)->getType() != WTYPE_SPINNER) + { + Widget* w = getFirstWidget(&within_vector->get(i)->m_children); + if (w != NULL) return w; + } + + Widget* item = within_vector->get(i); + if (item->getIrrlichtElement() == NULL || + item->getIrrlichtElement()->getTabOrder() == -1 || + item->getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !item->m_focusable) + { + continue; + } + + return item; + } + return NULL; +} // getFirstWidget + +// ----------------------------------------------------------------------------- + +Widget* AbstractTopLevelContainer::getLastWidget(ptr_vector<Widget>* within_vector) +{ + if (m_last_widget != NULL) return m_last_widget; + if (within_vector == NULL) within_vector = &m_widgets; + + for (int i = within_vector->size()-1; i >= 0; i--) + { + if (!within_vector->get(i)->m_focusable) continue; + + // if container, also checks children + if (within_vector->get(i)->getChildren().size() > 0 && + within_vector->get(i)->getType() != WTYPE_RIBBON && + within_vector->get(i)->getType() != WTYPE_SPINNER) + { + Widget* w = getLastWidget(&within_vector->get(i)->m_children); + if (w != NULL) return w; + } + + Widget* item = within_vector->get(i); + if (item->getIrrlichtElement() == NULL || + item->getIrrlichtElement()->getTabOrder() == -1 || + item->getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */ || + !item->m_focusable) + { + continue; + } + + return item; + } + return NULL; +} // getLastWidget + +// ---------------------------------------------------------------------------- Property changes on: main/trunk/src/guiengine/abstract_top_level_container.cpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: main/trunk/src/guiengine/abstract_top_level_container.hpp =================================================================== --- main/trunk/src/guiengine/abstract_top_level_container.hpp (rev 0) +++ main/trunk/src/guiengine/abstract_top_level_container.hpp 2010-08-16 00:54:39 UTC (rev 5748) @@ -0,0 +1,90 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2009 Marianne Gagnon +// +// This program 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 3 +// of the License, or (at your option) any later version. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __TOP_LEVEL_CONT_HPP__ +#define __TOP_LEVEL_CONT_HPP__ + +#include <cstring> // for NULL +#include "utils/ptr_vector.hpp" + +#include "guiengine/widget.hpp" + +namespace GUIEngine +{ + class Widget; + + class AbstractTopLevelContainer + { + protected: + /** the widgets in this screen */ + ptr_vector<Widget, HOLD> m_widgets; + + /** + * AbstractTopLevelContainer is generally able to determine its first widget just fine, + * but in highly complex screens (e.g. multiplayer kart selection) you can help it by + * providing the first widget manually. + */ + Widget* m_first_widget; + + /** + * AbstractTopLevelContainer is generally able to determine its last widget just fine, + * but in highly complex screens (e.g. multiplayer kart selection) you can help it by + * providing the first widget manually. + */ + Widget* m_last_widget; + + void addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent=NULL); + + + public: + virtual ~AbstractTopLevelContainer() {} + + virtual int getWidth() = 0; + virtual int getHeight() = 0; + + /** \return an object by name, or NULL if not found */ + Widget* getWidget(const char* name); + + /** \return an object by irrlicht ID, or NULL if not found */ + Widget* getWidget(const int id); + + /** \return an object by name, casted to specified type, or NULL if not found/wrong type */ + template <typename T> T* getWidget(const char* name) + { + Widget* out = getWidget(name); + T* outCasted = dynamic_cast<T*>( out ); + if (out != NULL && outCasted == NULL) + { + fprintf(stderr, "Screen::getWidget : Widget '%s' of type '%s' cannot be casted to " + "requested type '%s'!\n", name, typeid(*out).name(), typeid(T).name()); + abort(); + } + return outCasted; + } + + static Widget* getWidget(const char* name, ptr_vector<Widget>* within_vector); + static Widget* getWidget(const int id, ptr_vector<Widget>* within_vector); + + Widget* getFirstWidget(ptr_vector<Widget>* within_vector=NULL); + Widget* getLastWidget(ptr_vector<Widget>* within_vector=NULL); + + bool isMyChild(Widget* widget) const; + }; + +} + +#endif Property changes on: main/trunk/src/guiengine/abstract_top_level_container.hpp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-08-24 00:15:16
|
Revision: 5766 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5766&view=rev Author: auria Date: 2010-08-24 00:15:10 +0000 (Tue, 24 Aug 2010) Log Message: ----------- Added setVisible method to Widget. Unfortunately irrlicht allows hidden widgets to be navigated to so calling setVisible(false) doesn't disable widgets Modified Paths: -------------- main/trunk/src/guiengine/widget.cpp main/trunk/src/guiengine/widget.hpp Modified: main/trunk/src/guiengine/widget.cpp =================================================================== --- main/trunk/src/guiengine/widget.cpp 2010-08-23 14:16:39 UTC (rev 5765) +++ main/trunk/src/guiengine/widget.cpp 2010-08-24 00:15:10 UTC (rev 5766) @@ -297,3 +297,19 @@ m_parent = parent; } +// ----------------------------------------------------------------------------- + +void Widget::setVisible(bool visible) +{ + if (m_element != NULL) + { + m_element->setVisible(visible); + } + + const int childrenCount = m_children.size(); + for (int n=0; n<childrenCount; n++) + { + m_children[n].setVisible(visible); + } +} + Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2010-08-23 14:16:39 UTC (rev 5765) +++ main/trunk/src/guiengine/widget.hpp 2010-08-24 00:15:10 UTC (rev 5766) @@ -386,7 +386,7 @@ bool deleteChild(const char* id); /** - * Override in children to possibly receive updates (you may need to register to + * \brief Override in children to possibly receive updates (you may need to register to * them first) */ virtual void update(float delta) { } @@ -398,18 +398,23 @@ virtual EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID) { return EVENT_LET; } /** - * Create and add the irrLicht widget(s) associated with this object. + * \brief Create and add the irrLicht widget(s) associated with this object. * Call after Widget was read from XML file and laid out. */ virtual void add(); /** - * Called when irrLicht widgets cleared. Forget all references to them, they're no more valid. + * \brief Called when irrLicht widgets cleared. Forget all references to them, they're no more valid. */ virtual void elementRemoved(); int getID() const { return m_id; } + /** + * \brief Sets the widget (and its children, if any) visible or not + */ + void setVisible(bool visible); + bool searchInsideMe() const { return m_check_inside_me; } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-08-24 00:32:09
|
Revision: 5767 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5767&view=rev Author: auria Date: 2010-08-24 00:32:03 +0000 (Tue, 24 Aug 2010) Log Message: ----------- Made invisible widgets non-triggerable Modified Paths: -------------- main/trunk/src/guiengine/event_handler.cpp main/trunk/src/guiengine/widget.cpp main/trunk/src/guiengine/widget.hpp Modified: main/trunk/src/guiengine/event_handler.cpp =================================================================== --- main/trunk/src/guiengine/event_handler.cpp 2010-08-24 00:15:10 UTC (rev 5766) +++ main/trunk/src/guiengine/event_handler.cpp 2010-08-24 00:32:03 UTC (rev 5767) @@ -181,6 +181,7 @@ { Widget* w = GUIEngine::getFocusForPlayer(playerID); if (w == NULL) break; + // FIXME : consider returned value? onWidgetActivated( w, playerID ); } @@ -451,14 +452,19 @@ EventPropagation EventHandler::onWidgetActivated(GUIEngine::Widget* w, const int playerID) { + if (w->m_deactivated) return EVENT_BLOCK; + if (ModalDialog::isADialogActive()) { - if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID]) == EVENT_BLOCK) return EVENT_BLOCK; + if (ModalDialog::getCurrent()->processEvent(w->m_properties[PROP_ID]) == EVENT_BLOCK) + { + return EVENT_BLOCK; + } if (w->m_event_handler == NULL) return EVENT_LET; } //std::cout << "**** widget activated : " << w->m_properties[PROP_ID].c_str() << " ****" << std::endl; - + Widget* parent = w->m_event_handler; if (w->m_event_handler != NULL) { @@ -472,6 +478,8 @@ parent = parent->m_event_handler; } + if (parent->m_deactivated) return EVENT_BLOCK; + /* notify the found event event handler, and also notify the main callback if the parent event handler says so */ if (parent->transmitEvent(w, w->m_properties[PROP_ID], playerID) == EVENT_LET) @@ -488,7 +496,11 @@ sendEventToUser(parent, parent->m_properties[PROP_ID], playerID); } } - else sendEventToUser(w, w->m_properties[PROP_ID], playerID); + else + { + printf("sendEventToUser : '%s' is disabled = '%i'\n", w->m_properties[PROP_ID].c_str(), w->m_deactivated); + sendEventToUser(w, w->m_properties[PROP_ID], playerID); + } return EVENT_BLOCK; } Modified: main/trunk/src/guiengine/widget.cpp =================================================================== --- main/trunk/src/guiengine/widget.cpp 2010-08-24 00:15:10 UTC (rev 5766) +++ main/trunk/src/guiengine/widget.cpp 2010-08-24 00:32:03 UTC (rev 5767) @@ -305,6 +305,7 @@ { m_element->setVisible(visible); } + m_deactivated = !visible; const int childrenCount = m_children.size(); for (int n=0; n<childrenCount; n++) Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2010-08-24 00:15:10 UTC (rev 5766) +++ main/trunk/src/guiengine/widget.hpp 2010-08-24 00:32:03 UTC (rev 5767) @@ -411,7 +411,10 @@ int getID() const { return m_id; } /** - * \brief Sets the widget (and its children, if any) visible or not + * \brief Sets the widget (and its children, if any) visible or not. + * Note that setting a widget invisible implicitely calls setDeactivated(), and setting + * it visible implicitely calls setActivated(). If you mix visiblity and (de)activated calls, + * undefined behavior may ensue (like invisible but clickable buttons). */ void setVisible(bool visible); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-08-26 00:08:16
|
Revision: 5779 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5779&view=rev Author: auria Date: 2010-08-26 00:08:10 +0000 (Thu, 26 Aug 2010) Log Message: ----------- Added way for GUI screens to receive all player actions Modified Paths: -------------- main/trunk/src/guiengine/event_handler.cpp main/trunk/src/guiengine/screen.hpp Modified: main/trunk/src/guiengine/event_handler.cpp =================================================================== --- main/trunk/src/guiengine/event_handler.cpp 2010-08-25 22:55:58 UTC (rev 5778) +++ main/trunk/src/guiengine/event_handler.cpp 2010-08-26 00:08:10 UTC (rev 5779) @@ -95,9 +95,19 @@ // ----------------------------------------------------------------------------- -void EventHandler::processGUIAction(const PlayerAction action, const unsigned int value, - Input::InputType type, const int playerID) +void EventHandler::processGUIAction(const PlayerAction action, + const unsigned int value, + Input::InputType type, + const int playerID) { + Screen* screen = GUIEngine::getCurrentScreen(); + if (screen != NULL) + { + EventPropagation propg = screen->filterActions(action, value, + type, playerID); + if (propg == EVENT_BLOCK) return; + } + const bool pressedDown = value > Input::MAX_VALUE*2/3; if (!pressedDown && type == Input::IT_STICKMOTION) return; Modified: main/trunk/src/guiengine/screen.hpp =================================================================== --- main/trunk/src/guiengine/screen.hpp 2010-08-25 22:55:58 UTC (rev 5778) +++ main/trunk/src/guiengine/screen.hpp 2010-08-26 00:08:10 UTC (rev 5779) @@ -28,6 +28,7 @@ #include "config/stk_config.hpp" #include "guiengine/abstract_top_level_container.hpp" #include "guiengine/engine.hpp" +#include "guiengine/event_handler.hpp" #include "guiengine/layout_manager.hpp" #include "guiengine/widget.hpp" #include "input/input.hpp" @@ -254,10 +255,18 @@ * \brief Implementing method from AbstractTopLevelContainer */ virtual int getWidth(); + /** * \brief Implementing method from AbstractTopLevelContainer */ virtual int getHeight(); + + /** + * \brief override this if you need to be notified of player actions in subclasses + */ + virtual EventPropagation filterActions(PlayerAction action, const unsigned int value, + Input::InputType type, int playerId) { return EVENT_LET; } + }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-08-28 01:02:21
|
Revision: 5795 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5795&view=rev Author: auria Date: 2010-08-28 01:02:13 +0000 (Sat, 28 Aug 2010) Log Message: ----------- Fixed crash due to uninitialized variable in abstract top level container Modified Paths: -------------- main/trunk/src/guiengine/abstract_top_level_container.cpp main/trunk/src/guiengine/abstract_top_level_container.hpp main/trunk/src/guiengine/screen.cpp Modified: main/trunk/src/guiengine/abstract_top_level_container.cpp =================================================================== --- main/trunk/src/guiengine/abstract_top_level_container.cpp 2010-08-27 22:46:37 UTC (rev 5794) +++ main/trunk/src/guiengine/abstract_top_level_container.cpp 2010-08-28 01:02:13 UTC (rev 5795) @@ -34,6 +34,12 @@ using namespace io; using namespace gui; +AbstractTopLevelContainer::AbstractTopLevelContainer() +{ + m_first_widget = NULL; + m_last_widget = NULL; +} + void AbstractTopLevelContainer::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent) { const unsigned short widgets_amount = widgets.size(); Modified: main/trunk/src/guiengine/abstract_top_level_container.hpp =================================================================== --- main/trunk/src/guiengine/abstract_top_level_container.hpp 2010-08-27 22:46:37 UTC (rev 5794) +++ main/trunk/src/guiengine/abstract_top_level_container.hpp 2010-08-28 01:02:13 UTC (rev 5795) @@ -52,6 +52,7 @@ public: + AbstractTopLevelContainer(); virtual ~AbstractTopLevelContainer() {} virtual int getWidth() = 0; Modified: main/trunk/src/guiengine/screen.cpp =================================================================== --- main/trunk/src/guiengine/screen.cpp 2010-08-27 22:46:37 UTC (rev 5794) +++ main/trunk/src/guiengine/screen.cpp 2010-08-28 01:02:13 UTC (rev 5795) @@ -52,8 +52,6 @@ m_throttle_FPS = true; m_render_3d = false; m_loaded = false; - m_first_widget = NULL; - m_last_widget = NULL; m_pause_race = pause_race; } // Screen This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-09-04 23:55:38
|
Revision: 5890 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5890&view=rev Author: auria Date: 2010-09-04 23:55:32 +0000 (Sat, 04 Sep 2010) Log Message: ----------- tweaked help bubbles after testing in various languages Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/widgets/bubble_widget.cpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2010-09-04 23:40:30 UTC (rev 5889) +++ main/trunk/src/guiengine/skin.cpp 2010-09-04 23:55:32 UTC (rev 5890) @@ -1638,7 +1638,7 @@ core::rect< s32 > rect2 = rect; // minor adjustments... - rect2.UpperLeftCorner.X -= 15; + rect2.UpperLeftCorner.X -= 7; //rect2.LowerRightCorner.X -= 15; if (bubble->isFocusedForPlayer(PLAYER_ID_GAME_MASTER)) Modified: main/trunk/src/guiengine/widgets/bubble_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-04 23:40:30 UTC (rev 5889) +++ main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-04 23:55:32 UTC (rev 5890) @@ -52,8 +52,7 @@ m_expanded_size = m_shrinked_size; const int additionalNeededSize = std::max(0, text_height - m_shrinked_size.getHeight()); - // the '5' here is a bit arbitrary... - if (additionalNeededSize > 5) + if (additionalNeededSize > 0) { m_expanded_size.UpperLeftCorner.Y -= additionalNeededSize/2 + 10; m_expanded_size.LowerRightCorner.Y += additionalNeededSize/2 + 10; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-09-06 17:50:35
|
Revision: 5906 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5906&view=rev Author: auria Date: 2010-09-06 17:50:29 +0000 (Mon, 06 Sep 2010) Log Message: ----------- tweak text bubble widget so that the text cannot go too close to the right edge of the widget Modified Paths: -------------- main/trunk/src/guiengine/skin.cpp main/trunk/src/guiengine/widgets/bubble_widget.cpp main/trunk/src/guiengine/widgets/bubble_widget.hpp Modified: main/trunk/src/guiengine/skin.cpp =================================================================== --- main/trunk/src/guiengine/skin.cpp 2010-09-06 17:41:05 UTC (rev 5905) +++ main/trunk/src/guiengine/skin.cpp 2010-09-06 17:50:29 UTC (rev 5906) @@ -1639,7 +1639,7 @@ // minor adjustments... rect2.UpperLeftCorner.X -= 7; - //rect2.LowerRightCorner.X -= 15; + rect2.LowerRightCorner.X += BUBBLE_MARGIN_ON_RIGHT; if (bubble->isFocusedForPlayer(PLAYER_ID_GAME_MASTER)) drawBoxFromStretchableTexture(widget, rect2, SkinConfig::m_render_params["textbubble::focused"]); Modified: main/trunk/src/guiengine/widgets/bubble_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-06 17:41:05 UTC (rev 5905) +++ main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-06 17:50:29 UTC (rev 5906) @@ -34,7 +34,7 @@ void BubbleWidget::add() { - m_shrinked_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h); + m_shrinked_size = rect<s32>(m_x, m_y, m_x + m_w - BUBBLE_MARGIN_ON_RIGHT, m_y + m_h); stringw message = getText(); EGUI_ALIGNMENT align = EGUIA_UPPERLEFT; Modified: main/trunk/src/guiengine/widgets/bubble_widget.hpp =================================================================== --- main/trunk/src/guiengine/widgets/bubble_widget.hpp 2010-09-06 17:41:05 UTC (rev 5905) +++ main/trunk/src/guiengine/widgets/bubble_widget.hpp 2010-09-06 17:50:29 UTC (rev 5906) @@ -23,6 +23,7 @@ namespace GUIEngine { + const int BUBBLE_MARGIN_ON_RIGHT = 15; class BubbleWidget : public Widget { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-09-10 00:06:03
|
Revision: 5952 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=5952&view=rev Author: auria Date: 2010-09-10 00:05:56 +0000 (Fri, 10 Sep 2010) Log Message: ----------- Removed/fixed bogus/unneeded includes or forwards Modified Paths: -------------- main/trunk/src/guiengine/engine.hpp main/trunk/src/guiengine/layout_manager.hpp main/trunk/src/guiengine/modaldialog.hpp main/trunk/src/guiengine/screen.hpp main/trunk/src/guiengine/widget.hpp main/trunk/src/guiengine/widgets/bubble_widget.cpp main/trunk/src/guiengine/widgets/bubble_widget.hpp main/trunk/src/guiengine/widgets/button_widget.cpp main/trunk/src/guiengine/widgets/check_box_widget.cpp main/trunk/src/guiengine/widgets/label_widget.cpp main/trunk/src/guiengine/widgets/progress_bar_widget.cpp main/trunk/src/guiengine/widgets/text_box_widget.cpp main/trunk/src/guiengine/widgets/text_box_widget.hpp Modified: main/trunk/src/guiengine/engine.hpp =================================================================== --- main/trunk/src/guiengine/engine.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/engine.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -46,7 +46,6 @@ namespace GUIEngine { class Screen; - class CutScene; class Widget; class Skin; class AbstractStateManager; Modified: main/trunk/src/guiengine/layout_manager.hpp =================================================================== --- main/trunk/src/guiengine/layout_manager.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/layout_manager.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -21,8 +21,6 @@ #include <cstring> // for NULL #include "utils/ptr_vector.hpp" -#include "guiengine/widget.hpp" - namespace GUIEngine { class Widget; Modified: main/trunk/src/guiengine/modaldialog.hpp =================================================================== --- main/trunk/src/guiengine/modaldialog.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/modaldialog.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -21,12 +21,12 @@ #include "irrlicht.h" #include "utils/ptr_vector.hpp" #include "guiengine/abstract_top_level_container.hpp" -#include "guiengine/event_handler.hpp" -#include "guiengine/layout_manager.hpp" +//#include "guiengine/event_handler.hpp" +//#include "guiengine/layout_manager.hpp" #include "guiengine/skin.hpp" #include "input/input_manager.hpp" -class PlayerProfile; +//class PlayerProfile; /** * \ingroup guiengine Modified: main/trunk/src/guiengine/screen.hpp =================================================================== --- main/trunk/src/guiengine/screen.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/screen.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -29,7 +29,7 @@ #include "guiengine/abstract_top_level_container.hpp" #include "guiengine/engine.hpp" #include "guiengine/event_handler.hpp" -#include "guiengine/layout_manager.hpp" +//#include "guiengine/layout_manager.hpp" #include "guiengine/widget.hpp" #include "input/input.hpp" #include "utils/ptr_vector.hpp" Modified: main/trunk/src/guiengine/widget.hpp =================================================================== --- main/trunk/src/guiengine/widget.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widget.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -26,7 +26,7 @@ #include "guiengine/skin.hpp" #include "utils/constants.hpp" #include "utils/ptr_vector.hpp" -#include "utils/vec3.hpp" +//#include "utils/vec3.hpp" namespace GUIEngine { Modified: main/trunk/src/guiengine/widgets/bubble_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/bubble_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -20,6 +20,7 @@ #include <irrlicht.h> using namespace irr::core; using namespace irr::gui; +using namespace irr; using namespace GUIEngine; Modified: main/trunk/src/guiengine/widgets/bubble_widget.hpp =================================================================== --- main/trunk/src/guiengine/widgets/bubble_widget.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/bubble_widget.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -32,12 +32,12 @@ /** shrinked size of this widget (size allowed in layout; internal text may be bigger than that). * If the text all fits in the allowed layout space, m_shrinked_size == m_expanded_size. */ - irr::core::rect<s32> m_shrinked_size; + irr::core::rect<irr::s32> m_shrinked_size; /** Expanded size of this widget (size to see all text inside the bubble). * If the text all fits in the allowed layout space, m_shrinked_size == m_expanded_size. */ - irr::core::rect<s32> m_expanded_size; + irr::core::rect<irr::s32> m_expanded_size; /** Text shrinked to fit into the allowed layout space (will be same as m_text if all text fits) */ irr::core::stringw m_shrinked_text; Modified: main/trunk/src/guiengine/widgets/button_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/button_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/button_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -19,6 +19,7 @@ #include "guiengine/widgets/button_widget.hpp" using namespace GUIEngine; using namespace irr::core; +using namespace irr; // ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/widgets/check_box_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/check_box_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/check_box_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -19,6 +19,7 @@ #include "guiengine/widgets/check_box_widget.hpp" using namespace GUIEngine; using namespace irr::core; +using namespace irr; // ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/widgets/label_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/label_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/label_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -26,6 +26,7 @@ using namespace GUIEngine; using namespace irr::core; using namespace irr::gui; +using namespace irr; // ---------------------------------------------------------------------------- /** Constructs the label widget. Parameter: Modified: main/trunk/src/guiengine/widgets/progress_bar_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/progress_bar_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/progress_bar_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -21,6 +21,7 @@ #include <string.h> using namespace GUIEngine; using namespace irr::core; +using namespace irr; // ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/widgets/text_box_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/text_box_widget.cpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/text_box_widget.cpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -18,9 +18,11 @@ #include "guiengine/engine.hpp" #include "guiengine/modaldialog.hpp" #include "guiengine/widgets/text_box_widget.hpp" + using namespace GUIEngine; using namespace irr::core; using namespace irr::gui; +using namespace irr; // ----------------------------------------------------------------------------- Modified: main/trunk/src/guiengine/widgets/text_box_widget.hpp =================================================================== --- main/trunk/src/guiengine/widgets/text_box_widget.hpp 2010-09-09 13:41:44 UTC (rev 5951) +++ main/trunk/src/guiengine/widgets/text_box_widget.hpp 2010-09-10 00:05:56 UTC (rev 5952) @@ -53,7 +53,7 @@ virtual EventPropagation focused(const int playerID); virtual void unfocused(const int playerID); - core::stringw getText() const; + irr::core::stringw getText() const; }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <au...@us...> - 2010-09-19 17:22:55
|
Revision: 6063 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=6063&view=rev Author: auria Date: 2010-09-19 17:22:49 +0000 (Sun, 19 Sep 2010) Log Message: ----------- Suppressed unneeded warning from spinner widget Modified Paths: -------------- main/trunk/src/guiengine/engine.cpp main/trunk/src/guiengine/widgets/spinner_widget.cpp Modified: main/trunk/src/guiengine/engine.cpp =================================================================== --- main/trunk/src/guiengine/engine.cpp 2010-09-19 17:04:09 UTC (rev 6062) +++ main/trunk/src/guiengine/engine.cpp 2010-09-19 17:22:49 UTC (rev 6063) @@ -129,7 +129,7 @@ A spinner component (lets you choose numbers). Specify PROP_MIN_VALUE and PROP_MAX_VALUE to have control over values - (default will be from 0 to 10). You can specify an icon; then, include a + (default will be from 0 to 99). You can specify an icon; then, include a sprintf format string like %i in the name, and at runtime the current number will be inserted into the given name to find the right file for each possible value the spinner can take. It may also display arbitrary text Modified: main/trunk/src/guiengine/widgets/spinner_widget.cpp =================================================================== --- main/trunk/src/guiengine/widgets/spinner_widget.cpp 2010-09-19 17:04:09 UTC (rev 6062) +++ main/trunk/src/guiengine/widgets/spinner_widget.cpp 2010-09-19 17:22:49 UTC (rev 6063) @@ -37,6 +37,8 @@ m_check_inside_me = true; //FIXME: not sure this is necessary m_supports_multiplayer = true; + m_min = 0; + m_max = 999; } // ----------------------------------------------------------------------------- @@ -49,6 +51,7 @@ m_warp_around = (m_properties[PROP_WARP_AROUND] == "true"); + if (min_s.size() > 0) { int i; std::istringstream myStream(min_s); @@ -59,10 +62,11 @@ } else { - std::cerr << "WARNING : invalid value from spinner widget minimum value '" << min_s << "'\n"; - m_min = 0; + std::cerr << "WARNING : invalid value for spinner widget minimum value : '" << min_s << "'\n"; } } + + if (max_s.size() > 0) { int i; std::istringstream myStream(max_s); @@ -73,8 +77,7 @@ } else { - std::cerr << "WARNING : invalid value from spinner widget maximal value '" << max_s << "'\n"; - m_max = 10; + std::cerr << "WARNING : invalid value for spinner widget maximal value : '" << max_s << "'\n"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |