//-------------------------------------------------------------- void ofApp::draw(){ ofBackgroundGradient(100, 0); //if image exists, draw it if(receivedImage.getWidth() > 0){ ofSetColor(255); receivedImage.draw(ofGetWidth()/2-receivedImage.getWidth()/2, ofGetHeight()/2-receivedImage.getHeight()/2); } //draw recent unrecognized messages for(int i = 0; i < NUM_MSG_STRINGS; i++){ ofDrawBitmapStringHighlight(msg_strings[i], 10, 40 + 15 * i); } string buf = "listening for osc messages on port : " + ofToString(PORT); ofDrawBitmapStringHighlight(buf, 10, 20); // draw mouse state ofPoint mouseIn(mouseXf*ofGetWidth(),mouseYf*ofGetHeight()); if (mouseButtonInt == 0) { ofSetColor(255); }else ofSetColor(ofColor::salmon); ofDrawCircle(mouseIn, 20); ofDrawBitmapStringHighlight(mouseButtonState, mouseIn); }
void ofxWidget::mousePressed(ofMouseEventArgs & mouse){ this->mouse=mouse; if(mouseIn()){ yargs.relative_x=getRelativePosition(mouse.x,mouse.y).x; yargs.relative_y=getRelativePosition(mouse.x,mouse.y).y; yargs.abs_x = mouse.x; yargs.abs_y = mouse.y; newEvent(OFX_W_E_POINTER_PRESSED, yargs); } }
void ofxWidget::mouseDragged(ofMouseEventArgs & mouse){ this->mouse=mouse; if(mouseIn()){ yargs.relative_x=getRelativePosition(mouse.x,mouse.y).x; yargs.relative_y=getRelativePosition(mouse.x,mouse.y).y; yargs.abs_x = mouse.x; yargs.abs_y = mouse.y; newEvent(OFX_W_E_POINTER_OVER, yargs); }else{ yargs.relative_x=getRelativePosition(mouse.x,mouse.y).x; yargs.relative_y=getRelativePosition(mouse.x,mouse.y).y; yargs.abs_x = mouse.x; yargs.abs_y = mouse.y; newEvent(OFX_W_E_POINTER_OUT, yargs); } }
void RectangleButton::Update(){ isPressed = wasPressed = false; if (mouseIn()){ select(); if (mouseX_pre != mouseX && mouseY_pre != mouseY && onMouseIn) onMouseIn(); if (hge->Input_KeyUp(HGEK_LBUTTON)){ if(onMouseClick) onMouseClick(); wasPressed = true; } if (hge->Input_GetKeyState(HGEK_LBUTTON)){ float mod = 0.5; captionDx *= mod; captionDy *= mod; isPressed = true; } }else{ deselect(); if (in(mouseX_pre, mouseY_pre) && onMouseOut) onMouseOut(); } }
/** * Called whenever an action occurs, and processes it to * check if it's relevant to the surface and convert it * into a meaningful interaction like a "click", calling * the respective handlers. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void InteractiveSurface::handle(Action *action, State *state) { if (!_visible || _hidden) return; action->setSender(this); if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY()); } else if (action->getDetails()->type == SDL_MOUSEMOTION) { action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY()); } if (action->isMouseAction()) { if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) && (action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight())) { if (!_isHovered) { _isHovered = true; mouseIn(action, state); } mouseOver(action, state); } else { if (_isHovered) { _isHovered = false; mouseOut(action, state); } } } if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { if (_isHovered && !_buttonsPressed[action->getDetails()->button.button]) { _buttonsPressed[action->getDetails()->button.button] = true; mousePress(action, state); } } else if (action->getDetails()->type == SDL_MOUSEBUTTONUP) { if (_buttonsPressed[action->getDetails()->button.button]) { _buttonsPressed[action->getDetails()->button.button] = false; mouseRelease(action, state); if (_isHovered) { mouseClick(action, state); } } } if (_isFocused) { if (action->getDetails()->type == SDL_KEYDOWN) { keyboardPress(action, state); } else if (action->getDetails()->type == SDL_KEYUP) { keyboardRelease(action, state); } } }
/** * Called whenever an action occurs, and processes it to * check if it's relevant to the surface and convert it * into a meaningful interaction like a "click", calling * the respective handlers. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void InteractiveSurface::handle(Action *action, State *state) { if (!_visible || _hidden) return; action->setSender(this); if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY()); } else if (action->getDetails()->type == SDL_MOUSEMOTION) { action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY()); } if (action->isMouseAction()) { if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) && (action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight())) { if (!_isHovered) { _isHovered = true; mouseIn(action, state); } if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) { _buttonsPressed = SDL_GetMouseState(0, 0); for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) { if (isButtonPressed(i)) { action->getDetails()->button.button = i; mousePress(action, state); } } } mouseOver(action, state); } else { if (_isHovered) { _isHovered = false; mouseOut(action, state); if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION) { for (Uint8 i = 1; i <= NUM_BUTTONS; ++i) { if (isButtonPressed(i)) { setButtonPressed(i, false); } action->getDetails()->button.button = i; mouseRelease(action, state); } } } } } if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN) { if (_isHovered && !isButtonPressed(action->getDetails()->button.button)) { setButtonPressed(action->getDetails()->button.button, true); mousePress(action, state); } } else if (action->getDetails()->type == SDL_MOUSEBUTTONUP) { if (isButtonPressed(action->getDetails()->button.button)) { setButtonPressed(action->getDetails()->button.button, false); mouseRelease(action, state); if (_isHovered) { mouseClick(action, state); } } } if (_isFocused) { if (action->getDetails()->type == SDL_KEYDOWN) { keyboardPress(action, state); } else if (action->getDetails()->type == SDL_KEYUP) { keyboardRelease(action, state); } } }