예제 #1
0
/////////////////////////////////////////////////////////////////////////////////////////////////
// Method name	: LoadImage
// Arguments	: 
//	1) HDC hDC -- Screen Device context 
//	2) unsigned short *pszImageName -- File name (GDI+ support BMP, Graphics Interchange Format (GIF), JPEG, PNG, TIFF, and EMF)
//	3) RECT &r -- Rectangle size
// Return type	: HDC -- Load image into memory. Return memory device context.
// Description	: Loads an image into memory. That image file should be the following format.
//				  BMP, Graphics Interchange Format (GIF), JPEG, PNG, TIFF, and EMF
// Precondition	: gdiplus should be intialize
// Postcondition: It's return memory DC(Device Context). Call DeleteDC when you finish.
/////////////////////////////////////////////////////////////////////////////////////////////////
HDC CImageProcess::LoadImage(HDC hDC, unsigned short *pszImageName, RECT &r)
{
	if (m_hBitmap)
	{
		DeleteObject(m_hBitmap);
		m_hBitmap = NULL;
	}
	
	HDC hMemDC = CreateCompatibleDC(hDC);	
	//Image image(pszImageName);
	Bitmap image(pszImageName);

	m_nWidth  = image.GetWidth();
	m_nHeight = image.GetHeight();

	m_hBitmap = CreateCompatibleBitmap(hDC, m_nWidth, m_nHeight);
	SelectObject(hMemDC, m_hBitmap);

	Graphics g(hMemDC);
	CachedBitmap cachedBitmap(&image, &g);
	
	Rect rect(0, 0, m_nWidth, m_nHeight);
	
	//temporary solution to erase the background
	Region Rgn;
	g.GetClip(&Rgn);
	SolidBrush grayBrush(Color::White);
	g.FillRegion(&grayBrush, &Rgn);
	g.DrawCachedBitmap(&cachedBitmap, 0, 0);
	//g.DrawImage(&image, rect);
	g.Flush(FlushIntentionFlush) ;		

	
	RECT tmpRect = r;
	tmpRect.right += 0;
	tmpRect.bottom += 0;
	
	InvalidateRect(GetActiveWindow(), &tmpRect, FALSE);

	return hMemDC;
}
예제 #2
0
void wxNewBitmapButton::RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp,
                                          bool isEnabled, bool isPressed )
{
    if ( destBmp != 0 ) return;

    // render labels on-demand

    wxMemoryDC srcDc;
    srcDc.SelectObject( *srcBmp );

    bool hasText = ( mTextAlignment != NB_NO_TEXT ) &&
                   ( mLabelText.length() != 0 );

    bool hasImage = (mTextAlignment != NB_NO_IMAGE);

    wxSize destDim;
    wxPoint txtPos;
    wxPoint imgPos;

    if ( hasText )
    {
        long txtWidth, txtHeight;

        srcDc.SetFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) );
        srcDc.GetTextExtent( mLabelText, &txtWidth, &txtHeight );

        if ( mTextAlignment == NB_ALIGN_TEXT_RIGHT )
        {
            destDim.x = srcBmp->GetWidth() + 2*mTextToLabelGap + txtWidth;

            destDim.y =
                wxMax( srcBmp->GetHeight(), txtHeight );

            txtPos.x = srcBmp->GetWidth() + mTextToLabelGap;
            txtPos.y = (destDim.y - txtHeight)/2;
            imgPos.x = 0;
            imgPos.y = (destDim.y - srcBmp->GetHeight())/2;
        }
        else
        if ( mTextAlignment == NB_ALIGN_TEXT_BOTTOM )
        {
            destDim.x =
                wxMax( srcBmp->GetWidth(), txtWidth );

            destDim.y = srcBmp->GetHeight() + mTextToLabelGap + txtHeight;

            txtPos.x = (destDim.x - txtWidth)/2;
            txtPos.y = srcBmp->GetHeight() + mTextToLabelGap;
            imgPos.x = (destDim.x - srcBmp->GetWidth())/2;
            imgPos.y = 0;
        }
        else
        {
            wxFAIL_MSG(wxT("Unsupported FL alignment type detected in wxNewBitmapButton::RenderLabelImage()"));
        }
    }
    else
    {
        imgPos.x = 0;
        imgPos.y = 0;
        destDim.x = srcBmp->GetWidth();
        destDim.y = srcBmp->GetHeight();
    }

    destBmp = new wxBitmap( int(destDim.x), int(destDim.y) );

    wxMemoryDC destDc;
    destDc.SelectObject( *destBmp );

    wxBrush grayBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE), wxSOLID );

    destDc.SetBrush( grayBrush );
    destDc.SetPen( *wxTRANSPARENT_PEN );
    destDc.DrawRectangle( 0,0, destDim.x+1, destDim.y+1 );

    if ( isPressed )
    {
        ++imgPos.x; ++imgPos.y;
        ++txtPos.x; ++txtPos.y;
    }

    if ( hasImage )
    {

        destDc.Blit( imgPos.x, imgPos.y,
                 srcBmp->GetWidth(),
                 srcBmp->GetHeight(),
                 &srcDc, 0,0, wxCOPY,true );
    }

    if ( hasText )
    {
        wxWindow* pTopWnd = this;

        do
        {
            wxWindow* pParent = pTopWnd->GetParent();

            if ( pParent == 0 )
                break;

            pTopWnd = pParent;
        } while (1);

        destDc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT) );

        if ( isEnabled )
        {
            destDc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
        }
        else
        {
            destDc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) );
        }
        destDc.SetTextBackground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) );

        destDc.DrawText( mLabelText, txtPos.x, txtPos.y );
    }

    if ( !isEnabled ){

#ifdef __WXMSW__ // This is currently MSW specific
        gray_out_image_on_dc( destDc, destDim.x, destDim.y );
#else
        wxBitmap bmp( (const char*)_gDisableImage,8,8);
        wxBrush checkerBrush(bmp);
        checkerBrush.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
        destDc.SetBrush( checkerBrush );
        destDc.DrawRectangle( imgPos.x, imgPos.y, srcBmp->GetWidth()+1, srcBmp->GetHeight()+1);
#endif
    }
    // adjust button size to fit the new dimensions of the label
    if ( !mSizeIsSet && 0 )
    {
        mSizeIsSet = true;
        SetSize( wxDefaultCoord, wxDefaultCoord,
                 destBmp->GetWidth()  + mMarginX*2,
                 destBmp->GetHeight() + mMarginY*2, 0
            );
    }
    destDc.SelectObject( wxNullBitmap );

#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
    // Map to system colours
    (void) wxToolBar::MapBitmap(destBmp->GetHBITMAP(), destBmp->GetWidth(), destBmp->GetHeight());
#endif
}
twoChessBoard::twoChessBoard(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::twoChessBoard)
{

	// There are issues with this right now. Hardcoded integers are only used for testing on simulator, not actual phone.
    this->parent = parent;
    ui->setupUi(this);
    ui->widget->setGeometry(QRect(10,130,480,480));
    graphicsView = new QGraphicsView(ui->widget);
    scene = new QGraphicsScene(QRect(-240,-180,480,480));
    graphicsView->setGeometry(QRect(0,0,490,490));
    graphicsView->setScene(scene);
    select = 0;//used to check whether a piece is selected or not
    turn = 1;//used to check which players turn it is
    //the following are to check how many different kind of pieces are left in the board
    blackPawnsLeft = 8;
    whitePawnsLeft = 8;
    blackRooksLeft = 2;
    whiteRooksLeft = 2;
    blackKnightsLeft = 2;
    whiteKnightsLeft = 2;
    blackBishopsLeft = 2;
    whiteBishopsLeft = 2;
    blackQueenLeft = 1;
    whiteQueenLeft = 1;
    blackKingLeft = 1;
    whiteKingLeft = 1;

    // colors for pieces
    QBrush blackBrush(Qt::black);
    QBrush whiteBrush(Qt::white);
    QBrush greenBrush(Qt::green);
    QBrush redBrush(Qt::red);
    QBrush yellowBrush(Qt::yellow);
    QBrush blueBrush(Qt::blue);
    QBrush magentaBrush(Qt::magenta);
    QBrush grayBrush(Qt::gray);

    QBrush darkGreenBrush(Qt::darkGreen);
    QBrush darkRedBrush(Qt::darkRed);
    QBrush darkYellowBrush(Qt::darkYellow);
    QBrush darkBlueBrush(Qt::darkBlue);
    QBrush darkMagentaBrush(Qt::darkMagenta);
    QBrush darkGrayBrush(Qt::darkGray);

    QPen pen(Qt::transparent);
    pen.setWidth(0);


    // This loop generates the chessboard. Code was written by TA.
    for(int i=0;i<CHESSBOARD_SIZE;i++){

        chessboard[i].resize(CHESSBOARD_SIZE);
        for(int j = 0 ; j<CHESSBOARD_SIZE;j++){
            chessboard[i][j] = new QGraphicsRectItem(CHESSBOARD_GRID_SIZE*(j-CHESSBOARD_SIZE/2) , CHESSBOARD_GRID_SIZE*( -i+CHESSBOARD_SIZE/2) ,
                            CHESSBOARD_GRID_SIZE ,CHESSBOARD_GRID_SIZE);
            scene->addItem(chessboard[i][j]);
            chessboard[i][j]->setPen(pen);

            chessboard[i][j]->setBrush(((i+j)%2==0)?blackBrush:whiteBrush);

        }
    }

    graphicsView->show();
    qDebug("Initialized chessboard...");


    for(int i =0; i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            boardvalues[i][j] = 0;
        }
    }


    //initialising the board values
    for(int i = 0;i<8;i++)
    {
        //pawns
        boardvalues[1][i] = 1;
        boardvalues[6][i] = 7;
    }

    //rooks
    boardvalues[0][0] = 2;
    boardvalues[0][7] = 2;
    boardvalues[7][0] = 8;
    boardvalues[7][7] = 8;

    //knights
    boardvalues[0][1] = 3;
    boardvalues[0][6] = 3;
    boardvalues[7][1] =9;
    boardvalues[7][6] =9;

    //bishops
    boardvalues[0][2] = 4;
    boardvalues[0][5] = 4;
    boardvalues[7][2] =10;
    boardvalues[7][5] =10;

    //queen
    boardvalues[0][3] = 6;
    boardvalues[7][3] =12;

    //king
    boardvalues[0][4] = 5;
    boardvalues[7][4] =11;

    // white pawns
    for (int i = 0; i < 8; i++)
    {
        whitePawns.resize(8);
        whitePawns[i] = new QGraphicsRectItem(-225+60*i, -105, 30, 30 );
        whitePawns[i]->setBrush(greenBrush);
        scene->addItem(whitePawns[i]);
    }
    //black pawns
    for (int i = 0; i < 8; i++)
    {
        blackPawns.resize(8);
        blackPawns[i] = new QGraphicsRectItem(-225+60*i, 195, 30, 30 );
        blackPawns[i]->setBrush(darkGreenBrush);
        scene->addItem(blackPawns[i]);
    }

    // white and black pieces
    for (int i = 0; i < 2; i++)
    {
        whiteRooks.resize(2);
        whiteRooks[i] = new QGraphicsRectItem(-225+420*i,-165,30,30);
        whiteRooks[i]->setBrush(redBrush);
        scene->addItem(whiteRooks[i]);

        blackRooks.resize(2);
        blackRooks[i] = new QGraphicsRectItem(-225+420*i,255,30,30);
        blackRooks[i]->setBrush(darkRedBrush);
        scene->addItem(blackRooks[i]);

        whiteKnights.resize(2);
        whiteKnights[i] = new QGraphicsRectItem(-165+300*i,-165,30,30);
        whiteKnights[i]->setBrush(yellowBrush);
        scene->addItem(whiteKnights[i]);

        blackKnights.resize(2);
        blackKnights[i] = new QGraphicsRectItem(-165+300*i,255,30,30);
        blackKnights[i]->setBrush(darkYellowBrush);
        scene->addItem(blackKnights[i]);

        whiteBishops.resize(2);
        whiteBishops[i] = new QGraphicsRectItem(-105+180*i,-165,30,30);
        whiteBishops[i]->setBrush(blueBrush);
        scene->addItem(whiteBishops[i]);

        blackBishops.resize(2);
        blackBishops[i] = new QGraphicsRectItem(-105+180*i,255,30,30);
        blackBishops[i]->setBrush(darkBlueBrush);
        scene->addItem(blackBishops[i]);
    }


    whiteQueen = new QGraphicsRectItem(-45,-165,30,30);
    whiteQueen->setBrush(magentaBrush);
    scene->addItem(whiteQueen);

    blackQueen = new QGraphicsRectItem(-45,255,30,30);
    blackQueen->setBrush(darkMagentaBrush);
    scene->addItem(blackQueen);

    whiteKing = new QGraphicsRectItem(15,-165,30,30);
    whiteKing->setBrush(grayBrush);
    scene->addItem(whiteKing);

    blackKing = new QGraphicsRectItem(15,255,30,30);
    blackKing->setBrush(darkGrayBrush);
    scene->addItem(blackKing);

}