Esempio n. 1
0
void LcdConsole::WriteChar(const char ch)
{
    if (ch == '\n')
    {
        do
        {
            WriteChar(' ');
        } while (m_cursor_x != 0);
    }
    else
    {
        CellData *cell = &m_buffer[m_cursor_y * m_max_text_x + m_cursor_x];
        if (cell->ch != ch || cell->color != m_typewriter.GetTextColor()
                || cell->bg_color != m_typewriter.GetBgColor())
        {
            const Lcd::Rect &region = m_lcd->GetRegion();
            m_lcd->SetRegion(Lcd::Rect{
                m_cursor_x * LcdTypewriter::GetFontW() + m_region.x,
                m_cursor_y * LcdTypewriter::GetFontH() + m_region.y,
                LcdTypewriter::GetFontW(), LcdTypewriter::GetFontH()});
            m_typewriter.WriteChar(ch);
            m_lcd->SetRegion(region);

            cell->ch = ch;
            cell->color = m_typewriter.GetTextColor();
            cell->bg_color = m_typewriter.GetBgColor();
        }
        NewChar();
    }
}
Esempio n. 2
0
# define PENDING(n)     (newscr->_line[n].firstchar != _NOCHANGE)

#endif /* !HASHDEBUG */

#define oldhash		(SP->oldhash)
#define newhash		(SP->newhash)
#define hashtab		(SP->hashtab)
#define lines_alloc	(SP->hashtab_len)

#if USE_WIDEC_SUPPORT
#define HASH_VAL(ch) (ch.chars[0])
#else
#define HASH_VAL(ch) (ch)
#endif

static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);

static NCURSES_INLINE unsigned long
hash(NCURSES_CH_T * text)
{
    int i;
    NCURSES_CH_T ch;
    unsigned long result = 0;
    for (i = TEXTWIDTH; i > 0; i--) {
	ch = *text++;
	result += (result << 5) + HASH_VAL(ch);
    }
    return result;
}

/* approximate update cost */
**	lib_add_wch.c
**
**	The routine wadd_wch().
**
*/

#include <curses.priv.h>

#if HAVE_WCTYPE_H
#include <wctype.h>
#endif

MODULE_ID("$Id: lib_add_wch.c,v 1.14 2019/01/19 15:46:25 tom Exp $")

/* clone/adapt lib_addch.c */
static const cchar_t blankchar = NewChar(BLANK_TEXT);

/*
 * Ugly microtweaking alert.  Everything from here to end of module is
 * likely to be speed-critical -- profiling data sure says it is!
 * Most of the important screen-painting functions are shells around
 * wadd_wch().  So we make every effort to reduce function-call overhead
 * by inlining stuff, even at the cost of making wrapped copies for
 * export.  Also we supply some internal versions that don't call the
 * window sync hook, for use by string-put functions.
 */

/* Return bit mask for clearing color pair number if given ch has color */
#define COLOR_MASK(ch) (~(attr_t)(((ch) & A_COLOR) ? A_COLOR : 0))

static NCURSES_INLINE cchar_t
Esempio n. 4
0
wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
{
    NCURSES_CH_T blank = NewChar(BLANK_TEXT);
    NCURSES_SIZE_T y = win->_cury;
    NCURSES_SIZE_T x = win->_curx;
    int code = OK;
    struct ldat *line;
    int i, j, start, len, end;

    T((T_CALLED("wadd_wchnstr(%p,%s,%d)"), win, _nc_viscbuf(astr, n), n));

    if (!win)
	returnCode(ERR);

    if (n < 0) {
	n = _nc_wchstrlen(astr);
    }
    if (n > win->_maxx - x + 1)
	n = win->_maxx - x + 1;
    if (n == 0)
	returnCode(code);

    line = &(win->_line[y]);
    start = x;
    end = x + n - 1;

    /*
     * Reset orphaned cells of multi-column characters that extend up to the
     * new string's location to blanks.
     */
    if (x > 0 && isWidecExt(line->text[x])) {
	for (i = 0; i <= x; ++i) {
	    if (!isWidecExt(line->text[x - i])) {
		/* must be isWidecBase() */
		start -= i;
		while (i > 0) {
		    line->text[x - i--] = _nc_render(win, blank);
		}
		break;
	    }
	}
    }

    /*
     * Copy the new string to the window.
     */
    for (i = 0; i < n && x <= win->_maxx; ++i) {
	if (isWidecExt(astr[i]))
	    continue;

	len = wcwidth(CharOf(astr[i]));

	if (x + len - 1 <= win->_maxx) {
	    line->text[x] = _nc_render(win, astr[i]);
	    if (len > 1) {
		for (j = 0; j < len; ++j) {
		    if (j != 0) {
			line->text[x + j] = line->text[x];
		    }
		    SetWidecExt(line->text[x + j], j);
		}
	    }
	    x += len;
	    end += len - 1;
	} else {
	    break;
	}
    }

    /*
     * Set orphaned cells of multi-column characters which lie after the new
     * string to blanks.
     */
    while (x <= win->_maxx && isWidecExt(line->text[x])) {
	line->text[x] = _nc_render(win, blank);
	++end;
	++x;
    }
    CHANGED_RANGE(line, start, end);

    _nc_synchook(win);
    returnCode(code);
}