return event EGET_SCROLL_BAR_CHANGED
Need for compile class CNrpScrollBar and CNrpRotatableImage
Header
Code: Select all
/**********************************************
Copyright (C) 2009-2010 Dalerank and Gilly Oster
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*******************************************************/
#include "NrpScrollBar.h"
namespace irr
{
namespace gui
{
class CNrpRotatableImage;
class CNrpCircleScrollBar : public CNrpScrollBar
{
public:
//! constructor
CNrpCircleScrollBar( IGUIEnvironment* environment,
IGUIElement* parent, s32 id,
core::rect<s32> rectangle,
bool noclip=false);
//! destructor
virtual ~CNrpCircleScrollBar();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets the position of the scrollbar
virtual void setPos(s32 pos);
//! gets the current position of the scrollbar
virtual s32 getPos() const;
//! sets the texture which draw
virtual void setTexture( video::ITexture* texture );
virtual void setSliderTexture( video::ITexture* texture );
void updateAbsolutePosition();
private:
f32 GetCurrentAngle_( const core::position2di& mPos );
bool mouse2rotate_;
f32 startAngle_, aPos;
int circleCounter_;
gui::CNrpRotatableImage* rImage_;
};
}//namespace gui
}//namespace irr
Code: Select all
#include "NrpCircleScrollBar.h"
#include "NrpRotatableImage.h"
#include <irrlicht.h>
namespace irr
{
namespace gui
{
CNrpCircleScrollBar::CNrpCircleScrollBar(IGUIEnvironment* environment,
IGUIElement* parent, s32 id,
core::rect<s32> rectangle,
bool noclip) : CNrpScrollBar( false, environment, parent, id, rectangle )
{
#ifdef _DEBUG
setDebugName("CNrpCircleScrollBar");
#endif
while( Children.getSize() )
(*Children.begin())->remove();
UpButton = NULL;
DownButton = NULL;
mouse2rotate_ = false;
Min = 0;
Max = 100;
startAngle_ = 0;
circleCounter_ = 0;
aPos = 0;
rImage_ = new CNrpRotatableImage( core::recti( 0, 0, AbsoluteRect.getWidth(), AbsoluteRect.getHeight() ), environment, -1, this );
}
CNrpCircleScrollBar::~CNrpCircleScrollBar()
{
}
void CNrpCircleScrollBar::setPos( s32 pos )
{
aPos = (f32)core::s32_clamp ( pos, Min, Max );
startAngle_ = pos / 360.f;
rImage_->SetRotate( startAngle_ );
}
void CNrpCircleScrollBar::updateAbsolutePosition()
{
IGUIElement::updateAbsolutePosition();
setPos ( Pos );
}
bool CNrpCircleScrollBar::OnEvent( const SEvent& event )
{
switch( event.EventType )
{
case EET_GUI_EVENT:
if( event.GUIEvent.EventType == EGET_ELEMENT_LEFT )
{
mouse2rotate_ = false;
return true;
}
break;
case EET_MOUSE_INPUT_EVENT:
if( event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN )
{
mouse2rotate_ = true;
startAngle_ = GetCurrentAngle_( core::position2di( event.MouseInput.X, event.MouseInput.Y) );
return true;
}
if( event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP )
{
mouse2rotate_ = false;
return true;
}
if( event.MouseInput.Event == EMIE_MOUSE_MOVED && mouse2rotate_ )
{
f32 offset = GetCurrentAngle_( core::position2di( event.MouseInput.X, event.MouseInput.Y) ) - startAngle_;
if( aPos + offset >= Min && aPos + offset < Max )
{
startAngle_ += offset;
aPos += offset;
rImage_->SetRotate( rImage_->getRotate() - offset );
SEvent newEvent;
newEvent.EventType = EET_GUI_EVENT;
newEvent.GUIEvent.Caller = this;
newEvent.GUIEvent.Element = 0;
newEvent.GUIEvent.EventType = EGET_SCROLL_BAR_CHANGED;
Parent->OnEvent(newEvent);
return true;
}
else
{
#ifdef _DEBUG
OutputDebugString( IntToStr( (int)(offset + startAngle_) ).c_str() );
OutputDebugString( "\n" );
#endif
mouse2rotate_ = false;
}
}
break;
}
return false;
}
f32 CNrpCircleScrollBar::GetCurrentAngle_( const core::position2di& mPos )
{
f32 angle=startAngle_;
f32 dst = (f32)mPos.getDistanceFrom( AbsoluteRect.getCenter() );
f32 rad = AbsoluteRect.getWidth() / 2.f;
if( dst > 0.2 * rad && dst < rad )
{
angle = atan2f( (f32)(mPos.Y - AbsoluteRect.getCenter().Y),
(f32)(mPos.X - AbsoluteRect.getCenter().X) ) * 180 / core::PI + 90;
}
if( angle < 0 )
angle = 360 + angle;
if( angle + circleCounter_ * 360 - startAngle_ < -100 )
circleCounter_++;
else if( angle + circleCounter_ * 360 - startAngle_ > 100 )
circleCounter_--;
return angle + circleCounter_ * 360;
}
void CNrpCircleScrollBar::setTexture( video::ITexture* texture )
{
CNrpScrollBar::setTexture( texture );
}
irr::s32 CNrpCircleScrollBar::getPos() const
{
return (s32)aPos;
}
void CNrpCircleScrollBar::setSliderTexture( video::ITexture* texture )
{
CNrpScrollBar::setSliderTexture( texture );
rImage_->SetTexture( texture );
}
void CNrpCircleScrollBar::draw()
{
if( IsVisible )
{
if( texture_ )
{
core::recti srcRect = core::recti( core::position2di( 0, 0 ), texture_->getSize() );
Environment->getVideoDriver()->draw2DImage( texture_, AbsoluteRect, srcRect, 0, 0, true );
}
rImage_->draw();
IGUIElement::draw();
}
}
}//namesapce gui
}//namesapce irr
http://depositfiles.com/files/503k5efb5