void KeyboardMouse::UpdateCursorInput() { POINT point = {}; GetCursorPos(&point); // Get the cursor position relative to the upper left corner of the current window // (separate or render to main) ScreenToClient(m_hwnd, &point); // Get the size of the current window. (In my case Rect.top and Rect.left was zero.) RECT rect; GetClientRect(m_hwnd, &rect); // Width and height are the size of the rendering window. const auto win_width = rect.right - rect.left; const auto win_height = rect.bottom - rect.top; // Convert the cursor position to a range from -1 to 1. m_state_in.cursor.x = ControlState(point.x) / win_width * 2 - 1; m_state_in.cursor.y = ControlState(point.y) / win_height * 2 - 1; }
ControlState Joystick::Axis::GetState() const { return std::max(0.0f, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); }
void ContentWindowGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event) { // on Mac we've seen that mouse events can go to the wrong graphics item // this is due to the bug: https://bugreports.qt.nokia.com/browse/QTBUG-20493 // here we ignore the event if it shouldn't have been sent to us, which ensures // it will go to the correct item... if(boundingRect().contains(event->pos()) == false) { event->ignore(); return; } // button dimensions float buttonWidth, buttonHeight; getButtonDimensions(buttonWidth, buttonHeight); // item rectangle and event position QRectF r = boundingRect(); QPointF eventPos = event->pos(); // check to see if user clicked on the close button if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth && fabs(r.y() - eventPos.y()) <= buttonHeight) { close(); return; } // move to the front of the GUI display moveToFront(); ContentWindowManagerPtr contentWindow = getContentWindowManager(); if (!contentWindow) return; if (selected()) { contentWindow->getInteractionDelegate().mousePressEvent(event); return; } contentWindow->getContent()->blockAdvance( true ); // check to see if user clicked on the resize button if(fabs((r.x()+r.width()) - eventPos.x()) <= buttonWidth && fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight) { resizing_ = true; } // check to see if user clicked on the fullscreen button else if(fabs(r.x() - eventPos.x()) <= buttonWidth && fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight) { toggleFullscreen(); } else if(fabs(((r.x()+r.width())/2) - eventPos.x() - buttonWidth) <= buttonWidth && fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight && g_configuration->getOptions()->getShowMovieControls( )) { contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_PAUSED) ); } else if(fabs(((r.x()+r.width())/2) - eventPos.x()) <= buttonWidth && fabs((r.y()+r.height()) - eventPos.y()) <= buttonHeight && g_configuration->getOptions()->getShowMovieControls( )) { contentWindow->setControlState( ControlState(contentWindow->getControlState() ^ STATE_LOOP) ); } else moving_ = true; QGraphicsItem::mousePressEvent(event); }
* * 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 OR COPYRIGHT HOLDERS * 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. * * CPSC Computer Graphics 2014 * University of British Columbia */ #include "ControlState.h" #include <stdio.h> #include <stdlib.h> #include <cmath> ControlState c_state = ControlState(); ControlState::~ControlState() { glfwDestroyWindow(window); } int ControlState::init(WorldState &w) { this->w = &w; width = 640; height = 480; /* As of right now we only have one window */ window = glfwCreateWindow(width, height, "Window", NULL, NULL); if (!window)
ControlState Device::Axis::GetState() const { return ControlState(m_axis) / m_range; }
ControlState Device::Trigger::GetState() const { return ControlState(m_trigger) / m_range; }
ControlState Device::Axis::GetState() const { return std::max( 0.0f, ControlState(m_axis) / m_range ); }
ControlState KeyboardMouse::Cursor::GetState() const { return std::max(0.0, ControlState(m_axis) / (m_positive ? 1.0 : -1.0)); }
ControlState KeyboardMouse::Axis::GetState() const { return std::max(0.0, ControlState(m_axis) / m_range); }
ControlState KeyboardMouse::Axis::GetState() const { return ControlState(m_axis) / m_range; }