Exemplo n.º 1
0
static void chopRenderTerrain(struct CTerrain *ter, bool isground)
{

    int i = 1;

    int oldx = 0;

    while(i < ter->iNodesCount && oldx < iScreenX)
    {

        int x = ter->mNodes[i-1].x - iCameraPosX;
        int y = ter->mNodes[i-1].y;

        int x2 = ter->mNodes[i].x - iCameraPosX;
        int y2 = ter->mNodes[i].y;

        int ax, ay;

        if ((y < y2) != isground)
        {
            ax = x2;
            ay = y;
        }
        else
        {
            ax = x;
            ay = y2;
        }
#if LCD_DEPTH > 2
        rb->lcd_set_foreground(LCD_RGBPACK(100,255,100));
#elif LCD_DEPTH == 2
        rb->lcd_set_foreground(LCD_DARKGRAY);
#endif

        rb->lcd_drawline(SCALE(x), SCALE(y), SCALE(x2), SCALE(y2));

        xlcd_filltriangle(SCALE(x), SCALE(y), SCALE(x2), SCALE(y2),
                          SCALE(ax), SCALE(ay));

        if (isground)
        {
            y = ay;
            y2 = (LCD_HEIGHT*SIZE);
        }
        else
        {
            y = 0;
            y2 = ay;
        }
        if (y2-y > 0)
            rb->lcd_fillrect(SCALE(x), SCALE(y), SCALE(x2-x)+1, SCALE(y2-y)+1);

        oldx = x;
        i++;
    }
}
Exemplo n.º 2
0
static void
draw_all_marks (void)
{
    unsigned int x, y;
    for (x = MIN_X; x < MAX_X; ++x)
    {
        for (y = MIN_Y; y < MAX_Y; ++y)
        {
            if (display_marks[x + y * board_width] != ' ')
            {
#if LCD_DEPTH > 1
                if (display_marks[x + y * board_width] != 'b' &&
                    display_marks[x + y * board_width] != 'w')
                {
                    rb->lcd_set_foreground (MARK_COLOR);
                }
                else
                {
                    rb->lcd_set_foreground (CURSOR_COLOR);
                }
                rb->lcd_set_drawmode (DRMODE_FG);
#else
                rb->lcd_set_drawmode (DRMODE_FG + DRMODE_COMPLEMENT);
#endif

                if (display_marks[x + y * board_width] & (1 << 7))
                {
                    char to_display[2];
                    int width, height;

                    to_display[0] =
                        display_marks[x + y * board_width] & (~(1 << 7));
                    to_display[1] = '\0';

                    rb->lcd_getstringsize (to_display, &width, &height);

                    int display_x =
                        pixel_x (POS (x, y)) + LINE_OFFSET - (width / 2);
                    int display_y =
                        pixel_y (POS (x, y)) + LINE_OFFSET - (height / 2);

                    if (display_x < 0)
                    {
                        display_x = 0;
                    }

                    if (display_y < 0)
                    {
                        display_y = 0;
                    }

                    if (display_x + width >= LCD_WIDTH)
                    {
                        display_x = LCD_WIDTH - 1 - width;
                    }

                    if (display_y + height >= LCD_HEIGHT)
                    {
                        display_y = LCD_HEIGHT - 1 - height;
                    }

                    rb->lcd_putsxy (display_x, display_y, to_display);
                    continue;
                }

                switch (display_marks[x + y * board_width])
                {
                    /* moves, 'mark', 'square' */
                case 'b':
                case 'w':
                    if (intersection_size <= 5)
                    {
                        DEBUGF ("screen is too small to mark current move\n");
                        break;
                    }
                case 'm':
                    if (intersection_size <= 5)
                    {
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET +
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET +
                                           1);
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET -
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET -
                                           1);
                    }
                    else
                    {
                        rb->lcd_drawrect (pixel_x (POS (x, y)) + LINE_OFFSET -
                                          intersection_size / 6,
                                          pixel_y (POS (x, y)) + LINE_OFFSET -
                                          intersection_size / 6,
                                          (intersection_size / 6) * 2 + 1,
                                          (intersection_size / 6) * 2 + 1);
                    }
                    break;
                case 's':
                    if (intersection_size <= 5)
                    {
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET +
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET +
                                           1);
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET -
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET -
                                           1);
                    }
                    else
                    {
                        rb->lcd_fillrect (pixel_x (POS (x, y)) + LINE_OFFSET -
                                          intersection_size / 6,
                                          pixel_y (POS (x, y)) + LINE_OFFSET -
                                          intersection_size / 6,
                                          (intersection_size / 6) * 2 + 1,
                                          (intersection_size / 6) * 2 + 1);
                    }
                    break;

                case 'c':
                    if (intersection_size > 7)
                    {
                        draw_circle (pixel_x (POS (x, y)) + LINE_OFFSET,
                                     pixel_y (POS (x, y)) + LINE_OFFSET,
                                     (intersection_size - 1) / 4, true);
                        break;
                    }

                    /* purposely don't break here, draw small the same as
                       a triangle */

                case 't':
                    if (intersection_size <= 7)
                    {
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET -
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET +
                                           1);
                        rb->lcd_drawpixel (pixel_x (POS (x, y)) + LINE_OFFSET +
                                           1,
                                           pixel_y (POS (x, y)) + LINE_OFFSET -
                                           1);
                    }
                    else
                    {
                        xlcd_filltriangle (pixel_x (POS (x, y)) + LINE_OFFSET,
                                           pixel_y (POS (x, y)) + LINE_OFFSET -
                                           intersection_size / 4,
                                           pixel_x (POS (x, y)) + LINE_OFFSET +
                                           intersection_size / 4,
                                           pixel_y (POS (x, y)) + LINE_OFFSET +
                                           intersection_size / 4,
                                           pixel_x (POS (x, y)) + LINE_OFFSET -
                                           intersection_size / 4,
                                           pixel_y (POS (x, y)) + LINE_OFFSET +
                                           intersection_size / 4);
                    }
                    break;
                default:
                    DEBUGF ("tried to display unknown mark '%c' %d\n",
                            display_marks[x + y * board_width],
                            display_marks[x + y * board_width]);
                    break;
                };

                rb->lcd_set_drawmode (DRMODE_SOLID);
                /* don't have to undo the colors for LCD_DEPTH > 1, most
                   functions assume bg and fg get clobbered */
            }
        }
    }
}