Something went wrong. Try again.
Massive multiplayer game aiming to create a collaborative musical environment.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262/*********************************************************************** filename: CEGUIComboDropList.cpp created: 13/6/2004 author: Paul D Turner
purpose: Implements the Combobox Drop-List widget base class*************************************************************************//*************************************************************************** * 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/CEGUIComboDropList.h"#include "elements/CEGUIScrollbar.h"#include "elements/CEGUIListboxItem.h"#include "CEGUICoordConverter.h"
// Start of CEGUI namespace sectionnamespace CEGUI{const String ComboDropList::EventNamespace("ComboDropList");const String ComboDropList::WidgetTypeName("CEGUI/ComboDropList");
/************************************************************************* Constants*************************************************************************/// Event namesconst String ComboDropList::EventListSelectionAccepted( "ListSelectionAccepted" );
/************************************************************************* Constructor for ComboDropList base class*************************************************************************/ComboDropList::ComboDropList(const String& type, const String& name) : Listbox(type, name){ d_autoArm = false; d_armed = false; d_lastClickSelected = 0;
hide();
// pass captured inputs to children to enable scrollbars setDistributesCapturedInputs(true);}
/************************************************************************* Destructor for ComboDropList base class*************************************************************************/ComboDropList::~ComboDropList(void){}
/************************************************************************* Initialise the Window based object ready for use.*************************************************************************/void ComboDropList::initialiseComponents(void){ Listbox::initialiseComponents();
// set-up scroll bars so they return capture to us. getVertScrollbar()->setRestoreCapture(true); getHorzScrollbar()->setRestoreCapture(true);}
/************************************************************************* Handler for when list selection is confirmed.*************************************************************************/void ComboDropList::onListSelectionAccepted(WindowEventArgs& e){ d_lastClickSelected = getFirstSelectedItem(); fireEvent(EventListSelectionAccepted, e, EventNamespace);}
/************************************************************************* Handler for when list content has changed*************************************************************************/void ComboDropList::onListContentsChanged(WindowEventArgs& e){ // basically see if our 'sticky' selection was removed if ((d_lastClickSelected) && !isListboxItemInList(d_lastClickSelected)) d_lastClickSelected = 0;
// base class processing Listbox::onListContentsChanged(e);}
/************************************************************************* Handler for when list selection has changed*************************************************************************/void ComboDropList::onSelectionChanged(WindowEventArgs& e){ if (!isActive()) d_lastClickSelected = getFirstSelectedItem();
Listbox::onSelectionChanged(e);}
/************************************************************************* Handler for mouse movement events*************************************************************************/void ComboDropList::onMouseMove(MouseEventArgs& e){ Listbox::onMouseMove(e);
// if mouse is within our area (but not our children) if (isHit(e.position)) { if (!getChildAtPosition(e.position)) { // handle auto-arm if (d_autoArm) { d_armed = true; }
if (d_armed) { // // Convert mouse position to absolute window pixels // Point localPos(CoordConverter::screenToWindow(*this, e.position));
// check for an item under the mouse ListboxItem* selItem = getItemAtPoint(localPos);
// if an item is under mouse, select it if (selItem) { setItemSelectState(selItem, true); } else { clearAllSelections(); }
} }
e.handled = true; } // not within the list area else { // if left mouse button is down, clear any selection if (e.sysKeys & LeftMouse) { clearAllSelections(); }
}
}
/************************************************************************* Handler for mouse button pressed events*************************************************************************/void ComboDropList::onMouseButtonDown(MouseEventArgs& e){ Listbox::onMouseButtonDown(e);
if (e.button == LeftButton) { if (!isHit(e.position)) { clearAllSelections(); releaseInput(); } else { d_armed = true; }
e.handled = true; }
}
/************************************************************************* Handler for mouse button release events*************************************************************************/void ComboDropList::onMouseButtonUp(MouseEventArgs& e){ Listbox::onMouseButtonUp(e);
if (e.button == LeftButton) { if (d_armed && (getChildAtPosition(e.position) == 0)) { // if something was selected, confirm that selection. if (getSelectedCount() > 0) { WindowEventArgs args(this); onListSelectionAccepted(args); }
releaseInput(); } // if we are not already armed, in response to a left button up event, we auto-arm. else { d_armed = true; }
e.handled = true; }
}
/************************************************************************* Handler for when input capture is lost*************************************************************************/void ComboDropList::onCaptureLost(WindowEventArgs& e){ Listbox::onCaptureLost(e); d_armed = false; hide(); e.handled = true;
// ensure 'sticky' selection remains. if ((d_lastClickSelected) && !d_lastClickSelected->isSelected()) { clearAllSelections_impl(); setItemSelectState(d_lastClickSelected, true); }}
/************************************************************************* Handler for when window is activated*************************************************************************/void ComboDropList::onActivated(ActivationEventArgs& e){ Listbox::onActivated(e);}
} // End of CEGUI namespace section