Esempio n. 1
0
/**
 * Place some text on the screen using an attribute
 */
static errr Term_text_gcu(int x, int y, int n, int a, const wchar_t *s) {
	term_data *td = (term_data *)(Term->data);

#ifdef A_COLOR
	if (can_use_color) {
		/* the lower 7 bits of the attribute indicate the fg/bg */
		int attr = a & 127;
		int color = colortable[attr];

		/* the high bit of the attribute indicates a reversed fg/bg */
		bool reversed = a > 127;

		/* the following check for A_BRIGHT is to avoid #1813 */
		int mode;
		if (reversed && (color & A_BRIGHT))
			mode = (color & ~A_BRIGHT) | A_BLINK | A_REVERSE;
		else if (reversed)
			mode = color | A_REVERSE;
		else
			mode = color | A_NORMAL;

		wattrset(td->win, mode);
		mvwaddnwstr(td->win, y, x, s, n);
		wattrset(td->win, A_NORMAL);
		return 0;
	}
#endif

	mvwaddnwstr(td->win, y, x, s, n);
	return 0;
}
Esempio n. 2
0
File: base.c Progetto: chazu/stfl
unsigned int stfl_print_richtext(struct stfl_widget *w, WINDOW *win, unsigned int y, unsigned int x, const wchar_t * text, unsigned int width, const wchar_t * style_normal, int has_focus)
{
	const wchar_t *p = text;
	unsigned int retval = 0;

	unsigned int end_col = x + width;

	while (*p) {
		unsigned int len = compute_len_from_width(p, end_col - x);
		const wchar_t *p1 = wcschr(p, L'<');
		if (NULL == p1) {
			mvwaddnwstr(win, y, x, p, len);
			retval += len;
			break;
		} else {
			const wchar_t *p2 = wcschr(p1 + 1, L'>');

			if (len > (p1 - p))
				len = p1 - p;
			mvwaddnwstr(win, y, x, p, len);
			retval += len;
			x += wcswidth(p, len);

			if (p2) {
				wchar_t stylename[p2 - p1];
				wmemcpy(stylename, p1 + 1, p2 - p1 - 1);
				stylename[p2 - p1 - 1] = L'\0';
				if (wcscmp(stylename,L"")==0) {
					mvwaddnwstr(win, y, x, L"<", 1);
					retval += 1;
					++x;
				} else if (wcscmp(stylename, L"/")==0) {
					stfl_style(win, style_normal);
				} else {
					wchar_t lookup_stylename[128];
					const wchar_t * style;
					if (has_focus)
						swprintf(lookup_stylename, sizeof(lookup_stylename)/sizeof(*lookup_stylename), L"style_%ls_focus", stylename);
					else
						swprintf(lookup_stylename, sizeof(lookup_stylename)/sizeof(*lookup_stylename), L"style_%ls_normal", stylename);
					style = stfl_widget_getkv_str(w, lookup_stylename, L"");
					stfl_style(win, style);
				}
				p = p2 + 1;
			} else {
				break;
			}
		}
	}
	return retval;
}
Esempio n. 3
0
void splash_draw(ui_t *ui)
{
  int line = DSFY_MAX((ui->height - LOGO_HEIGHT * 2) / 2, 0);

  int x = DSFY_MAX((ui->width - LOGO_WIDTH) / 2, 0);

  wattron(ui->win, A_BOLD | COLOR_PAIR(UI_STYLE_DIM));
  for (int i = 0; i < LOGO_HEIGHT; ++i) {
    mvwaddnwstr(ui->win, ++line, x, g_wlogo[i], ui->width - x);
  }
  wattroff(ui->win, A_BOLD | COLOR_PAIR(UI_STYLE_DIM));

  mvwprintw(ui->win, line, x + 34, "despotify.se");
  mvwchgat(ui->win, line, x + 34, 12, A_BOLD | A_REVERSE, UI_STYLE_DIM, NULL);

  line += 2;

  mvwprintw(ui->win, ++line, x, "Type ':connect' to login, then press '/' to search for hits.");
  mvwprintw(ui->win, ++line, x + 3, "Press F1 for a list of all commands and key bindings.");

  line += 2;
  x += 18;

  mvwprintw(ui->win, ++line, x, "Web: http://despotify.se/");
  mvwprintw(ui->win, ++line, x, "IRC: #despotify @ EFNet");
}
Esempio n. 4
0
/**
 * mvwcch -- move the cursor and write a complex character and rendition
 * @win : pointer to a WINDOW
 * @y   : y-coordinate to write at
 * @x   : x-coordinate to write at
 * @wch : pointer to the wchar_t to be written
 * @attr: the desired window attributes
 * @pair: the desired color pair
 */
void mvwcch(WINDOW *win, int y, int x, const wchar_t *wch, attr_t attr, short pair)
{
        SAVEWIN(win);
        wattr_set(win, attr, pair, NULL);
        if (wch && (*wch != L'\0')) {
                mvwaddnwstr(win, y, x, wch, 1);
        }
        RESTORE(win);
}
Esempio n. 5
0
int t_mv_wprintn(WINDOW *win, int x, int y, int n, t_char *fmt, ...)
{
	wchar_t buf[MAX_PRINT_LEN];
	va_list args;
	va_start(args, fmt);
	vswprintf(buf, MAX_PRINT_LEN, fmt, args);
	va_end(args);

	return mvwaddnwstr(win, y, x, buf, n);
}
Esempio n. 6
0
/**
 * Place some text on the screen using an attribute
 */
static errr Term_text_gcu(int x, int y, int n, int a, const wchar_t *s) {
    term_data *td = (term_data *)(Term->data);

#ifdef A_COLOR
    if (can_use_color) {
        /* the lower 7 bits of the attribute indicate the fg/bg */
        int attr = a & 127;

        /* the high bit of the attribute indicates a reversed fg/bg */
        int flip = a > 127 ? A_REVERSE : A_NORMAL;

        wattrset(td->win, colortable[attr] | flip);
        mvwaddnwstr(td->win, y, x, s, n);
        wattrset(td->win, A_NORMAL);
        return 0;
    }
#endif

    mvwaddnwstr(td->win, y, x, s, n);
    return 0;
}
Esempio n. 7
0
static void wt_textview_draw(struct stfl_widget *w, struct stfl_form *f, WINDOW *win)
{
	//fix_offset_pos(w);

	int offset = stfl_widget_getkv_int(w, L"offset", 0);
	int is_richtext = stfl_widget_getkv_int(w, L"richtext", 0);

	const wchar_t *style_normal = stfl_widget_getkv_str(w, L"style_normal", L"");
	const wchar_t *style_end = stfl_widget_getkv_str(w, L"style_end", L"");

	struct stfl_widget *c;
	int i;

	stfl_style(win, style_normal);
	for (i=0, c=w->first_child; c && i < offset+w->h; i++, c=c->next_sibling)
	{
		const wchar_t *text = stfl_widget_getkv_str(c, L"text", L"");

		if (i < offset) {
			if (is_richtext)
				stfl_print_richtext(w, win, w->y, w->x, text, 0, style_normal, 0);
			continue;
		}

		if (is_richtext) {
			stfl_print_richtext(w, win, w->y+i-offset, w->x, text, w->w, style_normal, 0);
		} else {
			mvwaddnwstr(win, w->y+i-offset, w->x, text, w->w);
		}
	}

	stfl_style(win, style_end);
	while (i<offset+w->h) {
		mvwaddnwstr(win,w->y+i-offset,w->x,L"~",w->w);
		++i;
	}

	if (f->current_focus_id == w->id)
		f->root->cur_x = f->root->cur_y = f->cursor_x = f->cursor_y = -1;
}
Esempio n. 8
0
File: tasknc.c Progetto: irl/tasknc
int umvaddstr(WINDOW *win, const int y, const int x, const char *format, ...) /* {{{ */
{
	/* convert a string to a wchar string and mvaddwstr
	 * win    - the window to print the string in
	 * y      - the y coordinates to print the string at
	 * x      - the x coordinates to print the string at
	 * format - the format string to print
	 * additional args are accepted to use with the format string
	 * (similar to printf)
	 * return is the return of mvwaddnwstr
	 */
	int len, r;
	wchar_t *wstr;
	char *str;
	va_list args;

	/* build str */
	va_start(args, format);
	const int slen = sizeof(wchar_t)*(cols-x+1)/sizeof(char);
	str = calloc(slen, sizeof(char));
	vsnprintf(str, slen-1, format, args);
	va_end(args);

	/* allocate wchar_t string */
	len = strlen(str)+1;
	wstr = calloc(len, sizeof(wchar_t));

	/* check for valid allocation */
	if (wstr==NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "critical: umvaddstr failed to malloc");
		return -1;
	}

	/* perform conversion and write to screen */
	mbstowcs(wstr, str, len);
	len = wcslen(wstr);
	if (len>cols-x)
		len = cols-x;
	r = mvwaddnwstr(win, y, x, wstr, len);

	/* free memory allocated */
	free(wstr);
	free(str);

	return r;
} /* }}} */
Esempio n. 9
0
int
mvaddnwstr(int y, int x, wchar_t *ws, int n)
{
	return (mvwaddnwstr(stdscr, y, x, ws, n));
}
Esempio n. 10
0
 void CursesRenderer::drawChar(int x, int y, int c)
 {
   mvwaddnwstr(win(), y, x, (const wchar_t*) &c, 1);
 }
Esempio n. 11
0
static void uiview_draw_searchwin(void)
{
  if(listwin != NULL)
  {
    GSList *list = NULL;
    int i = 0;

    /* Search window border */
    wborder(listwin, 0, 0, 0, 0, 0, 0, 0, 0);

    /* Clear old results */
    if(search_results != NULL)
    {
      g_slist_free(search_results);
      search_results = NULL;
    }

    /* Find matching tracks */
    list = list_get();
    list_len = g_slist_length(list);
    for(i = 0; i < list_len; i++)
    {
      track_t *track = g_slist_nth_data(list, i);
      if(strcasestr(track->title, searchstr) ||
         strcasestr(track->artist, searchstr) ||
         strcasestr(track->path, searchstr))
      {
        search_results = g_slist_append(search_results, track);        
      }
    }
    list_len = g_slist_length(search_results);

    /* Try center around selected track */
    //if(prevent_offset_update == 0)
    {
      list_offset = search_selected - (track_max / 2);
      if((list_offset + track_max) > list_len)
      {
        list_offset = list_len - track_max;
      }
      if(list_offset < 0)
      {
        list_offset = 0;
      }
    }

    /* Determine max tracks to view */
    if(list_len > track_max)
    {
      view_max = track_max;
    }
    else
    {
      view_max = list_len;
    }

    /* Show track list */
    for(i = 0; i < view_max; i++)
    {
      wchar_t track_item[MW_W];
      track_t *track = NULL;
      track = g_slist_nth_data(search_results, i + list_offset);
      if((strlen(track->artist) > 0) && (strlen(track->title) > 0))
      {
        swprintf(track_item, MW_W - 3, L"%s - %s%-36s",
                 track->artist, track->title, "");
      }
      else
      {
        swprintf(track_item, MW_W - 3, L"%s%-36s", basename(track->path), "");
      }

      if((i + list_offset) == search_selected)
      {
        wattron(listwin, A_REVERSE);
        mvwaddnwstr(listwin, i + 1, 2, track_item, MW_W - 4);
        wattroff(listwin, A_REVERSE);
      }
      else
      {
        mvwaddnwstr(listwin, i + 1, 2, track_item, MW_W - 4);
      }
    }
    for(; i < track_max; i++)
    {
      mvwprintw(listwin, i + 1, 2, "%-36s", "");
    }
    list = NULL;

    /* Search window title */
    wattron(listwin, A_BOLD);      
    mvwprintw(listwin, 0, 2, " search: %-26s ", searchstr);
    wattroff(listwin, A_BOLD);
    wmove(listwin, 0, 11 + searchstr_pos);

    /* Refresh window */
    wrefresh(listwin);
  }
}
Esempio n. 12
0
static void uiview_draw_listwin(void)
{
  if(listwin != NULL)
  {
    GSList *list = NULL;
    int i = 0;
    track_t *current_track = NULL;

    /* List window border */
    wborder(listwin, 0, 0, 0, 0, 0, 0, 0, 0);

    /* List window title */
    if(listwinflag)
    {
      wattron(listwin, A_BOLD);      
      mvwprintw(listwin, 0, 15, " playlist ");
      wattroff(listwin, A_BOLD);
    }
    else
    {
      mvwprintw(listwin, 0, 15, " playlist ");
    }

    /* List tracks */
    list = list_get();
    list_len = g_slist_length(list);
    current_track = list_queue_current();

    /* Determine index of selected track */
    if(selected_track == -1)
    {
      track_t *track = NULL;
      for(i = 0; i < list_len; i++)
      {
        track = g_slist_nth_data(list, i + list_offset);
        if(track == current_track)
        {
          selected_track = i + list_offset;
        }
      }
    }

    /* Try center around selected track */
    if(prevent_offset_update == 0)
    {
      list_offset = selected_track - (track_max / 2);
      if((list_offset + track_max) > list_len)
      {
        list_offset = list_len - track_max;
      }
      if(list_offset < 0)
      {
        list_offset = 0;
      }
    }

    /* Determine max tracks to view */
    if(list_len > track_max)
    {
      view_max = track_max;
    }
    else
    {
      view_max = list_len;
    }

    /* Show track list */
    for(i = 0; i < view_max; i++)
    {
      wchar_t track_item[MW_W];
      track_t *track = NULL;
      track = g_slist_nth_data(list, i + list_offset);
      if((strlen(track->artist) > 0) && (strlen(track->title) > 0))
      {
        swprintf(track_item, MW_W - 3, L"%s - %s%-36s",
                 track->artist, track->title, "");
      }
      else
      {
        swprintf(track_item, MW_W - 3, L"%s%-36s", basename(track->path), "");
      }

      if(listwinflag && ((i + list_offset) == selected_track))
      {
        wattron(listwin, A_REVERSE);
        mvwaddnwstr(listwin, i + 1, 2, track_item, MW_W - 4);
        wattroff(listwin, A_REVERSE);
      }
      else
      {
        mvwaddnwstr(listwin, i + 1, 2, track_item, MW_W - 4);
      }
    }
    list = NULL;

    /* Refresh window */
    wrefresh(listwin);
  }
}
Esempio n. 13
0
static void uiview_draw_mainwin(void)
{
  int i = 0;
  wchar_t *tracktmp = NULL;
  wchar_t displaytitle[MAX_TRACK_SZ + 1] = { 0 };
  char displayshuffle = ' ';
  char displayrepeat = ' ';
  gint64 now_us = 0;
  gint64 offs = 0;

  /* Get current time */
  now_us = g_get_monotonic_time();

  /* Only perform update at certain interval (currently 100ms) */
  if((now_us - last_ui_update_us) > UI_UPDATE_US)
  {
    /* Main window border */
    wborder(mainwin, 0, 0, 0, 0, 0, 0, 0, 0);

    /* Main window title */
    if(!listwinflag)
    {
      wattron(mainwin, A_BOLD);      
      mvwprintw(mainwin, 0, 17, " namp ");
      wattroff(mainwin, A_BOLD);
    }
    else
    {
      mvwprintw(mainwin, 0, 17, " namp ");
    }

    /* Current track position */
    mvwprintw(mainwin, 1, 3, " %02d:%02d", 
              (trackposition / SECS_PER_MIN), 
              (trackposition % SECS_PER_MIN));

    /* Track title */
    if(trackname == NULL)
    {
      tracktmp = notracktitle;
    }
    else
    {
      tracktmp = trackname;
    }

    swprintf(displaytitle, MAX_TRACK_SZ, L"%ls", tracktmp + tracknameposition);

    mvwprintw(mainwin, 1, 11, "%-" STR(MAX_TRACK_SZ) "s", "");
    mvwaddnwstr(mainwin, 1, 11, displaytitle, sizeof(displaytitle));
    if(wcslen(tracktmp) > MAX_TRACK_SZ)
    {
      if((now_us - last_title_start_us) > TITLEHOLD_US)
      {
        offs = (((now_us-last_title_start_us)-TITLEHOLD_US)/TITLESTEP_US);
        tracknameposition = offs;
        if(tracknameposition > ((int)wcslen(tracktmp) - MAX_TRACK_SZ + 1))
        {
          if(last_title_stop_us < last_title_start_us)
          {
            last_title_stop_us = now_us;
          }

          if((now_us - last_title_stop_us) > TITLEHOLD_US)
          {
            tracknameposition = 0;
            last_title_start_us = now_us;            
          }
          else
          {
            tracknameposition = (wcslen(tracktmp) - MAX_TRACK_SZ + 1);
          }
        }
      }
    }

    /* Volume */
    mvwprintw(mainwin, 2, 11, "-                   +   PL");
    volume_draw_cnt = (19 * volumepercent) / 100;
    mvwhline(mainwin, 2, 12, 0, volume_draw_cnt);

    /* Progress */
    mvwprintw(mainwin, 3, 2, "|                                  |");
    if(trackduration != 0)
    {
      duration_draw_cnt = (34 * trackposition) / trackduration;
      mvwhline(mainwin, 3, 3, 0, duration_draw_cnt);
    }
    else
    {
      duration_draw_cnt = 0;
    }

    /* Spectrum */
    wmove(mainwin, 2, 2);
    for(i = 0; i < 8; i++)
    {
      waddnwstr(mainwin, &spectrum_wchars[spectrum[i]], 1);
    }

    /* Playback control buttons */
    if(shuffleflag)
    {
      displayshuffle = 'X';
    }
    if(repeatflag)
    {
      displayrepeat = 'X';
    }
    mvwprintw(mainwin, 4, 2, "|< |> || [] >|  [%c] Shuffle  [%c] Rep",
              displayshuffle, displayrepeat);

    /* Refresh window */
    wrefresh(mainwin);

    /* Store time */
    last_ui_update_us = now_us;
  }
}
Esempio n. 14
0
int t_mv_vwprintn(WINDOW *win, int x, int y, int n, t_char *fmt, va_list args)
{
	wchar_t buf[MAX_PRINT_LEN];
	vswprintf(buf, MAX_PRINT_LEN, fmt, args);
	return mvwaddnwstr(win, y, x, buf, n);
}