//! constructor CGUIColorSelectDialog::CGUIColorSelectDialog(const wchar_t* title, IGUIEnvironment* environment, IGUIElement* parent, s32 id) : IGUIColorSelectDialog(environment, parent, id, core::rect<s32>((parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2, (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2, (parent->getAbsolutePosition().getWidth()-CSD_WIDTH)/2+CSD_WIDTH, (parent->getAbsolutePosition().getHeight()-CSD_HEIGHT)/2+CSD_HEIGHT)), Dragging(false) { #ifdef _DEBUG IGUIElement::setDebugName("CGUIColorSelectDialog"); #endif Text = title; IGUISkin* skin = Environment->getSkin(); const s32 buttonw = environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH); const s32 posx = RelativeRect.getWidth() - buttonw - 4; CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1, L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close"); if (skin && skin->getSpriteBank()) { CloseButton->setSpriteBank(skin->getSpriteBank()); CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL)); CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), skin->getColor(EGDC_WINDOW_SYMBOL)); } CloseButton->setSubElement(true); CloseButton->setTabStop(false); CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); CloseButton->grab(); OKButton = Environment->addButton( core::rect<s32>(RelativeRect.getWidth()-80, 30, RelativeRect.getWidth()-10, 50), this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_OK) : L"OK"); OKButton->setSubElement(true); OKButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); OKButton->grab(); CancelButton = Environment->addButton( core::rect<s32>(RelativeRect.getWidth()-80, 55, RelativeRect.getWidth()-10, 75), this, -1, skin ? skin->getDefaultText(EGDT_MSG_BOX_CANCEL) : L"Cancel"); CancelButton->setSubElement(true); CancelButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); CancelButton->grab(); video::IVideoDriver* driver = Environment->getVideoDriver(); ColorRing.Texture = driver->getTexture ( "#colorring" ); if ( 0 == ColorRing.Texture ) { buildColorRing(core::dimension2d<u32>(128, 128), 1, Environment->getSkin()->getColor(EGDC_3D_SHADOW)); } core::rect<s32> r(20,20, 0,0); ColorRing.Control = Environment->addImage(ColorRing.Texture, r.UpperLeftCorner, true, this); ColorRing.Control->setSubElement(true); ColorRing.Control->grab(); for ( u32 i = 0; i != sizeof (Template) / sizeof ( subElementPredefines ); ++i ) { if ( Template[i].pre ) { r.UpperLeftCorner.X = Template[i].x; r.UpperLeftCorner.Y = Template[i].y; r.LowerRightCorner.X = r.UpperLeftCorner.X + 15; r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; IGUIElement *t = Environment->addStaticText(Template[i].pre, r, false, false, this); t->setSubElement(true); } if ( Template[i].post ) { r.UpperLeftCorner.X = Template[i].x + 56; r.UpperLeftCorner.Y = Template[i].y; r.LowerRightCorner.X = r.UpperLeftCorner.X + 15; r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; IGUIElement *t = Environment->addStaticText( Template[i].post, r, false, false, this); t->setSubElement(true); } r.UpperLeftCorner.X = Template[i].x + 15; r.UpperLeftCorner.Y = Template[i].y-2; r.LowerRightCorner.X = r.UpperLeftCorner.X + 40; r.LowerRightCorner.Y = r.UpperLeftCorner.Y + 20; gui::IGUISpinBox* spin = Environment->addSpinBox( Template[i].init, r, true, this); spin->setSubElement(true); spin->setDecimalPlaces(0); spin->setRange((f32)Template[i].range_down, (f32)Template[i].range_up); spin->grab(); Battery.push_back(spin); } bringToFront(CancelButton); bringToFront(OKButton); }
void MainWindow::creatActions() { //LogicItem exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcut(tr("Ctrl+Q")); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); addAndGateAction = new QAction(tr("Insert AND"), this); addAndGateAction->setCheckable(true); addAndGateAction->setIcon(QIcon(":/images/node.png")); addAndGateAction->setShortcut(tr("Ctrl+N")); addOrGateAction = new QAction(tr("OR"), this); addOrGateAction->setCheckable (true); addNotGateAction = new QAction(tr("NOT"), this); addNotGateAction->setCheckable(true); addNotGateAction->setIcon(QIcon()); addTextAction = new QAction(tr("Insert Text"),this); addTextAction->setCheckable(true); actionGroup = new QActionGroup(this); actionGroup->addAction(addAndGateAction); actionGroup->addAction(addOrGateAction); actionGroup->addAction(addNotGateAction); actionGroup->setExclusive(true); connect(actionGroup,SIGNAL(triggered(QAction*)),this,SLOT(actionGroupClicked(QAction*))); deleteAction = new QAction(tr("&Delete"), this); deleteAction->setIcon(QIcon(":/images/delete.png")); deleteAction->setShortcut(tr("Del")); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); cutAction = new QAction(tr("Cu&t"), this); cutAction->setIcon(QIcon(":/images/cut.png")); cutAction->setShortcut(tr("Ctrl+X")); connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())); copyAction = new QAction(tr("&Copy"), this); copyAction->setIcon(QIcon(":/images/copy.png")); copyAction->setShortcut(tr("Ctrl+C")); connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); pasteAction = new QAction(tr("&Paste"), this); pasteAction->setIcon(QIcon(":/images/paste.png")); pasteAction->setShortcut(tr("Ctrl+V")); connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); bringToFrontAction = new QAction(tr("Bring to &Front"), this); bringToFrontAction->setIcon(QIcon(":/images/bringtofront.png")); connect(bringToFrontAction, SIGNAL(triggered()), this, SLOT(bringToFront())); sendToBackAction = new QAction(tr("&Send to Back"), this); sendToBackAction->setIcon(QIcon(":/images/sendtoback.png")); connect(sendToBackAction, SIGNAL(triggered()), this, SLOT(sendToBack())); propertiesAction = new QAction(tr("P&roperties..."), this); connect(propertiesAction, SIGNAL(triggered()), this, SLOT(properties())); }
//! called if an event happened. bool MainMenu::onEvent(const NEvent& event) { if (isEnabled()) { switch(event.EventType) { case sEventGui: switch(event.GuiEvent.EventType) { case guiElementFocusLost: if (event.GuiEvent.Caller == this && !isMyChild(event.GuiEvent.Element)) { closeAllSubMenus_(); setHoverIndex_( -1 ); } break; case guiElementFocused: if (event.GuiEvent.Caller == this ) { bringToFront(); } break; default: break; } break; case sEventMouse: switch(event.MouseEvent.Event) { case mouseLbtnPressed: { if (!getEnvironment()->hasFocus(this)) { getEnvironment()->setFocus(this); } bringToFront(); Point p(event.MouseEvent.getPosition() ); bool shouldCloseSubMenu = hasOpenSubMenu_(); if (!getAbsoluteClippingRect().isPointInside(p)) { shouldCloseSubMenu = false; } isHighlighted_( event.MouseEvent.getPosition(), true); if ( shouldCloseSubMenu ) { getEnvironment()->removeFocus(this); } return true; } case mouseLbtnRelease: { Point p(event.MouseEvent.getPosition() ); if (!getAbsoluteClippingRect().isPointInside(p)) { int t = sendClick_(p); if ((t==0 || t==1) && isFocused()) removeFocus(); } return true; } case mouseMoved: { if (getEnvironment()->hasFocus(this) && getHoveredIndex() >= 0) { int oldHighLighted = getHoveredIndex(); isHighlighted_( event.MouseEvent.getPosition(), true); if ( getHoveredIndex() < 0 ) { setHoverIndex_( oldHighLighted ); // keep last hightlight active when moving outside the area } } return true; } default: break; } break; default: break; } } return Widget::onEvent(event); }
// ---------------------------------------------------------------------- // static method - called once for all widgets by the // WidgetEventResponder, which self- // registers to all events upon creation of the first widget. // bool ofxWidget::mouseEvent(ofMouseEventArgs& args_) { // If we register a mouse down event, we do a hit test over // all visible widgets, and re-order if necessary. // Then, and in all other cases, we do a hit-test on the // frontmost widget and, if positive, forward the event to this // widget. updateVisibleWidgetsList(); if (sVisibleWidgets.empty()) return false; // ---------| invariant: there are some widgets flying around. bool eventAttended = false; float mx = args_.x; float my = args_.y; // if we have a mouse down on a widget, we need to check which // widget was hit and potentially re-order widgets. // find the first widget that is under the mouse, that is also visible // if it is not yet up front, bring it to the front. // hit-test only visible widgets - this makes sure to only evaluate // the widgets which are visible, and whose parents are visible, too. auto itUnderMouse = std::find_if(sVisibleWidgets.begin(), sVisibleWidgets.end(), [&mx, &my](std::weak_ptr<ofxWidget>& w) ->bool { auto p = w.lock(); if (p && p->mVisible && p->mRect.inside(mx, my)) { return true; } else { return false; } }); // if we have a click, we want to make sure the widget gets to be the topmost widget. if (args_.type == ofMouseEventArgs::Pressed) { // --- now iterate over sAllWidgets instead of just the visible widgets. // we need to do this, because otherwise the reorder check won't be safe // as the number of children in sVisibleWidgets is potentially incorrect, // as the number of children there refers to all children of a widget, // and not just the visible children of the widget. auto itPressedWidget = (itUnderMouse == sVisibleWidgets.end() ? sAllWidgets.end() : findIt(*itUnderMouse, sAllWidgets.begin(), sAllWidgets.end())); if (itPressedWidget != sAllWidgets.end()) { if (!isSame(*itPressedWidget, sFocusedWidget)) { // change in focus detected. // first, let the first element know that it is losing focus if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget = *itPressedWidget; // now that the new wiget is at the front, send an activate callback. if (auto nextFocusedWidget = sFocusedWidget.lock()) if (nextFocusedWidget->onFocusEnter) nextFocusedWidget->onFocusEnter(); } bringToFront(itPressedWidget); // reorder widgets } else { // hit test was not successful, no wigets found. if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget.reset(); // no widget gets the focus, then. } } // end if (args_.type == ofMouseEventArgs::Pressed) // now, we will attempt to send the mouse event to the widget that // is in focus. if (itUnderMouse != sVisibleWidgets.end()) { // a widget is under the mouse. // is it the same as the current widget under the mouse? if (!isSame(*itUnderMouse, sWidgetUnderMouse)) { if (auto nU = itUnderMouse->lock()) { // there is a new widget under the mouse if (auto w = sWidgetUnderMouse.lock()) { // there was an old widget under the mouse if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; } if (nU->onMouseEnter) nU->onMouseEnter(); nU->mHover = true; sWidgetUnderMouse = *itUnderMouse; } } } else { if (auto w = sWidgetUnderMouse.lock()) { // there was a widget under mouse, // but now there is none. if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; sWidgetUnderMouse.reset(); } } if (auto w = sFocusedWidget.lock()) { if (w->onMouse) { w->onMouse(args_); eventAttended = true; } } // store last mouse position last thing, so that // we are able to calculate a difference. sLastMousePos.set(mx, my); return eventAttended; }
//! called if an event happened. bool MainMenu::onEvent(const NEvent& event) { if (isEnabled()) { switch(event.EventType) { case OC3_GUI_EVENT: switch(event.GuiEvent.EventType) { case OC3_ELEMENT_FOCUS_LOST: if (event.GuiEvent.Caller == this && !isMyChild(event.GuiEvent.Element)) { closeAllSubMenus_(); setHoverIndex_( -1 ); } break; case OC3_ELEMENT_FOCUSED: if (event.GuiEvent.Caller == this ) { bringToFront(); } break; default: break; } break; case OC3_MOUSE_EVENT: switch(event.MouseEvent.Event) { case OC3_LMOUSE_PRESSED_DOWN: { if (!getEnvironment()->hasFocus(this)) { getEnvironment()->setFocus(this); } bringToFront(); Point p(event.MouseEvent.getPosition() ); bool shouldCloseSubMenu = hasOpenSubMenu_(); if (!getAbsoluteClippingRect().isPointInside(p)) { shouldCloseSubMenu = false; } isHighlighted_( event.MouseEvent.getPosition(), true); if ( shouldCloseSubMenu ) { getEnvironment()->removeFocus(this); } return true; } case OC3_LMOUSE_LEFT_UP: { Point p(event.MouseEvent.getPosition() ); if (!getAbsoluteClippingRect().isPointInside(p)) { int t = sendClick_(p); if ((t==0 || t==1) && isFocused()) removeFocus(); } return true; } case OC3_MOUSE_MOVED: { if (getEnvironment()->hasFocus(this) && getHoveredIndex() >= 0) { int oldHighLighted = getHoveredIndex(); isHighlighted_( event.MouseEvent.getPosition(), true); if ( getHoveredIndex() < 0 ) { setHoverIndex_( oldHighLighted ); // keep last hightlight active when moving outside the area } } return true; } default: break; } break; default: break; } } return Widget::onEvent(event); }