Example #1
0
// if colornum==-1, create new color
int GFX_MakeRandomCustomColor(int colornum){
  static int num_colors = first_custom_colornum;

  if (colornum==-1)
    colornum = num_colors++;

  custom_colors[colornum] = mix_colors(QColor(qrand()%255,qrand()%255,qrand()%255), get_qcolor(HIGH_EDITOR_BACKGROUND_COLOR_NUM), 0.10f);

  return colornum;
}
Example #2
0
// if colornum==-1, create new color
int GFX_MakeRandomCustomColor(struct Tracker_Windows *tvisual, int colornum){
  static int num_colors = first_custom_colornum;

  if (colornum==-1)
    colornum = num_colors++;

  EditorWidget *editor=(EditorWidget *)tvisual->os_visual.widget;

  custom_colors[colornum] = mix_colors(QColor(qrand()%255,qrand()%255,qrand()%255), editor->colors[15], 0.10f);

  return colornum;
}
Example #3
0
static void configure_note_colors(void){
  for(int i=0;i<NUM_NOTE_COLOR_CONF;i++){
    QColor start_color = get_custom_qcolor(note_color_conf[i][1]);
    QColor end_color = get_custom_qcolor(note_color_conf[i+1][1]);
    int start_note = note_color_conf[i][0];
    int end_note = note_color_conf[i+1][0];

    if(start_note<64)
      start_color = get_qcolor(TEXT_COLOR_NUM);
    else
      end_color = get_qcolor(WAVEFORM_COLOR_NUM);

    for(int note=start_note;note<end_note;note++){
      //printf("setting %d (%d-%d) to %d %d %f\n",note,start_note,end_note,note_color_conf[i][1], note_color_conf[i+1][1], (float)(note-start_note)/(end_note-start_note));
      g_note_colors[note] = mix_colors(end_color, start_color, (float)(note-start_note)/(end_note-start_note));
    }
  }
}
Example #4
0
static void configure_note_colors(EditorWidget *editor){
  for(int i=0;i<NUM_NOTE_COLOR_CONF;i++){
    QColor start_color = editor->colors[note_color_conf[i][1]];
    QColor end_color = editor->colors[note_color_conf[i+1][1]];
    int start_note = note_color_conf[i][0];
    int end_note = note_color_conf[i+1][0];

    if(start_note<64)
      start_color = editor->colors[1];
    else
      end_color = editor->colors[2];

    for(int note=start_note;note<end_note;note++){
      //printf("setting %d (%d-%d) to %d %d %f\n",note,start_note,end_note,note_color_conf[i][1], note_color_conf[i+1][1], (float)(note-start_note)/(end_note-start_note));
      g_note_colors[note] = mix_colors(end_color, start_color, (float)(note-start_note)/(end_note-start_note));
    }
  }
}
void
ProcessController::DefaultColors()
{
	swap_color.red = 203;
	swap_color.green = 0;
	swap_color.blue = 0;
	swap_color.alpha = 255;
	bool set = false;

	if (!set) {
		active_color = kKernelBlue;
		active_color = tint_color (active_color, B_LIGHTEN_2_TINT);
		idle_color = active_color;
		idle_color.green /= 3;
		idle_color.red /= 3;
		idle_color.blue /= 3;
		frame_color = kBlack;
		mix_colors (memory_color, active_color, swap_color, 0.2);
	}
}
Example #6
0
File: cmdline.c Project: sklnd/vifm
/*
 * op == 0 - draw
 * op < 0 - redraw
 * op > 0 - reset
 */
static void
draw_wild_menu(int op)
{
	static int last_pos;

	const char ** list = get_completion_list();
	int pos = get_completion_pos();
	int count = get_completion_count() - 1;
	int i;
	int len = getmaxx(stdscr);
	
	if(sub_mode == MENU_CMD_SUBMODE || input_stat.complete == NULL)
		return;

	if(count < 2)
		return;

	if(op > 0)
	{
		last_pos = 0;
		return;
	}

	if(pos == 0 || pos == count)
		last_pos = 0;
	if(last_pos == 0 && pos == count - 1)
		last_pos = count;
	if(pos < last_pos)
	{
		int l = len;
		while(last_pos > 0 && l > 2)
		{
			last_pos--;
			l -= strlen(list[last_pos]);
			if(last_pos != 0)
				l -= 2;
		}
		if(l < 2)
			last_pos++;
	}

	werase(stat_win);
	wmove(stat_win, 0, 0);

	for(i = last_pos; i < count && len > 0; i++)
	{
		len -= strlen(list[i]);
		if(i != 0)
			len -= 2;

		if(i == last_pos && last_pos > 0)
		{
			wprintw(stat_win, "< ");
		}
		else if(i > last_pos)
		{
			if(len < 2)
			{
				wprintw(stat_win, " >");
				break;
			}
			wprintw(stat_win, "  ");
		}

		if(i == pos)
		{
			col_attr_t col;
			col = cfg.cs.color[STATUS_LINE_COLOR];
			mix_colors(&col, &cfg.cs.color[MENU_COLOR]);

			init_pair(DCOLOR_BASE + MENU_COLOR, col.fg, col.bg);
			wbkgdset(stat_win, COLOR_PAIR(DCOLOR_BASE + MENU_COLOR) | col.attr);
		}
		wprint(stat_win, list[i]);
		if(i == pos)
		{
			wbkgdset(stat_win, COLOR_PAIR(DCOLOR_BASE + STATUS_LINE_COLOR) |
					cfg.cs.color[STATUS_LINE_COLOR].attr);
			pos = -pos;
		}
	}
	if(pos > 0 && pos != count)
	{
		last_pos = pos;
		draw_wild_menu(op);
		return;
	}
	if(op == 0 && len < 2 && i - 1 == pos)
		last_pos = i;
	wrefresh(stat_win);
}
static void
decorate_text (GimpAboutDialog *dialog,
               gint             anim_type,
               gdouble          time)
{
  GtkStyle       *style = gtk_widget_get_style (dialog->anim_area);
  const gchar    *text;
  const gchar    *ptr;
  gint            letter_count = 0;
  gint            text_length  = 0;
  gint            text_bytelen = 0;
  gint            cluster_start, cluster_end;
  gunichar        unichr;
  PangoAttrList  *attrlist = NULL;
  PangoAttribute *attr;
  PangoRectangle  irect = {0, 0, 0, 0};
  PangoRectangle  lrect = {0, 0, 0, 0};
  GdkColor        mix;

  mix_colors (style->bg + GTK_STATE_NORMAL,
              style->fg + GTK_STATE_NORMAL, &mix, time);

  text = pango_layout_get_text (dialog->layout);
  g_return_if_fail (text != NULL);

  text_length = g_utf8_strlen (text, -1);
  text_bytelen = strlen (text);

  attrlist = pango_attr_list_new ();

  dialog->textrange[0] = 0;
  dialog->textrange[1] = text_bytelen;

  switch (anim_type)
    {
    case 0: /* Fade in */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_insert (attrlist, attr);
      break;

    case 1: /* Fade in, spread */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          ptr = g_utf8_next_char (ptr);
          cluster_end = (ptr - text);

          if (unichr == 0x200b)
            {
              lrect.width = (1.0 - time) * 15.0 * PANGO_SCALE + 0.5;
              attr = pango_attr_shape_new (&irect, &lrect);
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);
            }
          cluster_start = cluster_end;
        }
      break;

    case 2: /* Fade in, sinewave */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;

      while ((unichr = g_utf8_get_char (ptr)))
        {
          if (unichr == 0x200b)
            {
              cluster_end = ptr - text;
              attr = pango_attr_rise_new ((1.0 -time) * 18000 *
                                          sin (4.0 * time +
                                               (float) letter_count * 0.7));
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);

              letter_count++;
              cluster_start = cluster_end;
            }

          ptr = g_utf8_next_char (ptr);
        }
      break;

    case 3: /* letterwise Fade in */
      ptr = text;

      letter_count  = 0;
      cluster_start = 0;

      while ((unichr = g_utf8_get_char (ptr)))
        {
          gint    border = (text_length + 15) * time - 15;
          gdouble pos;

          if (letter_count < border)
            pos = 0;
          else if (letter_count > border + 15)
            pos = 1;
          else
            pos = ((gdouble) (letter_count - border)) / 15;

          mix_colors (style->fg + GTK_STATE_NORMAL,
                      style->bg + GTK_STATE_NORMAL,
                      &mix, pos);

          ptr = g_utf8_next_char (ptr);

          cluster_end = ptr - text;

          attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
          attr->start_index = cluster_start;
          attr->end_index = cluster_end;
          pango_attr_list_change (attrlist, attr);

          if (pos < 1.0)
            dialog->textrange[1] = cluster_end;

          letter_count++;
          cluster_start = cluster_end;
        }

      break;

    default:
      g_printerr ("Unknown animation type %d\n", anim_type);
    }

  pango_layout_set_attributes (dialog->layout, attrlist);
  pango_attr_list_unref (attrlist);
}
Example #8
0
static void
status_bar_message_i(const char message[], int error)
{
	/* TODO: Refactor this function status_bar_message_i() */

	static char *msg;
	static int err;

	int len;
	const char *p, *q;
	int lines;
	int status_bar_lines;
	size_t screen_length;
	const char *out_msg;
	char truncated_msg[2048];

	if(curr_stats.load_stage == 0)
	{
		return;
	}

	if(message != NULL)
	{
		if(replace_string(&msg, message))
		{
			return;
		}

		err = error;

		save_status_bar_msg(msg);
	}

	if(msg == NULL || vle_mode_is(CMDLINE_MODE))
	{
		return;
	}

	p = msg;
	q = msg - 1;
	status_bar_lines = 0;
	len = getmaxx(stdscr);
	while((q = strchr(q + 1, '\n')) != NULL)
	{
		status_bar_lines += DIV_ROUND_UP(q - p, len );
		if(q == p)
		{
			++status_bar_lines;
		}
		p = q + 1;
	}
	if(*p == '\0')
	{
		++status_bar_lines;
	}
	screen_length = utf8_strsw(p);
	status_bar_lines += DIV_ROUND_UP(screen_length, len);
	if(status_bar_lines == 0)
	{
		status_bar_lines = 1;
	}

	lines = status_bar_lines;
	if(status_bar_lines > 1 || screen_length > (size_t)getmaxx(status_bar))
	{
		++lines;
	}

	out_msg = msg;

	if(lines > 1)
	{
		if(cfg.trunc_normal_sb_msgs && !err && curr_stats.allow_sb_msg_truncation)
		{
			truncate_with_ellipsis(msg, getmaxx(stdscr) - FIELDS_WIDTH(),
					truncated_msg);
			out_msg = truncated_msg;
			lines = 1;
		}
		else
		{
			const int extra = DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG) - 1, len) - 1;
			lines += extra;
		}
	}

	if(lines > getmaxy(stdscr))
	{
		lines = getmaxy(stdscr);
	}

	(void)ui_stat_reposition(lines);
	mvwin(status_bar, getmaxy(stdscr) - lines, 0);
	if(lines == 1)
	{
		wresize(status_bar, lines, getmaxx(stdscr) - FIELDS_WIDTH());
	}
	else
	{
		wresize(status_bar, lines, getmaxx(stdscr));
	}
	checked_wmove(status_bar, 0, 0);

	if(err)
	{
		col_attr_t col = cfg.cs.color[CMD_LINE_COLOR];
		mix_colors(&col, &cfg.cs.color[ERROR_MSG_COLOR]);
		wattron(status_bar, COLOR_PAIR(colmgr_get_pair(col.fg, col.bg)) | col.attr);
	}
	else
	{
		int attr = cfg.cs.color[CMD_LINE_COLOR].attr;
		wattron(status_bar, COLOR_PAIR(cfg.cs.pair[CMD_LINE_COLOR]) | attr);
	}
	werase(status_bar);

	wprint(status_bar, out_msg);
	multiline_status_bar = lines > 1;
	if(multiline_status_bar)
	{
		checked_wmove(status_bar,
				lines - DIV_ROUND_UP(ARRAY_LEN(PRESS_ENTER_MSG), len), 0);
		wclrtoeol(status_bar);
		if(lines < status_bar_lines)
			wprintw(status_bar, "%d of %d lines.  ", lines, status_bar_lines);
		wprintw(status_bar, "%s", PRESS_ENTER_MSG);
	}

	wattrset(status_bar, 0);

	update_all_windows();
	/* This is needed because update_all_windows() doesn't call doupdate() if
	 * curr_stats.load_stage == 1. */
	doupdate();
}
Example #9
0
void draw_sprite(TileSet * tileset, s_sprite sprite, s_map_block * block, float x, float y, int shrink, bool flip = 0, int offset = 0, bool shiftup = false)
{
    if(offset < 0)
        return;
    int target_width = al_get_bitmap_width(al_get_target_bitmap());
    int target_height = al_get_bitmap_height(al_get_target_bitmap());
    if((x + sprite.origin_x > target_width) || (y + sprite.origin_y > target_height) ||
        ((x + sprite.origin_x + sprite.width) < 0) || ((y + sprite.origin_y + (sprite.height - shrink)) < 0))return;
    int flags = 0;
    if(flip)
        flags = ALLEGRO_FLIP_HORIZONTAL;
    ALLEGRO_COLOR color;
    switch(sprite.color_by)
    {
    case COLOR_NONE:
        color = block->light;
        break;
    case COLOR_INI:
        color = mix_colors(sprite.color, block->light);
        break;
    case COLOR_BIOME:
        color = mix_colors(block->biome_color, block->light);
        break;
    case COLOR_COMBINED:
        color = mix_colors(block->combined_color, block->light);
        break;
    case COLOR_STRUCTURE:
        color = mix_colors(block->structure_color, block->light);
        break;
    case COLOR_TRADE:
        color = mix_colors(block->trade_color, block->light);
        break;
    case COLOR_PALETTE:
        switch(sprite.color_source)
        {
        case SOURCE_ELEV:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number, block->height), block->light);
            break;
        case SOURCE_DEPTH:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->water_height-block->height), block->light);
            break;
        case SOURCE_TEMPERATURE:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_TEMPERATURE]), block->light);
            break;
        case SOURCE_RAINFALL:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_RAINFALL]), block->light);
            break;
        case SOURCE_DRAINAGE:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_DRAINAGE]), block->light);
            break;
        case SOURCE_SAVAGERY:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SAVAGERY]), block->light);
            break;
        case SOURCE_VOLCANISM:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_VOLCANISM]), block->light);
            break;
        case SOURCE_EVIL:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_EVIL]), block->light);
            break;
        case SOURCE_SALINITY:
            color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SALINITY]), block->light);
            break;
        default:
            color = block->light;
        }
        break;
    default:
        color = block->light;
        break;
    }
    al_draw_tinted_bitmap_region(
        imagelist.get_image(sprite.index),
        color,
        sprite.x + (sprite.width * offset),
        sprite.y + ((!shiftup)*shrink),
        sprite.width,
        sprite.height - shrink,
        x + sprite.origin_x,
        y + sprite.origin_y,
        flags);
}
Example #10
0
unsigned int GFX_mix_colors(unsigned int c1, unsigned int c2, float how_much){
  return mix_colors(QColor(c1), QColor(c2), how_much).rgb();
}
Example #11
0
File: menus.c Project: lyuts/vifm
void
draw_menu(menu_info *m)
{
	int i;
	int win_len;
	int x, y;

	getmaxyx(menu_win, y, x);
	win_len = x;
	werase(menu_win);

	normalize_top(m);

	x = m->top;

	box(menu_win, 0, 0);
	wattron(menu_win, A_BOLD);
	checked_wmove(menu_win, 0, 3);
	wprint(menu_win, m->title);
	wattroff(menu_win, A_BOLD);

	for(i = 1; x < m->len; i++, x++)
	{
		int z, off;
		char *buf;
		char *ptr = NULL;
		col_attr_t col;
		int type = WIN_COLOR;

		chomp(m->items[x]);
		if((ptr = strchr(m->items[x], '\n')) || (ptr = strchr(m->items[x], '\r')))
			*ptr = '\0';

		col = cfg.cs.color[WIN_COLOR];

		if(cfg.hl_search && m->matches != NULL && m->matches[x])
		{
			mix_colors(&col, &cfg.cs.color[SELECTED_COLOR]);
			type = SELECTED_COLOR;
		}

		init_pair(DCOLOR_BASE + type, col.fg, col.bg);
		wattron(menu_win, COLOR_PAIR(DCOLOR_BASE + type) | col.attr);

		z = m->hor_pos;
		off = 0;
		while(z-- > 0 && m->items[x][off] != '\0')
		{
			size_t l = get_char_width(m->items[x] + off);
			off += l;
		}

		buf = strdup(m->items[x] + off);
		for(z = 0; buf[z] != '\0'; z++)
			if(buf[z] == '\t')
				buf[z] = ' ';

		checked_wmove(menu_win, i, 2);
		if(get_screen_string_length(buf) > win_len - 4)
		{
			size_t len = get_normal_utf8_string_widthn(buf, win_len - 3 - 4);
			memset(buf + len, ' ', strlen(buf) - len);
			buf[len + 3] = '\0';
			wprint(menu_win, buf);
			mvwaddstr(menu_win, i, win_len - 5, "...");
		}
		else
		{
			const size_t len = get_normal_utf8_string_widthn(buf, win_len - 4);
			buf[len] = '\0';
			wprint(menu_win, buf);
		}
		waddstr(menu_win, " ");

		free(buf);

		wattroff(menu_win, COLOR_PAIR(DCOLOR_BASE + type) | col.attr);

		if(i + 3 > y)
			break;
	}
}
Example #12
0
File: menus.c Project: lyuts/vifm
void
move_to_menu_pos(int pos, menu_info *m)
{
	/* TODO: refactor this function move_to_menu_pos() */

	int redraw = 0;
	int x, z;
	char *buf = NULL;
	col_attr_t col;
	int off = 0;

	pos = MIN(m->len - 1, MAX(0, pos));
	if(pos < 0)
		return;

	normalize_top(m);

	if(pos > get_last_visible_line(m))
	{
		m->top = pos - (m->win_rows - 2 - 1);
		redraw = 1;
	}
	else if(pos < m->top)
	{
		m->top = pos;
		redraw = 1;
	}

	if(cfg.scroll_off > 0)
	{
		int s = MIN(DIV_ROUND_UP(m->win_rows - 2, 2), cfg.scroll_off);
		if(pos - m->top < s && m->top > 0)
		{
			m->top -= s - (pos - m->top);
			normalize_top(m);
			redraw = 1;
		}
		if(pos > get_last_visible_line(m) - s)
		{
			m->top += s - (get_last_visible_line(m) - pos);
			normalize_top(m);
			redraw = 1;
		}
	}

	m->current = 1 + (pos - m->top);

	if(redraw)
		draw_menu(m);

	x = getmaxx(menu_win) + get_utf8_overhead(m->items[pos]);
	buf = malloc(x + 2);
	if(buf == NULL)
		return;
	/* TODO: check if this can be false. */
	if(m->items[pos] != NULL)
	{
		z = m->hor_pos;
		while(z-- > 0 && m->items[pos][off] != '\0')
		{
			size_t l = get_char_width(m->items[pos] + off);
			off += l;
			x -= l - 1;
		}

		snprintf(buf, x, " %s", m->items[pos] + off);
	}
	else
	{
		buf[0] = '\0';
	}

	for(z = 0; buf[z] != '\0'; z++)
		if(buf[z] == '\t')
			buf[z] = ' ';

	for(z = strlen(buf); z < x; z++)
		buf[z] = ' ';

	buf[x] = ' ';
	buf[x + 1] = '\0';

	col = cfg.cs.color[WIN_COLOR];

	if(cfg.hl_search && m->matches != NULL && m->matches[pos])
		mix_colors(&col, &cfg.cs.color[SELECTED_COLOR]);

	mix_colors(&col, &cfg.cs.color[CURR_LINE_COLOR]);

	init_pair(DCOLOR_BASE + MENU_CURRENT_COLOR, col.fg, col.bg);
	wattrset(menu_win, COLOR_PAIR(DCOLOR_BASE + MENU_CURRENT_COLOR) | col.attr);

	checked_wmove(menu_win, m->current, 1);
	if(get_screen_string_length(m->items[pos] + off) > getmaxx(menu_win) - 4)
	{
		size_t len = get_normal_utf8_string_widthn(buf,
				getmaxx(menu_win) - 3 - 4 + 1);
		memset(buf + len, ' ', strlen(buf) - len);
		buf[len + 3] = '\0';
		wprint(menu_win, buf);
		mvwaddstr(menu_win, m->current, getmaxx(menu_win) - 5, "...");
	}
	else
	{
		size_t len = get_normal_utf8_string_widthn(buf, getmaxx(menu_win) - 4 + 1);
		buf[len] = '\0';
		wprint(menu_win, buf);
	}
	waddstr(menu_win, " ");

	wattroff(menu_win, COLOR_PAIR(DCOLOR_BASE + MENU_CURRENT_COLOR) | col.attr);

	m->pos = pos;
	free(buf);
	show_position_in_menu(m);
}
Example #13
0
File: menus.c Project: lyuts/vifm
void
clean_menu_position(menu_info *m)
{
	int x, z;
	int off = 0;
	char * buf = (char *)NULL;
	col_attr_t col;
	int type = MENU_COLOR;

	x = getmaxx(menu_win) + get_utf8_overhead(m->items[m->pos]);

	buf = malloc(x + 2);

	/* TODO: check if this can ever be false. */
	if(m->items[m->pos] != NULL)
	{
		z = m->hor_pos;
		while(z-- > 0 && m->items[m->pos][off] != '\0')
		{
			size_t l = get_char_width(m->items[m->pos] + off);
			off += l;
			x -= l - 1;
		}
		snprintf(buf, x, " %s", m->items[m->pos] + off);
	}
	else
	{
		buf[0] = '\0';
	}

	for(z = 0; buf[z] != '\0'; z++)
		if(buf[z] == '\t')
			buf[z] = ' ';

	for(z = strlen(buf); z < x; z++)
		buf[z] = ' ';

	buf[x] = ' ';
	buf[x + 1] = '\0';

	col = cfg.cs.color[WIN_COLOR];

	if(cfg.hl_search && m->matches != NULL && m->matches[m->pos])
	{
		mix_colors(&col, &cfg.cs.color[SELECTED_COLOR]);
		type = SELECTED_COLOR;
	}

	init_pair(DCOLOR_BASE + type, col.fg, col.bg);
	wattrset(menu_win, COLOR_PAIR(type + DCOLOR_BASE) | col.attr);

	checked_wmove(menu_win, m->current, 1);
	if(get_screen_string_length(m->items[m->pos] + off) > getmaxx(menu_win) - 4)
	{
		size_t len = get_normal_utf8_string_widthn(buf,
				getmaxx(menu_win) - 3 - 4 + 1);
		memset(buf + len, ' ', strlen(buf) - len);
		buf[len + 3] = '\0';
		wprint(menu_win, buf);
		mvwaddstr(menu_win, m->current, getmaxx(menu_win) - 5, "...");
	}
	else
	{
		size_t len = get_normal_utf8_string_widthn(buf, getmaxx(menu_win) - 4 + 1);
		buf[len] = '\0';
		wprint(menu_win, buf);
	}
	waddstr(menu_win, " ");

	wattroff(menu_win, COLOR_PAIR(type + DCOLOR_BASE) | col.attr);

	free(buf);
}
Example #14
0
/*******************************************************************************
 * For each pixel we must generate a primary ray and test for intersection with
 * all of the objects in the scene. If there is more than one ray-object
 * intersection then we must choose the closest intersection (the smallest
 * positive value of t).To ensure that there are no objects intersected in
 * front of the image plane (this is called near plane clipping), we keep the
 * distance of the primary ray to the screen and test all intersections against
 * this distance. If the t value is less than this distance, then we ignore the
 * object.
 *
 * If there is an intersection then we must compute the shadow rays and the
 * reflection rays. */
color_t trace_ray(ray3_t* test_ray, int depth) {
  int    occluded = 0;
  ray3_t shadow_ray;
  ray3_t reflected_ray;
  color_t ray_color = { 0.0, 0.0, 0.0, 0.0 };
  color_t nul_color = {0.0, 0.0, 0.0, 1.0};
  light_t* light_ptr = 0;
  double intersect_ray_length_curr = 0.0;
  double intersect_ray_length_close = 0.0;
  int     intersection_exists = 0;
  colored_sphere_t* sphere_close_ptr = 0;
  vector3_t intersection;
  vector3_t intersection_vector;
  int sphere_index = 0;
  int light_index = 0;
  int shadow_index;
  color_t add_color;

  /* test ray against all objects in scene, search until closest intersection
   * is found. */
  for (sphere_index = 0; sphere_index < sphere_list_count; ++sphere_index) {
    colored_sphere_t* sphere_ptr = &sphere_list[sphere_index];

    /* test for intersection between ray and scene object */
    if (1 == find_ray_sphere_intersect(test_ray, &sphere_ptr->sphere, &intersect_ray_length_curr)) {
      if (intersect_ray_length_curr < 0.0)
        continue;

      if (0 == intersection_exists) {
        intersection_exists = 1;
        intersect_ray_length_close = intersect_ray_length_curr;
        sphere_close_ptr = sphere_ptr;
      }
      else if (intersect_ray_length_curr < intersect_ray_length_close) {
        intersect_ray_length_curr = intersect_ray_length_close;
        sphere_close_ptr = sphere_ptr;
      }
    }
  }

  if (1 == intersection_exists) {
    intersection.x = test_ray->origin.x + test_ray->vector.x * intersect_ray_length_close;
    intersection.y = test_ray->origin.y + test_ray->vector.y * intersect_ray_length_close;
    intersection.z = test_ray->origin.z + test_ray->vector.z * intersect_ray_length_close;

    shadow_ray.origin = intersection;

    /* Shadow rays are sent towards all light sources to determine if any objects occlude the intersection spot. */
    for (light_index = 0; light_index < light_list_count; ++light_index) {
      occluded = 0;
      light_ptr = &light_list[light_index];
      shadow_ray.vector.x = (light_ptr->origin.x - shadow_ray.origin.x);
      shadow_ray.vector.y = (light_ptr->origin.y - shadow_ray.origin.y);
      shadow_ray.vector.z = (light_ptr->origin.z - shadow_ray.origin.z);
      normalize_vector(&shadow_ray.vector);

      /* Test intersection to determine if ray is in occlusion. */
      for (shadow_index = 0; shadow_index < sphere_list_count; ++shadow_index) {
        if (1 == find_ray_sphere_intersect(&shadow_ray, &sphere_list[shadow_index].sphere, &intersect_ray_length_curr)) {
          occluded = 1;
          break;
        }
      }

      if (occluded == 0) {
        /* Calculate the total light intensity. */
        double light_intensity = calc_dot_product(&shadow_ray.vector, &test_ray->vector);
        if (light_intensity < 0.0) light_intensity = -light_intensity;

        ray_color = mix_colors(&nul_color, &sphere_close_ptr->color, light_intensity);

        if (depth < 4) {
          reflected_ray.origin.x = intersection.x;
          reflected_ray.origin.y = intersection.y;
          reflected_ray.origin.z = intersection.z;

          intersection_vector.x = (intersection.x - sphere_close_ptr->sphere.center.x);
          intersection_vector.y = (intersection.y - sphere_close_ptr->sphere.center.y);
          intersection_vector.z = (intersection.z - sphere_close_ptr->sphere.center.z);

          normalize_vector(&intersection_vector);
          calc_reflected_vector(&reflected_ray.vector, &test_ray->vector, &intersection_vector);

          add_color = trace_ray(&reflected_ray, ++depth);
          if ((add_color.r != 0x00) ||
              (add_color.g != 0x00) ||
              (add_color.b != 0x00)) {
            double mix_ratio = calc_dot_product(&reflected_ray.vector, &intersection_vector);
            if (mix_ratio < 0.0) mix_ratio = -mix_ratio;
            ray_color = mix_colors(&ray_color, &add_color, mix_ratio);
          }
        }
      }
    }
  }

  return ray_color;
}
void
ProcessController::DoDraw(bool force)
{
	BRect bounds(Bounds());

	float h = floorf(bounds.Height ()) - 2;
	float top = 1, left = 1;
	float bottom = top + h;
	float barWidth = layout[gCPUcount].cpu_width;
	// interspace
	float right = left + gCPUcount * (barWidth + layout[gCPUcount].cpu_inter)
		- layout[gCPUcount].cpu_inter; // right of CPU frame...
	if (force && Parent()) {
		SetHighColor(Parent()->ViewColor());
		FillRect(BRect(right + 1, top - 1, right + 2, bottom + 1));
	}

	if (force) {
		SetHighColor(frame_color);
		StrokeRect(BRect(left - 1, top - 1, right, bottom + 1));
		if (gCPUcount > 1 && layout[gCPUcount].cpu_inter == 1) {
			for (unsigned int x = 1; x < gCPUcount; x++)
				StrokeLine(BPoint(left + x * barWidth + x - 1, top),
					BPoint(left + x * barWidth + x - 1, bottom));
		}
	}
	float leftMem = bounds.Width() - layout[gCPUcount].mem_width;
	if (force)
		StrokeRect(BRect(leftMem - 1, top - 1,
			leftMem + layout[gCPUcount].mem_width, bottom + 1));

	for (unsigned int x = 0; x < gCPUcount; x++) {
		right = left + barWidth - 1;
		float rem = fCPUTimes[x] * (h + 1);
		float barHeight = floorf (rem);
		rem -= barHeight;
		float limit = bottom - barHeight;	// horizontal line
		float previousLimit = bottom - fLastBarHeight[x];
		float idleTop = top;

		if (!force && previousLimit > top)
			idleTop = previousLimit - 1;
		if (limit > idleTop) {
			SetHighColor(idle_color);
			FillRect(BRect(left, idleTop, right, limit - 1));
		}
		if (barHeight <= h) {
			rgb_color fraction_color;
			mix_colors(fraction_color, idle_color, active_color, rem);
			SetHighColor(fraction_color);
			StrokeLine(BPoint(left, bottom - barHeight), BPoint(right,
				bottom - barHeight));
		}
		float active_bottom = bottom;
		if (!force && previousLimit < bottom)
			active_bottom = previousLimit + 1;
		if (limit < active_bottom) {
			SetHighColor(active_color);
			FillRect(BRect(left, limit + 1, right, active_bottom));
		}
		left += layout[gCPUcount].cpu_width + layout[gCPUcount].cpu_inter;
		fLastBarHeight[x] = barHeight;
	}

	float rightMem = bounds.Width() - 1;
	float rem = fMemoryUsage * (h + 1);
	float barHeight = floorf(rem);
	rem -= barHeight;

	rgb_color used_memory_color;
	float sq = fMemoryUsage * fMemoryUsage;
	sq *= sq;
	sq *= sq;
	mix_colors(used_memory_color, memory_color, swap_color, sq);

	float limit = bottom - barHeight;	// horizontal line
	float previousLimit = bottom - fLastMemoryHeight;
	float free_top = top;
	if (!force && previousLimit > top)
		free_top = previousLimit - 1;
	if (limit > free_top) {
		SetHighColor (idle_color);
		FillRect(BRect(leftMem, free_top, rightMem, limit - 1));
	}
	if (barHeight <= h) {
		rgb_color fraction_color;
		mix_colors(fraction_color, idle_color, used_memory_color, rem);
		SetHighColor(fraction_color);
		StrokeLine(BPoint(leftMem, bottom - barHeight), BPoint(rightMem,
			bottom - barHeight));
	}
	float usedBottom = bottom;
//	if (!force && previousLimit < bottom)
//		usedBottom = previousLimit + 1;
	if (limit < usedBottom) {
		SetHighColor(used_memory_color);
		FillRect(BRect(leftMem, limit + 1, rightMem, usedBottom));
	}
	fLastMemoryHeight = barHeight;
}
Example #16
0
static void updatePalette(EditorWidget *my_widget, QWidget *widget, QPalette &pal){
  if(system_color==NULL){
    system_color=new QColor(SETTINGS_read_string("system_color","#d2d0d5"));
    SETTINGS_write_string("system_color",system_color->name());
  }
  if(button_color==NULL){
    button_color=new QColor(SETTINGS_read_string("button_color","#c1f1e3"));
    SETTINGS_write_string("button_color",button_color->name());
  }

  if(override_default_qt_colors==false){
    //qapplication->setPalette(t.palette());

    //my_widget->setPalette( QApplication::palette( my_widget ) );
    return;
  }

  // Background
  {

    //QColor c(0xe5, 0xe5, 0xe5);
    QColor c(*system_color);
    QColor b(*button_color);

    if(dynamic_cast<QComboBox*>(widget)!=NULL){
      c = my_widget->colors[13];
      c=mix_colors(c.light(70),QColor(98,59,33),0.55);//editor->colors[colnum].light(52);
      c.setAlpha(76);
    }

    pal.setColor( QPalette::Active, QColorGroup::Background, b);
    pal.setColor( QPalette::Inactive, QColorGroup::Background, b);
    pal.setColor( QPalette::Disabled, QColorGroup::Background, b.light(95));

    pal.setColor( QPalette::Active, QColorGroup::Button, c);
    pal.setColor( QPalette::Inactive, QColorGroup::Button, c);
    pal.setColor( QPalette::Disabled, QColorGroup::Button, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::Base, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Base, c);
    pal.setColor(QPalette::Disabled, QColorGroup::Base, c.light(80));

    pal.setBrush(QPalette::Highlight, (const QBrush&)QBrush(b.light(85)));

    pal.setColor(QPalette::Disabled, QPalette::Light, c.light(80));

    //pal.setBrush((QPalette::ColorGroup)QColorGroup::Button, QPalette::Highlight, (const QBrush&)QBrush(b.light(95)));
    //pal.setBrush(QPalette::Highlight, QColorGroup::Button, QBrush(c.light(80)));
    //pal.setBrush(QPalette::Highlight, QColorGroup::Base, QBrush(c.light(80)));


#if 0
    pal.setColor(QPalette::Active, QColorGroup::Window, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Window, c);
    pal.setColor(QPalette::Disabled, QColorGroup::Window, c.light(80));
#endif

#if 0
    pal.setColor(QPalette::Active, QColorGroup::BrightText, c);
    pal.setColor(QPalette::Inactive, QColorGroup::BrightText, c);
    pal.setColor(QPalette::Disabled, QColorGroup::BrightText, c.light(80));
#endif

  }

  // Foreground, text, etc. (everything blackish)
  {
    QColor c(my_widget==NULL ? QColor(SETTINGS_read_string("color1","black")) : my_widget->colors[1]);
    c.setAlpha(180);

    pal.setColor(QPalette::Active, QColorGroup::Foreground, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Foreground, c.light(93));
    pal.setColor(QPalette::Disabled, QColorGroup::Foreground, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::Foreground, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Foreground, c.light(93));
    pal.setColor(QPalette::Disabled, QColorGroup::Foreground, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::ButtonText, c);
    pal.setColor(QPalette::Inactive, QColorGroup::ButtonText, c.light(93));
    pal.setColor(QPalette::Disabled, QColorGroup::ButtonText, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::ButtonText, c);
    pal.setColor(QPalette::Inactive, QColorGroup::ButtonText, c.light(93));
    pal.setColor(QPalette::Disabled, QColorGroup::ButtonText, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::Text, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Text, c.light(90));
    pal.setColor(QPalette::Disabled, QColorGroup::Text, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::HighlightedText, c.light(100));
    pal.setColor(QPalette::Inactive, QColorGroup::HighlightedText, c.light(90));
    pal.setColor(QPalette::Disabled, QColorGroup::HighlightedText, c.light(80));

    pal.setColor(QPalette::Active, QColorGroup::Text, c);
    pal.setColor(QPalette::Inactive, QColorGroup::Text, c.light(90));
    pal.setColor(QPalette::Disabled, QColorGroup::Text, c.light(80));
  }
}