Ejemplo n.º 1
0
	// рисует много линий
	void Form1::drawLines()
	{
		clearCanvas();

		auto c = canvas();

		int width = pictureBox1->Width;
		int height = pictureBox1->Height;

		int shiftX = width / 20;
		int shiftY = height / 20;
		int eps = 2;

		drawLine(shiftX, shiftY, width - shiftX, height - shiftY);
		c->DrawLine(circlePen, shiftX+eps, shiftY+eps, width - shiftX+eps, height - shiftY+eps);

		drawLine(width / 2, shiftY, width / 2, height - shiftY);
		c->DrawLine(circlePen, width / 2+eps, shiftY+eps, width / 2+eps, height - shiftY+eps);

		drawLine(shiftX, height / 2, width - shiftX, height / 2);
		c->DrawLine(circlePen, shiftX+eps, height / 2+eps, width - shiftX+eps, height / 2+eps);

		drawLine(shiftX, height - shiftY, width - shiftX, shiftY);
		c->DrawLine(circlePen, shiftX+eps, height - shiftY+eps, width - shiftX+eps, shiftY+eps);

	}
Ejemplo n.º 2
0
void ScheduleDialog::swapRows(int index1, int index2)
{
    Q_ASSERT(index1 != index2);
    Q_ASSERT(index1 >= 0);
    Q_ASSERT(index1 < (int)blocks_.size());
    Q_ASSERT(index2 >= 0);
    Q_ASSERT(index2 < (int)blocks_.size());
    Q_ASSERT((int)blocks_.size() == timingTable->numRows());

    BlockNode *node = blocks_[index1];
    blocks_[index1] = blocks_[index2];
    blocks_[index2] = node;

    timingTable->swapRows(index1, index2);
    timingTable->clearSelection();

    timingTable->updateContents();

    // set row selection
    // doesnt work with qt 3.0.6:
    //    timingTable->selectRow(index2);
    // workaround:
    QTableSelection selection;
    selection.init(index2, 0);
    selection.expandTo(index2, timingTable->numCols() -1);
    timingTable->addSelection(selection);


    // redraw canvas
    clearCanvas();
    initCanvas();
    // sync selection
    updateHighlighter(index2, 0);
}
Ejemplo n.º 3
0
void ScheduleDialog::autoSchedule()
{
    AutoSchedulingDialog *dialog = new AutoSchedulingDialog(graph_);

    int result = dialog->exec();
    delete dialog;
    if (result == QDialog::Accepted) {
    int count = timingTable->numRows();
    for (int i = 0; i < count; ++i) {
        static_cast<SpinBoxItem*>(timingTable->item(i, 3))->updateText();
    }
    clearCanvas();
    initCanvas();
    }
}
Ejemplo n.º 4
0
/// Dibuja el fondo.
void BndsModifier::show()
{
      PrintConsole con = g_video->consoleMain();
      consoleSelect( &con );

      clearCanvas();
      u16* buffer = (u16*) bgGetGfxPtr ( g_video->backgroundMain() );
  
      /// Barra lateral izquierda.
      drawRectangle8bpp ( 0, 0, 40, 191, 0, buffer );
      
      /// Barra inferior.
      drawRectangle8bpp ( 0, 171, 255, 192, 0, buffer );

      /// Boton cancelar.
      drawRectangle8bpp ( 0, 175, 70, 192, 2, buffer );
      iprintf("\x1b[23;0HCancelar");

      /// Boton aceptar.
      drawRectangle8bpp ( 180, 175, 255, 192, 2, buffer );
      iprintf("\x1b[23;24HAceptar");
      
}
Ejemplo n.º 5
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_scene(new QGraphicsScene),
    m_turtleGraphics(new TurtleCanvasGraphicsItem),
    m_cmds(m_turtleGraphics),
    m_prefsDialog(new PreferencesDialog(this)),
    m_aboutDialog(new AboutDialog(this)),
    m_canvasSaveOptionsDialog(new CanvasSaveOptionsDialog(this)),
    m_settings("settings.ini")
{
    ui->setupUi(this);

    m_scene->addItem(m_turtleGraphics);
    ui->graphicsView->setScene(m_scene);
    ui->graphicsView->centerOn(0.0, 0.0);

    // Add the graphics view actions
    QAction* centerAction = new QAction("&Center View", NULL);
    QAction* clearAction  = new QAction("C&lear Canvas", NULL);
    ui->graphicsView->addAction(centerAction);
    ui->graphicsView->addAction(clearAction);
    connect(centerAction, SIGNAL(triggered()), this, SLOT(centerGraphicsScene()));
    connect(clearAction,  SIGNAL(triggered()), this, SLOT(clearCanvas()));

    ui->graphicsView->setContextMenuPolicy(Qt::ActionsContextMenu);

    ui->errorMessagesTextEdit->setTextColor(Qt::red);

    // These buttons are only enabled while a script is running.
    ui->haltButton->setEnabled(false);
    ui->pauseButton->setEnabled(false);
    ui->resumeButton->setEnabled(false);

    // Messages dock is hidden by default.
    ui->messagesDockWidget->hide();

    connect(m_turtleGraphics, SIGNAL(canvasResized()), this, SLOT(resizeGraphicsScene()));

    connect(ui->runButton,    SIGNAL(clicked()), this, SLOT(runScript()));
    connect(ui->haltButton,   SIGNAL(clicked()), this, SLOT(haltScript()));
    connect(ui->pauseButton,  SIGNAL(clicked()), this, SLOT(pauseScript()));
    connect(ui->resumeButton, SIGNAL(clicked()), this, SLOT(resumeScript()));

    connect(ui->action_Open_Script, SIGNAL(triggered()), this, SLOT(loadScript()));
    connect(ui->action_Save_Script, SIGNAL(triggered()), this, SLOT(saveScript()));
    connect(ui->action_Save_Canvas, SIGNAL(triggered()), this, SLOT(saveCanvas()));
    connect(ui->action_Preferences, SIGNAL(triggered()), m_prefsDialog, SLOT(show()));
    connect(ui->action_About,       SIGNAL(triggered()), m_aboutDialog,  SLOT(show()));

    connect(ui->action_Errors, SIGNAL(triggered(bool)), this, SLOT(showErrors()));
    connect(ui->action_Script_Output, SIGNAL(triggered(bool)),
            this, SLOT(showScriptOutputs()));

    connect(m_prefsDialog, SIGNAL(rejected()), this, SLOT(loadPreferences()));
    connect(m_prefsDialog, SIGNAL(accepted()), this, SLOT(applyPreferences()));
    connect(m_prefsDialog, SIGNAL(accepted()), this, SLOT(savePreferences()));

    connect(&m_cmds, SIGNAL(scriptError(QString)),
            this,    SLOT(showScriptError(QString)),
            Qt::QueuedConnection);

    connect(&m_cmds, SIGNAL(scriptMessageReceived()),
            this,    SLOT(showScriptOutput()),
            Qt::QueuedConnection);

    loadPreferences();
    applyPreferences();

    m_cmds.start();

    m_cmds.setRequirePaths("");
    for (const QString& path : m_settings.requirePaths())
    {
        m_cmds.addRequirePath(path);
    }

    for (const QString& filename : m_settings.startupScripts())
    {
        m_cmds.runScriptFile(filename);
    }

    // Don't connect this until all the startup scripts have run
    // to prevent the error messages box from being cleared by successful scripts.
    connect(&m_cmds, SIGNAL(scriptFinished(bool)),
            this,    SLOT(scriptFinished(bool)),
            Qt::QueuedConnection);
}
Ejemplo n.º 6
0
void PaintWindow::createMenu() {
    // Adding the drop down menu to the menubar
    m_menu_app = menuBar()->addMenu(tr("&Application"));
    m_menu_tools = menuBar()->addMenu(tr("&Tools"));
    m_menu_colour = menuBar()->addMenu(tr("&Colour"));
    m_menu_help = menuBar()->addMenu(tr("&Help"));

    // Adding the menu items for each drop down menu
    QAction* quitAct = new QAction(tr("&Quit"), this);
    quitAct->setShortcuts(QKeySequence::Quit);
    quitAct->setStatusTip(tr("Exits the program"));
    connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
    m_menu_app->addAction(quitAct);
    
    QAction* clearAct = new QAction(tr("&Clear"), this);
    clearAct->setShortcut(QKeySequence(Qt::Key_C));
    connect(clearAct, SIGNAL(triggered()), m_canvas, SLOT(clearCanvas()));
    m_menu_app->addAction(clearAct);

    QAction* drawLineAct = new QAction(tr("&Line"), this);
    drawLineAct->setStatusTip(tr("Draws a line"));
    drawLineAct->setShortcut(QKeySequence(Qt::Key_L));
    drawLineAct->setCheckable(true);
    connect(drawLineAct, SIGNAL(triggered()), this, SLOT(set_line()));

    QAction* drawOvalAct = new QAction(tr("&Oval"), this);
    drawOvalAct->setStatusTip(tr("Draws an Oval"));
    drawOvalAct->setShortcut(QKeySequence(Qt::Key_O));
    drawOvalAct->setCheckable(true);
    connect(drawOvalAct, SIGNAL(triggered()), this, SLOT(set_oval()));

    QAction* drawRectangleAct = new QAction(tr("&Rectangle"), this);
    drawRectangleAct->setStatusTip(tr("Draws a rectangle"));
    drawRectangleAct->setShortcut(QKeySequence(Qt::Key_R));
    drawRectangleAct->setCheckable(true);
    connect(drawRectangleAct, SIGNAL(triggered()), this, SLOT(set_rect()));
    
	QActionGroup *toolsActionGroup = new QActionGroup(this);
	toolsActionGroup->addAction(drawLineAct);
	toolsActionGroup->addAction(drawOvalAct);
	toolsActionGroup->addAction(drawRectangleAct);
	toolsActionGroup->setExclusive(true);
	drawLineAct->setChecked(true);
	
    m_menu_tools->addAction(drawLineAct);
    m_menu_tools->addAction(drawOvalAct);
    m_menu_tools->addAction(drawRectangleAct);

    QAction* setColourBlackAct = new QAction(tr("&Black"), this);
    connect(setColourBlackAct, SIGNAL(triggered()), this, SLOT(setColourBlack()));
    
    QAction* setColourRedAct = new QAction(tr("&Red"), this);
    connect(setColourRedAct, SIGNAL(triggered()), this, SLOT(setColourRed()));
    
    QAction* setColourGreenAct = new QAction(tr("&Green"), this);
    connect(setColourGreenAct, SIGNAL(triggered()), this, SLOT(setColourGreen()));
    
    QAction* setColourBlueAct = new QAction(tr("&Blue"), this);
    connect(setColourBlueAct, SIGNAL(triggered()), this, SLOT(setColourBlue()));
    
    m_menu_colour->addAction(setColourBlackAct);
    m_menu_colour->addAction(setColourRedAct);
    m_menu_colour->addAction(setColourGreenAct);
    m_menu_colour->addAction(setColourBlueAct);

    QAction* helpLineAct = new QAction(tr("&Line Help"), this);
    helpLineAct->setStatusTip(tr("Help Instructions"));
    connect(helpLineAct, SIGNAL(triggered()), this, SLOT(help_line()));
    m_menu_help->addAction(helpLineAct);
    
    QAction* helpRectangleAct = new QAction(tr("&Rectangle Help"), this);
    helpRectangleAct->setStatusTip(tr("Help Instructions for rectangles"));
    connect(helpRectangleAct, SIGNAL(triggered()), this, SLOT(help_rectangle()));
    m_menu_help->addAction(helpRectangleAct);

    QAction* helpOvalAct = new QAction(tr("&Oval Help"), this);
    helpOvalAct->setStatusTip(tr("Help Instructions for ovals"));
    connect(helpOvalAct, SIGNAL(triggered()), this, SLOT(help_oval()));
    m_menu_help->addAction(helpOvalAct);
}
Ejemplo n.º 7
0
int BndsModifier::exec()
{
	/// Inicializa las 2 pantallas a negro.
	g_video->resetAllMain();
	g_video->resetAllSub();
	
	show();

	touchPosition touch;
	int pulsado;
	int pulsadoClick;
	int grosorX = 1;
	int grosorY = 2;
	bool tactil = false;
	int origenX = 0;
	int origenY = 0;
	
	/// Limites donde dibujar.
	int limXmin = 40 + 2;
	int limXmax = 256;
	int limYmin = 0;
	int limYmax = 171 - 2;
	
	u16* buffer = (u16*) bgGetGfxPtr ( g_video->backgroundMain() );
	
	/// Espera hasta que no se este pulsando en la pantalla. Nos aseguramos de
	/// no estar pintando antes de tiempo.
	while (1) {
	    scanKeys();
	    touchRead(&touch);
	    pulsado = keysHeld();
	    if (pulsado & KEY_TOUCH) {
	    } else {
		break;
	    } // end if
	} // end while


	while (1) {
	    scanKeys();
	    touchRead(&touch);
	    pulsado = keysHeld();
	    pulsadoClick = keysDown();
	    
	
	    if ((pulsado & KEY_TOUCH) && ((touch.px >= limXmin) && (touch.px <= limXmax) && (touch.py >= limYmin) && (touch.py <= limYmax)) ) {
		/// Se esta pulsando en la pantalla tactil.
		if (tactil == false) {
		    /// Se acaba de pulsar en la pantalla tactil. Se registra la posicion inicial.
		    origenX = touch.px;
		    origenY = touch.py;
		    tactil = true;
		} // end if
		
		//drawRectangle8bpp ( touch.px - (grosorX / 2), touch.py - (grosorY / 2), touch.px + (grosorX / 2), touch.py + (grosorY / 2), 1, buffer);
		drawLine(origenX, origenY, touch.px, touch.py, grosorX, grosorY, 0, buffer);
		
		/// Registra para el proximo dibujado.
		origenX = touch.px;
		origenY = touch.py;
		
	    } else {
		/// No se esta pulsando la pantalla tactil.
		tactil = false;
	    } // end if


	    if ( (pulsado & KEY_L) && (pulsado & KEY_R)) {
		/// Resetea la pantalla
		clearCanvas();
	    } // end if

	    if (pulsado & KEY_A) {
		/// Se pulsa la tecla A (aceptar).
		return 1;
	    } // end if

	    /// Si se pulsa en el boton 'aceptar'.
	    if ( (pulsadoClick & KEY_TOUCH) &&
		  (touch.px >= 180) && (touch.px <= 255 ) &&
		  (touch.py >= 175) && (touch.py <= 192 ) ) {

		  /// Se guarda la imagen en disco
		  time_t seconds;
		  seconds = time (NULL);
	    
		  string sec;
		  stringstream out;
		  out << seconds;
		  sec = out.str();
	    
		  string nombreArchivo = "tmp_ndsbulmatpv_" + sec + ".bmp.base64";
		  screenshotToBmp1BitBase64(nombreArchivo.c_str());
		  m_nombreArchivo = nombreArchivo;
	      
		  return 1;
	    } // end if

	    /// Si se pulsa en el boton 'cancelar'.
	    if ( (pulsadoClick & KEY_TOUCH) &&
		  (touch.px >= 0) && (touch.px <= 70 ) &&
		  (touch.py >= 175) && (touch.py <= 192 ) ) {
		    return -1;
	    } // end if

	    swiWaitForVBlank();
	
	} // end while

	return 0;
}
Ejemplo n.º 8
0
void ScheduleDialog::modelChanged(int, int)
{
    modified_ = true;
    clearCanvas();
    initCanvas();
}
Ejemplo n.º 9
0
void ScheduleDialog::zoomChanged(int zoom)
{
    zoom_ = 1.0 + (zoom/5);
    clearCanvas();
    initCanvas();
}
Ejemplo n.º 10
0
/**
 * This is the main loop for the program.  It is given a reference image and
 * the size, as well as various parameters used to define polygon type,
 * how many to use, and the target difference percentage.
 */
static void main_loop(Color_t *original, int width, int height,
        int n_points, int n_polygons, double target_percentage)
{
    int old_diff = -1;
    unsigned int new_diff;
    unsigned int n_used, n_tried;
    unsigned int max_diff;
    double current_percent = 0.0f;
    char output[64];
    Color_t *temporary;
    Color_t *canvas;

    n_used = n_tried = 0;

    /* The most different a test image can be. */
    max_diff = MAX_COLOR_VALUE * (unsigned int)width * (unsigned int)height * 3;

    /* Allocate the buffers used--one for a temporary buffer, and one for
     * holding our work-in-progress. */
    temporary = malloc(width * height * sizeof(Color_t));
    if (!temporary)
        abort_("Unable to allocate temporary buffer.\n");

    canvas = malloc(width * height * sizeof(Color_t));
    if (!canvas)
        abort_("Unable to allocate canvas buffer.\n");

    /* Start with a blank canvas. */
    clearCanvas(canvas, width, height);

    do {
        n_tried++;

        /* Generate a randomly-colored polygon. */
        Color_t color = getRandomColor();
        Polygon_t polygon = getRandomPolygon(width, height, n_points);

        /* Create the temporary canvas by starting with the current work in
         * progress. */
        memcpy(temporary, canvas, width*height*sizeof(Color_t));

        /* Generate a random weighting to use for merging in the new polygon. */
        double weight = drandrange(0.25, 0.75);

        /* Add a polygon. */
        drawPolygon(temporary, width, height, polygon, n_points, color, weight);

        /* Compare to the original. */
        new_diff = isSecondOneBetter(original, temporary, width, height, old_diff);
        if (new_diff < 0)
            continue;

        /* If we've improved, keep the new version */
        if (old_diff < 0 || new_diff < old_diff) {
            n_used++;
            current_percent =
                100.0f - ((100.0f * (double)new_diff) / (double)max_diff);

            printf("%d / %d (tested %d) -- %.02f%% (Weight %2.2f)\n",
                    n_used, n_polygons, n_tried, current_percent, weight);

            memcpy(canvas, temporary, width*height*sizeof(Color_t));
            old_diff = new_diff;
            sprintf(output, "./out/img_%d.png", n_used);
            writePNG(output, canvas, width, height);

            if (current_percent > target_percentage && target_percentage > 0.0f)
                break;
        }
    } while (n_used < n_polygons);

    free(temporary);
    free(canvas);
}
Ejemplo n.º 11
0
QMenuBar* MainWindow::createMenuBar()
{
   QMenuBar* bar = new QMenuBar(this);

   QMenu* sessionMenu = bar->addMenu(tr("&File"));
   sessionMenu->addAction(QIcon(":/icons/16x16/canvas-add.png"), tr("&Create"), this, SLOT(createCanvas()));
   sessionMenu->addAction(QIcon(":/icons/16x16/canvas-add.png"), tr("N&etwork"), d->netWin, SLOT(show()));
   sessionMenu->addAction(QIcon(":/icons/16x16/save-as.png"), tr("&Save Image"), this, SLOT(renderCanvas()), tr("Ctrl+S"));
   sessionMenu->addSeparator();
   sessionMenu->addAction(QIcon(":/icons/16x16/exit.png"), tr("&Quit"), this, SLOT(close()), tr("Ctrl+Q"));

   QMenu* editMenu = bar->addMenu(tr("&Edit"));
   editMenu->addAction(QIcon(":/icons/16x16/canvas-clear.png"), tr("&Clear"), d->containment, SLOT(clearCanvas()));
   editMenu->addSeparator();
   editMenu->addAction(QIcon(":/icons/16x16/configure.png"), tr("&Gestures"),d->ge, SLOT(show()));
   editMenu->addAction(QIcon(":/icons/16x16/configure.png"), tr("&Options"))->setEnabled(false);

   QMenu* helpMenu = bar->addMenu(tr("&Help"));
   helpMenu->addAction(QIcon(":/icons/16x16/help-contents.png"), tr("&Help"))->setEnabled(false);
   helpMenu->addSeparator();
   helpMenu->addAction(QIcon(":/icons/16x16/application.png"), tr("&About"), this, SLOT(about()));
   helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));

   return bar;
}