diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIScrollBar.h Irrlicht_starsonata/include/IGUIScrollBar.h --- irrlicht-svn-ss/trunk/include/IGUIScrollBar.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIScrollBar.h 2008-06-05 04:47:02.000000000 +0200 @@ -41,6 +41,22 @@ namespace gui //! sets the current position of the scrollbar virtual void setPos(s32 pos) = 0; + + // StarSonata, Micha + //! override the background color + virtual void setBackgroundOverrideColor(const video::SColor &color) = 0; + + // StarSonata, Micha + //! clear the background color override + virtual void clearBackgroundOverrideColor() = 0; + + // StarSonata, Micha + //! set the page size used for a variable sized thumb + virtual void setPageSize(s32 pageSize) = 0; + + // StarSonata, Micha + //! get the page size used for a variable sized thumb + virtual s32 getPageSize() = 0; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIScrollBar.cpp Irrlicht_starsonata/source/Irrlicht/CGUIScrollBar.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIScrollBar.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIScrollBar.cpp 2008-06-05 06:40:54.000000000 +0200 @@ -21,8 +21,8 @@ CGUIScrollBar::CGUIScrollBar(bool horizo IGUIElement* parent, s32 id, core::rect rectangle, bool noclip) : IGUIScrollBar(environment, parent, id, rectangle), UpButton(0), DownButton(0), - Dragging(false), Horizontal(horizontal), Pos(0), DrawPos(0), - DrawHeight(0), Max(100), SmallStep(10) + Dragging(false), Horizontal(horizontal), Pos(0), DrawCenter(0), + ThumbSize(0), Max(100), SmallStep(10), MinThumbSize(10), PageSize(100) { #ifdef _DEBUG setDebugName("CGUIScrollBar"); @@ -54,6 +54,9 @@ CGUIScrollBar::~CGUIScrollBar() //! called if an event happened. bool CGUIScrollBar::OnEvent(SEvent event) { + if (!IsEnabled) + return IGUIElement::OnEvent(event); + switch(event.EventType) { case EET_KEY_INPUT_EVENT: @@ -144,6 +147,18 @@ bool CGUIScrollBar::OnEvent(SEvent event { Dragging = true; Environment->setFocus(this); + + s32 oldPos = Pos; + setPosFromMousePos(event.MouseInput.X, event.MouseInput.Y); + if (Pos != oldPos && Parent) + { + SEvent event; + event.EventType = EET_GUI_EVENT; + event.GUIEvent.Caller = this; + event.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED; + Parent->OnEvent(event); + } + return true; } else @@ -193,20 +208,21 @@ void CGUIScrollBar::draw() core::rect rect = AbsoluteRect; // draws the background - skin->draw2DRectangle(this, skin->getColor(EGDC_SCROLLBAR), rect, &AbsoluteClippingRect); + video::SColor backgroundCol = BackgroundOverrideColor.Use ? BackgroundOverrideColor.Color : skin->getColor(EGDC_SCROLLBAR); + skin->draw2DRectangle(this, backgroundCol, rect, &AbsoluteClippingRect); if (Max!=0) { // draw thumb if (Horizontal) { - rect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawPos + RelativeRect.getHeight() - DrawHeight/2; - rect.LowerRightCorner.X = rect.UpperLeftCorner.X + DrawHeight; + rect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + DrawCenter - ThumbSize/2; + rect.LowerRightCorner.X = rect.UpperLeftCorner.X + ThumbSize; } else { - rect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawPos + RelativeRect.getWidth() - DrawHeight/2; - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + DrawHeight; + rect.UpperLeftCorner.Y = AbsoluteRect.UpperLeftCorner.Y + DrawCenter - ThumbSize/2; + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + ThumbSize; } skin->draw3DButtonPaneStandard(this, rect, &AbsoluteClippingRect); @@ -221,38 +237,58 @@ void CGUIScrollBar::updateAbsolutePositi IGUIElement::updateAbsolutePosition(); // todo: properly resize refreshControls(); + refreshThumbPlacing(); +} + +void CGUIScrollBar::setBackgroundOverrideColor(const video::SColor &color) +{ + BackgroundOverrideColor.Use = true; + BackgroundOverrideColor.Color = color; +} +void CGUIScrollBar::clearBackgroundOverrideColor() +{ + BackgroundOverrideColor.Use = false; +} + +void CGUIScrollBar::setPosFromMousePos(s32 x, s32 y) +{ + s32 halfThumb = ThumbSize/2; if (Horizontal) { - f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight()*3.0f)) / (f32)Max; - DrawPos = (s32)((Pos * f) + ((f32)RelativeRect.getHeight() * 0.5f)); - DrawHeight = RelativeRect.getHeight(); + f32 f = (RelativeRect.getWidth() - (f32)RelativeRect.getHeight()*2.0f - (f32)ThumbSize) / (f32)Max; + setPos( (s32)((f32)(x-RelativeRect.getHeight()-AbsoluteRect.UpperLeftCorner.X-halfThumb) / f) ); } else { - f32 f = 0.0f; - if (Max != 0) - f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth()*3.0f)) / (f32)Max; - - DrawPos = (s32)((Pos * f) + ((f32)RelativeRect.getWidth() * 0.5f)); - DrawHeight = RelativeRect.getWidth(); + f32 f = (RelativeRect.getHeight() - (f32)RelativeRect.getWidth()*2.0f - (f32)ThumbSize) / (f32)Max; + setPos( (s32)((f32)(y-RelativeRect.getWidth()-AbsoluteRect.UpperLeftCorner.Y-halfThumb) / f) ); } } -void CGUIScrollBar::setPosFromMousePos(s32 x, s32 y) +void CGUIScrollBar::refreshThumbPlacing() { + s32 border = 0; + s32 thumbArea = 0; if (Horizontal) { - f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight()*3.0f)) / (f32)Max; - setPos((s32)(((f32)(x - AbsoluteRect.UpperLeftCorner.X - RelativeRect.getHeight())) / f)); + border = RelativeRect.getHeight(); + thumbArea = RelativeRect.getWidth() - 2*border; } else { - f32 f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth()*3.0f)) / (f32)Max; - setPos((s32)(((f32)y - AbsoluteRect.UpperLeftCorner.Y - RelativeRect.getWidth()) / f)); + border = RelativeRect.getWidth(); + thumbArea = RelativeRect.getHeight() - 2*border; } -} + ThumbSize = Max && PageSize < Max ? s32(f32(PageSize*thumbArea)/f32(Max)) : thumbArea; + if ( ThumbSize < MinThumbSize ) + ThumbSize = MinThumbSize; + if ( ThumbSize > thumbArea ) + ThumbSize = thumbArea; + f32 f = Max ? (f32)(thumbArea-ThumbSize) / (f32)Max : 0.f; + DrawCenter = (s32)core::round( (Pos * f) + ((f32)ThumbSize * 0.5f) )+ border; +} //! sets the position of the scrollbar @@ -264,21 +300,7 @@ void CGUIScrollBar::setPos(s32 pos) if (Pos > Max) Pos = Max; - if (Horizontal) - { - f32 f = (RelativeRect.getWidth() - ((f32)RelativeRect.getHeight()*3.0f)) / (f32)Max; - DrawPos = (s32)((Pos * f) + ((f32)RelativeRect.getHeight() * 0.5f)); - DrawHeight = RelativeRect.getHeight(); - } - else - { - f32 f = 0.0f; - if (Max != 0) - f = (RelativeRect.getHeight() - ((f32)RelativeRect.getWidth()*3.0f)) / (f32)Max; - - DrawPos = (s32)((Pos * f) + ((f32)RelativeRect.getWidth() * 0.5f)); - DrawHeight = RelativeRect.getWidth(); - } + refreshThumbPlacing(); } @@ -340,7 +362,7 @@ void CGUIScrollBar::refreshControls() if (skin) { sprites = skin->getSpriteBank(); - color = skin->getColor(EGDC_WINDOW_SYMBOL); + color = skin->getColor(EGDC_ICON); } if (Horizontal) @@ -356,7 +378,7 @@ void CGUIScrollBar::refreshControls() { UpButton->setSpriteBank(sprites); UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), color); - UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), color); + UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT_PRESSED), color); } UpButton->setRelativePosition(core::rect(0,0, h, h)); UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); @@ -370,7 +392,7 @@ void CGUIScrollBar::refreshControls() { DownButton->setSpriteBank(sprites); DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), color); - DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), color); + DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT_PRESSED), color); } DownButton->setRelativePosition(core::rect(RelativeRect.getWidth()-h, 0, RelativeRect.getWidth(), h)); DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); @@ -388,7 +410,7 @@ void CGUIScrollBar::refreshControls() { UpButton->setSpriteBank(sprites); UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_UP), color); - UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_UP), color); + UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_UP_PRESSED), color); } UpButton->setRelativePosition(core::rect(0,0, w, w)); UpButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); @@ -402,13 +424,24 @@ void CGUIScrollBar::refreshControls() { DownButton->setSpriteBank(sprites); DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), color); - DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), color); + DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN_PRESSED), color); } DownButton->setRelativePosition(core::rect(0,RelativeRect.getHeight()-w, w, RelativeRect.getHeight())); DownButton->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT); } } +void CGUIScrollBar::setPageSize(s32 pageSize) +{ + PageSize = pageSize; + refreshThumbPlacing(); +} + +s32 CGUIScrollBar::getPageSize() +{ + return PageSize; +} + //! Writes attributes of the element. void CGUIScrollBar::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) { @@ -418,6 +451,8 @@ void CGUIScrollBar::serializeAttributes( out->addInt ("Value", Pos); out->addInt ("Max", Max); out->addInt ("SmallStep", SmallStep); + out->addInt ("MinThumbSize", MinThumbSize); + out->addInt ("PageSize", PageSize); } //! Reads attributes of the element @@ -429,9 +464,12 @@ void CGUIScrollBar::deserializeAttribute setMax(in->getAttributeAsInt("Max")); setPos(in->getAttributeAsInt("Value")); setSmallStep(in->getAttributeAsInt("SmallStep")); + MinThumbSize = in->getAttributeAsInt("MinThumbSize"); + PageSize = in->getAttributeAsInt("PageSize"); NoClip = in->getAttributeAsBool("NoClip"); refreshControls(); + refreshThumbPlacing(); } diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIScrollBar.h Irrlicht_starsonata/source/Irrlicht/CGUIScrollBar.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIScrollBar.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIScrollBar.h 2008-06-05 04:47:46.000000000 +0200 @@ -53,6 +53,22 @@ namespace gui //! updates the rectangle virtual void updateAbsolutePosition(); + // StarSonata, Micha + //! override the background color + virtual void setBackgroundOverrideColor(const video::SColor &color); + + // StarSonata, Micha + //! clear the background color override + virtual void clearBackgroundOverrideColor(); + + // StarSonata, Micha + //! set the page size used for a variable sized thumb + virtual void setPageSize(s32 pageSize); + + // StarSonata, Micha + //! get the page size used for a variable sized thumb + virtual s32 getPageSize(); + //! Writes attributes of the element. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options); @@ -63,18 +79,29 @@ namespace gui private: void refreshControls(); + void refreshThumbPlacing(); void setPosFromMousePos(s32 x, s32 y); + struct OverrideColor + { + OverrideColor() : Use(false) {} + bool Use; + video::SColor Color; + }; + IGUIButton* UpButton; IGUIButton* DownButton; bool Dragging; bool Horizontal; s32 Pos; - s32 DrawPos; - s32 DrawHeight; + s32 DrawCenter; + s32 ThumbSize; s32 Max; s32 SmallStep; + s32 MinThumbSize; + s32 PageSize; + OverrideColor BackgroundOverrideColor; }; } // end namespace gui