int main() { printf("I'm alive!\n"); drawing* d = (drawing*)malloc(sizeof(drawing)); d->canvas = makeArray(CHRCX, CHRCY); drawString(d,"ABC",3,5); rotateCw(d); testPrint(d); printf("\n\n\n"); testPrintBoard(); insertDrawing(d); printf("\n\n\n"); testPrintBoard(); //system("Pause");//needed for C++ return 0; }
MainWindow::MainWindow(const QString& initialFilename, QWidget *parent) : QMainWindow(parent), m_appSettings("OpenSource", "Sproxel"), m_activeFilename(""), m_project(new SproxelProject()) { // Project VoxelGridGroupPtr sprite(new VoxelGridGroup(Imath::V3i(DEFAULT_VOXGRID_SZ, DEFAULT_VOXGRID_SZ, DEFAULT_VOXGRID_SZ), ColorPalettePtr())); sprite->setName("unnamed"); m_project->sprites.push_back(sprite); // Windows m_glModelWidget = new GLModelWidget(this, &m_appSettings, &m_undoManager, sprite); setCentralWidget(m_glModelWidget); // The docking palette widget m_paletteDocker = new QDockWidget(tr("Palette"), this); m_paletteDocker->setObjectName("paletteDocker"); m_paletteDocker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); m_paletteWidget = new PaletteWidget(this, &m_undoManager); m_paletteDocker->setWidget(m_paletteWidget); m_paletteWidget->setPalette(m_project->mainPalette); addDockWidget(Qt::RightDockWidgetArea, m_paletteDocker); // The docking project widget m_projectDocker=new QDockWidget(tr("Project"), this); m_projectDocker->setObjectName("projectDocker"); m_projectWidget=new ProjectWidget(this, &m_undoManager, &m_appSettings); m_projectDocker->setWidget(m_projectWidget); m_projectWidget->setProject(m_project); addDockWidget(Qt::RightDockWidgetArea, m_projectDocker); // The docking layers widget //m_layersDocker = new QDockWidget(tr("Layers"), this); //m_layersDocker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); //m_layersWidget = new LayersWidget(this); //m_layersDocker->setWidget(m_layersWidget); //addDockWidget(Qt::RightDockWidgetArea, m_layersDocker); // Connect some window signals together QObject::connect(m_paletteWidget, SIGNAL(activeColorChanged(Imath::Color4f, int)), m_glModelWidget, SLOT(setActiveColor(Imath::Color4f, int))); QObject::connect(m_glModelWidget, SIGNAL(colorSampled(Imath::Color4f, int)), m_paletteWidget, SLOT(setActiveColor(Imath::Color4f, int))); QObject::connect(&m_undoManager, SIGNAL(cleanChanged(bool)), this, SLOT(reactToModified(bool))); QObject::connect(m_projectWidget, SIGNAL(spriteSelected(VoxelGridGroupPtr)), m_glModelWidget, SLOT(setSprite(VoxelGridGroupPtr))); // Toolbar m_toolbar = new QToolBar("Tools", this); m_toolbar->setObjectName("toolbar"); m_toolbar->setOrientation(Qt::Vertical); addToolBar(Qt::LeftToolBarArea, m_toolbar); // Actions & Menus menuBar()->show(); m_menuFile = menuBar()->addMenu("Fi&le"); m_actFileNew = new QAction("&New", this); m_actFileNew->setShortcut(Qt::CTRL + Qt::Key_N); m_menuFile->addAction(m_actFileNew); connect(m_actFileNew, SIGNAL(triggered()), this, SLOT(newGrid())); m_menuFile->addSeparator(); m_actFileOpen = new QAction("&Open", this); m_actFileOpen->setShortcut(Qt::CTRL + Qt::Key_O); m_menuFile->addAction(m_actFileOpen); connect(m_actFileOpen, SIGNAL(triggered()), this, SLOT(openFile())); m_actFileSave = new QAction("&Save", this); m_actFileSave->setShortcut(Qt::CTRL + Qt::Key_S); m_menuFile->addAction(m_actFileSave); connect(m_actFileSave, SIGNAL(triggered()), this, SLOT(saveFile())); m_actFileSaveAs = new QAction("Save &As", this); m_menuFile->addAction(m_actFileSaveAs); connect(m_actFileSaveAs, SIGNAL(triggered()), this, SLOT(saveFileAs())); m_menuFile->addSeparator(); m_actFileImport = new QAction("&Import...", this); m_menuFile->addAction(m_actFileImport); connect(m_actFileImport, SIGNAL(triggered()), this, SLOT(import())); m_actFileExportGrid = new QAction("&Export...", this); m_menuFile->addAction(m_actFileExportGrid); connect(m_actFileExportGrid, SIGNAL(triggered()), this, SLOT(exportGrid())); m_menuFile->addSeparator(); m_actQuit = new QAction("&Quit", this); m_actQuit->setShortcut(Qt::CTRL + Qt::Key_Q); m_menuFile->addAction(m_actQuit); connect(m_actQuit, SIGNAL(triggered()), this, SLOT(close())); // ------ edit menu m_menuEdit = menuBar()->addMenu("&Edit"); m_actUndo=m_undoManager.createUndoAction(this, "Undo"); m_actUndo->setShortcut(Qt::CTRL + Qt::Key_Z); m_menuEdit->addAction(m_actUndo); m_actRedo=m_undoManager.createRedoAction(this, "Redo"); m_actRedo->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z); m_menuEdit->addAction(m_actRedo); m_menuEdit->addSeparator(); m_actShiftUp = new QAction("Shift up", this); m_actShiftUp->setShortcut(Qt::CTRL + Qt::Key_BracketRight); m_menuEdit->addAction(m_actShiftUp); connect(m_actShiftUp, SIGNAL(triggered()), this, SLOT(shiftUp())); m_actShiftDown = new QAction("Shift down", this); m_actShiftDown->setShortcut(Qt::CTRL + Qt::Key_BracketLeft); m_menuEdit->addAction(m_actShiftDown); connect(m_actShiftDown, SIGNAL(triggered()), this, SLOT(shiftDown())); m_actShiftWrap = new QAction("Wrap shift ops", this); m_actShiftWrap->setCheckable(true); m_actShiftWrap->setChecked(m_glModelWidget->shiftWrap()); m_menuEdit->addAction(m_actShiftWrap); connect(m_actShiftWrap, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setShiftWrap(bool))); m_actRotateCw = new QAction("Rotate clockwise", this); m_actRotateCw->setShortcut(Qt::CTRL + Qt::Key_Greater); m_menuEdit->addAction(m_actRotateCw); connect(m_actRotateCw, SIGNAL(triggered()), this, SLOT(rotateCw())); m_actRotateCcw = new QAction("Rotate counter-clockwise", this); m_actRotateCcw->setShortcut(Qt::CTRL + Qt::Key_Less); m_menuEdit->addAction(m_actRotateCcw); connect(m_actRotateCcw, SIGNAL(triggered()), this, SLOT(rotateCcw())); m_actMirror = new QAction("Mirror", this); m_actMirror->setShortcut(Qt::CTRL + Qt::Key_M); m_menuEdit->addAction(m_actMirror); connect(m_actMirror, SIGNAL(triggered()), this, SLOT(mirror())); m_menuEdit->addSeparator(); m_actPreferences = new QAction("Preferences...", this); m_menuEdit->addAction(m_actPreferences); connect(m_actPreferences, SIGNAL(triggered()), this, SLOT(editPreferences())); // ------ grid menu m_menuGrid = menuBar()->addMenu("&Grid"); m_actExtendUp = new QAction("Extend grid dimension up", this); m_actExtendUp->setShortcut(Qt::CTRL + Qt::Key_Plus); m_menuGrid->addAction(m_actExtendUp); connect(m_actExtendUp, SIGNAL(triggered()), this, SLOT(extendUp())); m_actExtendDown = new QAction("Extend grid dimension down", this); m_actExtendDown->setShortcut(Qt::CTRL + Qt::Key_Minus); m_menuGrid->addAction(m_actExtendDown); connect(m_actExtendDown, SIGNAL(triggered()), this, SLOT(extendDown())); m_actContractUp = new QAction("Contract grid dimension from above", this); m_menuGrid->addAction(m_actContractUp); connect(m_actContractUp, SIGNAL(triggered()), this, SLOT(contractUp())); m_actContractDown = new QAction("Contract grid dimension from below", this); m_menuGrid->addAction(m_actContractDown); connect(m_actContractDown, SIGNAL(triggered()), this, SLOT(contractDown())); m_menuGrid->addSeparator(); m_actUpRes = new QAction("Double grid resolution", this); m_menuGrid->addAction(m_actUpRes); connect(m_actUpRes, SIGNAL(triggered()), this, SLOT(upRes())); m_actDownRes = new QAction("Half grid resolution", this); m_menuGrid->addAction(m_actDownRes); connect(m_actDownRes, SIGNAL(triggered()), this, SLOT(downRes())); // ------ view menu m_menuView = menuBar()->addMenu("&View"); QAction *action=new QAction(tr("Frame sprite"), this); action->setShortcut(Qt::Key_Z); m_menuView->addAction(action); connect(action, SIGNAL(triggered()), m_glModelWidget, SLOT(frameFull())); m_actViewGrid = new QAction("View Grid", this); m_actViewGrid->setShortcut(Qt::CTRL + Qt::Key_G); m_actViewGrid->setCheckable(true); m_actViewGrid->setChecked(m_glModelWidget->drawGrid()); m_menuView->addAction(m_actViewGrid); connect(m_actViewGrid, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setDrawGrid(bool))); m_actViewVoxgrid = new QAction("Voxel Grid", this); m_actViewVoxgrid->setShortcut(Qt::Key_G); m_actViewVoxgrid->setCheckable(true); m_actViewVoxgrid->setChecked(m_glModelWidget->drawVoxelGrid()); m_menuView->addAction(m_actViewVoxgrid); connect(m_actViewVoxgrid, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setDrawVoxelGrid(bool))); m_actViewBBox = new QAction("Bounding Box", this); m_actViewBBox->setShortcut(Qt::CTRL + Qt::Key_B); m_actViewBBox->setCheckable(true); m_actViewBBox->setChecked(m_glModelWidget->drawBoundingBox()); m_menuView->addAction(m_actViewBBox); connect(m_actViewBBox, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setDrawBoundingBox(bool))); action=new QAction("Sprite Bounds", this); action->setShortcut(Qt::Key_B); action->setCheckable(true); action->setChecked(m_glModelWidget->drawSpriteBounds()); m_menuView->addAction(action); connect(action, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setDrawSpriteBounds(bool))); // ------ window menu m_menuWindow = menuBar()->addMenu("&Window"); m_menuWindow->addAction(m_toolbar->toggleViewAction()); m_menuWindow->addAction(m_paletteDocker->toggleViewAction()); m_menuWindow->addAction(m_projectDocker->toggleViewAction()); //m_menuWindow->addAction(m_layersDocker->toggleViewAction()); m_menuWindow->addAction(get_python_console_widget()->toggleViewAction()); get_python_console_widget()->toggleViewAction()->setChecked(false); // ------ toolbar hookups // Icons from the brilliant icon pack located at : http://pen-art.ru/ m_toolbarActionGroup = new QActionGroup(this); m_actToolSplat = new QAction("Splat", m_toolbarActionGroup); m_actToolSplat->setIcon(QIcon(QPixmap(":/icons/splat.png"))); m_actToolSplat->setCheckable(true); connect(m_actToolSplat, SIGNAL(toggled(bool)), this, SLOT(setToolSplat(bool))); m_actToolReplace = new QAction("Replace", m_toolbarActionGroup); m_actToolReplace->setIcon(QIcon(QPixmap(":/icons/pencil.png"))); m_actToolReplace->setCheckable(true); connect(m_actToolReplace, SIGNAL(toggled(bool)), this, SLOT(setToolReplace(bool))); m_actToolFlood = new QAction("Flood", m_toolbarActionGroup); m_actToolFlood->setIcon(QIcon(QPixmap(":/icons/paintBucket.png"))); m_actToolFlood->setCheckable(true); connect(m_actToolFlood, SIGNAL(toggled(bool)), this, SLOT(setToolFlood(bool))); m_actToolDropper = new QAction("Dropper", m_toolbarActionGroup); m_actToolDropper->setIcon(QIcon(QPixmap(":/icons/eyeDropper.png"))); m_actToolDropper->setCheckable(true); connect(m_actToolDropper, SIGNAL(toggled(bool)), this, SLOT(setToolDropper(bool))); m_actToolEraser = new QAction("Eraser", m_toolbarActionGroup); m_actToolEraser->setIcon(QIcon(QPixmap(":/icons/eraser.png"))); m_actToolEraser->setCheckable(true); connect(m_actToolEraser, SIGNAL(toggled(bool)), this, SLOT(setToolEraser(bool))); m_actToolSlab = new QAction("Slab", m_toolbarActionGroup); m_actToolSlab->setIcon(QIcon(QPixmap(":/icons/slab.png"))); m_actToolSlab->setCheckable(true); connect(m_actToolSlab, SIGNAL(toggled(bool)), this, SLOT(setToolSlab(bool))); m_actToolLine = new QAction("Line", m_toolbarActionGroup); m_actToolLine->setIcon(QIcon(QPixmap(":/icons/line.png"))); m_actToolLine->setCheckable(true); connect(m_actToolLine, SIGNAL(toggled(bool)), this, SLOT(setToolLine(bool))); m_actToolBox = new QAction("Box", m_toolbarActionGroup); m_actToolBox->setIcon(QIcon(QPixmap(":/icons/box.png"))); m_actToolBox->setCheckable(true); connect(m_actToolBox, SIGNAL(toggled(bool)), this, SLOT(setToolBox(bool))); m_actToolExtrude = new QAction("Extrude", m_toolbarActionGroup); m_actToolExtrude->setIcon(QIcon(QPixmap(":/icons/extrude.png"))); m_actToolExtrude->setCheckable(true); connect(m_actToolExtrude, SIGNAL(toggled(bool)), this, SLOT(setToolExtrude(bool))); //m_actToolRay = new QAction("Ray", this); m_actToolSplat->setChecked(true); m_toolbar->addActions(m_toolbarActionGroup->actions()); // Toolbar widgets for slicing m_toolbar->addSeparator(); m_minSliceBox=new QSpinBox(); m_maxSliceBox=new QSpinBox(); m_toolbar->addWidget(m_maxSliceBox); m_toolbar->addWidget(m_minSliceBox); connect(m_glModelWidget, SIGNAL(sliceChanged(int, int, int)), this, SLOT(updateSlice(int, int, int))); connect(m_minSliceBox, SIGNAL(valueChanged(int)), m_glModelWidget, SLOT(setMinSlice(int))); connect(m_maxSliceBox, SIGNAL(valueChanged(int)), m_glModelWidget, SLOT(setMaxSlice(int))); // axis selection QActionGroup *axisGroup=new QActionGroup(this); QAction *a=new QAction("X", axisGroup); a->setCheckable(true); connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisX())); m_actAxisX=a; a=new QAction("Y", axisGroup); a->setCheckable(true); connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisY())); m_actAxisY=a; a=new QAction("Z", axisGroup); a->setCheckable(true); connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisZ())); m_actAxisZ=a; m_toolbar->addSeparator(); m_toolbar->addActions(axisGroup->actions()); m_actAxisY->setChecked(true); // Remaining verbosity setWindowTitle(BASE_WINDOW_TITLE); statusBar()->showMessage(tr("Ready")); // Load up some settings if (m_appSettings.value("saveUILayout", true).toBool()) { resize(m_appSettings.value("MainWindow/size", QSize(546, 427)).toSize()); move(m_appSettings.value("MainWindow/position", QPoint(200, 200)).toPoint()); setWindowState((Qt::WindowStates)m_appSettings.value("MainWindow/windowState", Qt::WindowActive).toInt()); restoreState(m_appSettings.value("MainWindow/widgetsState").toByteArray()); m_toolbar->setVisible(m_appSettings.value("toolbar/visibility", true).toBool()); m_paletteDocker->setVisible(m_appSettings.value("paletteWindow/visibility", true).toBool()); m_projectDocker->setVisible(m_appSettings.value("projectWindow/visibility", true).toBool()); //m_layersDocker->setVisible(m_appSettings.value("layersWindow/visibility", true).toBool()); } // Load the commandline supplied filename if (initialFilename != "") { openFile(initialFilename); } // Better way to keep the state in one place //std::cout << (m_toolbarActionGroup->checkedAction()->text() == "Splat") << std::endl; //std::cout << qPrintable(m_toolbarActionGroup->checkedAction()->text()) << std::endl; // Start things off focused on the GLWidget m_glModelWidget->setFocus(); }