Esempio n. 1
0
/*
  This function writes a string in a single line starting at a given
  position of the window, and without changing line. Each new line
  character contained in the string will be considered as a string
  termination, and if the string is too long to fit in the screen, it
  will be truncated. 
  
  So, if on the screen of the example we execute the functions:
  
  win_write_line_at(sc, 3, 26, "en un lugar de la mancha");
  win_write_line_at(sc, 5, 24, "oh!\nI didn't know");
   
  
  we get:
  
                       19             33
     0                  v             v    39
    +----------------------------------------+
  0 |                                        |
    |                                        |
    |                          en un lu      | < 2
    |                                        | 
    |                        oh!             |
    |                                        |
    |                                        | < 6
    |                                        | 
    |                                        |
   9|                                        |
    +----------------------------------------+
  
    Parameters:
      sc:  the window structure on which the function operates.
      r:   the row of the window at which the writing begins
      c:   the column of the window at which the writing begins
      str: the screen that we must write
  
    Returns:
      the number of characters actually written on the screen.
  
 */
int win_write_line_at(sc_rectangle *sc, int r, int c, char *str) {
    char *nl_p;
    char save, av_space, ret;

    if (!_is_visible(sc)) return 0;
    if (r >= sc->nr || c >= sc->nc) return 0;
    nl_p = strchr(str, '\n');
    if (nl_p) *nl_p = 0;
  
    av_space = sc->nc - c;
    save = -1;
    if (strlen(str) > av_space) {
        save = str[av_space - 1];
        str[av_space - 1] = 0;
    }
  
    _prepare_font(sc);
    _move_to(sc, r, c);
    printf("%s", str);
    fflush(stdout);
    if (save > 0) {
        str[av_space - 1] = save;
        ret = av_space;
    } else
        ret = strlen(str);
    if (nl_p) *nl_p = '\n';
    sc->last_line = r;
    return ret;
}
Esempio n. 2
0
/*
  Writes a char at a given position of the window.

    Parameters:
      sc:  the window structure on which the function operates.
      r:   the row of the window at which the writing begins
      c:   the column of the window at which the writing begins
      ch: the character that we must write
  
    Returns:
      The constant 1
  
*/
int win_write_char_at(sc_rectangle *sc, int r, int c, char ch) {
  
    if (!_is_visible(sc)) return 0;
    if (r >= sc->nr || c >= sc->nc) return 0;
  
    _move_to(sc, r, c);
    printf("%c", ch);
    fflush(stdout);
    return 1;
}
Esempio n. 3
0
static void
show_axis(cairo_t *cr, _point_t p, float r, float g, float b, float w, float h)
{
    _point_t ap[4];

    ap[0] = _move(p, _size(-w, 0));
    ap[1] = _move(p, _size( w, 0));
    ap[2] = _move(p, _size( 0, h));
    ap[3] = _move(p, _size( 0,-h));

    cairo_set_source_rgba(cr, r, g, b, 0.6);
    cairo_set_line_width(cr, 1.0);

    _move_to(cr, ap[0]);
    _line_to(cr, ap[1]);
    cairo_stroke(cr);

    _move_to(cr, ap[2]);
    _line_to(cr, ap[3]);
    cairo_stroke(cr);
}
Esempio n. 4
0
/*
  Clears a window, leaving it all in the current background color
  
  Parameters:
      sc: the window structure on which the function operates.
  
  Returns:
      nothing.
 */
void win_cls(sc_rectangle *sc) {
    char *buf;
    int i;
  
    sc->last_line = 0;
    //    if (!_is_visible(sc)) return;
    buf = (char *) malloc((sc->nc + 1) * sizeof (char));
    memset(buf, ' ', sc->nc);
    buf[sc->nc] = 0;
    _prepare_font(sc);
    for (i = sc->r1; i < sc->r1 + sc->nr; i++) {
        _move_to(sc, i - sc->r1, 0); /*Este -1 esta puesto de forma aleatoria, pero funciona*/
        printf("%s", buf);
        /*    printf("%d", i); 
            fflush(stdout); */
    }
    fflush(stdout);
    free(buf);
    return;
}
Esempio n. 5
0
static void 
draw_connect(cairo_t *cr, _point_t p1, _point_t p2, int type)
{
    _point_t ep[4], hp[5], sp[10];

    int mode = calc_connect_ep(p1, p2, ep, 50);

    switch (mode) {
    case 0:
	break;
    case 1:
	calc_connect_hp(p1, p2, ep, hp, mode, 50);
	calc_connect_sp(p1, p2, ep, hp, sp, mode, 50);
	break;
    }

    cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
    cairo_new_path(cr);
    _move_to(cr, p1);

    switch (mode) {
    case 1:
	_curve_to(cr, sp[1], sp[2], ep[1]);
	_curve_to(cr, sp[3], sp[4], hp[2]);
	_curve_to(cr, sp[5], sp[6], ep[2]);
	_curve_to(cr, sp[7], sp[8], p2);
	break;
    case 0:
	_curve_to(cr, ep[0], ep[3], p2);
	break;
    }

    cairo_set_source_rgba(cr, RGBA_CONNECT);
    cairo_set_line_width(cr, 4.0);
    cairo_stroke_preserve(cr);

    cairo_set_source_rgba(cr, RGBA_CONNECT_HL);
    cairo_set_line_width(cr, 3.0);
    cairo_stroke(cr);
}