Something went wrong. Try again.
Massive multiplayer game aiming to create a collaborative musical environment.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331/*********************************************************************** filename: CEGUIThumb.cpp created: 25/4/2004 author: Paul D Turner purpose: Implements common parts of the Thumb base class widget*************************************************************************//*************************************************************************** * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************/#include "elements/CEGUIThumb.h"#include "CEGUICoordConverter.h"
// Start of CEGUI namespace sectionnamespace CEGUI{const String Thumb::EventNamespace("Thumb");const String Thumb::WidgetTypeName("CEGUI/Thumb");
/************************************************************************* Static Properties for this class*************************************************************************/ThumbProperties::HotTracked Thumb::d_hotTrackedProperty;ThumbProperties::VertFree Thumb::d_vertFreeProperty;ThumbProperties::HorzFree Thumb::d_horzFreeProperty;ThumbProperties::VertRange Thumb::d_vertRangeProperty;ThumbProperties::HorzRange Thumb::d_horzRangeProperty;
/************************************************************************* Event name constants*************************************************************************/// generated internally by Windowconst String Thumb::EventThumbPositionChanged( "ThumbPosChanged" );const String Thumb::EventThumbTrackStarted( "ThumbTrackStarted" );const String Thumb::EventThumbTrackEnded( "ThumbTrackEnded" );
/************************************************************************* Constructor for Thumb objects*************************************************************************/Thumb::Thumb(const String& type, const String& name) : PushButton(type, name), d_hotTrack(true), d_vertFree(false), d_horzFree(false), d_vertMin(0.0f), d_vertMax(1.0f), d_horzMin(0.0f), d_horzMax(1.0f), d_beingDragged(false){ addThumbProperties();}
/************************************************************************* Destructor for Thumb objects *************************************************************************/Thumb::~Thumb(void){}
/************************************************************************* set the movement range of the thumb for the vertical axis. *************************************************************************/void Thumb::setVertRange(float min, float max){ // ensure min <= max, swap if not. if (min > max) { float tmp = min; max = min; min = tmp; }
d_vertMax = max; d_vertMin = min;
// validate current position. float cp = getYPosition().asRelative(getParentPixelHeight());
if (cp < min) { setYPosition(cegui_reldim(min)); } else if (cp > max) { setYPosition(cegui_reldim(max)); }
}
/************************************************************************* set the movement range of the thumb for the horizontal axis.*************************************************************************/void Thumb::setHorzRange(float min, float max){ Size parentSize(getParentPixelSize());
// ensure min <= max, swap if not. if (min > max) { float tmp = min; max = min; min = tmp; }
d_horzMax = max; d_horzMin = min;
// validate current position. float cp = getXPosition().asAbsolute(parentSize.d_width);
if (cp < min) { setXPosition(cegui_absdim(min)); } else if (cp > max) { setXPosition(cegui_absdim(max)); }
}
/************************************************************************* event triggered internally when the position of the thumb *************************************************************************/void Thumb::onThumbPositionChanged(WindowEventArgs& e){ fireEvent(EventThumbPositionChanged, e, EventNamespace);}
/************************************************************************* Handler triggered when the user begins to drag the thumb. *************************************************************************/void Thumb::onThumbTrackStarted(WindowEventArgs& e){ fireEvent(EventThumbTrackStarted, e, EventNamespace);}
/************************************************************************* Handler triggered when the thumb is released*************************************************************************/void Thumb::onThumbTrackEnded(WindowEventArgs& e){ fireEvent(EventThumbTrackEnded, e, EventNamespace);}
/************************************************************************* Handler for mouse movement events*************************************************************************/void Thumb::onMouseMove(MouseEventArgs& e){ // default processing PushButton::onMouseMove(e);
// only react if we are being dragged if (d_beingDragged) { Size parentSize(getParentPixelSize());
Vector2 delta; float hmin, hmax, vmin, vmax;
delta = CoordConverter::screenToWindow(*this, e.position);
hmin = d_horzMin; hmax = d_horzMax; vmin = d_vertMin; vmax = d_vertMax;
// calculate amount of movement delta -= d_dragPoint; delta.d_x /= parentSize.d_width; delta.d_y /= parentSize.d_height;
// // Calculate new (pixel) position for thumb // UVector2 newPos(getPosition());
if (d_horzFree) { newPos.d_x.d_scale += delta.d_x;
// limit value to within currently set range newPos.d_x.d_scale = (newPos.d_x.d_scale < hmin) ? hmin : (newPos.d_x.d_scale > hmax) ? hmax : newPos.d_x.d_scale; }
if (d_vertFree) { newPos.d_y.d_scale += delta.d_y;
// limit new position to within currently set range newPos.d_y.d_scale = (newPos.d_y.d_scale < vmin) ? vmin : (newPos.d_y.d_scale > vmax) ? vmax : newPos.d_y.d_scale; }
// update thumb position if needed if (newPos != getPosition()) { setPosition(newPos);
// send notification as required if (d_hotTrack) { WindowEventArgs args(this); onThumbPositionChanged(args); }
}
}
e.handled = true;}
/************************************************************************* Handler for mouse button down events*************************************************************************/void Thumb::onMouseButtonDown(MouseEventArgs& e){ // default processing PushButton::onMouseButtonDown(e);
if (e.button == LeftButton) { // initialise the dragging state d_beingDragged = true; d_dragPoint = CoordConverter::screenToWindow(*this, e.position);
// trigger tracking started event WindowEventArgs args(this); onThumbTrackStarted(args);
e.handled = true; }
}
/************************************************************************* Handler for event triggered when we lose capture of mouse input*************************************************************************/void Thumb::onCaptureLost(WindowEventArgs& e){ // default handling PushButton::onCaptureLost(e);
d_beingDragged = false;
// trigger tracking ended event WindowEventArgs args(this); onThumbTrackEnded(args);
// send notification whenever thumb is released onThumbPositionChanged(args);}
/************************************************************************* Return a std::pair that describes the current range set for the vertical movement. *************************************************************************/std::pair<float, float> Thumb::getVertRange(void) const{ return std::make_pair(d_vertMin, d_vertMax);}
/************************************************************************* Return a std::pair that describes the current range set for the horizontal movement. *************************************************************************/std::pair<float, float> Thumb::getHorzRange(void) const{ return std::make_pair(d_horzMin, d_horzMax);}
/************************************************************************* Add thumb specifiec properties*************************************************************************/void Thumb::addThumbProperties(void){ addProperty(&d_hotTrackedProperty); addProperty(&d_vertFreeProperty); addProperty(&d_horzFreeProperty); addProperty(&d_vertRangeProperty); addProperty(&d_horzRangeProperty);
// if we're an autowindow we ban some properties from XML if (isAutoWindow()) { banPropertyFromXML(&d_vertRangeProperty); banPropertyFromXML(&d_horzRangeProperty); banPropertyFromXML(&d_vertFreeProperty); banPropertyFromXML(&d_horzFreeProperty); }}
} // End of CEGUI namespace section