QRect TrackMouseEffect::starRect( int num ) const { int a = angle + 360 / STARS * num; int x = cursorPos().x() + int( DIST * cos( a * ( 2 * M_PI / 360 ))); int y = cursorPos().y() + int( DIST * sin( a * ( 2 * M_PI / 360 ))); return QRect( QPoint( x - textureSize.width() / 2, y - textureSize.height() / 2 ), textureSize ); }
void TrackMouseEffect::prePaintScreen(ScreenPrePaintData& data, int time) { if (m_active) { QTime t = QTime::currentTime(); m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase); m_lastRect[0].moveCenter(cursorPos()); m_lastRect[1].moveCenter(cursorPos()); data.paint |= m_lastRect[0].adjusted(-1,-1,1,1); } effects->prePaintScreen(data, time); }
void battleDisplayPlayerHealth(characterInfo player) { // cursorPos(17, 3); setColour(1, 16); if(player.health >= 100) { cout<<player.health << "/" <<player.totalHealth; } else if(player.health > 0) { cout<<player.health << "/" <<player.totalHealth<< " "; } else { cout<<player.health << "/" <<player.totalHealth<< " "; } setColour(15, 1); cout<< ":"; setColour(5, 16); int healthBar1 = player.totalHealth / 10; for(int i = 0; i < healthBar1; i++) { cout<< " "; } setColour(15, 1); cout<< ":"; cursorPos(25, 3); setColour(13, 16); int healthBar2 = player.health / 10; for(int i = 0; i < healthBar2; i++) { cout<< " "; } setColour(1, 8); // }
void battleDisplayEnemyHealth(enemyInfo enemy) { // cursorPos(17, 7); setColour(1, 16); if(enemy.health >= 100) { cout<<enemy.health << "/" <<enemy.totalHealth; } else if(enemy.health > 0) { cout<<enemy.health << "/" <<enemy.totalHealth<< " "; } else { cout<<enemy.health << "/" <<enemy.totalHealth<< " "; } setColour(15, 1); cout<< ":"; setColour(5, 16); int healthBar1 = enemy.totalHealth / 10; for(int i = 0; i < healthBar1; i++) { cout<< " "; } setColour(15, 1); cout<< ":"; cursorPos(25, 7); setColour(13, 16); int healthBar2 = enemy.health / 10; for(int i = 0; i < healthBar2; i++) { cout<< " "; } setColour(1, 8); // }
void battleDisplayPlayerMana(characterInfo player) { // cursorPos(17, 4); setColour(1, 16); if(player.mana >= 100) { cout<<player.mana << "/" <<player.totalMana; } else if(player.mana > 0) { cout<<player.mana << "/" <<player.totalMana<< " "; } else { cout<<player.mana << "/" <<player.totalMana<< " "; } setColour(15, 1); cout<< ":"; setColour(2, 16); int manaBar1 = player.totalMana / 10; for(int i = 0; i < manaBar1; i++) { cout<< " "; } setColour(15, 1); cout<< ":"; cursorPos(25, 4); setColour(10, 16); int manaBar2 = player.mana / 10; for(int i = 0; i < manaBar2; i++) { cout<< " "; } setColour(1, 8); // }
void battleDisplayEnemyMana(enemyInfo enemy) { // cursorPos(17, 8); setColour(1, 16); if(enemy.mana >= 100) { cout<<enemy.mana << "/" <<enemy.totalMana; } else if(enemy.mana > 0) { cout<<enemy.mana << "/" <<enemy.totalMana<< " "; } else { cout<<enemy.mana << "/" <<enemy.totalMana<< " "; } setColour(15, 1); cout<< ":"; setColour(2, 16); int manaBar1 = enemy.totalMana / 10; for(int i = 0; i < manaBar1; i++) { cout<< " "; } setColour(15, 1); cout<< ":"; cursorPos(25, 8); setColour(10, 16); int manaBar2 = enemy.mana / 10; for(int i = 0; i < manaBar2; i++) { cout<< " "; } setColour(1, 8); // }
bool MainWindow::winEvent(MSG *message, long *result) { if (message->message == WM_NCHITTEST) { QPoint cursorPos(GET_X_LPARAM(message->lParam), GET_Y_LPARAM(message->lParam)); cursorPos = mapFromGlobal(cursorPos); *result = hitTest(cursorPos); return *result != HTCLIENT && *result != HTCAPTION; } else if (message->message == WM_LBUTTONDOWN) { QPoint cursorPos(GET_X_LPARAM(message->lParam), GET_Y_LPARAM(message->lParam)); if (hitTest(cursorPos) == HTCAPTION) { PostMessage(message->hwnd, WM_SYSCOMMAND, HTCAPTION | SC_MOVE, 0); return true; } } else if (message->message == WM_LBUTTONDBLCLK) { QPoint cursorPos(GET_X_LPARAM(message->lParam), GET_Y_LPARAM(message->lParam)); long ht = hitTest(cursorPos); if (ht == HTCAPTION) { onMaximize(); return true; } } else if (message->message == WM_NCCALCSIZE) { *result = 0; QRect rect; if (message->wParam) { NCCALCSIZE_PARAMS *ncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(message->lParam); if (IsZoomed(message->hwnd)) { QDesktopWidget desktopWidget; rect = desktopWidget.availableGeometry(this); ncsp->rgrc[0].left = rect.left(); ncsp->rgrc[0].top = rect.top(); ncsp->rgrc[0].right = rect.right(); ncsp->rgrc[0].bottom = rect.bottom(); } } return true; } return false; }
bool GuiList::OnDoubleClickEvent(const DoubleClickEvent& dce) { if (dce.button != AMJU_BUTTON_MOUSE_LEFT) { return false; } if (!IsVisible()) { return false; } if (m_doubleClickFunc) { Vec2f cursorPos(dce.x, dce.y); for (unsigned int i = 0; i < m_children.size(); i++) { GuiElement* item = m_children[i]; Rect r = GetRect(item); if (r.IsPointIn(cursorPos)) { m_doubleClickFunc(this, i); return true; } } } return false; }
bool MoviePlayerView::CursorInsidePlaybackControls() const { if ( !uiActive ) { return false; } int left, bottom, right, top; // get the playback controls position if ( !Native::GetPlaybackControlsRect( Cinema.app, left, bottom, right, top ) ) { // it takes a few frames to initilize the bounds of the controls LOG( "PlaybackControlsRect Not initialized"); return false; } const Vector2f panelCursor = GazeCoordinatesOnPanel( Cinema.SceneMgr.Scene.CenterViewMatrix(), Cinema.app->GetActivityPanel().Matrix, Cinema.app->GetActivityPanel().AlternateGazeCheck ); Vector2f cursorPos( (panelCursor.x * 0.5 + 0.5) * Cinema.app->GetActivityPanel().Width, (0.5 - panelCursor.y * 0.5) * Cinema.app->GetActivityPanel().Height ); if ( ( cursorPos.x >= left ) && ( cursorPos.x < right ) && ( cursorPos.y >= top ) && ( cursorPos.y < bottom ) ) { return true; } return false; }
bool GuiList::OnMouseButtonEvent(const MouseButtonEvent& mbe) { if (!IsVisible()) { return false; } Vec2f cursorPos(mbe.x, mbe.y); if (mbe.button == AMJU_BUTTON_MOUSE_LEFT && mbe.isDown) { // Stop scrolling, no? GuiScroll* scroll = dynamic_cast<GuiScroll*>(GetParent()); Assert(scroll); scroll->StopScrolling(); // Check each item int selected = -1; for (unsigned int i = 0; i < m_children.size(); i++) { GuiElement* item = m_children[i]; Rect r = GetRect(item); if (r.IsPointIn(cursorPos)) { selected = i; break; } } if (selected != -1) { // TODO Should react on mouse up when up item == down item ?? if (IsMultiSel()) { // Toggle selected flag for this child SetSelected(selected, !IsSelected(selected)); } else { SetSelected(selected, true); if (m_singleClickFunc) { m_singleClickFunc(this, selected); } } // TODO Why is this a bad idea ? //m_items[m_selected]->ExecuteCommand(); // Problem with nested item, but should open up on mouse over anyway... // SetVisible(false); // TODO flag for this behaviour return true; // handled } } return false; // not handled }
bool undo() { if (!currentBuffer().undoStack_.empty()) { currentBuffer().redoStack_.emplace_back(currentDoc(), cursorPos(), EditAction::UndoRedo); UndoState const& state = currentBuffer().undoStack_.back(); currentDoc() = state.doc_; cursorPos() = state.cursor_; currentBuffer().undoStack_.pop_back(); return true; } return false; }
void QHexEditPrivate::mouseMoveEvent(QMouseEvent * event) { _blink = false; update(); int actPos = cursorPos(event->pos()); setCursorPos(actPos); setSelection(actPos); }
void QHexEditPrivate::mousePressEvent(QMouseEvent * event) { _blink = false; update(); int cPos = cursorPos(event->pos()); resetSelection(cPos); setCursorPos(cPos); }
void Cursor::scale(float ratioX, float ratioY) { sf::Vector2f cursorPos(_cursor.getPosition()); _cursor.scale(ratioX, ratioY); cursorPos.x *= ratioX; cursorPos.y *= ratioY; _cursor.setPosition(cursorPos); }
void battleDisplay(characterInfo player, enemyInfo enemy) { // cursorPos(17, 2); cout<<player.name; cursorPos(17, 6); cout<<enemy.name; battleDisplayPlayerHealth(player); battleDisplayPlayerMana(player); battleDisplayEnemyHealth(enemy); battleDisplayEnemyMana(enemy); cursorPos(1, 10); // }
EventPropagation TextEditor::mouseDown(Input::IMouse::Button btn, float x, float y) { if (btn == Input::IMouse::ButtonLeft) { cursorPos(XToColumn(x), YToLine(y)); pDragPos(pCursorPos); pDragging = true; invalidate(); } return epStop; }
bool TrackMouseEffect::init() { effects->makeOpenGLContextCurrent(); #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (!(m_texture[0] || m_picture[0] || m_image[0].isNull())) { loadTexture(); if (!(m_texture[0] || m_picture[0] || m_image[0].isNull())) return false; } #else if (!m_texture[0] || m_image[0].isNull()) { loadTexture(); if (!m_texture[0] || m_image[0].isNull()) return false; } #endif m_lastRect[0].moveCenter(cursorPos()); m_lastRect[1].moveCenter(cursorPos()); m_active = true; m_angle = 0; return true; }
static void takeUndoSnapshot(EditAction action, bool canMerge) { bool createNew = true; if (!currentBuffer().undoStack_.empty()) { UndoState & state = currentBuffer().undoStack_.back(); if (state.action_ == action && (canMerge || forceUndoMerge_)) createNew = false; } if (createNew) { currentBuffer().undoStack_.emplace_back(currentDoc(), cursorPos(), action); currentBuffer().redoStack_.clear(); } }
void MibEditor::ExecuteGotoLine(void) { QTextBlock currentBlock = s->MainUI()->MIBFile->document()->begin(); QTextBlock foundBlock; int l = 1; int found = 0; int line = goto_uid.spinLine->value(); // Loop through the blocks while(currentBlock.isValid()) { if (l == line) { found = 1; foundBlock = currentBlock; break; } currentBlock = currentBlock.next(); l++; }; if (found) { // Change scrollbar to put the marker visible in the middle of the editor int halfViewPortHeight = s->MainUI()->MIBFile->maximumViewportSize().height()/2; int yCoord = (int)foundBlock.layout()->position().y(); int yAdjust = (yCoord < halfViewPortHeight)?yCoord : halfViewPortHeight; int halfLineHeight = (int)foundBlock.layout()->boundingRect().height()/2; s->MainUI()->MIBFile->verticalScrollBar()->setValue(yCoord - yAdjust); // Set the cursor position to the marker line QPoint cursorPos(0, yAdjust+halfLineHeight); QTextCursor tc = s->MainUI()->MIBFile->cursorForPosition(cursorPos); s->MainUI()->MIBFile->setTextCursor(tc); // Finally, set the focus to the editor s->MainUI()->MIBFile->setFocus(Qt::OtherFocusReason); } }
void UIHexEditorWnd::autoScroll() { s64 actPos = cursorPos(autoScrollDragPos, false); if (actPos < 0) { // Check to see if we can scroll up or down actPos = (s64)(((autoScrollDragPos.y() - 3) / fontHeight) + (s64)verticalScrollBar()->value()) * 2 * (s64)bytesPerLine; } if (autoScrollDir == -1) // Scroll Up verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepSub); if (autoScrollDir == 1) // Scroll Down verticalScrollBar()->triggerAction(QAbstractSlider::SliderSingleStepAdd); // Adjust cursor/selection position setCursorPos(actPos & ~1); setSelection(actPos & ~1); }
void TextField::OnClicked(void* arg) { assert(this == arg); if (!IsKeyboardFocused()) { UIManager::GetInstance().SetFocusUI(mSelfPtr.lock()); } auto injector = InputManager::GetInstance().GetInputInjector(); long x, y; injector->GetMousePos(x, y); Vec2I cursorPos(x, y); const auto& finalPos = GetFinalPos(); cursorPos = cursorPos - finalPos; cursorPos.x -= mTextGap.x; cursorPos.x += mCursorOffset; auto font = Renderer::GetInstance().GetFontWithHeight(mTextSize); if (font) { float length = 0.f; if (cursorPos.x >= (int)mTextWidth) { UIManager::GetInstance().GetTextManipulator()->SetCursorPos(mTextw.size()); } else { for (int i = 0; i < (int)mTextw.size(); i++) { float halfLength = font->GetTextWidth((const char*)&mTextw[i], 2) *.5f; length += halfLength; if (cursorPos.x < length) { UIManager::GetInstance().GetTextManipulator()->SetCursorPos(i); break; } length += halfLength; } } } injector->Invalidate(InputDevice::Mouse); }
EventPropagation TextEditor::charInput(const AnyString& str) { switch (str[0]) { // Backspace case 0x08: for (uint i = 0; i < str.size(); ++i) { // Cannot use backspace when at beginning of file if (0 == pCursorPos.y && 1 == pCursorPos.x) return epStop; // When at beginning of line but not on first line, move up if (0 == pCursorPos.y && pCursorPos.x > 1) cursorPos(pCursorPos.x - 1, columnCount(pCursorPos.x - 1)); else cursorPos(pCursorPos.x, pCursorPos.y - 1); // Erase pText.erase(cursorToByte(pCursorPos), 1); } invalidate(); break; // Space case ' ': pText.insert(cursorToByte(pCursorPos), str); pCursorPos.x += str.size(); invalidate(); break; // Tab case '\t': pText.insert(cursorToByte(pCursorPos), str); cursorPos(pCursorPos.x, pCursorPos.y + str.size() * pTabWidth); invalidate(); break; // Carriage Return case '\r': // New Line / Line Feed case '\n': for (uint i = 0; i < str.size(); ++i) pText.insert(cursorToByte(pCursorPos), '\n'); pCursorPos.y += str.size(); invalidate(); break; // Normal displayable characters default: // Normal ASCII if ((uint8)str[0] < 0x80) { // Non-displayable characters are ignored std::locale loc; if (!std::isgraph(str[0], loc)) break; } pText.insert(cursorToByte(pCursorPos), str); // Advance the cursor pCursorPos.x += str.utf8size(); invalidate(); break; } return epStop; }
void GuiOffscreenCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) { if (!mTargetDirty) return; #ifdef TORQUE_ENABLE_GFXDEBUGEVENTS char buf[256]; dSprintf(buf, sizeof(buf), "OffsceenCanvas %s", getName() ? getName() : getIdString()); GFXDEBUGEVENT_SCOPE_EX(GuiOffscreenCanvas_renderFrame, ColorI::GREEN, buf); #endif PROFILE_START(OffscreenCanvasPreRender); #ifdef TORQUE_GFX_STATE_DEBUG GFX->getDebugStateManager()->startFrame(); #endif if (mTarget->getSize() != mTargetSize) { _setupTargets(); mNamedTarget.setViewport( RectI( Point2I::Zero, mTargetSize ) ); } // Make sure the root control is the size of the canvas. Point2I size = mTarget->getSize(); if(size.x == 0 || size.y == 0) { PROFILE_END(); return; } RectI screenRect(0, 0, size.x, size.y); maintainSizing(); //preRender (recursive) all controls preRender(); PROFILE_END(); // Are we just doing pre-render? if(preRenderOnly) { return; } resetUpdateRegions(); PROFILE_START(OffscreenCanvasRenderControls); GuiCursor *mouseCursor = NULL; bool cursorVisible = true; Point2I cursorPos((S32)mCursorPt.x, (S32)mCursorPt.y); mouseCursor = mDefaultCursor; mLastCursorEnabled = cursorVisible; mLastCursor = mouseCursor; mLastCursorPt = cursorPos; // Set active target GFX->pushActiveRenderTarget(); GFX->setActiveRenderTarget(mTarget); // Clear the current viewport area GFX->setViewport( screenRect ); GFX->clear( GFXClearTarget, ColorF(0,0,0,0), 1.0f, 0 ); resetUpdateRegions(); // Make sure we have a clean matrix state // before we start rendering anything! GFX->setWorldMatrix( MatrixF::Identity ); GFX->setViewMatrix( MatrixF::Identity ); GFX->setProjectionMatrix( MatrixF::Identity ); RectI contentRect(Point2I(0,0), mTargetSize); { // Render active GUI Dialogs for(iterator i = begin(); i != end(); i++) { // Get the control GuiControl *contentCtrl = static_cast<GuiControl*>(*i); GFX->setClipRect( contentRect ); GFX->setStateBlock(mDefaultGuiSB); contentCtrl->onRender(contentCtrl->getPosition(), contentRect); } // Fill Blue if no Dialogs if(this->size() == 0) GFX->clear( GFXClearTarget, ColorF(0,0,0,1), 1.0f, 0 ); GFX->setClipRect( contentRect ); // Draw cursor // if (mCursorEnabled && mouseCursor && mShowCursor) { Point2I pos((S32)mCursorPt.x, (S32)mCursorPt.y); Point2I spot = mouseCursor->getHotSpot(); pos -= spot; mouseCursor->render(pos); } GFX->getDrawUtil()->clearBitmapModulation(); } mTarget->resolve(); GFX->popActiveRenderTarget(); PROFILE_END(); // Keep track of the last time we rendered. mLastRenderMs = Platform::getRealMilliseconds(); mTargetDirty = mDynamicTarget; onFrameRendered(); }
void AStylePart::beautifySource() { KTextEditor::EditInterface *iface = dynamic_cast<KTextEditor::EditInterface*>(partController()->activePart()); if (!iface) return; bool has_selection = false; KTextEditor::SelectionInterface *sel_iface = dynamic_cast<KTextEditor::SelectionInterface*>(partController()->activePart()); if (sel_iface && sel_iface->hasSelection()) has_selection = true; //if there is a selection, we only format it. ASStringIterator is(has_selection ? sel_iface->selection() : iface->text()); KDevFormatter formatter(m_project); formatter.init(&is); QString output; QTextStream os(&output, IO_WriteOnly); // put the selection back to the same indent level. // taking note of the config options. unsigned int indentCount=0; QString indentWith(""); if ( has_selection){ QString original = sel_iface->selection(); for (;indentCount<original.length();indentCount++){ QChar ch = original[indentCount]; if ( ch.isSpace()){ if ( ch == QChar('\n') || ch == QChar('\r')){ indentWith=""; } else{ indentWith+=original[indentCount]; } } else{ break; } } int wsCount = m_project["FillCount"].toInt(); if (m_project["Fill"].toString() == "Tabs") { // tabs and wsCount spaces to be a tab QString replace; for (int i =0;i<wsCount;i++) replace+=' '; indentWith=indentWith.replace(replace, QChar('\t')); indentWith=indentWith.remove(' '); } else { if ( m_project["FillForce"].toBool()){ //convert tabs to spaces QString replace; for (int i =0;i<wsCount;i++) replace+=' '; indentWith=indentWith.replace(QChar('\t'),replace); } } } while (formatter.hasMoreLines()){ if ( has_selection ){ os << indentWith; } os << QString::fromUtf8(formatter.nextLine().c_str()) << endl; } uint col = 0; uint line = 0; if(has_selection) //there was a selection, so only change the part of the text related to it { //remove the final newline character, unless it should be there if ( !sel_iface->selection().endsWith( "\n" ) ) output.setLength(output.length()-1); sel_iface->removeSelectedText(); cursorPos( partController()->activePart(), &col, &line ); iface->insertText( col, line, output); return; } cursorPos( partController()->activePart(), &col, &line ); iface->setText( output ); setCursorPos( partController()->activePart(), col, line ); }
TEST_F(InputFixture, MousePositionTest) { // Description text sf::Text description; description.setCharacterSize(12); description.setString("This test checks if KeyboardMouseInput correctly " "calculates the mouse coordinates.\nClick on the four red boxes below " "to complete the test, or press Escape to exit (forces a failure).\n\n" "You'll have to do this twice: once for locked mouse input, and once " "for unlocked.\nLocked constrains the mouse to the window, while " "unlocked doesn't."); sf::Text currentTest; currentTest.setCharacterSize(12); currentTest.setString("Currently testing locked mode"); currentTest.setPosition(0.f, 80.f); // Mouse coordinate display sf::Text mouseCoords; mouseCoords.setCharacterSize(12); mouseCoords.setPosition(0.f, 468.f); // Cursor display polygon sf::ConvexShape cursor(3); cursor.setPoint(0, sf::Vector2f(0.f, 0.f)); cursor.setPoint(1, sf::Vector2f(0.f, 8.f)); cursor.setPoint(2, sf::Vector2f(4.f, 6.f)); cursor.setFillColor(sf::Color::White); // Boxes to click sf::IntRect topLeft(100, 100, 16, 16); sf::IntRect topRight(540, 100, 16, 16); sf::IntRect bottomLeft(100, 380, 16, 16); sf::IntRect bottomRight(540, 380, 16, 16); // Box display polygon sf::RectangleShape shape(sf::Vector2f(16.f, 16.f)); shape.setFillColor(sf::Color::Red); // Squares left to draw std::set<sf::IntRect*> remaining { &topLeft, &topRight, &bottomLeft, &bottomRight }; // Hide OS cursor window.setMouseCursorVisible(false); // Lock mouse to screen input.setMouseLock(true); bool locked = true; // Focus switches bool focused = true; bool running = true; while (running) { input.preUpdate(); sf::Event event; while (window.pollEvent(event)) { input.handleEvent(event); if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { running = false; FAIL() << "Skipped test"; } else if (event.type == sf::Event::LostFocus) { focused = false; } else if (event.type == sf::Event::GainedFocus) { focused = true; } } if (!focused) { continue; } input.postUpdate(); // Check box intersections sf::Vector2i cursorPos(input.getCursorPosition().x, input.getCursorPosition().y); if (topLeft.contains(cursorPos) && input.isButtonDown(Input::Shoot)) { remaining.erase(&topLeft); } if (topRight.contains(cursorPos) && input.isButtonDown(Input::Shoot)) { remaining.erase(&topRight); } if (bottomLeft.contains(cursorPos) && input.isButtonDown(Input::Shoot)) { remaining.erase(&bottomLeft); } if (bottomRight.contains(cursorPos) && input.isButtonDown(Input::Shoot)) { remaining.erase(&bottomRight); } cursor.setPosition(input.getCursorPosition()); // Exit once all boxes are clicked if (remaining.empty()) { // Repeat the tests, but using an unlocked cursor. if (locked) { locked = false; input.setMouseLock(false); remaining.insert(&topLeft); remaining.insert(&topRight); remaining.insert(&bottomLeft); remaining.insert(&bottomRight); currentTest.setString("Currently testing unlocked mode"); } else { running = false; SUCCEED(); } } std::stringstream ss; ss << "Mouse (" << input.getCursorPosition().x << ", " << input.getCursorPosition().y << ')'; mouseCoords.setString(ss.str()); window.clear(); // Draw the remaining boxes std::set<sf::IntRect*>::iterator iter; for (iter = remaining.begin(); iter != remaining.end(); iter++) { shape.setPosition((*iter)->left, (*iter)->top); window.draw(shape); } window.draw(description); window.draw(currentTest); window.draw(mouseCoords); window.draw(cursor); window.display(); }; }
void KillWindow::start() { static Cursor kill_cursor = 0; if (!kill_cursor) kill_cursor = XCreateFontCursor(display(), XC_pirate); if (XGrabPointer(display(), rootWindow(), False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask, GrabModeAsync, GrabModeAsync, None, kill_cursor, CurrentTime) == GrabSuccess) { grabXKeyboard(); XEvent ev; int return_pressed = 0; int escape_pressed = 0; int button_released = 0; grabXServer(); while (!return_pressed && !escape_pressed && !button_released) { XMaskEvent(display(), KeyPressMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &ev); if (ev.type == KeyPress) { int kc = XKeycodeToKeysym(display(), ev.xkey.keycode, 0); int mx = 0; int my = 0; return_pressed = (kc == XK_Return) || (kc == XK_space); escape_pressed = (kc == XK_Escape); if (kc == XK_Left) mx = -10; if (kc == XK_Right) mx = 10; if (kc == XK_Up) my = -10; if (kc == XK_Down) my = 10; if (ev.xkey.state & ControlMask) { mx /= 10; my /= 10; } QCursor::setPos(cursorPos()+QPoint(mx, my)); } if (ev.type == ButtonRelease) { button_released = (ev.xbutton.button == Button1); if ( ev.xbutton.button == Button3 ) { escape_pressed = true; break; } if( ev.xbutton.button == Button1 || ev.xbutton.button == Button2 ) workspace->killWindowId(ev.xbutton.subwindow); } continue; } if (return_pressed) { Window root, child; int dummy1, dummy2, dummy3, dummy4; unsigned int dummy5; if( XQueryPointer( display(), rootWindow(), &root, &child, &dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true && child != None ) workspace->killWindowId( child ); } ungrabXServer(); ungrabXKeyboard(); XUngrabPointer(display(), CurrentTime); } }
void MultiCursorAppCpp::display(void) { const float divisionX = 12; float cellLength = VEC_WIN_WIDTH[0] / divisionX; glClearColor(1.0, 1.0, 1.0, 1.0); for (size_t i = 0; i < VEC_WIN_WIDTH.size(); ++i) { glutSetWindow(WinIDs[(int)0]); glClear(GL_COLOR_BUFFER_BIT); } if (userData.size() > 0) { for (int i = 0; i < userData.size(); ++i) { if (!userData.empty() && userData[i].cursorInfo.isShownCursor) { // 描画ウィンドウをセット glutSetWindow(WinIDs[userData[i].cursorInfo.displayNum]); int windowWidth = VEC_WIN_WIDTH[userData[i].cursorInfo.displayNum]; int windowHeight = VEC_WIN_HEIGHT[userData[i].cursorInfo.displayNum]; windowWidth = windowWidth; windowHeight = windowHeight; #if 1 // 分割したグリッドでカーソル描画 int posX = (int)(userData[i].cursorInfo.position.x) / (int)(cellLength) * cellLength; int posY = ((int)(windowHeight - userData[i].cursorInfo.position.y) / (int)(cellLength) + 1) * cellLength; float posXGL = ((float)posX - (float)windowWidth / 2) / ((float)windowWidth / 2); float posYGL = ((float)posY - (float)windowHeight / 2) / ((float)windowHeight / 2); float ofX = cellLength / ((float)windowWidth / 2); float ofY = cellLength / ((float)windowHeight / 2); glColor4f(0.1f, 1.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glVertex2f(posXGL, posYGL); glVertex2f(posXGL + ofX, posYGL); glVertex2f(posXGL + ofX, posYGL - ofY); glVertex2f(posXGL, posYGL - ofY); glEnd(); //cout << posXGL << ", " << posYGL << endl; #endif #if 1 // 正確な位置を表すポインタ描画 #ifdef USE_KINECT_V1 Point2f cursorPos((userData[i].cursorInfo.position.x - windowWidth / 2) / windowWidth, -(userData[i].cursorInfo.position.y - windowHeight / 2) / windowHeight); #else Point2f cursorPos((userData[i].cursorInfo.position.x - windowWidth / 2) / windowWidth * 2, (windowHeight - userData[i].cursorInfo.position.y - windowHeight / 2) / windowHeight * 2); #endif glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); float offset = 40; float offsetX = (offset / (float)windowWidth); float offsetY = (offset / (float)windowHeight); glVertex2f(cursorPos.x, cursorPos.y); glVertex2f(cursorPos.x + offsetX, cursorPos.y); glVertex2f(cursorPos.x + offsetX, cursorPos.y + offsetY); glVertex2f(cursorPos.x, cursorPos.y + offsetY); glEnd(); #endif } } } glFlush(); glutSwapBuffers(); }