コード例 #1
0
ファイル: simulator.cpp プロジェクト: megaknoc/mini_hexagon
void Simulator::updateColors(void)
{
    bright  = colorschemes.at(2*colorscheme  );
    dark    = colorschemes.at(2*colorscheme+1);

    if (colors_inverted) {
        swapColors();
    }

    calculateFramebuffer(true);
}
コード例 #2
0
void DualColorButton::mouseReleaseEvent(QMouseEvent *event)
{
	if(event->button() != Qt::LeftButton)
		return;
	QRectF fgr = foregroundRect();
	QRectF bgr = backgroundRect();
	if(fgr.contains(event->pos()))
		emit foregroundClicked(foreground_);
	else if(bgr.contains(event->pos()))
		emit backgroundClicked(background_);
	else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top())
		swapColors();
	else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom()) {
		foreground_ = Qt::black;
		background_ = Qt::white;
		emit foregroundChanged(foreground_);
		emit backgroundChanged(background_);
		update();
	}
}
コード例 #3
0
void ac::MedianBlendSoft(cv::Mat &frame) {
    static MatrixCollection<8> collection;
    MedianBlur(frame);
    collection.shiftFrames(frame);
    for(int z = 0; z < frame.rows; ++z) {
        for(int i = 0; i < frame.cols; ++i) {
            cv::Scalar value;
            for(int j = 0; j < collection.size(); ++j) {
                cv::Vec3b pixel = collection.frames[j].at<cv::Vec3b>(z, i);
                for(int q = 0; q < 3; ++q) {
                    value[q] += pixel[q];
                }
            }
            cv::Vec3b &pixel = frame.at<cv::Vec3b>(z, i);
            for(int j = 0; j < 3; ++j) {
                int val = 1+static_cast<int>(value[j]);
                pixel[j] = static_cast<unsigned char>(pixel[j] ^ val);
            }
            swapColors(frame, z, i);// swap colors
            if(isNegative) invert(frame, z, i);// if isNegative invert pixel */
        }
    }
}
コード例 #4
0
void rbSolveUnbalancedTree(RBTree tree, Node replace, Node replacefather) {
	/* Soient :
	 * y : replace, le noeud remplacé 
	 * p : replacefather, le pere du noeud remplacé 
	 * f : frere de y 
	 * g : fils gauche de f
	 * d : fils droit de f
	 * */
	int isdoubleblack = 1; /* etat de replace */
	while(replace != rbfirst(tree) && isdoubleblack) { /* on s'arretera à la racine */

		if(replace == replacefather->left) { /* CAS GAUCHE */
			if(replacefather->right->color == black) { /* f est noir */
				if(replacefather->right->right->color == black && replacefather->right->left->color == black) {/* CAS 1.A */ /*(g et d sont noirs)*/
					//printf("Cas 1.A gauche\n");
					replace->color = black; /* y devient simple noir */
					replacefather->right->color = red; /* f devient rouge */
					addBlack(replacefather,&isdoubleblack); /* p devient double noir */					
					
					replace = replacefather; /* y devient p */
					replacefather = replace->father;
				}
				else if(replacefather->right->right->color == red) { /* CAS 1.B */
					//printf("Cas 1.B gauche\n");
					swapColors(replacefather,replacefather->right); /* f prend la couleur de p */
					replacefather->right->right->color = black; /* d devient noir */
					replacefather->color = black; /* p devient noir */
					rbtreeRotateLeft(tree,replacefather); /* rotation gauche en p */
					isdoubleblack = 0; /* y devient noir */
					mendSentinels(tree);
					return;
				}
				else if(replacefather->right->left->color == red && replacefather->right->right->color == black) { /* CAS 1.C */
					//printf("Cas 1.C gauche\n"); /* f est noir, g est rouge, d est noir */
					swapColors(replacefather->right->left,replacefather->right);/* g devient noir, f rouge */
					rbtreeRotateRight(tree,replacefather->right); /* rotation droite en f */
					/* la prochaine boucle retournera sur 1.B */
				}
			}
			else { /* f est rouge */
				//printf("Cas 2 gauche\n");
				swapColors(replacefather,replacefather->right); /* on echange les couleurs de p et f */
				rbtreeRotateLeft(tree,replacefather); /* rotation gauche en p */
				/* on revient au cas 1 */
			}
		} 

		else { /* CAS DROIT */
			if(replacefather->left->color == black) { /* f est noir */
				if(replacefather->left->left->color == black && replacefather->left->right->color == black) {/* CAS 1.A */ /*(g et d sont noirs)*/
					//printf("Cas 1.A droit\n");
					replace->color = black; /* y devient simple noir */
					replacefather->left->color = red; /* f devient rouge */
					addBlack(replacefather,&isdoubleblack); /* p devient double noir */					
					
					replace = replacefather; /* y devient p */
					replacefather = replace->father;
				}
				else if(replacefather->left->left->color == red) { /* CAS 1.B */
					//printf("Cas 1.B droit\n");
					swapColors(replacefather,replacefather->left); /* f prend la couleur de p */
					replacefather->left->left->color = black; /* d devient noir */
					replacefather->color = black; /* p devient noir */
					rbtreeRotateRight(tree,replacefather); /* rotation gauche en p */
					isdoubleblack = 0; /* y devient noir */
					mendSentinels(tree);
					return;
				}
				else if(replacefather->left->right->color == red && replacefather->left->left->color == black) { /* CAS 1.C */
					//printf("Cas 1.C droit\n"); /* f est noir, g est rouge, d est noir */
					swapColors(replacefather->left->right,replacefather->left);/* g devient noir, f rouge */
					rbtreeRotateLeft(tree,replacefather->left); /* rotation droite en f */

					/* la prochaine boucle retournera sur 1.B */
				}
			}
			else { /* f est rouge */
				//printf("Cas 2 droit\n");
				swapColors(replacefather,replacefather->left); /* on echange les couleurs de p et f */
				rbtreeRotateRight(tree,replacefather); /* rotation gauche en p */
				/* on revient au cas 1 en ne changeant rien */
			}
		} 
	}
	mendSentinels(tree);
}
コード例 #5
0
ファイル: boardsetup.cpp プロジェクト: Wushaowei001/chessx
BoardSetupDialog::BoardSetupDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f),
    m_wheelCurrentDelta(0), m_selectedPiece(Empty), inDrag(false)
{
    setObjectName("BoardSetupDialog");
    ui.setupUi(this);

    QPushButton *pasteButton = ui.buttonBox->addButton(tr("Paste FEN"), QDialogButtonBox::ActionRole);
    copyButton = ui.buttonBox->addButton(tr("Copy FEN"), QDialogButtonBox::ApplyRole);
    btCopyText = ui.buttonBox->addButton(tr("Copy Text"), QDialogButtonBox::ApplyRole);

    restoreLayout();

    ui.boardView->configure();
    ui.boardView->setFlags(BoardView::IgnoreSideToMove | BoardView::SuppressGuessMove | BoardView::AllowCopyPiece);
    ui.boardView->showMoveIndicator(false);
    ui.boardView->showCoordinates(true);

    m_minDeltaWheel = AppSettings->getValue("/Board/minWheelCount").toInt();

    for(int piece = Empty; piece <= BlackPawn; piece++)
    {
        BoardSetupToolButton* button = new BoardSetupToolButton(this);
        button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
        button->setMinimumSize(QSize(10, 10));
        button->m_piece = (Piece)piece;
        if(piece == Empty)
        {
            button->m_pixmap = QPixmap(0, 0);
            ui.buttonLayout->addWidget(button, 6, 0);
        }
        else
        {
            button->m_pixmap = ui.boardView->theme().piece(Piece(piece));
            ui.buttonLayout->addWidget(button, (piece - 1) % 6, piece >= BlackKing);
        }
        connect(button, SIGNAL(signalDragStarted(QWidget*, QMouseEvent*)), this, SLOT(startDrag(QWidget*, QMouseEvent*)));
        connect(button, SIGNAL(signalClicked(Piece)), this, SLOT(labelClicked(Piece)));
        connect(this, SIGNAL(signalClearBackground(Piece)), button, SLOT(slotClearBackground(Piece)));
    }

    emit signalClearBackground(Empty);

    ui.buttonBoxTools->button(QDialogButtonBox::RestoreDefaults)->setText(tr("Clear"));
    connect(ui.buttonBoxTools->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(slotClear()));
    connect(ui.buttonBoxTools->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(slotReset()));

    connect(ui.boardView, SIGNAL(clicked(Square, int, QPoint, Square)), SLOT(slotSelected(Square, int)));
    connect(ui.boardView, SIGNAL(moveMade(Square, Square, int)), SLOT(slotMovePiece(Square, Square)));
    connect(ui.boardView, SIGNAL(copyPiece(Square, Square)), SLOT(slotCopyPiece(Square, Square)));
    connect(ui.boardView, SIGNAL(invalidMove(Square)), SLOT(slotInvalidMove(Square)));
    connect(ui.boardView, SIGNAL(wheelScrolled(int)), SLOT(slotChangePiece(int)));
    connect(ui.boardView, SIGNAL(pieceDropped(Square, Piece)), SLOT(slotDroppedPiece(Square, Piece)));
    connect(ui.toMoveButton, SIGNAL(clicked()), SLOT(slotToggleSide()));
    connect(ui.wkCastleCheck, SIGNAL(stateChanged(int)), SLOT(slotCastlingRights()));
    connect(ui.wqCastleCheck, SIGNAL(stateChanged(int)), SLOT(slotCastlingRights()));
    connect(ui.bkCastleCheck, SIGNAL(stateChanged(int)), SLOT(slotCastlingRights()));
    connect(ui.bqCastleCheck, SIGNAL(stateChanged(int)), SLOT(slotCastlingRights()));
    connect(ui.epCombo, SIGNAL(currentIndexChanged(int)), SLOT(slotEnPassantSquare()));
    connect(ui.halfmoveSpin, SIGNAL(valueChanged(int)), SLOT(slotHalfmoveClock()));
    connect(ui.moveSpin, SIGNAL(valueChanged(int)), SLOT(slotMoveNumber()));
    connect(ui.btFlipBoard, SIGNAL(clicked()), ui.boardView, SLOT(flip()));
    ui.btFlipBoard->setCheckable(true);

    connect(copyButton, SIGNAL(clicked()), SLOT(slotCopyFen()));
    connect(pasteButton, SIGNAL(clicked()), SLOT(slotPasteFen()));
    connect(btCopyText, SIGNAL(clicked()), SLOT(slotCopyText()));

    connect(ui.btFlipVertical, SIGNAL(clicked()), SLOT(mirrorVertical()));
    connect(ui.btFlipHorizontal, SIGNAL(clicked()), SLOT(mirrorHorizontal()));
    connect(ui.btSwapColor, SIGNAL(clicked()), SLOT(swapColors()));

    ui.tabWidget->setCurrentIndex(0);
}
コード例 #6
0
		LCDCommand(PASET);  // page start/end ram
		LCDData(x);
		LCDData(ENDPAGE);

		LCDCommand(CASET);  // column start/end ram
		LCDData(y);
		LCDData(ENDCOL);

		LCDCommand(RAMWR);  // write
		LCDData((color>>4)&0x00FF);
		LCDData(((color&0x0F)<<4)|(color>>8));
		LCDData(color&0x0FF);
	}
	else  // otherwise it's a phillips
	{
        color = swapColors(color);
		LCDCommand(PASETP); // page start/end ram
		LCDData(x);
		LCDData(x);

		LCDCommand(CASETP); // column start/end ram
		LCDData(y);
		LCDData(y);

		LCDCommand(RAMWRP); // write

		LCDData((unsigned char)((color>>4)&0x00FF));
		LCDData((unsigned char)(((color&0x0F)<<4)|0x00));
	}
}