bool MainScene::Notify(NOTIFIED_EVENT_TYPE_T eventType, const bool& value) { bool result = true; switch(eventType) { case NE_VIEWPORT_CHANGED: ViewportChanged(); break; case NE_GAME_COMMAND_ZOOM_IN: DecreaseScale(); break; case NE_GAME_COMMAND_ZOOM_OUT: IncreaseScale(); break; case NE_GAME_COMMAND_TRACK: if(_camera.IsTrackingEnabled()) { _camera.SetTrackingMode(ViewportCamera::TM_OFF); } else { _camera.SetTrackingMode(ViewportCamera::TM_FOLLOW_EDGE); } break; default: result = false; break; } return result; }
void ReRulerWidget::mouseMoveEvent( QMouseEvent* _event ) { if( m_cursorDragInfo.IsMoving() ) { int cursorBackup = m_cursor; int cursor = 0; int delta = 0; int newCursor = 0; if( IsHorizontal() ) { cursor = _event->pos().x(); if( cursor < 0 ) cursor = 0; else if( cursor >= width() ) cursor = width() - 1; delta = cursor - m_cursorDragInfo.GetCursorPosBackup().x(); newCursor = m_cursorDragInfo.GetCursorPosBackup().x() + delta / m_snap * m_snap; } else { cursor = _event->pos().y(); if( cursor < 0 ) cursor = 0; else if( cursor >= height() ) cursor = height() - 1; delta = cursor - m_cursorDragInfo.GetCursorPosBackup().y(); newCursor = m_cursorDragInfo.GetCursorPosBackup().y() + delta / m_snap * m_snap; } if( newCursor != m_cursor ) { OnCursorChanged( newCursor ); emit CursorChanged( newCursor ); } } else if( m_viewportDragInfo.IsMoving() ) { int viewPortBackup = m_viewport; QPoint delta = _event->pos() - m_viewportDragInfo.GetCursorPosBackup(); int newViewportPos = IsHorizontal() ? m_viewportDragInfo.GetItemPosBackup().x() - delta.x() : m_viewportDragInfo.GetItemPosBackup().y() - delta.y(); newViewportPos = newViewportPos / m_snap * m_snap; if( newViewportPos != viewPortBackup ) { OnViewportChanged( newViewportPos ); emit ViewportChanged( newViewportPos ); } } }
void ReRulerWidget::SetValue( qreal _value, bool _scrollViewport ) { int newCursor = qRound( _value / m_unitValue * m_unit ) - m_viewport; OnCursorChanged( newCursor ); emit CursorChanged( newCursor ); if( m_cursor < 0 && _scrollViewport ) { OnViewportChanged( newCursor ); emit ViewportChanged( newCursor ); } }
int RE::ReRulerWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = ReBaseWidget<QLabel>::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: CursorChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: ViewportChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: OnCursorChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: OnViewportChanged((*reinterpret_cast< int(*)>(_a[1]))); break; default: ; } _id -= 4; } return _id; }
void MainScene::onEnter() { CCScene::onEnter(); // Create physical world CreatePhysics(); // Add a color background. This will make it easier on the eyes. addChild(SunBackgroundLayer::create()); // Adding the debug lines so that we can draw the path followed. DebugLinesLayer* linesLayer = DebugLinesLayer::create(); assert(linesLayer != NULL); addChild(DebugLinesLayer::create()); linesLayer->setTag(TAG_DEBUG_LINES); addChild(linesLayer); // Grid // This should be at the bottom of the layer stack. GridLayer* gridLayer = GridLayer::create(5); assert(gridLayer != NULL); gridLayer->setTag(TAG_DEBUG_GRID); addChild(gridLayer); // Box2d Debug Box2DDebugDrawLayer* debugLayer = Box2DDebugDrawLayer::create(_world); assert(debugLayer != NULL); debugLayer->setTag(TAG_DEBUG_BOX2D); addChild(debugLayer); // Asteroids _asteroidLayer = SpriteBatchLayer::create("Asteroids_ImgData.png", "Asteroids_ImgData.plist"); assert(_asteroidLayer != NULL); addChild(_asteroidLayer); // Space Ships _shipLayer = SpriteBatchLayer::create("EntitySpriteImages.png", "EntitySpriteImages.plist"); assert(_shipLayer != NULL); addChild(_shipLayer); // Touch Input addChild(TapDragPinchInput::create(this)); // User Controls addChild(PlayerGameControlsLayer::create()); // Create the Anchor CreateAnchor(); // Asteroids CreateAsteroids(); // Populate physical world CreateEntity(); // Create the sensor grid CreateSensors(); // Contact Counts // addChild(GraphSensorContactLayer::create()); // Register for events Notifier::Instance().Attach(this, NE_VIEWPORT_CHANGED); Notifier::Instance().Attach(this, NE_GAME_COMMAND_ZOOM_IN); Notifier::Instance().Attach(this, NE_GAME_COMMAND_ZOOM_OUT); Notifier::Instance().Attach(this, NE_GAME_COMMAND_TRACK); // Kickstart all sizes ViewportChanged(); }