Exemplo n.º 1
0
//Drawing function
void Interface::Draw()
{
    //if nothing changed, just return
    if(!changed)
        return;

    //If wrong destination surface or font not initialized, return
    if(!SDest || !font)
        return;

    //clear screen (black)
    Surface::DrawRect(SDest,0,0,1024,768,SDL_MapRGB(SDest->format, 0,0,0));

    //Set default color to yellow
    SetColor(255,255,0);

    //Write our ID
    Surface::DrawFont(SDest,10,10,font,"Vase ID: %s",gStore.GetName());

    //And draw stage-specific stuff
    switch(stage)
    {
    case STAGE_MENU: //For menu stage
        SetColor(0,0,0);
        Surface::DrawRect(SDest,60,80,100,25,SDL_MapRGB(SDest->format,255,255,255));
        Surface::DrawFont(SDest,63,83,font,"Nova hra");

        Surface::DrawRect(SDest,60,130,100,25,SDL_MapRGB(SDest->format,255,255,255));
        Surface::DrawFont(SDest,63,133,font,"Konec");
        break;
    case STAGE_CONNECTING: //For waiting stage (Waiting for oponnent...)
        SetColor(255,255,255);
        Surface::DrawFont(SDest,63,83,font,"Cekam na protihrace...");
        break;
    case STAGE_GAME: //For main game
        Surface::DrawFont(SDest,10,25,font,"ID protihrace: %s",gStore.GetOponnentName());
        //Draw first two lines for frame
        Surface::DrawRect(SDest,10,45,2+40*(2+15),2,SDL_MapRGB(SDest->format,255,255,255));
        Surface::DrawRect(SDest,10,45,2,2+40*(2+15),SDL_MapRGB(SDest->format,255,255,255));
        //And draw whole field
        for(int i = 0; i < 40; i++)
        {
            //Lines...
            Surface::DrawRect(SDest,10,45+2+15+i*(2+15),2+40*(2+15),2,SDL_MapRGB(SDest->format,255,255,255));
            Surface::DrawRect(SDest,10+2+15+i*(2+15),45,2,2+40*(2+15),SDL_MapRGB(SDest->format,255,255,255));
            //Draw field values (blank, cross or circle)
            for(int j = 0; j < 40; j++)
                DrawFieldElem(i,j,gStore.GetFieldValue(i,j));
        }

        //if someone won
        if(gStore.GetWinner())
        {
            thickLineColor(SDest, 10+9+gStore.GetWinCoords(0)*(2+15), 45+2+7+gStore.GetWinCoords(1)*(2+15), 10+9+gStore.GetWinCoords(2)*(2+15), 45+2+7+gStore.GetWinCoords(3)*(2+15), 4, 0x1010FFFF);
        }
        break;
    default:
        break;
    }

    //And after drawing, set changed to false, to avoid re-drawing the same
    changed = false;
}