void MGuiEditText::autoScrolling(void) { MGuiWindow * parent = getParentWindow(); MVector2 newScroll = parent->getScroll(); MVector2 charPos; // min, max window (with scroll) MVector2 min = - parent->getScroll(); MVector2 max = parent->getScale() - parent->getScroll(); // selection unsigned int sIds[2]; bool selection = getSelectionIds(&sIds[0], &sIds[1]); if(selection) { // charPos charPos = getFont()->getCharacterPosition( getText(), getPosition(), getTextSize(), m_endSelectionId ); } else { // charPos charPos = getFont()->getCharacterPosition( getText(), getPosition(), getTextSize(), getCharId() ); } // new scrolling if(charPos.x > max.x) newScroll.x -= charPos.x - max.x + getTextSize()*0.2f; if((charPos.y + getTextSize()) > max.y) newScroll.y -= (charPos.y + getTextSize()) - max.y; if(charPos.x < min.x) newScroll.x += min.x - charPos.x; if(charPos.y < min.y) newScroll.y += min.y - charPos.y; parent->setScroll(newScroll); parent->resizeScroll(); parent->limitScroll(); }
void MGuiEditText::onEvent(MWinEvent * windowEvent) { MGuiWindow * parent = getParentWindow(); MMouse * mouse = MMouse::getInstance(); switch(windowEvent->type) { case MWIN_EVENT_MOUSE_WHEEL_MOVE: case MWIN_EVENT_MOUSE_MOVE: if(parent->isHighLight() && isMouseInside()) { setHighLight(true); if(m_pointerEvent) // send mouse move gui event { MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_MOUSE_MOVE; guiEvent.data[0] = windowEvent->data[0]; guiEvent.data[1] = windowEvent->data[1]; m_pointerEvent(this, &guiEvent); } // break events if(parent->breakEvents()) return; } else { setHighLight(false); } if(isPressed() && mouse->isLeftButtonPushed()) { m_endSelectionId = getFont()->findPointedCharacter( getText(), getPosition(), getTextSize(), getMouseLocalPosition() ); autoScrolling(); } break; case MWIN_EVENT_MOUSE_BUTTON_DOWN: if(isHighLight()) { if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT) { // unpress all edit text unsigned int i; unsigned int size = parent->getEditTextsNumber(); for(i=0; i<size; i++) parent->getEditText(i)->setPressed(false); setPressed(true); setCharId( getFont()->findPointedCharacter( getText(), getPosition(), getTextSize(), getMouseLocalPosition() ) ); // start select setSelection(getCharId(), getCharId()); } if(m_pointerEvent) // send mouse button down gui event { MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_DOWN; guiEvent.data[0] = windowEvent->data[0]; m_pointerEvent(this, &guiEvent); } } else { if(isPressed() && windowEvent->data[0] == MMOUSE_BUTTON_LEFT) { setPressed(false); sendVariable(); } } break; case MWIN_EVENT_CHAR: case MWIN_EVENT_KEY_DOWN: if(isPressed()) { editText(windowEvent); autoScrolling(); } break; } }
void MGuiSlide::onEvent(MWinEvent * windowEvent) { MGuiWindow * parent = getParentWindow(); MMouse * mouse = MMouse::getInstance(); switch(windowEvent->type) { case MWIN_EVENT_MOUSE_WHEEL_MOVE: case MWIN_EVENT_MOUSE_MOVE: if(parent->isHighLight() && m_button.isPointInside(getMouseLocalPosition()) && (! mouse->isLeftButtonPushed()) && (! mouse->isMiddleButtonPushed()) && (! mouse->isRightButtonPushed())) { setHighLight(true); if(m_pointerEvent) // send gui event { MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_MOUSE_MOVE; guiEvent.data[0] = windowEvent->data[0]; guiEvent.data[1] = windowEvent->data[1]; m_pointerEvent(this, &guiEvent); } // break events if(parent->breakEvents()) return; } else{ setHighLight(false); } if(isPressed()) { float value = getValueFromPoint(getMouseLocalPosition()); setValue(value); } break; case MWIN_EVENT_MOUSE_BUTTON_DOWN: if(isHighLight()) { if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT){ setPressed(true); m_offset = getMouseLocalPosition() - m_button.getPosition(); } if(m_pointerEvent) // send gui event { MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_DOWN; guiEvent.data[0] = windowEvent->data[0]; m_pointerEvent(this, &guiEvent); } } break; case MWIN_EVENT_MOUSE_BUTTON_UP: if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT) { setPressed(false); } break; } }