MapWidget::MapWidget(QWidget *parent) : QWidget(parent), m_center(55.755831, 37.617673), m_zoom(10), m_online(true), m_lockWheel(false) { m_tiles = new TilesMap(m_center, m_zoom, m_online, this); connect(m_tiles, SIGNAL(updated(QRect)), SLOT(updateMap(QRect))); connect(m_tiles, SIGNAL(tilesLoading(int)), SIGNAL(tilesLoading(int))); connect(m_tiles, SIGNAL(zoomChanged(int)), SIGNAL(zoomChanged(int))); m_overlays = new Overlays(m_center, m_zoom, this); m_pointDialog = new PointDialog(this); connect(m_pointDialog, SIGNAL(accepted()), SLOT(pointDialogAccepted())); QShortcut *sc; sc = new QShortcut(QKeySequence("Left"), this); connect(sc, SIGNAL(activated()), SLOT(panLeft())); sc = new QShortcut(QKeySequence("Right"), this); connect(sc, SIGNAL(activated()), SLOT(panRight())); sc = new QShortcut(QKeySequence("Down"), this); connect(sc, SIGNAL(activated()), SLOT(panDown())); sc = new QShortcut(QKeySequence("Up"), this); connect(sc, SIGNAL(activated()), SLOT(panUp())); sc = new QShortcut(QKeySequence("PgUp"), this); connect(sc, SIGNAL(activated()), SLOT(zoomIn())); sc = new QShortcut(QKeySequence("PgDown"), this); connect(sc, SIGNAL(activated()), SLOT(zoomOut())); sc = new QShortcut(QKeySequence("Escape"), this); connect(sc, SIGNAL(activated()), SLOT(hideAll())); sc = new QShortcut(QKeySequence("Shift+Insert"), this); connect(sc, SIGNAL(activated()), SLOT(openAddPointDialog())); sc = new QShortcut(QKeySequence("E"), this); connect(sc, SIGNAL(activated()), SLOT(openEditPointDialog())); sc = new QShortcut(QKeySequence("Delete"), this); connect(sc, SIGNAL(activated()), SLOT(openDeletePointDialog())); sc = new QShortcut(QKeySequence("Alt+I"), this); connect(sc, SIGNAL(activated()), SLOT(switchOnline())); sc = new QShortcut(QKeySequence("Alt+O, Alt+O"), this); connect(sc, SIGNAL(activated()), SLOT(openInOSM())); sc = new QShortcut(QKeySequence("Alt+O, Alt+G"), this); connect(sc, SIGNAL(activated()), SLOT(openInGoogleMaps())); sc = new QShortcut(QKeySequence("Alt+O, Alt+Y"), this); connect(sc, SIGNAL(activated()), SLOT(openInYandexMaps())); }
bool Camera::pollEvent( SDL_Event *event ) // This should be called at regular intervals to avoid key-response lag { if( !SDL_PollEvent(event) ) { if( event->type==SDL_QUIT ) exit(0); if( event->type!=SDL_KEYDOWN ) { step(); return false; } } switch( event->key.keysym.sym ) { case SDLK_LEFT: if( event->key.keysym.mod & KMOD_SHIFT ) revolveLeft(); else if( event->key.keysym.mod & KMOD_CTRL ) rotateCW(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateLeft(accInc); else panLeft(); break; case SDLK_RIGHT: if( event->key.keysym.mod & KMOD_SHIFT ) revolveRight(); else if( event->key.keysym.mod & KMOD_CTRL ) rotateCCW(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateRight(accInc); else panRight(); break; case SDLK_UP: if( event->key.keysym.mod & KMOD_SHIFT ) revolveUp(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateUp(accInc); else panUp(); break; case SDLK_DOWN: if( event->key.keysym.mod & KMOD_SHIFT ) revolveDown(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateDown(accInc); else panDown(); break; case SDLK_f: case SDLK_PERIOD: accelerate(accInc); break; case SDLK_b: case SDLK_COMMA: accelerate(-accInc); break; case SDLK_SPACE: stop(); break; case SDLK_F1: accInc = accel[0]; break; case SDLK_F2: accInc = accel[1]; break; case SDLK_F3: accInc = accel[2]; break; case SDLK_F4: accInc = accel[3]; break; case SDLK_F5: accInc = accel[4]; break; case SDLK_F6: accInc = accel[5]; break; case SDLK_F7: accInc = accel[6]; break; case SDLK_F8: accInc = accel[7]; break; case SDLK_F9: accInc = accel[8]; break; case SDLK_ESCAPE: exit(0); break; case SDLK_TAB: if( event->key.keysym.mod & KMOD_SHIFT ) storeCamera(camStore); else restoreCamera(camStore); stop(); break; default: break; } step(); return true; }
EditorMainWindow::EditorMainWindow(QWidget *parent) : QMainWindow(parent) { camera_ = 0; ui.setupUi(this); QApplication::connect(ui.action_Open, SIGNAL(triggered()), this, SLOT(openRequested())); QApplication::connect(ui.action_Save, SIGNAL(triggered()), this, SLOT(saveRequested())); QApplication::connect(ui.actionDerive_map, SIGNAL(triggered()), this, SLOT(deriveMap())); QApplication::connect(ui.action_Quit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit())); QApplication::connect(ui.actionZoom_In, SIGNAL(triggered()), this, SLOT(zoominRequested())); QApplication::connect(ui.actionZoom_Out, SIGNAL(triggered()), this, SLOT(zoomoutRequested())); QApplication::connect(ui.horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScroll(int))); QApplication::connect(ui.verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(vertScroll(int))); QApplication::connect(ui.actionRotate_Left, SIGNAL(triggered()), this, SLOT(rotateLeft())); QApplication::connect(ui.actionRotate_Right, SIGNAL(triggered()), this, SLOT(rotateRight())); QApplication::connect(ui.actionTilt_Up, SIGNAL(triggered()), this, SLOT(tiltUp())); QApplication::connect(ui.actionTilt_Down, SIGNAL(triggered()), this, SLOT(tiltDown())); QApplication::connect(ui.actionUndo, SIGNAL(triggered()), this, SLOT(undo())); QApplication::connect(ui.actionRedo, SIGNAL(triggered()), this, SLOT(redo())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S),this), SIGNAL(activated()), this, SLOT(saveRequested())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_O),this), SIGNAL(activated()), this, SLOT(openRequested())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_Z),this), SIGNAL(activated()), this, SLOT(zoominRequested())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_X),this), SIGNAL(activated()), this, SLOT(zoomoutRequested())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left),this), SIGNAL(activated()), this, SLOT(rotateLeft())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right),this), SIGNAL(activated()), this, SLOT(rotateRight())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up),this), SIGNAL(activated()), this, SLOT(tiltUp())); QApplication::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down),this), SIGNAL(activated()), this, SLOT(tiltDown())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_Left),this), SIGNAL(activated()), this, SLOT(panLeft())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_Right),this), SIGNAL(activated()), this, SLOT(panRight())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_Up),this), SIGNAL(activated()), this, SLOT(panUp())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_Down),this), SIGNAL(activated()), this, SLOT(panDown())); ui.action_Save->setEnabled(false); ui.editorGLWidget->setEnabled(false); QToolButton* party_button = new QToolButton(); party_button->setText("Parties"); party_button->setCheckable(true); party_button->setChecked(false); handlers_.push_back(new TerrainHandler(*this, "party", false, tool_buttons_.size())); QApplication::connect(party_button, SIGNAL(pressed()), handlers_.back(), SLOT(terrainSelected())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_P),this), SIGNAL(activated()), handlers_.back(), SLOT(terrainSelected())); ui.tilesToolBar->addWidget(party_button); tool_buttons_.push_back(party_button); QToolButton* height_button = new QToolButton(); height_button->setText("Height"); height_button->setCheckable(true); height_button->setChecked(true); handlers_.push_back(new TerrainHandler(*this, "", false, tool_buttons_.size())); QApplication::connect(height_button, SIGNAL(pressed()), handlers_.back(), SLOT(terrainSelected())); QApplication::connect(new QShortcut(QKeySequence(Qt::Key_H),this), SIGNAL(activated()), handlers_.back(), SLOT(terrainSelected())); ui.tilesToolBar->addWidget(height_button); tool_buttons_.push_back(height_button); QToolButton* picker_button = new QToolButton(); picker_button->setText("Picker"); picker_button->setCheckable(true); handlers_.push_back(new TerrainHandler(*this, "", true, tool_buttons_.size())); QApplication::connect(picker_button, SIGNAL(pressed()), handlers_.back(), SLOT(terrainSelected())); ui.tilesToolBar->addWidget(picker_button); tool_buttons_.push_back(picker_button); std::vector<std::string> terrain_ids; hex::base_terrain::get_terrain_ids(terrain_ids); for(int n = 0; n != terrain_ids.size(); ++n) { QToolButton* b = new QToolButton(); b->setText(hex::base_terrain::get(terrain_ids[n])->name().c_str()); b->setCheckable(true); handlers_.push_back(new TerrainHandler(*this, terrain_ids[n], false, tool_buttons_.size())); QApplication::connect(b, SIGNAL(pressed()), handlers_.back(), SLOT(terrainSelected())); ui.tilesToolBar->addWidget(b); tool_buttons_.push_back(b); } terrain_ids.clear(); hex::terrain_feature::get_feature_ids(terrain_ids); for(int n = 0; n != terrain_ids.size(); ++n) { QToolButton* b = new QToolButton(); b->setText(hex::terrain_feature::get(terrain_ids[n])->name().c_str()); b->setCheckable(true); handlers_.push_back(new TerrainHandler(*this, terrain_ids[n], true, tool_buttons_.size())); QApplication::connect(b, SIGNAL(pressed()), handlers_.back(), SLOT(terrainSelected())); ui.tilesToolBar->addWidget(b); tool_buttons_.push_back(b); } }
void sandbox(SDL_Surface *s, int width, int height){ form sand(0,0,1000,600); cout<<sand.children.size()<<"\n"; XAutomataEngine game(&sand,200,100,750,400,width,height); //configure key events to pass preview to sand. sand.tag = &game; sand.addHandler(event_keydown,sandKey); //pan controls Button panUp(&sand,70,190,45,45); panUp.text = "Up"; Button panDown(&sand,70,290,45,45); panDown.text = "Down"; Button panLeft(&sand,20,240,45,45); panLeft.text = "Left"; Button panRight(&sand,120,240,45,45); panRight.text = "Right"; Button home(&sand,70,240,45,45); home.text = (width==-1&&height==-1?"Home":"Fit"); panUp.tag = panDown.tag = panLeft.tag = panRight.tag = home.tag = (void*)(&game); panUp.addHandler(event_Lclick,sandUpHandler); panDown.addHandler(event_Lclick,sandDownHandler); panLeft.addHandler(event_Lclick,sandLeftHandler); panRight.addHandler(event_Lclick,sandRightHandler); home.addHandler(event_Lclick,sandHomeHandler); //zoom controls Button zoomIn(&sand,55,375,75,45); zoomIn.text = "Zoom in"; Button zoomOut(&sand,55,445,75,45); zoomOut.text = "Zoom out"; zoomIn.tag = zoomOut.tag = (void*)(&game); zoomIn.addHandler(event_Lclick,sandZoomInHandler); zoomOut.addHandler(event_Lclick,sandZoomOutHandler); //speed controls label speedLabel(&sand,200,530,130,30); speedLabel.text = "Speed: Paused"; HScroll speedScroll(&sand,350,530,200,30,1,10,5); Button pause(&sand,600,530,70,30); pause.text = "Pause"; Button step(&sand,700,530,70,30); step.text = "Step"; speedLabel.tag = speedScroll.tag = pause.tag = step.tag = (void*)(&game); speedScroll.addHandler(event_scroll,sandScrollHandler); pause.addHandler(event_Lclick,sandPause); step.addHandler(event_Lclick,sandStep); //colour controls radioButton white(&sand,300,35,80,20,NULL); white.setTextColour(255,255,255); white.setText("Master"); radioButton red(&sand,400,35,80,20,&white); red.setTextColour(255,100,100); red.setText("Red"); radioButton green(&sand,500,35,80,20,&red); green.setTextColour(0,255,100); green.setText("Green"); radioButton blue(&sand,600,35,80,20,&green); blue.setTextColour(100,100,255); blue.setText("Blue"); radioButton yellow(&sand,700,35,80,20,&green); yellow.setTextColour(255,255,0); yellow.setText("Yellow"); checkBox bind(&sand,300,70,150,30); bind.setText("Enforce rules"); bind.tag = (void*)&game; bind.addHandler(event_checkchanged,changeRestrict); teamRadioStruct params[5]; radioButton *colours[5] = {&white,&red,&green,&blue,&yellow}; for(int i = 0; i < 5; i++){ params[i] = teamRadioStruct(i,&game); colours[i]->tag = ¶ms[i]; colours[i]->addHandler(event_checkchanged,changeTeam); } white.select(); game.fit(); //adding a save feature. No open yet... Button save(&sand,900,10,80,40); save.text = "Save"; //exit controls Button back(&sand,50,50,100,50); back.text = "Back"; back.addHandler(event_Lclick,sandBack); sand.addHandler(event_quit,sandBack); //keep that label and pause button updated pause.addHandler(event_frameTick,sandPauseButtonText); speedLabel.addHandler(event_frameTick,sandLabelText); sand.startFramerate(20,s); running = true; while(running){ sand.wait(); SDL_Flip(s); } cout<<"Ended"; }