*/JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeInsertText( JNIEnv* env, jclass clazz, jint handle, jstring textString) { if (handle) { IrrlichtDevice* device = (IrrlichtDevice*) handle; IGUIEnvironment* irrenv = device->getGUIEnvironment(); IGUIElement* element = irrenv->getFocus(); if (element && element->getType() == EGUIET_EDIT_BOX) { IGUIEditBox* editbox = (IGUIEditBox*) element; const char* text = env->GetStringUTFChars(textString, NULL); wchar_t content[256]; BufferIO::DecodeUTF8(text, content); editbox->setText(content); irrenv->removeFocus(editbox); irrenv->setFocus(editbox->getParent()); SEvent changeEvent; changeEvent.EventType = EET_GUI_EVENT; changeEvent.GUIEvent.Caller = editbox; changeEvent.GUIEvent.Element = 0; changeEvent.GUIEvent.EventType = EGET_EDITBOX_CHANGED; editbox->getParent()->OnEvent(changeEvent); SEvent enterEvent; enterEvent.EventType = EET_GUI_EVENT; enterEvent.GUIEvent.Caller = editbox; enterEvent.GUIEvent.Element = 0; enterEvent.GUIEvent.EventType = EGET_EDITBOX_ENTER; editbox->getParent()->OnEvent(enterEvent); env->DeleteLocalRef(textString); } } }
void SSGUIStatusBar::draw() { IVideoDriver *driver = Environment->getVideoDriver(); if (!IsVisible) return; if (Background) { driver->draw2DImage(Background, AbsoluteRect.UpperLeftCorner, rect<s32>(position2d<s32>(0,0), Background->getOriginalSize()), 0, SColor(255,255,255,255), true); IGUIElement *ElementUnderCursor = Environment->getRootGUIElement()->getElementFromPoint(CursorControl->getPosition()); s32 index = -1; while (ElementUnderCursor && ElementUnderCursor != this && ElementUnderCursor != Environment->getRootGUIElement() && index == -1) { index = RegisteredElements.binary_search(ElementUnderCursor); if (ElementUnderCursor != this && index == -1) ElementUnderCursor = ElementUnderCursor->getParent(); } if (index >= 0 || ElementUnderCursor == this) { if (ElementUnderCursor->getType() == EGUIET_BUTTON) Label.Text = ((SSGUIButton*)ElementUnderCursor)->getHelpText().c_str(); if (ElementUnderCursor->getType() == EGUIET_SCROLL_BAR) Label.Text = ((SSGUIScrollBar*)ElementUnderCursor)->getHelpText().c_str(); if (ElementUnderCursor->getType() == EGUIET_WINDOW) Label.Text = ((SSGUISatelliteInfoWindow*)ElementUnderCursor)->getHelpText().c_str(); if (ElementUnderCursor == this) Label.Text = HelpText.c_str(); if (Label.Text) Label.Font->draw(Label.Text, Label.Rect, Label.Color, false, true); } else Label.Text = 0; } }
bool Desktop::OnGUIElementClosed(irr::SEvent::SGUIEvent event) { IGUIElement* pElem = event.Caller; switch ( pElem->getType() ) { case EGUIET_WINDOW: { InGameAppWindow* pWnd = NULL; m_mutexApps.Lock(); AppWindowVector::iterator it = m_arrApps.begin(); while ( it != m_arrApps.end() ) { if ( (*it)->GetGUIWindow() == pElem ) { // get the InGameAppWindow object pWnd = (*it); // remove it from the active apps list m_arrApps.erase(it); // notify the AppBar that the app has closed if ( m_pAppBar ) m_pAppBar->setActiveApp(NULL); // notify the model that the app has been closed FCViewEvent e(VE_AppClosed, pWnd->GetOptionID()); m_owner.GetContainer()->GetController()->OnViewEvent(e); // delete the InGameAppWindow Object delete pWnd; // set focus back to the desktop Environment->setFocus(this); break; } it++; } m_mutexApps.Unlock(); } break; case EGUIET_ELEMENT: { FCDialog* pDlg = NULL; if ( (pElem == (IGUIElement*)GetUtilityWindow(pElem)) ) { CloseUtilityWindow(pElem); } } break; } return false; }
//! called if an event happened. bool CGUITextureCacheBrowser::OnEvent(const SEvent &event) { switch(event.EventType) { case EET_GUI_EVENT: if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { if (event.GUIEvent.Caller == (IGUIElement*)this) Dragging = false; return true; } else if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { if (event.GUIEvent.Caller == CloseButton) { remove(); return true; } } break; case EET_MOUSE_INPUT_EVENT: switch(event.MouseInput.Event) { case EMIE_LMOUSE_PRESSED_DOWN: DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; if (getElementFromPoint(DragStart) == this) { if (!Environment->hasFocus(this)) { Dragging = true; //Environment->setFocus(this); if (Parent) Parent->bringToFront(this); } return true; } else { if (Panel->getAbsolutePosition().isPointInside(DragStart)) { // select an image IGUIElement* el = Panel->getElementFromPoint(DragStart); if (el && el != Panel) { if (el->getType() == EGUIET_IMAGE) { setSelected(el->getID()); } } else { setSelected(); } } } break; case EMIE_LMOUSE_LEFT_UP: Dragging = false; //Environment->removeFocus(this); return true; case EMIE_MOUSE_MOVED: if (Dragging) { // gui window should not be dragged outside its parent if (Parent) if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 || event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 || event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 || event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1) return true; move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; return true; } break; } } return Parent ? Parent->OnEvent(event) : false; }
EventPropagation EventHandler::onGUIEvent(const SEvent& event) { if (event.EventType == EET_GUI_EVENT) { if (event.GUIEvent.Caller == NULL) return EVENT_LET; const s32 id = event.GUIEvent.Caller->getID(); switch (event.GUIEvent.EventType) { case EGET_BUTTON_CLICKED: case EGET_SCROLL_BAR_CHANGED: case EGET_CHECKBOX_CHANGED: case EGET_LISTBOX_SELECTED_AGAIN: { Widget* w = GUIEngine::getWidget(id); if (w == NULL) break; if (w->m_deactivated) { GUIEngine::getCurrentScreen()->onDisabledItemClicked(w->m_properties[PROP_ID].c_str()); return EVENT_BLOCK; } w->onClick(); // These events are only triggered by mouse (or so I hope) // The player that owns the mouser receives "game master" priviledges return onWidgetActivated(w, PLAYER_ID_GAME_MASTER); // These events are only triggered by keyboard/mouse (or so I hope...) //const int playerID = input_manager->getPlayerKeyboardID(); //if (input_manager->masterPlayerOnly() && playerID != PLAYER_ID_GAME_MASTER) break; //else if (playerID != -1) return onWidgetActivated(w, playerID); //else break; } case EGET_ELEMENT_HOVERED: { Widget* w = GUIEngine::getWidget(id); if (w == NULL) break; if (!w->m_focusable) return GUIEngine::EVENT_BLOCK; // When a modal dialog is shown, don't select widgets out of the dialog if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(w)) { // check for parents too before discarding event if (w->m_event_handler != NULL) { if (!ModalDialog::getCurrent()->isMyChild(w->m_event_handler)) { break; } } } // select ribbons on hover if (w->m_event_handler != NULL && w->m_event_handler->m_type == WTYPE_RIBBON) { // FIXME: don't make a special case for ribbon here, there should be a generic callback // that all widgets may hook onto RibbonWidget* ribbon = (RibbonWidget*)(w->m_event_handler); if (ribbon == NULL) break; // give the mouse "game master" priviledges const int playerID = PLAYER_ID_GAME_MASTER; //input_manager->getPlayerKeyboardID(); if (playerID == -1) break; if (input_manager->masterPlayerOnly() && playerID != PLAYER_ID_GAME_MASTER) break; ribbon->mouseHovered(w, playerID); if (ribbon->m_event_handler != NULL) ribbon->m_event_handler->mouseHovered(w, playerID); ribbon->setFocusForPlayer(playerID); } else { // focus on hover for other widgets // give the mouse "game master" priviledges const int playerID = PLAYER_ID_GAME_MASTER; //input_manager->getPlayerKeyboardID(); if (input_manager->masterPlayerOnly() && playerID != PLAYER_ID_GAME_MASTER) break; if (playerID != -1) { // lists don't like that combined with scrollbars // (FIXME: find why instead of working around) if (w->getType() != WTYPE_LIST) { w->setFocusForPlayer(playerID); } } } break; } /* case EGET_ELEMENT_LEFT: { Widget* el = getWidget(id); if(el == NULL) break; break; } */ case EGET_ELEMENT_FOCUSED: { Widget* w = GUIEngine::getWidget(id); if (w == NULL) break; // forbid list for gaining "irrLicht focus", then they will process key events and // we don't want that since we do our own custom processing for keys if (w->m_type == WTYPE_LIST) { // FIXME: fix that better // cheap way to remove the focus from the element (nope, IGUIEnv::removeFocus doesn't work) // Obviously will not work if the list is the first item of the screen. IGUIElement* elem = getCurrentScreen()->getFirstWidget()->getIrrlichtElement(); if (elem->getType() == EGUIET_LIST_BOX) { elem = getCurrentScreen()->getLastWidget()->getIrrlichtElement(); assert(elem->getType() != EGUIET_LIST_BOX); } GUIEngine::getGUIEnv()->setFocus( elem ); return EVENT_BLOCK; // confirms to irrLicht that we processed it } break; } case EGET_LISTBOX_CHANGED: { Widget* w = GUIEngine::getWidget(id); if (w == NULL) break; assert(w->getType() == WTYPE_LIST); const int playerID = input_manager->getPlayerKeyboardID(); if (input_manager->masterPlayerOnly() && playerID != PLAYER_ID_GAME_MASTER) break; if (!w->isFocusedForPlayer(playerID)) w->setFocusForPlayer(playerID); break; } case EGET_EDITBOX_ENTER: { // currently, enter pressed in text ctrl events can only happen in dialogs. // FIXME : find a cleaner way to route the event to its proper location if (ModalDialog::isADialogActive()) ModalDialog::onEnterPressed(); break; } default: break; } // end switch } /* EGET_BUTTON_CLICKED, EGET_SCROLL_BAR_CHANGED, EGET_CHECKBOX_CHANGED, EGET_TAB_CHANGED, EGET_MENU_ITEM_SELECTED, EGET_COMBO_BOX_CHANGED, EGET_SPINBOX_CHANGED, EGET_EDITBOX_ENTER, EGET_LISTBOX_CHANGED, EGET_LISTBOX_SELECTED_AGAIN, EGET_FILE_SELECTED, EGET_FILE_CHOOSE_DIALOG_CANCELLED, EGET_MESSAGEBOX_YES, EGET_MESSAGEBOX_NO, EGET_MESSAGEBOX_OK, EGET_MESSAGEBOX_CANCEL, EGET_TABLE_CHANGED, EGET_TABLE_HEADER_CHANGED, EGET_TABLE_SELECTED_AGAIN EGET_ELEMENT_FOCUS_LOST, EGET_ELEMENT_FOCUSED, EGET_ELEMENT_HOVERED, EGET_ELEMENT_LEFT, EGET_ELEMENT_CLOSED, */ return EVENT_LET; }