Esempio n. 1
0
/*
 * Draw a shaded square
 */
void gl_list_square (fpoint tl, fpoint br,
                     texp tex, fsize tex_tl, fsize tex_br, fsize uv,
                     color hi, color med, color lo)
{
    glEnable(GL_TEXTURE_2D);

    /*
     * Draw the central flat square
     */
    glcolor(med);

    Begin(GL_TRIANGLE_STRIP);

    if (!memcmp(&hi, &med, sizeof(color)) &&
        !memcmp(&hi, &lo, sizeof(color))) {
        vertex(tl, br, tl.x, tl.y, tex_tl, tex_br, uv);
        vertex(tl, br, br.x, tl.y, tex_tl, tex_br, uv);
        vertex(tl, br, tl.x, br.y, tex_tl, tex_br, uv);
        vertex(tl, br, br.x, br.y, tex_tl, tex_br, uv);
    } else {
        glcolor(hi);
        vertex(tl, br, tl.x, tl.y, tex_tl, tex_br, uv);
        glcolor(med);
        vertex(tl, br, br.x, tl.y, tex_tl, tex_br, uv);
        vertex(tl, br, tl.x, br.y, tex_tl, tex_br, uv);
        glcolor(lo);
        vertex(tl, br, br.x, br.y, tex_tl, tex_br, uv);
    }

    End();
}
Esempio n. 2
0
/*
 * Draw a square outline 3D relief
 */
void
gl_list_square_outline_bevelled_plain (fpoint tl, fpoint br,
                                       texp tex, fsize tex_tl, fsize tex_br,
                                       fsize uv, color hi, color med, color lo,
                                       fsize bevel)
{
    //
    //
    //        x-----A-----------------------B----x
    //        |\               2                /|
    //        | \                              / |
    //        |  x - A1------------------B1 - x  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |             1              |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  x - C1------------------D1 - x  |
    //        | /              3               \ |
    //        |/                                \|
    //        x-----C-----------------------D----x
    //
    //

    fpoint a = {tl.x, tl.y};
    fpoint b = {br.x, tl.y};
    fpoint c = {br.x, br.y};
    fpoint d = {tl.x, br.y};
    fpoint a1 = {tl.x + bevel.width, tl.y + bevel.height};
    fpoint b1 = {br.x - bevel.width, tl.y + bevel.height};
    fpoint c1 = {br.x - bevel.width, br.y - bevel.height};
    fpoint d1 = {tl.x + bevel.width, br.y - bevel.height};

    glEnable(GL_TEXTURE_2D);

    /*
     * Draw the central flat square
     */

    /*
     * Now draw the bevelled border
     */
    glcolor(lo);
    quaduv(tl, br, c1, c, d, d1, tex_tl, tex_br, uv);
    glcolor(hi);
    quaduv(tl, br, a, a1, d1, d, tex_tl, tex_br, uv);

    glcolor(hi);
    quaduv(tl, br, a, b, b1, a1, tex_tl, tex_br, uv);
    glcolor(lo);
    quaduv(tl, br, b, c, c1, b1, tex_tl, tex_br, uv);
}
Esempio n. 3
0
static void wid_intro_create (void)
{
    if (wid_intro) {
        return;
    }

    music_play_intro();

    wid_intro = wid_new_window("intro");

    wid_set_no_shape(wid_intro);

    fpoint tl = {0.0f, 0.0f};
    fpoint br = {1.0f, 1.0f};
    wid_set_tl_br_pct(wid_intro, tl, br);

    color col = BLACK;
    col.a = 0;
    glcolor(col);

    wid_set_mode(wid_intro, WID_MODE_NORMAL);
    wid_set_color(wid_intro, WID_COLOR_TL, col);
    wid_set_color(wid_intro, WID_COLOR_BR, col);
    wid_set_color(wid_intro, WID_COLOR_BG, col);

    wid_intro_bg_create();
    wid_update(wid_intro);

    wid_move_to_pct_centered(wid_intro, 0.5f, 0.5f);
    wid_fade_in(wid_intro_title, intro_effect_delay*2);

    wid_intro_menu_create();
}
Esempio n. 4
0
/*
 * Draw a square with 3D relief
 */
void gl_list_square_bevelled_plain (fpoint tl, fpoint br,
                                    texp tex, fsize tex_tl, fsize tex_br,
                                    fsize uv, color hi, color med, color lo,
                                    fsize bevel)
{
    fpoint a = {tl.x, tl.y};
    fpoint b = {br.x, tl.y};
    fpoint c = {br.x, br.y};
    fpoint d = {tl.x, br.y};
    fpoint a1 = {tl.x + bevel.width, tl.y + bevel.height};
    fpoint b1 = {br.x - bevel.width, tl.y + bevel.height};
    fpoint c1 = {br.x - bevel.width, br.y - bevel.height};
    fpoint d1 = {tl.x + bevel.width, br.y - bevel.height};

    glEnable(GL_TEXTURE_2D);

    /*
     * Draw the central flat square
     */
    Begin(GL_TRIANGLE_FAN);

    glcolor(med);
    vertex(tl, br, a.x, a.y, tex_tl, tex_br, uv);
    vertex(tl, br, b.x, b.y, tex_tl, tex_br, uv);
    vertex(tl, br, c.x, c.y, tex_tl, tex_br, uv);
    vertex(tl, br, d.x, d.y, tex_tl, tex_br, uv);

    End();

    /*
     * Now draw the bevelled border
     */
    glcolor(lo);
    quaduv(tl, br, c1, c, d, d1, tex_tl, tex_br, uv);
    glcolor(hi);
    quaduv(tl, br, a, a1, d1, d, tex_tl, tex_br, uv);

    glcolor(hi);
    quaduv(tl, br, a, b, b1, a1, tex_tl, tex_br, uv);
    glcolor(lo);
    quaduv(tl, br, b, c, c1, b1, tex_tl, tex_br, uv);
}
Esempio n. 5
0
File: price.c Progetto: kevinarpe/kx
void drawkeys()
{
  int len,h2,x,y,*kx;
  len=Key->n;
  if (2>len) return;
  h2=LabelHit/2;
  kx=g_malloc(len*sizeof(int));
  pango_layout_set_font_description(PL,LabelFont);
  DO(len,kx[i]=gettextwidth(Key->v[i]));
  x=Gx+Gw-(10+KeyWid+maxi(len,kx));
  y=Gy+10+h2;
  cairo_set_line_width(CR,2);
  DO(len,{
    cairo_set_source(CR,glcolor(i));
    cairo_move_to(CR,x,y);
    cairo_line_to(CR,x+KeyWid,y);
    cairo_stroke(CR);
    y+=LabelHit;
  });
Esempio n. 6
0
/*
 * Draw a rounded square with 3D relief
 */
void gl_list_rounded_square_bevelled (fpoint tl, fpoint br,
                                      texp tex, fsize tex_tl, fsize tex_br,
                                      fsize uv, color hi, color med, color lo,
                                      fsize bevel, fsize radius, int32_t sides)
{
    radius.width = min(radius.width, (br.x - tl.x)/3);
    radius.height = min(radius.height, (br.y - tl.y)/3);

    //
    //
    //
    //        x-----A-----------------------B----x
    //        |\               2                /|
    //        | \                              / |
    //        |  x - A1------------------B1 - x  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |             1              |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  |                            |  |
    //        |  x - C1------------------D1 - x  |
    //        | /              3               \ |
    //        |/                                \|
    //        x-----C-----------------------D----x
    //
    //
    //
    glEnable(GL_TEXTURE_2D);

    {
    fpoint a = {tl.x + bevel.width + radius.width, tl.y};
    fpoint b = {br.x - bevel.width - radius.width, tl.y};
    fpoint c = {br.x - bevel.width - radius.width, br.y};
    fpoint d = {tl.x + bevel.width + radius.width, br.y};
    fpoint a1 = {tl.x + bevel.width + radius.width, tl.y + bevel.height};
    fpoint b1 = {br.x - bevel.width - radius.width, tl.y + bevel.height};
    fpoint c1 = {br.x - bevel.width - radius.width, br.y - bevel.height};
    fpoint d1 = {tl.x + bevel.width + radius.width, br.y - bevel.height};

    /*
     * Draw the central flat square (1);
     */
    glcolor(med);
    quaduv(tl, br, a1, b1, c1, d1, tex_tl, tex_br, uv);

    /*
     * Now draw the bevelled border (2);
     */
    glcolor(lo);
    quaduv(tl, br, c1, c, d, d1, tex_tl, tex_br, uv);
    quaduv(tl, br, a, a1, d1, d, tex_tl, tex_br, uv);

    /*
     * (3);
     */
    glcolor(hi);
    quaduv(tl, br, a, b, b1, a1, tex_tl, tex_br, uv);
    quaduv(tl, br, b, c, c1, b1, tex_tl, tex_br, uv);
    }

    //
    //
    //
    //        x----------------------------------x
    //        |\                                /|
    //        | \                              / |
    //        |  x----------------------------x  |
    //        |  |                            |  |
    //        A  A1                          B1  B
    //        |  |                            |  |
    //        | 3|1            1             2|4 |
    //        |  |                            |  |
    //        C  C1                          D1  D
    //        |  |                            |  |
    //        |  x----------------------------x  |
    //        | /                              \ |
    //        |/                                \|
    //        x----------------------------------x
    //
    //
    //
    fpoint a = {tl.x, tl.y + bevel.height + radius.height};
    fpoint b = {br.x, tl.y + bevel.height + radius.height};
    fpoint c = {br.x, br.y - bevel.height - radius.height};
    fpoint d = {tl.x, br.y - bevel.height - radius.height};

    fpoint a1 = {tl.x + bevel.width, tl.y + bevel.height + radius.height};
    fpoint b1 = {br.x - bevel.width, tl.y + bevel.height + radius.height};
    fpoint c1 = {br.x - bevel.width, br.y - bevel.height - radius.height};
    fpoint d1 = {tl.x + bevel.width, br.y - bevel.height - radius.height};

    fpoint a2 = {tl.x + bevel.width + radius.width, tl.y + bevel.height + radius.height};
    fpoint b2 = {br.x - bevel.width - radius.width, tl.y + bevel.height + radius.height};
    fpoint c2 = {br.x - bevel.width - radius.width, br.y - bevel.height - radius.height};
    fpoint d2 = {tl.x + bevel.width + radius.width, br.y - bevel.height - radius.height};

    /*
     * Draw the central flat squares (1);
     */
    glcolor(med);
    quaduv(tl, br, a1, a2, d2, d1, tex_tl, tex_br, uv);
    quaduv(tl, br, b2, b1, c1, c2, tex_tl, tex_br, uv);

    /*
     * Now draw the bevelled border
     */

    /*
     * (3);
     */
    glcolor(hi);
    quaduv(tl, br, a, a1, d1, d, tex_tl, tex_br, uv);

    /*
     * (4);
     */
    glcolor(lo);
    quaduv(tl, br, b, c, c1, b1, tex_tl, tex_br, uv);

    float step = RAD_360 / sides;

    /*
     * Now draw the rounded filled edges, large first, with highlights
     */
    radius.width += bevel.width;
    radius.height += bevel.height;

    /*
     * Top right
     */
    Begin(GL_TRIANGLE_STRIP);

    float x = br.x - radius.width;
    float y = br.y - radius.height;
    float j = 0.0f;

    glcolor(lo);
    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    int32_t i;
    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + (radius.width-bevel.width)*sin(j),
            y + (radius.height-bevel.height)*cos(j),
            tex_tl, tex_br, uv);
        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;

        if (i == sides/8) {
            glcolor(lo);
        }
    }

    End();

    /*
     * Bottom right
     */
    Begin(GL_TRIANGLE_STRIP);

    x = br.x - radius.width;
    y = tl.y + radius.height;
    j = RAD_90;

    glcolor(lo);
    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + (radius.width-bevel.width)*sin(j),
            y + (radius.height-bevel.height)*cos(j),
            tex_tl, tex_br, uv);

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;

        if (i == sides/8) {
            glcolor(hi);
        }
    }

    End();

    /*
     * Bottom left
     */
    Begin(GL_TRIANGLE_STRIP);

    x = tl.x + radius.width;
    y = tl.y + radius.height;
    j = RAD_180;

    glcolor(hi);
    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + (radius.width-bevel.width)*sin(j),
            y + (radius.height-bevel.height)*cos(j),
            tex_tl, tex_br, uv);

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Top right
     */
    Begin(GL_TRIANGLE_STRIP);

    x = tl.x + radius.width;
    y = br.y - radius.height;
    j = RAD_270;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    glcolor(hi);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + (radius.width-bevel.width)*sin(j),
            y + (radius.height-bevel.height)*cos(j),
            tex_tl, tex_br, uv);

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        if (i == sides/8) {
            glcolor(lo);
        }

        j += step;
    }

    End();

    glcolor(med);

    /*
     * Now draw the rounded filled edges, smaller, plain
     */
    radius.width -= bevel.width;
    radius.height -= bevel.height;

    /*
     * Top right
     */
    Begin(GL_TRIANGLE_FAN);

    x = br.x - radius.width - bevel.width;
    y = br.y - radius.height - bevel.height;
    j = 0;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom right
     */
    Begin(GL_TRIANGLE_FAN);

    x = br.x - radius.width - bevel.width;
    y = tl.y + radius.height + bevel.height;
    j = RAD_90;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom left
     */
    Begin(GL_TRIANGLE_FAN);

    x = tl.x + radius.width + bevel.width;
    y = tl.y + radius.height + bevel.height;
    j = RAD_180;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom right
     */
    Begin(GL_TRIANGLE_FAN);

    x = tl.x + radius.width + bevel.width;
    y = br.y - radius.height - bevel.height;
    j = RAD_270;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();
}
Esempio n. 7
0
/*
 * Draw a rounded square
 */
void gl_list_rounded_square (fpoint tl, fpoint br,
                             texp tex, fsize tex_tl, fsize tex_br, fsize uv,
                             color hi, color med, color lo,
                             fsize radius, int32_t sides)
{
    radius.width = min(radius.width, (br.x - tl.x)/3);
    radius.height = min(radius.height, (br.y - tl.y)/3);

    glcolor(med);

    glEnable(GL_TEXTURE_2D);

    fpoint a = {tl.x, tl.y + radius.height};
    fpoint b = {br.x, tl.y + radius.height};
    fpoint c = {br.x, br.y - radius.height};
    fpoint d = {tl.x, br.y - radius.height};

    fpoint a1 = {tl.x + radius.width, tl.y};
    fpoint b1 = {br.x - radius.width, tl.y};
    fpoint c1 = {br.x - radius.width, br.y};
    fpoint d1 = {tl.x + radius.width, br.y};

    /*
     * Draw the central flat square
     */
    quaduv(tl, br, a1, b1, c1, d1, tex_tl, tex_br, uv);

    /*
     * Now side squares
     */
    quaduv(tl, br, a, b, c, d, tex_tl, tex_br, uv);

    float step = RAD_360 / (float)sides;

    /*
     * Now draw the rounded filled edges, smaller, plain
     */

    /*
     * Top right
     */
    Begin(GL_TRIANGLE_FAN);

    float x = br.x - radius.width;
    float y = br.y - radius.height;
    float j = 0.0f;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    int32_t i;
    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom right
     */
    Begin(GL_TRIANGLE_FAN);

    x = br.x - radius.width;
    y = tl.y + radius.height;
    j = RAD_90;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom left
     */
    Begin(GL_TRIANGLE_FAN);

    x = tl.x + radius.width;
    y = tl.y + radius.height;
    j = RAD_180;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();

    /*
     * Bottom right
     */
    Begin(GL_TRIANGLE_FAN);

    x = tl.x + radius.width;
    y = br.y - radius.height;
    j = RAD_270;

    vertex(tl, br, x, y, tex_tl, tex_br, uv);

    for (i = 0; i <= sides/4; i++) {

        vertex(tl, br,
            x + radius.width*sin(j),
            y + radius.height*cos(j),
            tex_tl, tex_br, uv);

        j += step;
    }

    End();
}
Esempio n. 8
0
/*
 * Blit the font to the screen
 */
static void ttf_puts_internal (font *f, const char *text,
                               double x, double y,
                               double scaling, double advance,
                               uint8_t include_formatting,
                               uint8_t draw_cursor,
                               uint8_t fixed_width)
{
    color saved_color = gl_color_current();
    uint8_t color_retore_needed = false;
    uint8_t found_format_string = false;
    int32_t c;
    texp tex;
    tilep tile;
    tpp tp;
    color fg;
    double x_start = x;

    while ((c = *text++) != '\0') {
        if (c == '\\') {
            c = ' ';
        }

	if (!found_format_string) {
	    if (c == '%') {
		found_format_string = true;
		continue;
	    }
	} else if (found_format_string) {
	    if (c == '%') {
		if (!strncmp(text, "fg=", 3)) {
		    text += 3;

                    fg = string2color(&text);
                    fg.a = saved_color.a;

                    if (!color_retore_needed) {
                        color_retore_needed = true;
                        if (include_formatting) {
                            glcolor_save();
                        }
                    }

                    if (include_formatting) {
                        glcolor(fg);
                    }

		    found_format_string = false;
		    continue;

		} else if (!strncmp(text, "fmt=", 4)) {
		    text += 4;

                    (void)string2fmt(&text);

		    found_format_string = false;
		    continue;

		} else if (!strncmp(text, "font=", 5)) {
		    text += 5;
                    f = string2font(&text);
		    found_format_string = false;
		    continue;

		} else if (!strncmp(text, "tex=", 4)) {
		    text += 4;
                    tex = string2tex(&text);

                    /*
                     * Move forward half the texture size so it is centered.
                     */
                    x += (tex_get_width(tex) * scaling * advance)/2;

                    point at;
                    at.x = x;
                    at.y = y + (tex_get_height(tex) * scaling * advance)/2;
                    tex_blit(tex, at);

                    /*
                     * Now the other half.
                     */
                    x += (tex_get_width(tex) * scaling * advance)/2;

		    found_format_string = false;
		    continue;

		} else if (!strncmp(text, "tile=", 5)) {
		    text += 5;
                    tile = string2tile(&text);

                    fpoint tl;
                    fpoint br;

                    double bx = x;

                    tl.x = (x);
                    tl.y = (y);
                    br.x = (x + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch);
                    br.y = (y + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * (scaling));

                    fpoint otl = tl;
                    fpoint obr = br;

                    tile_get_blit_size(0, tile, 0, &otl, &obr);

                    double dy = ((obr.y - otl.y) - (br.y - tl.y));
                    double dx = ((obr.x - otl.x) - (br.x - tl.x));

                    tl.y += dy;
                    br.y += dy;
                    tl.x += dx/2;
                    br.x += dx/2;

                    double stretch =
                        (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch) -
                        (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling);
                    tl.x -= stretch / 2.0;

                    tile_blit_fat(0, tile, 0, &tl, &br);

                    x = bx;
                    x += obr.x - otl.x;

		    found_format_string = false;
		    continue;

		} else if (!strncmp(text, "tp=", 3)) {
		    text += 3;
                    tp = string2tp(&text);
                    tilep tile = tp_first_tile(tp);

                    fpoint tl;
                    fpoint br;

                    double bx = x;

                    tl.x = (x);
                    tl.y = (y);
                    br.x = (x + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch);
                    br.y = (y + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * (scaling));

                    fpoint otl = tl;
                    fpoint obr = br;

                    double oh = br.y - tl.y;

                    tile_get_blit_size(tp, tile, 0, &otl, &obr);

                    double dx = ((obr.x - otl.x) - (br.x - tl.x));

                    tl.y += oh * tp_get_blit_top_off(tp);
                    br.y += oh * tp_get_blit_top_off(tp);
                    tl.x += dx/2;
                    br.x += dx/2;

                    double stretch =
                        (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch) -
                        (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling);
                    tl.x -= stretch / 2.0;

                    tile_blit_fat(tp, tile, 0, &tl, &br);

                    x = bx;
                    x += obr.x - otl.x;

		    found_format_string = false;
		    continue;
		}
	    }
	}

	found_format_string = false;

        if (c == '\t') {
            x = ((((x-x_start) / TTF_TABSTOP) + 1) * TTF_TABSTOP);
            x = x + x_start;
        } else if (c == '~') {
            x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance;
        } else {
            double maxc = f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width;
            double thisc = f->glyphs[(int) c].width;

            int fixed = fixed_width;

            if (fixed) {
                thisc = maxc;
            }

            double pad = ((maxc - thisc) * scaling * advance) / 2.0;

            if (fixed) {
                x += pad;
            }

            if (c == TTF_CURSOR_CHAR) {
                if (draw_cursor) {
                    ttf_putc(f, c, x, y, scaling);
                }
            } else {
                ttf_putc(f, c, x, y, scaling);
            }

            if (fixed) {
                x += thisc;
                x += pad;
            } else {
                if (c == TTF_CURSOR_CHAR) {
                    x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance;
                } else {
                    x += f->glyphs[c].width * scaling * advance;
                }
            }
        }
    }

    if (color_retore_needed) {
        glcolor(saved_color);
    }
}
Esempio n. 9
0
/*
 * Blit the font to the screen
 */
void ttf_putc (font *f, int32_t c, double x, double y, double scaling)
{
    double texMinX = f->glyphs[c].texMinX;
    double texMaxX = f->glyphs[c].texMaxX;
    double texMinY = f->glyphs[c].texMinY;
    double texMaxY = f->glyphs[c].texMaxY;

    if (c == TTF_CURSOR_CHAR) {

        c = TTF_FIXED_WIDTH_CHAR;

        GLfloat left = (GLfloat)(x);
        GLfloat right = (GLfloat)(x + f->glyphs[c].width * scaling);
        GLfloat top = (GLfloat)(y);
        GLfloat bottom = (GLfloat)(y + f->glyphs[c].height * (scaling));

#ifdef CURSOR_FLASH
        static uint32_t last;
        static uint8_t first = true;

        glBindTexture(GL_TEXTURE_2D, 0);

        if (first) {
            first = false;
            last = time_get_time_ms();
        }

        glcolor_save();

        if (time_have_x_tenths_passed_since(10, last)) {
            glcolor(CONSOLE_CURSOR_COLOR);
            last = time_get_time_ms();
        } else if (time_have_x_tenths_passed_since(5, last)) {
            glcolor(CONSOLE_CURSOR_COLOR);
        } else {
            glcolor(CONSOLE_CURSOR_OTHER_COLOR);

            gl_blitsquare(left, top, right, bottom);

            left += 1;
            right -= 1;
            top += 1;
            bottom -= 1;

            gl_blitquad(left, top, right, bottom);

            glcolor_restore();
            return;
        }

        gl_blitquad(left, top, right, bottom);

        glcolor(BLACK);

        left += 1;
        right -= 1;
        top += 1;
        bottom -= 1;

        gl_blitquad(left, top, right, bottom);

        glcolor_restore();
        return;
#else
        glBindTexture(GL_TEXTURE_2D, 0);

        {
            color c = CONSOLE_CURSOR_COLOR;

            c.a = 200;

            glcolor(c);

            gl_blitsquare(left, top, right, bottom);

            glcolor_restore();
            return;
        }
#endif
    }

    GLfloat left = (GLfloat)(x);
    GLfloat right = (GLfloat)(x + f->glyphs[c].width * scaling);
    GLfloat top = (GLfloat)(y);
    GLfloat bottom = (GLfloat)(y + f->glyphs[c].height * (scaling));

    blit(f->tex[c].tex,
         texMinX, texMinY, texMaxX, texMaxY, left, top, right, bottom);
}
Esempio n. 10
0
void cloud_tick (int display)
{
    double w = game.video_gl_width;
    double h = game.video_gl_height;

    double cloud_w = w / 30.0;
    double cloud_h = w / 40.0;
    static double wind = 0.3;

    static tilep tile;
    if (!tile) {
        tile = tile_find("snow_mound5");
    }

    fpoint tl, br;

    blit_init();

    cloud *f;
    cloud *f_eo = clouds + nclouds;

    f = clouds;

    while (f < f_eo) {
        if (!f->active) {
            f->active = true;

            f->x = myrand() % (int)w;
            f->y = myrand() % (int)h;
            f->scale = gauss(1.5, 0.2);
        }

        double dw = cloud_w * (f->scale + 0.2);
        double dh = cloud_h * (f->scale + 0.2);

        tl.x = f->x - dw;
        tl.y = f->y - dh;
        br.x = f->x + dw;
        br.y = f->y + dh;

        color c = BLACK;
        c.a = 100.0;
        glcolor(c);
        tl.x += w / 20;
        tl.y += w / 12;
        br.x += w / 20;
        br.y += w / 12;

        if (display) {
            tile_blit_fat(0, tile, 0, &tl, &br);
        }

        f++;
    }

    f = clouds;

    while (f < f_eo) {
        double dw = cloud_w * f->scale;
        double dh = cloud_h * f->scale;

        tl.x = f->x - dw;
        tl.y = f->y - dh;
        br.x = f->x + dw;
        br.y = f->y + dh;

        f->x += wind;

        color c = WHITE;
        c.a = 150.0;
        glcolor(c);

        if (display) {
            tile_blit_fat(0, tile, 0, &tl, &br);
        }

        f++;
    }

    blit_flush();

    cloud_move(false);
}