void Screen::Screen_display() { glViewport( globalPos().x, Main::height()-_height-globalPos().y, _width, _height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,_width,_height,0,1,-1); render(this); }
Coord Widget::toGlobal( const Coord& coord ) const { Coord c = globalPos(); c.x += coord.x; c.y += coord.y; return c; }
void QEvdevTabletData::report() { if (!state.lastReportTool && state.tool) reportProximityEnter(); qreal nx = (state.x - minValues.x) / qreal(maxValues.x - minValues.x); qreal ny = (state.y - minValues.y) / qreal(maxValues.y - minValues.y); QRect winRect = QGuiApplication::primaryScreen()->geometry(); QPointF globalPos(nx * winRect.width(), ny * winRect.height()); int pointer = state.tool; // Prevent sending confusing values of 0 when moving the pen outside the active area. if (!state.down && state.lastReportDown) { globalPos = state.lastReportPos; pointer = state.lastReportTool; } qreal pressure = (state.p - minValues.p) / qreal(maxValues.p - minValues.p); if (state.down || state.lastReportDown) { QWindowSystemInterface::handleTabletEvent(0, state.down, QPointF(), globalPos, QTabletEvent::Stylus, pointer, pressure, 0, 0, 0, 0, 0, 1, qGuiApp->keyboardModifiers()); } if (state.lastReportTool && !state.tool) reportProximityLeave(); state.lastReportDown = state.down; state.lastReportTool = state.tool; state.lastReportPos = globalPos; }
bool CMakeBuildSettingsWidget::eventFilter(QObject *target, QEvent *event) { // handle context menu events: if (target != m_configView->viewport() || event->type() != QEvent::ContextMenu) return false; auto e = static_cast<QContextMenuEvent *>(event); const QModelIndex idx = mapToSource(m_configView, m_configView->indexAt(e->pos())); if (!idx.isValid()) return false; auto menu = new QMenu(this); connect(menu, &QMenu::triggered, menu, &QMenu::deleteLater); QAction *action = nullptr; if ((action = createForceAction(ConfigModel::DataItem::BOOLEAN, idx))) menu->addAction(action); if ((action = createForceAction(ConfigModel::DataItem::FILE, idx))) menu->addAction(action); if ((action = createForceAction(ConfigModel::DataItem::DIRECTORY, idx))) menu->addAction(action); if ((action = createForceAction(ConfigModel::DataItem::STRING, idx))) menu->addAction(action); menu->move(e->globalPos()); menu->show(); return true; }
void QDirectFbInput::handleWheelEvent(const DFBEvent &event) { QPoint p(event.window.x, event.window.y); QPoint globalPos(event.window.cx, event.window.cy); long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000); QWindow *tlw = m_tlwMap.value(event.window.window_id); QWindowSystemInterface::handleWheelEvent(tlw, timestamp, p, globalPos, event.window.step*120, Qt::Vertical); }
static void mouseUp(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) { QPoint globalPos(x,y); QWindow *tlw = m_mouseGrabber.data(); if (!tlw) tlw = topLevelWindowAt(globalPos); QPoint localPos = tlw ? (globalPos -tlw->position()) : globalPos; QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos , Qt::MouseButtons(Qt::NoButton)); m_ignoreMouseEvents = false; m_mouseGrabber = 0; }
void Menubar::_receive( const Msg_p& pMsg ) { Widget::_receive(pMsg); switch( pMsg->type() ) { case MsgType::MouseMove: case MsgType::MousePress: { Coord pos = InputMsg::cast(pMsg)->pointerPos() - globalPos(); uint32_t item = _getItemAtAbsPos( pos.x, pos.y ); if( item && !m_items.get(item-1)->m_bEnabled ) item = 0; // Item is disabled and can't be marked. if(m_markedItem != item) { m_markedItem = item; _requestRender(); } // If a menu entry already is selected we should // switch to the new marked one. if( m_selectedItem ) { if( m_markedItem && m_selectedItem != m_markedItem ) { _closeMenu( m_selectedItem ); _openMenu( m_markedItem ); } } // If this was a press, we need to select the item and open the menu. //TODO: A click on an already open entry should close the menu. if( item && pMsg->type()== MsgType::MousePress ) { _openMenu( item ); } } case MsgType::MouseLeave: m_markedItem = 0; _requestRender(); break; } }
Projectile * Gun::fireProjectile( const Vec3d& pos0, const Mat3d& rot0, const Vec3d& gvel ){ //printf( " Gun fireProjectile \n" ); Projectile * p = new Projectile(); Mat3d rotmat; globalPos( pos0, rot0, p->pos ); globalRot( rot0, rotmat ); p->vel.set_mul( rotmat.a, muzzle_velocity ); p->vel.add( gvel ); p->setMass( projectile_mass ); p->update_old_pos(); //printf( " Gun fireProjectile DONE \n" ); return p; }
static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) { if (m_ignoreMouseEvents) return; QPoint globalPos(x,y); QWindow *tlw = topLevelWindowAt(globalPos); m_mouseGrabber = tlw; QPoint localPos = tlw ? (globalPos - tlw->position()) : globalPos; QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, Qt::MouseButtons(Qt::LeftButton)); }
void QDirectFbInput::handleMouseEvents(const DFBEvent &event) { QPoint p(event.window.x, event.window.y); QPoint globalPos(event.window.cx, event.window.cy); Qt::MouseButtons buttons = QDirectFbConvenience::mouseButtons(event.window.buttons); QDirectFBPointer<IDirectFBDisplayLayer> layer(QDirectFbConvenience::dfbDisplayLayer()); QDirectFBPointer<IDirectFBWindow> window; layer->GetWindow(layer.data(), event.window.window_id, window.outPtr()); long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000); QWindow *tlw = m_tlwMap.value(event.window.window_id); QWindowSystemInterface::handleMouseEvent(tlw, timestamp, p, globalPos, buttons); }
void CompositorHelper::sendFakeMouseEvent() { if (qApp->thread() != QThread::currentThread()) { QMetaObject::invokeMethod(this, "sendFakeMouseEvent", Qt::BlockingQueuedConnection); return; } // in HMD mode we need to fake our mouse moves... QPoint globalPos(_reticlePositionInHMD.x, _reticlePositionInHMD.y); auto button = Qt::NoButton; auto buttons = QApplication::mouseButtons(); auto modifiers = QApplication::keyboardModifiers(); static auto renderingWidget = PluginContainer::getInstance().getPrimaryWidget(); QMouseEvent event(QEvent::MouseMove, globalPos, button, buttons, modifiers); _fakeMouseEvent = true; qApp->sendEvent(renderingWidget, &event); _fakeMouseEvent = false; }
void Screen::blint(Sprite *sprite) { if(alive(sprite)) { if(sprite->visible) { glBindTexture(GL_TEXTURE_2D,sprite->id()); { vector2 p = sprite->globalPos() - globalPos(); vector2 o = sprite->globalOrigin()*sprite->scale; double rot = sprite->globalRotation(); float r = sprite->globalRed(); float g = sprite->globalGreen(); float b = sprite->globalBlue(); float a = sprite->globalAlpha(); double w = sprite->width()*sprite->scale.x; double h = sprite->height()*sprite->scale.y; double sn = sin(rot*PI/180); double cn = cos(rot*PI/180); GLfloat qx = -cn*o.x+sn*o.y, qxw = cn*(w-o.x)+sn*o.y, qy = -sn*o.x-cn*o.y, qyw = sn*(w-o.x)-cn*o.y, qxh = -cn*o.x-sn*(h-o.y), qxwh = cn*(w-o.x)-sn*(h-o.y), qyh = -sn*o.x+cn*(h-o.y), qywh = sn*(w-o.x)+cn*(h-o.y); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBegin(GL_QUADS); glColor4f(r,g,b,a); glTexCoord2f(0,0); glVertex3f(p.x+qx, p.y+qy,0); glTexCoord2f(1,0); glVertex3f(p.x+qxw, p.y+qyw,0); glTexCoord2f(1,1); glVertex3f(p.x+qxwh,p.y+qywh,0); glTexCoord2f(0,1); glVertex3f(p.x+qxh, p.y+qyh,0); glEnd(); } } } }
static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y) { //### TODO: add proper API for Qt 5.2 static bool rightMouseFromLongPress = qgetenv("QT_NECESSITAS_COMPATIBILITY_LONG_PRESS").toInt(); if (!rightMouseFromLongPress) return; m_ignoreMouseEvents = true; QPoint globalPos(x,y); QWindow *tlw = topLevelWindowAt(globalPos); QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; // Release left button QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, Qt::MouseButtons(Qt::NoButton)); // Press right button QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, Qt::MouseButtons(Qt::RightButton)); }
void Popup::display() { m_menu->setArea(Rect(globalPos(), vec2(max(m_menu->width(), width()), m_menu->height()))); m_menu->display(); }
Rect Widget::_globalComponentGeo( const Component * pComponent ) const { return _componentGeo( pComponent ) + globalPos(); }
Coord Widget::_globalComponentPos( const Component * pComponent ) const { return _componentPos( pComponent ) + globalPos(); }
Coord Widget::toLocal( const Coord& coord ) const { Coord c = globalPos(); return Coord( coord.x - c.x, coord.y - c.y ); }
void SplitPanel::_receive(Msg * pMsg) { //TODO: Implement!!! State handleState = m_handleState; switch (pMsg->type()) { case MsgType::MouseEnter: case MsgType::MouseMove: { if (m_handleState.isPressed()) return; Coord pos = InputMsg::cast(pMsg)->pointerPos() - globalPos(); bool bHovered = m_handleGeo.contains(pos); handleState.setHovered(bHovered); break; } case MsgType::MouseLeave: { // Unhover handle unless it is pressed if (!handleState.isPressed()) handleState.setHovered(false); break; } case MsgType::MousePress: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; Coord pos = p->pointerPos() - globalPos(); if (m_handleGeo.contains(pos)) { m_handlePressOfs = m_bHorizontal ? pos.x - m_handleGeo.x : pos.y - m_handleGeo.y; handleState.setPressed(true); pMsg->swallow(); } break; } case MsgType::MouseRelease: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; if (handleState.isPressed() ) { handleState.setPressed(false); pMsg->swallow(); } break; } case MsgType::MouseDrag: { auto p = MouseButtonMsg::cast(pMsg); if (p->button() != MouseButton::Left) return; if (handleState.isPressed()) { Coord pos = p->pointerPos() - globalPos(); int diff = (m_bHorizontal ? pos.x - m_handleGeo.x : pos.y - m_handleGeo.y) - m_handlePressOfs; _updateGeo(diff); pMsg->swallow(); } break; } default: break; } if (handleState != m_handleState && m_pHandleSkin) { if (!m_pHandleSkin->isStateIdentical(handleState, m_handleState)) _requestRender(m_handleGeo); m_handleState = handleState; } }
void GCode::Read(Model *model, ViewProgress *progress, string filename) { clear(); ifstream file; file.open(filename.c_str()); //open a file file.seekg (0, ios::end); double filesize = double(file.tellg()); file.seekg (0); progress->start(_("Loading GCode"), filesize); int progress_steps=(int)(filesize/1000); if (progress_steps==0) progress_steps=1; buffer_zpos_lines.clear(); if(!file.good()) { // MessageBrowser->add(str(boost::format("Error opening file %s") % Filename).c_str()); return; } uint LineNr = 0; string s; Vector3d globalPos(0,0,0); Min.set(99999999.0,99999999.0,99999999.0); Max.set(-99999999.0,-99999999.0,-99999999.0); std::vector<Command> loaded_commands; double lastZ=0.; double lastE=0.; double lastF=0.; layerchanges.clear(); bool belowzero = false; stringstream alltext; while(getline(file,s)) { alltext << s << endl; LineNr++; unsigned long fpos = file.tellg(); if (fpos%progress_steps==0) if (!progress->update(fpos)) break; Command command; try { command = Command(s, globalPos); } catch (Glib::OptionError e) { if (!belowzero) // only once cerr << "GCode below zero!"<< endl;// ; //alert("GCode problem"); belowzero = true; } if (command.e==0) command.e= lastE; else lastE=command.e; if (command.f==0) command.f= lastF; else lastF=command.f; // cout << s << endl; //cerr << command.info()<< endl; if(command.where.x() < -100) continue; if(command.where.y() < -100) continue; globalPos = command.where; if(command.where.x() < Min.x()) Min.x() = command.where.x(); if(command.where.y() < Min.y()) Min.y() = command.where.y(); if(command.where.z() < Min.z()) Min.z() = command.where.z(); if(command.where.x() > Max.x()) Max.x() = command.where.x(); if(command.where.y() > Max.y()) Max.y() = command.where.y(); if(command.where.z() > Max.z()) Max.z() = command.where.z(); if (command.where.z() > lastZ) { // if (lastZ > 0){ // don't record first layer unsigned long num = loaded_commands.size(); layerchanges.push_back(num); // } lastZ = command.where.z(); buffer_zpos_lines.push_back(LineNr-1); } else if (command.where.z() < lastZ) { lastZ=command.where.z(); if (layerchanges.size()>0) layerchanges.erase(layerchanges.end()-1); } loaded_commands.push_back(command); } commands = loaded_commands; buffer->set_text(alltext.str()); Center.x() = (Max.x() + Min.x() )/2; Center.y() = (Max.y() + Min.y() )/2; Center.z() = (Max.z() + Min.z() )/2; model->m_signal_gcode_changed.emit(); double time = GetTimeEstimation(); int h = (int)time/3600; int min = ((int)time%3600)/60; int sec = ((int)time-3600*h-60*min); cout << "GCode Time Estimation "<< h <<"h "<<min <<"m " <<sec <<"s" <<endl; //??? to statusbar or where else? }
void LineEditor::_receive( const Msg_p& pMsg ) { Widget::_receive(pMsg); MsgRouter_p pHandler = Base::msgRouter(); MsgType event = pMsg->type(); if( event == MsgType::Tick ) { if( _isSelectable() && m_state.isFocused() ) { m_text.incTime( TickMsg::cast(pMsg)->timediff() ); _requestRender(); //TODO: Should only render the cursor and selection! } return; } if( (event == MsgType::MousePress || event == MsgType::MouseDrag) && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) { MouseButtonMsg_p pButtonMsg = MouseButtonMsg::cast(pMsg); if( !m_state.isFocused() ) grabFocus(); if( m_state.isFocused() ) { if( _isSelectable() && (pButtonMsg->modKeys() & MODKEY_SHIFT) ) { m_text.setSelectionMode(true); } Coord ofs = pButtonMsg->pointerPos() - globalPos(); int x = ofs.x + m_viewOfs; int y = 0; if( m_bPasswordMode ) { TextAttr attr; m_text.getBaseAttr( attr ); Pen pen; pen.setAttributes( attr ); pen.setChar(m_pwGlyph); pen.advancePos(); int spacing = pen.getPosX(); int height = pen.getLineSpacing(); int line = y/height; int col = (x+spacing/2)/spacing; if(col < 0) { col = 0; line = 0; } m_text.gotoSoftPos(line,col); } else { m_text.cursorGotoCoord( Coord(x, 0), Rect(0,0,1000000,1000000) ); } if(_isSelectable() && event == MsgType::MousePress && !(pButtonMsg->modKeys() & MODKEY_SHIFT)) { m_text.clearSelection(); m_text.setSelectionMode(true); } } _adjustViewOfs(); } if( event == MsgType::MouseRelease ) { if( m_state.isFocused() && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) m_text.setSelectionMode(false); } if( event == MsgType::TextInput ) { String str = TextInputMsg::cast(pMsg)->text(); if( _isEditable() && m_state.isFocused() ) { if(m_text.hasSelection()) m_text.delSelection(); m_text.setSelectionMode(false); bool bModified = false; for( int i = 0 ; i < str.length() ; i++ ) { unsigned short ch = str.chars()[i].getGlyph(); if( ch >= 32 && ch != 127 ) { if( m_text.putChar( ch ) ) bModified = true; } } if( bModified ) { if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); _adjustViewOfs(); } } } if( event == MsgType::KeyRelease && m_state.isFocused() ) { Key key = KeyMsg::cast(pMsg)->translatedKeyCode(); switch( key ) { case Key::Shift: if(!Base::inputHandler()->isButtonPressed(MouseButton::Left)) m_text.setSelectionMode(false); break; } } if( (event == MsgType::KeyPress || event == MsgType::KeyRepeat) && _isEditable() && m_state.isFocused() ) { KeyMsg_p pKeyMsg = KeyMsg::cast(pMsg); Key key = pKeyMsg->translatedKeyCode(); switch( key ) { case Key::Left: if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pKeyMsg->modKeys() & MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.goBol(); else m_text.gotoPrevWord(); } else { m_text.goLeft(); } break; case Key::Right: if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); if( pKeyMsg->modKeys() & MODKEY_CTRL ) { if( m_bPasswordMode ) m_text.goEol(); else m_text.gotoNextWord(); } else { m_text.goRight(); } break; case Key::Backspace: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode) m_text.delPrevWord(); else m_text.delPrevChar(); if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); break; } case Key::Delete: { if(m_text.hasSelection()) m_text.delSelection(); else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode) m_text.delNextWord(); else m_text.delNextChar(); if( pHandler ) pHandler->post( new TextEditMsg(text.ptr(),false) ); break; } case Key::Home: /* * I am not sure if this is the proper way to this, but in my opinion, the default * "actions" has to be separated from any modifier key action combination */ switch( pKeyMsg->modKeys() ) { case MODKEY_CTRL: break; default: // no modifier key was pressed if(pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.goBol(); break; } break; case Key::End: /* * I am not sure if this is the proper way to this, but in my opinion, the default * "actions" has to be separated from any modifier key action combination */ switch( pKeyMsg->modKeys() ) { case MODKEY_CTRL: break; default: // no modifier key was pressed if( pKeyMsg->modKeys() & MODKEY_SHIFT ) m_text.setSelectionMode(true); m_text.goEol(); break; } break; default: break; } _adjustViewOfs(); } // Swallow message depending on rules. if( pMsg->isMouseButtreceive() ) { if( MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left ) pMsg->swallow(); } else if( pMsg->isKeyMsg() ) { Key key = KeyMsg::cast(pMsg)->translatedKeyCode(); if( KeyMsg::cast(pMsg)->isMovementKey() == true || key == Key::Delete || key == Key::Backspace ) pMsg->swallow(); //TODO: Would be good if we didn't forward any character-creating keys either... } }
vec2 Widget::transformToLocal(vec2 globalPoint) const { return globalPoint - globalPos(); }
vec2 Widget::transformToGlobal(vec2 localPoint) const { return localPoint + globalPos(); }
void GCode::Read(Model *model, const vector<char> E_letters, ViewProgress *progress, string filename) { clear(); ifstream file; file.open(filename.c_str()); //open a file file.seekg (0, ios::end); double filesize = double(file.tellg()); file.seekg (0); progress->start(_("Loading GCode"), filesize); int progress_steps=(int)(filesize/1000); if (progress_steps==0) progress_steps=1; buffer_zpos_lines.clear(); if(!file.good()) { // MessageBrowser->add(str(boost::format("Error opening file %s") % Filename).c_str()); return; } set_locales("C"); uint LineNr = 0; string s; bool relativePos = false; Vector3d globalPos(0,0,0); Min.set(99999999.0,99999999.0,99999999.0); Max.set(-99999999.0,-99999999.0,-99999999.0); std::vector<Command> loaded_commands; double lastZ=0.; double lastE=0.; double lastF=0.; layerchanges.clear(); stringstream alltext; int current_extruder = 0; while(getline(file,s)) { alltext << s << endl; LineNr++; unsigned long fpos = file.tellg(); if (fpos%progress_steps==0) if (!progress->update(fpos)) break; Command command; if (relativePos) command = Command(s, Vector3d::ZERO, E_letters); else command = Command(s, globalPos, E_letters); if (command.Code == COMMENT) { continue; } if (command.Code == UNKNOWN) { cerr << "Unknown GCode " << s << endl; continue; } if (command.Code == RELATIVEPOSITIONING) { relativePos = true; continue; } if (command.Code == ABSOLUTEPOSITIONING) { relativePos = false; continue; } if (command.Code == SELECTEXTRUDER) { current_extruder = command.extruder_no; continue; } command.extruder_no = current_extruder; // not used yet // if (command.Code == ABSOLUTE_ECODE) { // relativeE = false; // continue; // } // if (command.Code == RELATIVE_ECODE) { // relativeE = true; // continue; // } if (command.e == 0) command.e = lastE; else lastE = command.e; if (command.f != 0) lastF = command.f; else command.f = lastF; // cout << s << endl; //cerr << command.info()<< endl; // if(command.where.x() < -100) // continue; // if(command.where.y() < -100) // continue; if (command.Code == SETCURRENTPOS) { continue;//if (relativePos) globalPos = command.where; } else { command.addToPosition(globalPos, relativePos); } if (globalPos.z() < 0){ cerr << "GCode below zero!"<< endl; continue; } if ( command.Code == RAPIDMOTION || command.Code == COORDINATEDMOTION || command.Code == ARC_CW || command.Code == ARC_CCW || command.Code == GOHOME ) { if(globalPos.x() < Min.x()) Min.x() = globalPos.x(); if(globalPos.y() < Min.y()) Min.y() = globalPos.y(); if(globalPos.z() < Min.z()) Min.z() = globalPos.z(); if(globalPos.x() > Max.x()) Max.x() = globalPos.x(); if(globalPos.y() > Max.y()) Max.y() = globalPos.y(); if(globalPos.z() > Max.z()) Max.z() = globalPos.z(); if (globalPos.z() > lastZ) { // if (lastZ > 0){ // don't record first layer unsigned long num = loaded_commands.size(); layerchanges.push_back(num); loaded_commands.push_back(Command(LAYERCHANGE, layerchanges.size())); // } lastZ = globalPos.z(); buffer_zpos_lines.push_back(LineNr-1); } else if (globalPos.z() < lastZ) { lastZ = globalPos.z(); if (layerchanges.size()>0) layerchanges.erase(layerchanges.end()-1); } } loaded_commands.push_back(command); } file.close(); reset_locales(); commands = loaded_commands; buffer->set_text(alltext.str()); Center = (Max + Min)/2; model->m_signal_gcode_changed.emit(); double time = GetTimeEstimation(); int h = (int)time/3600; int min = ((int)time%3600)/60; int sec = ((int)time-3600*h-60*min); cerr << "GCode Time Estimation "<< h <<"h "<<min <<"m " <<sec <<"s" <<endl; //??? to statusbar or where else? }