Exemplo n.º 1
0
/* draw the menuitem button or bool
 * menuitem->pos.[x|y|w] - Position and X-Size inside the menu
 *           label       - Text of the Button/Bool
 */
void menu_draw_button (_menuitem *mi)
{
    int px, py, i;
    SDL_Rect dest;

    if (mi->type != MENU_button && mi->type != MENU_bool)
        return;

    dest.x = mi->pos.x;
    dest.y = mi->pos.y;
    dest.w = mi->pos.w;
    dest.h = menubuttonimages[0][0]->h;
    menu_draw_background ((_menu *)mi->menu, &dest);

    /* check the focus of the button */
    if (((_menu *)mi->menu)->focusvis && mi == ((_menu *)mi->menu)->focus)
        mi->state = 1;
    else if (mi->type == MENU_bool && (*((int*) mi->ptrdata)) > 0)
        mi->state = 2; // bool
    else
        mi->state = 0; // button or bool == FALSE

    // draw the left side of the button
    dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x;
    dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
    dest.w = menubuttonimages[mi->state][0]->w;
    dest.h = menubuttonimages[mi->state][0]->h;
    gfx_blit (menubuttonimages[mi->state][0], NULL, gfx.screen, &dest, 10000);
    // draw the center of the button
    for (i = 0; i < ((mi->pos.w - (menubuttonimages[mi->state][0]->w + menubuttonimages[mi->state][2]->w)) / menubuttonimages[mi->state][1]->w); i++) {
        dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + menubuttonimages[mi->state][0]->w + (i * menubuttonimages[mi->state][1]->w);
        dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
        dest.w = menubuttonimages[mi->state][1]->w;
        dest.h = menubuttonimages[mi->state][1]->h;
        gfx_blit (menubuttonimages[mi->state][1], NULL, gfx.screen, &dest, 10000);
    }
    // draw the right side of the button
    dest.x = MENUOFFSET_X(((_menu *)mi->menu)) + mi->pos.x + mi->pos.w - menubuttonimages[mi->state][2]->w;
    dest.y = MENUOFFSET_Y(((_menu *)mi->menu)) + mi->pos.y;
    dest.w = menubuttonimages[mi->state][2]->w;
    dest.h = menubuttonimages[mi->state][2]->h;
    gfx_blit (menubuttonimages[mi->state][2], NULL, gfx.screen, &dest, 10000);

    // calculate the center of the button
    px = (mi->pos.w - (strlen (mi->label) * font[MENU_BUTTON_FONTSIZE].size.x)) / 2 + mi->pos.x;
    py = (menubuttonimages[mi->state][0]->h - font[MENU_BUTTON_FONTSIZE].size.y) / 2 + mi->pos.y;

    if (mi->type == MENU_bool && mi->state == 2) // disabled bool == FALSE
        font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + px, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_black, 10000);
    else
        font_gfxdraw (MENUOFFSET_X(((_menu *)mi->menu)) + px, MENUOFFSET_Y(((_menu *)mi->menu)) + py, mi->label, MENU_BUTTON_FONTSIZE, COLOR_yellow, 10000);

};
Exemplo n.º 2
0
void p_pic2_run() {
	float time = 0;
	do {
		//time = 

		gfx_genstatic();
		gfx_blit();
		time ++;
	} while( !gfx_kbhit() && time<512 );

};
Exemplo n.º 3
0
void
TipButton::feel( int mouse )
	{
	init_dialog( Tip, NULL, NULL );
	ready_dialog( Tip, NULL, NULL, tip_feel, NULL, NULL, NULL );
	center_dialog( Tip );
	save_under_dialog( Tip );
	draw_dialog( Tip );

	//CRASH//debug( "Render icon" );
	gfx_blit( kyle_icon_data, Tip[ICON].sx, Tip[ICON].sy,
		Tip[ICON].width, Tip[ICON].height, 15 );

	_nTipOfTheDay = rand() % _nTips;
	drawTipText();

	do_dialog( Tip, -1 );
	restore_under_dialog();

	dialog_done = 0;			// override inside dialog box's setting
	}
Exemplo n.º 4
0
void
game_showresultnormal (int pos_x, int pos_y, int pos_w, int pos_h)
{
    char text[255];
    int i,
        p,
        x,
        y,
        pl_cnt = 0,
        pl_x,
        pl_y,                   // player in a row/col
        dx,
        dy,                     // distance
        sx,
        sy,
        px;                     // start view and position

    SDL_Rect dest,
             src;
    _player *pl[MAX_PLAYERS];


    /* Sort the playerlist */
    for (p = 0, pl_cnt = 0; p < MAX_PLAYERS; p++)
        if (PS_IS_used (players[p].state)) {
            // Set isplayer statistics for futur display
            players[p].gamestats.isaplayer = 1;
            // Sort player
            pl[pl_cnt] = &players[p];
            i = pl_cnt;

            while (i > 0 && (pl[i - 1]->points < players[p].points
                             || (pl[i - 1]->points == players[p].points
                                 && pl[i - 1]->wins < players[p].wins))) {
                pl[i] = pl[i - 1];
                i--;
                pl[i] = &players[p];
            }
            pl_cnt++;
        }

    if (pl_cnt == 0) {
        /* we still haven't joined the game */
    }

    /* calc the best view and start point */
    pl_x = 0;
    do {
        pl_x++;
        pl_y = ceil ((float) (((float) pl_cnt) / ((float) pl_x)));
        if (pl_y == 0)
            pl_y++;
        dy = pos_h / pl_y;
    } while (dy < SHOWRESULT_HEIGHT);
    dx = pos_w / pl_x;

    x = sx = (dx - SHOWRESULT_WIDTH) / 2;
    y = sy = (dy - SHOWRESULT_HEIGHT) / 2;
    px = 0;

    d_printf ("game_showresultnormal: pl_x:%d, pl_y:%d, dx:%d, dy:%d\n", pl_x, pl_y, dx, dy);

    /* draw the playerlist */
    for (i = 1, p = 0; p < pl_cnt; p++) {
        if (PS_IS_used (pl[p]->state)) {
            if (PS_IS_alife (pl[p]->state)) {
                font_gfxdrawbold (10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8, pos_y + y - 10,
                                  pl[p]->name, 0, COLOR_brown, 1, 1);
                font_gfxdraw (10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X + 8, pos_y + y - 10,
                              pl[p]->name, 0, COLOR_yellow, 1);
            } else
                font_gfxdraw (10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X, pos_y + y - 10, pl[p]->name,
                              0, COLOR_gray, 1);

            sprintf (text, "%3d (%2d)", pl[p]->points, pl[p]->wins);
            font_gfxdraw (10 + pos_x + x + GFX_MENUPLAYERIMGSIZE_X, pos_y + y + 6, text, 0, 0, 1);

            if (pl[p]->gfx != NULL) {
                dest.x = pos_x + x;
                dest.y = pos_y + y - 16;
                src.w = dest.w = pl[p]->gfx->menu_image->w;
                src.h = dest.h = pl[p]->gfx->menu_image->h;
                src.x = 0;
                src.y = 0;
                gfx_blit (pl[p]->gfx->menu_image, &src, gfx.screen, &dest, 1);
            } else {
                dest.x = pos_x + x;
                dest.y = pos_y + y - 16;
                src.w = dest.w = gfx.ghost->w;
                src.h = dest.h = gfx.ghost->h;
                src.x = 0;
                src.y = 0;
                gfx_blit (gfx.ghost, &src, gfx.screen, &dest, 1);
            }
            /* setup the new position */
            y += (dy / pl_x);
            x += dx;
            px++;
            if (px >= pl_x) {
                px = 0;
                x = sx;
            }
        }
    }
}
Exemplo n.º 5
0
void
game_showresultteam (int pos_x, int pos_y, int pos_w, int pos_h)
{
    int i,
        t_nr,
        p_nr;                     // counter for teams and players
    struct {
        _team *team;            // pointer to the team
        _player *pl[MAX_PLAYERS]; // players in the team (sorted)
        int cnt;
    } tdata[MAX_TEAMS];         // hold some team informations (sorted)
    int t_count = 0,
        p_maxcount = 0,
        p_sumcount = 0;
    int sx,
        sy,
        p_y,
        p_x,
        dx,
        dy,
        col,
        x = 0;
    SDL_Rect dest,
             src;
    char text[255];

    /* sort all teams */
    for (t_nr = 0; t_nr < MAX_TEAMS; t_nr++) {
        tdata[t_nr].team = NULL;
        tdata[t_nr].cnt = 0;
    }

    for (t_nr = 0; t_nr < MAX_TEAMS; t_nr++) {
        for (p_nr = 0; (p_nr < MAX_PLAYERS && teams[t_nr].players[p_nr] == NULL); p_nr++);

        if (p_nr < MAX_PLAYERS && teams[t_nr].players[p_nr] != NULL) {
            tdata[t_count].team = &teams[t_nr];
            i = t_count;

            while (i > 0 && (tdata[i - 1].team->wins < teams[t_nr].wins
                             || (tdata[i - 1].team->wins == teams[t_nr].wins
                                 && tdata[i - 1].team->points < teams[t_nr].points))) {
                tdata[i].team = tdata[i - 1].team;
                i--;
                tdata[i].team = &teams[t_nr];
            }
            t_count++;
        }
    }

    /* sort all players dependsing on the number of wins they have */
    for (t_nr = 0; t_nr < t_count; t_nr++)
        for (p_nr = 0, tdata[t_nr].cnt = 0; p_nr < MAX_PLAYERS; p_nr++) {
            if (t_nr < t_count) {
                if (tdata[t_nr].team->players[p_nr] != NULL
                        && PS_IS_used (tdata[t_nr].team->players[p_nr]->state)) {
                    tdata[t_nr].pl[tdata[t_nr].cnt] = tdata[t_nr].team->players[p_nr];
                    i = tdata[t_nr].cnt;

                    while (i > 0
                            && (tdata[t_nr].pl[i - 1]->wins < tdata[t_nr].team->players[p_nr]->wins
                                || (tdata[t_nr].pl[i - 1]->wins ==
                                    tdata[t_nr].team->players[p_nr]->wins
                                    && tdata[t_nr].pl[i - 1]->points <
                                    tdata[t_nr].team->players[p_nr]->points))) {
                        tdata[t_nr].pl[i] = tdata[t_nr].pl[i - 1];
                        i--;
                        tdata[t_nr].pl[i] = tdata[t_nr].team->players[p_nr];
                    }
                    tdata[t_nr].cnt++;
                }
            }
        }

    /* check the max number of players in one team and number of all players */
    for (t_nr = 0, p_maxcount = 0; t_nr < t_count; t_nr++) /* t_count + 1 */
        if (p_maxcount < tdata[t_nr].cnt)
            p_maxcount = tdata[t_nr].cnt;

    for (p_sumcount = 0, p_nr = 0; p_nr < MAX_PLAYERS; p_nr++)
        if (PS_IS_used (players[p_nr].state))
            p_sumcount++;

    /* calculate the best view */
    p_x = dx = dy = 0;
    do {
        p_x++;
        p_y = 0;                // calc. again for this setting
        for (t_nr = 0; t_nr < t_count; t_nr++) {
            p_y += ceil ((float) (((float) tdata[t_nr].cnt) / ((float) p_x)));
        }
        if (p_y == 0)
            p_y = 1;
        dy = (pos_h - (SHOWRESULT_TEAMHEAD * t_count)) / p_y;
    } while (dy < SHOWRESULT_TEAMPLAYER);

    if (dy > 2 * SHOWRESULT_TEAMPLAYER)
        dy = 2 * SHOWRESULT_TEAMPLAYER;

    /* draw everything */
    sy = (pos_h - (SHOWRESULT_TEAMHEAD * t_count + dy * p_y)) / 2;
    for (t_nr = 0; t_nr < t_count; t_nr++) {
        sprintf (text, "%s Victorys %d (%d)", tdata[t_nr].team->name, tdata[t_nr].team->wins,
                 tdata[t_nr].team->points);
        sx = (pos_w - strlen (text) * font[0].size.x) / 2;
        font_gfxdrawbold (10 + pos_x + sx, pos_y + sy + 3, text, 0, COLOR_brown, 1, 1);
        font_gfxdraw (10 + pos_x + sx, pos_y + sy + 3, text, 0, COLOR_yellow, 2);
        sy += SHOWRESULT_TEAMHEAD;
        dx = pos_w / p_x;
        sx = (dx - SHOWRESULT_TEAMPLAYERWIDTH) / 2;

        for (col = 0, p_nr = 0; p_nr < tdata[t_nr].cnt; p_nr++) {
            if (col == 0 || col >= p_x) {
                if (col >= p_x)
                    sy += dy;
                col = 0;
                x = sx;
            }

            if (tdata[t_nr].pl[p_nr]->gfx != NULL) {
                dest.x = pos_x + x;
                dest.y = pos_y + sy;
                src.w = dest.w = tdata[t_nr].pl[p_nr]->gfx->small_image->w;
                src.h = dest.h = tdata[t_nr].pl[p_nr]->gfx->small_image->h;
                src.x = 0;
                src.y = 0;
                gfx_blit (tdata[t_nr].pl[p_nr]->gfx->small_image, &src, gfx.screen, &dest, 1);
            } else {
                dest.x = pos_x + x;
                dest.y = pos_y + sy;
                src.w = dest.w = gfx.ghost_small->w;
                src.h = dest.h = gfx.ghost_small->h;
                src.x = 0;
                src.y = 0;
                gfx_blit (gfx.ghost_small, &src, gfx.screen, &dest, 1);
            }
            sprintf (text, "%s(%d/%d)", tdata[t_nr].pl[p_nr]->name, tdata[t_nr].pl[p_nr]->wins,
                     tdata[t_nr].pl[p_nr]->points);
            font_gfxdraw (10 + pos_x + x + GFX_SMALLPLAYERIMGSIZE_X * 2, pos_y + sy + 2, text, 0, 0,
                          2);
            x += dx;
            col++;
        }
        sy += dy;
    }
}
Exemplo n.º 6
0
/*
   this is needed to draw the whole uppdate of everything 
*/
void
draw_netupdatestate (char st)
{
    char text[255];
    unsigned char b;
    int y = 0,
        b1,
        z,
        zx = 200,
        i,
        j,
        s = map.size.y + MAX_PLAYERS + GAME_MAX_TUNNELS;
    SDL_Rect src,
      dest;
    z = gfx.res.x - zx - 30 - 8;
    for (i = 0; i < MAX_PLAYERS; i++)
        if (PS_IS_used (players[i].state)) {
            y += 50;
            if (st) {
                redraw_logo (0, y, gfx.res.x, y + 50);

                if (players[i].gfx_nr != -1) {
                    dest.w = src.w = players[i].gfx->small_image->w;
                    dest.h = src.h = players[i].gfx->small_image->h;
                    src.x = players[i].gfx->small_image->w * down;
                    src.y = 0;

                    dest.x = 50;
                    dest.y = y;

                    SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest);
                    gfx_blitupdaterectadd (&dest);
                }

                dest.x = zx;
                dest.y = y;
                dest.w = menulistimages[1][0]->w;
                dest.h = menulistimages[1][0]->h;
                gfx_blit (menulistimages[1][0], NULL, gfx.screen, &dest, 10000);
                dest.x = z + zx + 4;
                gfx_blit (menulistimages[1][2], NULL, gfx.screen, &dest, 10000);
                // draw the bottom left and right of the list
                dest.y = y + 29;
                gfx_blit (menulistimages[1][8], NULL, gfx.screen, &dest, 10000);
                dest.x = zx;
                gfx_blit (menulistimages[1][6], NULL, gfx.screen, &dest, 10000);
                //top & bottom
                for (j = 4; j < z + 4; j += 4) {
                    dest.x = j + zx;
                    dest.y = y;
                    gfx_blit (menulistimages[1][1], NULL, gfx.screen, &dest, 10000);
                    dest.y = y + 29;
                    gfx_blit (menulistimages[1][7], NULL, gfx.screen, &dest, 10000);
                }
                //left &right
                for (j = 4; j < 29; j += 4) {
                    dest.x = zx;
                    dest.y = y + j;
                    gfx_blit (menulistimages[1][3], NULL, gfx.screen, &dest, 10000);
                    dest.x = z + zx + 4;
                    gfx_blit (menulistimages[1][5], NULL, gfx.screen, &dest, 10000);
                }
                sprintf (text, "%s", players[i].name);
                font_draw (80, y, text, 0, 4);
            }
            // calc percentage, this a range from 0 to 255)   
            switch (players[i].net.net_istep) {
            case 3:
                sprintf (text, "Getting Tunnel Data %d.", players[i].net.net_status);
                b = (players[i].net.net_status + 1) * 255 / s;
                break;
            case 2:
                sprintf (text, "Getting Field Data %d of %d.",
                         players[i].net.net_status, map.size.y);
                b = (players[i].net.net_status + 1 + GAME_MAX_TUNNELS) * 255 / s;
                break;
            case 1:
                sprintf (text, "Getting Player Data %d of %d.",
                         players[i].net.net_status, MAX_PLAYERS);
                b = (players[i].net.net_status + 1 + GAME_MAX_TUNNELS + map.size.y) * 255 / s;
                break;
            default:
                sprintf (text, "Ready");
                b = 255;
                break;
            }

            //draw bar
            if (b > 0) {
                b1 = b * z / 255;
                dest.x = zx + 4;
                dest.y = y + 4;
                dest.w = menubuttonimages[2][0]->w;
                dest.h = menubuttonimages[2][0]->h;
                gfx_blit (menubuttonimages[2][0], NULL, gfx.screen, &dest, 10000);
                dest.x = zx + 4 + b1 - menubuttonimages[1][2]->w;
                if (dest.x < zx + 4)
                    dest.x = zx + 4;
                dest.w = menubuttonimages[2][2]->w;
                dest.h = menubuttonimages[2][2]->h;
                gfx_blit (menubuttonimages[2][2], NULL, gfx.screen, &dest, 10000);
                if (b1 > menubuttonimages[2][0]->w + menubuttonimages[2][2]->w) {
                    dest.w = menubuttonimages[2][1]->w;
                    dest.h = menubuttonimages[2][1]->h;
                    for (j = menubuttonimages[2][0]->w;
                         j < b1 - menubuttonimages[2][2]->w; j += menubuttonimages[2][1]->w) {
                        dest.x = j + zx + 4;
                        gfx_blit (menubuttonimages[2][1], NULL, gfx.screen, &dest, 10000);
                    }
                }
            }
            // draw old status in case of debug
            if (!players[i].net.net_istep)
                font_draw (80, y + 20, text, 0, 4);
            else if (debug) {
                redraw_logo (80, y + 35, gfx.res.x - 80, 15);
                font_draw (80, y + 35, text, 0, 4);
            }
        }
    gfx_blitdraw ();
    return;
}