Example #1
0
void Font::draw_text_ellipsis(Canvas &canvas, float dest_x, float dest_y, Rectf content_box, const std::string &text, const Colorf &color)
{
	if (impl)
	{
		FontMetrics fm = get_font_metrics();
		int ascent = fm.get_ascent();
		int descent = fm.get_descent();
		int line_spacing = fm.get_height() + fm.get_external_leading();
		std::vector<std::string> lines = StringHelp::split_text(text, "\n", false);
		for (std::vector<std::string>::size_type i=0; i<lines.size(); i++)
		{
			if (i == 0 || (dest_y - ascent >= content_box.top && dest_y + descent < content_box.bottom))
			{
				Size size = get_text_size(canvas, lines[i]);
				if (dest_x + size.width <= content_box.right)
				{
					draw_text(canvas, dest_x, dest_y, lines[i], color);
				}
				else
				{
					Size ellipsis = get_text_size(canvas, "...");

					int seek_start = 0;
					int seek_end = lines[i].size();
					int seek_center = (seek_start + seek_end) / 2;

					UTF8_Reader utf8_reader(lines[i].data(), lines[i].length());
					while (true)
					{
						utf8_reader.set_position(seek_center);
						utf8_reader.move_to_leadbyte();
						if (seek_center != utf8_reader.get_position())
							utf8_reader.next();
						seek_center = utf8_reader.get_position();
						if (seek_center == seek_end)
							break;

						utf8_reader.set_position(seek_start);
						utf8_reader.next();
						if (utf8_reader.get_position() == seek_end)
							break;

						Size text_size = get_text_size(canvas, lines[i].substr(0, seek_center));

						if (dest_x + text_size.width + ellipsis.width >= content_box.right)
							seek_end = seek_center;
						else
							seek_start = seek_center;
						seek_center = (seek_start+seek_end)/2;
					}

					draw_text(canvas, dest_x, dest_y, lines[i].substr(0, seek_center) + "...", color);
				}

				dest_y += line_spacing;
			}
		}
	}
}
Example #2
0
/* berechnet alle Werte, die man zum Zeichnen eines Koordinatensystems
   und von Graphen benötigt, anhand der Größe des Feldes, und den
   maximal erwarteten Werten */
void coord_system_adjust(CoordSystem *coord, GtkWidget *darea,
                         gdouble min_x, gdouble max_x,
                         gdouble min_y, gdouble max_y)
{
    GdkScreen *screen;
    PangoLayout *layout;
    gint x_axis, y_axis, cm_x, cm_y;

    /* bricht ab, wenn der größte Wert niedriger als der
       Kleinste ist, oder umgekehrt */
    if (min_x >= max_x || min_y >= max_y)
        return;

    layout = g_object_get_data(G_OBJECT(darea), "layout");

    /* rechnet einen Zentimeter in Pixel um */
    screen = gdk_screen_get_default();
    cm_x = (gint) ((gdouble) (10 * gdk_screen_get_width(screen)) /
                   (gdouble) gdk_screen_get_width_mm(screen) + 0.5);
    cm_y = (gint) ((gdouble) (10 * gdk_screen_get_height(screen)) /
                   (gdouble) gdk_screen_get_height_mm(screen) + 0.5);

    /* kopiert die Minimal- und Maximalwerte in die Struktur */
    coord->min_x = min_x;
    coord->max_x = max_x;
    coord->min_y = min_y;
    coord->max_y = max_y;

    /* berechnet die Beginn- und Endpunkte der Achsen */
    coord->x_axis_begin = get_y_label_width(coord, layout) + 15;
    coord->x_axis_end = darea->allocation.width - ARROW_SHANK -
                        get_text_size(WIDTH, layout, "%s [%s]",
                        coord->x_title, coord->x_unit) - 5;
    coord->y_axis_begin = darea->allocation.height -
                          get_x_label_height(coord, layout) - 15;
    coord->y_axis_end = ARROW_SHANK + get_text_size(HEIGHT, layout,
                        "%s [%s]", coord->y_title, coord->y_unit) + 10;

    /* berechnet die Länge der Achsen */
    x_axis = ABS(coord->x_axis_end - coord->x_axis_begin);
    y_axis = ABS(coord->y_axis_end - coord->y_axis_begin);

    /* berechnet den Faktor zum Umrechnen der Größen */
    coord->x_fact = (gdouble) x_axis / (gdouble) (max_x - min_x);
    coord->y_fact = (gdouble) y_axis / (gdouble) (max_y - min_y);

    /* errechnet die Schrittgröße der Achsen */
    coord->step_x = gen_step_size(2 * cm_x / coord->x_fact, coord->fract_x);
    coord->step_y = gen_step_size(2 * cm_y / coord->y_fact, coord->fract_y);

    /* berechnet die Koordinaten des Ursprungs */
    coord->zero_x = coord->x_axis_begin - ((gdouble) x_axis *
                    ((gdouble) min_x / (gdouble) (max_x - min_x)));
    coord->zero_y = coord->y_axis_end + ((gdouble) y_axis *
                    ((gdouble) max_y / (gdouble) (max_y - min_y)));
}
Example #3
0
static int get_detailed_scroll_button_width(cairo_t *cairo,
		struct swaynag *swaynag) {
	int up_width, down_width, temp_height;
	get_text_size(cairo, swaynag->type->font, &up_width, &temp_height, NULL,
			swaynag->scale, true,
			"%s", swaynag->details.button_up.text);
	get_text_size(cairo, swaynag->type->font, &down_width, &temp_height, NULL,
			swaynag->scale, true,
			"%s", swaynag->details.button_down.text);

	int text_width =  up_width > down_width ? up_width : down_width;
	int border = swaynag->type->button_border_thickness * swaynag->scale;
	int padding = swaynag->type->button_padding * swaynag->scale;

	return text_width + border * 2 + padding * 2;
}
Example #4
0
static void render_details_scroll_button(cairo_t *cairo,
		struct swaynag *swaynag, struct swaynag_button *button) {
	int text_width, text_height;
	get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
			swaynag->scale, true, "%s", button->text);

	int border = swaynag->type->button_border_thickness * swaynag->scale;
	int padding = swaynag->type->button_padding * swaynag->scale;

	cairo_set_source_u32(cairo, swaynag->type->border);
	cairo_rectangle(cairo, button->x, button->y,
			button->width, button->height);
	cairo_fill(cairo);

	cairo_set_source_u32(cairo, swaynag->type->button_background);
	cairo_rectangle(cairo, button->x + border, button->y + border,
			button->width - (border * 2), button->height - (border * 2));
	cairo_fill(cairo);

	cairo_set_source_u32(cairo, swaynag->type->text);
	cairo_move_to(cairo, button->x + border + padding,
			button->y + border + (button->height - text_height) / 2);
	pango_printf(cairo, swaynag->type->font, swaynag->scale, true,
			"%s", button->text);
}
Example #5
0
void set_window_height(struct window *window, int height) {
		int text_width, text_height;
		get_text_size(window->cairo, window->font, &text_width, &text_height, "Test string for measuring purposes");
		if (height > 0) {
			margin = (height - text_height) / 2;
			ws_vertical_padding = margin - 1.5;
		}
		window->height = text_height + margin * 2;
}
Example #6
0
/* berechnet die Breite der Y-Achsen Beschriftung */
static gint get_y_label_width(CoordSystem *coord, PangoLayout *layout)
{
    gint pos, neg, title;

    pos = get_number_size(coord->max_y, coord->fract_y, WIDTH, layout);
    neg = get_number_size(coord->min_y, coord->fract_y, WIDTH, layout);
    title = get_text_size(WIDTH, layout, "%s [%s]",
                          coord->y_title, coord->y_unit);

    return max_n(3, pos, neg, title);
}
Example #7
0
g_size graph::get_text_size(const st_cell& text,const g_size& sz_father)
{
	const stFont* font = get_font(text.font);
	if (!font)
		return g_size(0,0);

	auto_free af(core::UTF8ToUnicode(text.text));
	if (af.ptr == 0)
		return g_size(0,0);
	g_size sz = get_text_size(text,sz_father,font,af.ptr);
	return sz;
}
Example #8
0
/* berechnet die Höhe der X-Achsen Beschriftung */
static gint get_x_label_height(CoordSystem *coord, PangoLayout *layout)
{
    gint pos, neg, title;

    pos = get_number_size(coord->max_x, coord->fract_x, HEIGHT, layout);
    neg = get_number_size(coord->min_x, coord->fract_x, HEIGHT, layout);
    layout_printf(layout, "%s [%s]", coord->x_title, coord->x_unit);
    title = get_text_size(HEIGHT, layout, "%s [%s]",
                          coord->x_title, coord->x_unit);

    return max_n(3, pos, neg, title);
}
Example #9
0
void render(struct output *output, struct config *config, struct status_line *line) {
	int i;

	struct window *window = output->window;
	cairo_t *cairo = window->cairo;

	// Clear
	cairo_save(cairo);
	cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
	cairo_paint(cairo);
	cairo_restore(cairo);

	// Background
	cairo_set_source_u32(cairo, config->colors.background);
	cairo_paint(cairo);

	// Command output
	cairo_set_source_u32(cairo, config->colors.statusline);
	int width, height;

	if (line->protocol == TEXT) {
		get_text_size(window->cairo, window->font, &width, &height, "%s", line->text_line);
		cairo_move_to(cairo, window->width - margin - width, margin);
		pango_printf(window->cairo, window->font, "%s", line->text_line);
	} else if (line->protocol == I3BAR && line->block_line) {
		double pos = window->width - 0.5;
		bool edge = true;
		for (i = line->block_line->length - 1; i >= 0; --i) {
			struct status_block *block = line->block_line->items[i];
			if (block->full_text && block->full_text[0]) {
				render_block(window, config, block, &pos, edge);
				edge = false;
			}
		}
	}

	cairo_set_line_width(cairo, 1.0);
	double x = 0.5;

	// Workspaces
	if (config->workspace_buttons) {
		for (i = 0; i < output->workspaces->length; ++i) {
			struct workspace *ws = output->workspaces->items[i];
			render_workspace_button(window, config, ws, &x);
		}
	}

	// binding mode indicator
	if (config->mode && config->binding_mode_indicator) {
		render_binding_mode_indicator(window, config, x);
	}
}
Example #10
0
static uint32_t render_message(cairo_t *cairo, struct swaynag *swaynag) {
	int text_width, text_height;
	get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
			swaynag->scale, true, "%s", swaynag->message);

	int padding = swaynag->type->message_padding * swaynag->scale;

	uint32_t ideal_height = text_height + padding * 2;
	uint32_t ideal_surface_height = ideal_height / swaynag->scale;
	if (swaynag->height < ideal_surface_height) {
		return ideal_surface_height;
	}

	cairo_set_source_u32(cairo, swaynag->type->text);
	cairo_move_to(cairo, padding, (int)(ideal_height - text_height) / 2);
	pango_printf(cairo, swaynag->type->font, swaynag->scale, false,
			"%s", swaynag->message);

	return ideal_surface_height;
}
Example #11
0
static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag,
		int button_index, int *x) {
	struct swaynag_button *button = swaynag->buttons->items[button_index];

	int text_width, text_height;
	get_text_size(cairo, swaynag->type->font, &text_width, &text_height, NULL,
			swaynag->scale, true, "%s", button->text);

	int border = swaynag->type->button_border_thickness * swaynag->scale;
	int padding = swaynag->type->button_padding * swaynag->scale;

	uint32_t ideal_height = text_height + padding * 2 + border * 2;
	uint32_t ideal_surface_height = ideal_height / swaynag->scale;
	if (swaynag->height < ideal_surface_height) {
		return ideal_surface_height;
	}

	button->x = *x - border - text_width - padding * 2 + 1;
	button->y = (int)(ideal_height - text_height) / 2 - padding + 1;
	button->width = text_width + padding * 2;
	button->height = text_height + padding * 2;

	cairo_set_source_u32(cairo, swaynag->type->border);
	cairo_rectangle(cairo, button->x - border, button->y - border,
			button->width + border * 2, button->height + border * 2);
	cairo_fill(cairo);

	cairo_set_source_u32(cairo, swaynag->type->button_background);
	cairo_rectangle(cairo, button->x, button->y,
			button->width, button->height);
	cairo_fill(cairo);

	cairo_set_source_u32(cairo, swaynag->type->text);
	cairo_move_to(cairo, button->x + padding, button->y + padding);
	pango_printf(cairo, swaynag->type->font, swaynag->scale, true,
			"%s", button->text);

	*x = button->x - border;

	return ideal_surface_height;
}
Example #12
0
static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) {
	int width, height;
	get_text_size(window->cairo, window->font, &width, &height, "%s", config->mode);

	// background
	cairo_set_source_u32(window->cairo, config->colors.binding_mode.background);
	cairo_rectangle(window->cairo, pos, 1.5, width + ws_horizontal_padding * 2 - 1,
			height + ws_vertical_padding * 2);
	cairo_fill(window->cairo);

	// border
	cairo_set_source_u32(window->cairo, config->colors.binding_mode.border);
	cairo_rectangle(window->cairo, pos, 1.5, width + ws_horizontal_padding * 2 - 1,
			height + ws_vertical_padding * 2);
	cairo_stroke(window->cairo);

	// text
	cairo_set_source_u32(window->cairo, config->colors.binding_mode.text);
	cairo_move_to(window->cairo, (int)pos + ws_horizontal_padding, margin);
	pango_printf(window->cairo, window->font, "%s", config->mode);
}
Example #13
0
static int draw_node(cairo_t *cairo, struct sway_node *node,
		struct sway_node *focus, int x, int y) {
	int text_width, text_height;
	char *buffer = get_string(node);
	get_text_size(cairo, "monospace", &text_width, &text_height, NULL,
		1, false, buffer);
	cairo_save(cairo);
	cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height);
	cairo_set_source_u32(cairo, 0xFFFFFFE0);
	cairo_fill(cairo);
	int height = text_height;
	list_t *children = get_children(node);
	if (children) {
		for (int i = 0; i < children->length; ++i) {
			// This is really dirty - the list contains specific structs but
			// we're casting them as nodes. This works because node is the first
			// item in each specific struct. This is acceptable because this is
			// debug code.
			struct sway_node *child = children->items[i];
			if (node_get_parent(child) == node) {
				cairo_set_source_u32(cairo, 0x000000FF);
			} else {
				cairo_set_source_u32(cairo, 0xFF0000FF);
			}
			height += draw_node(cairo, child, focus, x + 10, y + height);
		}
	}
	cairo_set_source_u32(cairo, 0xFFFFFFE0);
	cairo_rectangle(cairo, x, y, 2, height);
	cairo_fill(cairo);
	cairo_restore(cairo);
	cairo_move_to(cairo, x, y);
	if (focus == node) {
		cairo_set_source_u32(cairo, 0x0000FFFF);
	}
	pango_printf(cairo, "monospace", 1, false, buffer);
	free(buffer);
	return height;
}
Example #14
0
static void render_workspace_button(struct window *window, struct config *config, struct workspace *ws, double *x) {
	// strip workspace numbers if required
	char *name = handle_workspace_number(config->strip_workspace_numbers, ws->name);

	int width, height;
	get_text_size(window->cairo, window->font, &width, &height, "%s", name);
	struct box_colors box_colors;
	if (ws->urgent) {
		box_colors = config->colors.urgent_workspace;
	} else if (ws->focused) {
		box_colors = config->colors.focused_workspace;
	} else if (ws->visible) {
		box_colors = config->colors.active_workspace;
	} else {
		box_colors = config->colors.inactive_workspace;
	}

	// background
	cairo_set_source_u32(window->cairo, box_colors.background);
	cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1,
			height + ws_vertical_padding * 2);
	cairo_fill(window->cairo);

	// border
	cairo_set_source_u32(window->cairo, box_colors.border);
	cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1,
			height + ws_vertical_padding * 2);
	cairo_stroke(window->cairo);

	// text
	cairo_set_source_u32(window->cairo, box_colors.text);
	cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin);
	pango_printf(window->cairo, window->font, "%s", name);

	*x += width + ws_horizontal_padding * 2 + ws_spacing;

	free(name);
}
Example #15
0
static int get_text_height(const char *text){
  int height,width;
  get_text_size(text,&width,&height);
  return height;
}
Example #16
0
static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) {
	int width, height, sep_width;
	get_text_size(window->cairo, window->font, &width, &height, "%s", block->full_text);

	int textwidth = width;
	double block_width = width;

	if (width < block->min_width) {
		width = block->min_width;
	}

	*x -= width;

	if (block->border != 0 && block->border_left > 0) {
		*x -= (block->border_left + margin);
		block_width += block->border_left + margin;
	}

	if (block->border != 0 && block->border_right > 0) {
		*x -= (block->border_right + margin);
		block_width += block->border_right + margin;
	}

	// Add separator
	if (!edge) {
		if (config->sep_symbol) {
			get_text_size(window->cairo, window->font, &sep_width, &height, "%s", config->sep_symbol);
			if (sep_width > block->separator_block_width) {
				block->separator_block_width = sep_width + margin * 2;
			}
		}

		*x -= block->separator_block_width;
	} else {
		*x -= margin;
	}

	double pos = *x;

	// render background
	if (block->background != 0x0) {
		cairo_set_source_u32(window->cairo, block->background);
		cairo_rectangle(window->cairo, pos - 0.5, 1, block_width, window->height - 2);
		cairo_fill(window->cairo);
	}

	// render top border
	if (block->border != 0 && block->border_top > 0) {
		render_sharp_line(window->cairo, block->border,
				pos - 0.5,
				1,
				block_width,
				block->border_top);
	}

	// render bottom border
	if (block->border != 0 && block->border_bottom > 0) {
		render_sharp_line(window->cairo, block->border,
				pos - 0.5,
				window->height - 1 - block->border_bottom,
				block_width,
				block->border_bottom);
	}

	// render left border
	if (block->border != 0 && block->border_left > 0) {
		render_sharp_line(window->cairo, block->border,
				pos - 0.5,
				1,
				block->border_left,
				window->height - 2);

		pos += block->border_left + margin;
	}

	// render text
	double offset = 0;

	if (strncmp(block->align, "left", 5) == 0) {
		offset = pos;
	} else if (strncmp(block->align, "right", 5) == 0) {
		offset = pos + width - textwidth;
	} else if (strncmp(block->align, "center", 6) == 0) {
		offset = pos + (width - textwidth) / 2;
	}

	cairo_move_to(window->cairo, offset, margin);
	cairo_set_source_u32(window->cairo, block->color);
	pango_printf(window->cairo, window->font, "%s", block->full_text);

	pos += width;

	// render right border
	if (block->border != 0 && block->border_right > 0) {
		pos += margin;

		render_sharp_line(window->cairo, block->border,
				pos - 0.5,
				1,
				block->border_right,
				window->height - 2);

		pos += block->border_right;
	}

	// render separator
	if (!edge && block->separator) {
		cairo_set_source_u32(window->cairo, config->colors.separator);
		if (config->sep_symbol) {
			offset = pos + (block->separator_block_width - sep_width) / 2;
			cairo_move_to(window->cairo, offset, margin);
			pango_printf(window->cairo, window->font, "%s", config->sep_symbol);
		} else {
			cairo_set_line_width(window->cairo, 1);
			cairo_move_to(window->cairo, pos + block->separator_block_width/2,
					margin);
			cairo_line_to(window->cairo, pos + block->separator_block_width/2,
					window->height - margin);
			cairo_stroke(window->cairo);
		}
	}

}
Example #17
0
void init_taskbar_panel(void *p)
{
	Panel *panel =(Panel*)p;
	int j;

	if (panel->g_taskbar.background[TASKBAR_NORMAL] == 0) {
		panel->g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, 0);
		panel->g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, 0);
	}
	if (panel->g_taskbar.background_name[TASKBAR_NORMAL] == 0) {
		panel->g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, 0);
		panel->g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, 0);
	}
	if (panel->g_task.area.bg == 0)
		panel->g_task.area.bg = &g_array_index(backgrounds, Background, 0);

	// taskbar name
	panel->g_taskbar.area_name.panel = panel;
	panel->g_taskbar.area_name.size_mode = SIZE_BY_CONTENT;
	panel->g_taskbar.area_name._resize = resize_taskbarname;
	panel->g_taskbar.area_name._draw_foreground = draw_taskbarname;
	panel->g_taskbar.area_name._on_change_layout = 0;
	panel->g_taskbar.area_name.resize = 1;
	panel->g_taskbar.area_name.on_screen = 1;

	// taskbar
	panel->g_taskbar.area.parent = panel;
	panel->g_taskbar.area.panel = panel;
	panel->g_taskbar.area.size_mode = SIZE_BY_LAYOUT;
	panel->g_taskbar.area._resize = resize_taskbar;
	panel->g_taskbar.area._draw_foreground = draw_taskbar;
	panel->g_taskbar.area._on_change_layout = on_change_taskbar;
	panel->g_taskbar.area.resize = 1;
	panel->g_taskbar.area.on_screen = 1;
	if (panel_horizontal) {
		panel->g_taskbar.area.posy = panel->area.bg->border.width + panel->area.paddingy;
		panel->g_taskbar.area.height = panel->area.height - (2 * panel->g_taskbar.area.posy);
		panel->g_taskbar.area_name.posy = panel->g_taskbar.area.posy;
		panel->g_taskbar.area_name.height = panel->g_taskbar.area.height;
	}
	else {
		panel->g_taskbar.area.posx = panel->area.bg->border.width + panel->area.paddingy;
		panel->g_taskbar.area.width = panel->area.width - (2 * panel->g_taskbar.area.posx);
		panel->g_taskbar.area_name.posx = panel->g_taskbar.area.posx;
		panel->g_taskbar.area_name.width = panel->g_taskbar.area.width;
	}

	// task
	panel->g_task.area.panel = panel;
	panel->g_task.area.size_mode = SIZE_BY_LAYOUT;
	panel->g_task.area._draw_foreground = draw_task;
	panel->g_task.area._on_change_layout = on_change_task;
	panel->g_task.area.resize = 1;
	panel->g_task.area.on_screen = 1;
	if ((panel->g_task.config_asb_mask & (1<<TASK_NORMAL)) == 0) {
		panel->g_task.alpha[TASK_NORMAL] = 100;
		panel->g_task.saturation[TASK_NORMAL] = 0;
		panel->g_task.brightness[TASK_NORMAL] = 0;
	}
	if ((panel->g_task.config_asb_mask & (1<<TASK_ACTIVE)) == 0) {
		panel->g_task.alpha[TASK_ACTIVE] = panel->g_task.alpha[TASK_NORMAL];
		panel->g_task.saturation[TASK_ACTIVE] = panel->g_task.saturation[TASK_NORMAL];
		panel->g_task.brightness[TASK_ACTIVE] = panel->g_task.brightness[TASK_NORMAL];
	}
	if ((panel->g_task.config_asb_mask & (1<<TASK_ICONIFIED)) == 0) {
		panel->g_task.alpha[TASK_ICONIFIED] = panel->g_task.alpha[TASK_NORMAL];
		panel->g_task.saturation[TASK_ICONIFIED] = panel->g_task.saturation[TASK_NORMAL];
		panel->g_task.brightness[TASK_ICONIFIED] = panel->g_task.brightness[TASK_NORMAL];
	}
	if ((panel->g_task.config_asb_mask & (1<<TASK_URGENT)) == 0) {
		panel->g_task.alpha[TASK_URGENT] = panel->g_task.alpha[TASK_ACTIVE];
		panel->g_task.saturation[TASK_URGENT] = panel->g_task.saturation[TASK_ACTIVE];
		panel->g_task.brightness[TASK_URGENT] = panel->g_task.brightness[TASK_ACTIVE];
	}
	if ((panel->g_task.config_font_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.font[TASK_NORMAL] = (Color){{0, 0, 0}, 0};
	if ((panel->g_task.config_font_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.font[TASK_ACTIVE] = panel->g_task.font[TASK_NORMAL];
	if ((panel->g_task.config_font_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.font[TASK_ICONIFIED] = panel->g_task.font[TASK_NORMAL];
	if ((panel->g_task.config_font_mask & (1<<TASK_URGENT)) == 0) panel->g_task.font[TASK_URGENT] = panel->g_task.font[TASK_ACTIVE];
	if ((panel->g_task.config_background_mask & (1<<TASK_NORMAL)) == 0) panel->g_task.background[TASK_NORMAL] = &g_array_index(backgrounds, Background, 0);
	if ((panel->g_task.config_background_mask & (1<<TASK_ACTIVE)) == 0) panel->g_task.background[TASK_ACTIVE] = panel->g_task.background[TASK_NORMAL];
	if ((panel->g_task.config_background_mask & (1<<TASK_ICONIFIED)) == 0) panel->g_task.background[TASK_ICONIFIED] = panel->g_task.background[TASK_NORMAL];
	if ((panel->g_task.config_background_mask & (1<<TASK_URGENT)) == 0) panel->g_task.background[TASK_URGENT] = panel->g_task.background[TASK_ACTIVE];

	if (panel_horizontal) {
		panel->g_task.area.posy = panel->g_taskbar.area.posy + panel->g_taskbar.background[TASKBAR_NORMAL]->border.width + panel->g_taskbar.area.paddingy;
		panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy);
	}
	else {
		panel->g_task.area.posx = panel->g_taskbar.area.posx + panel->g_taskbar.background[TASKBAR_NORMAL]->border.width + panel->g_taskbar.area.paddingy;
		panel->g_task.area.width = panel->area.width - (2 * panel->g_task.area.posx);
		panel->g_task.area.height = panel->g_task.maximum_height;
	}

	for (j=0; j<TASK_STATE_COUNT; ++j) {
		if (panel->g_task.background[j] == 0)
			panel->g_task.background[j] = &g_array_index(backgrounds, Background, 0);
		if (panel->g_task.background[j]->border.rounded > panel->g_task.area.height/2) {
			printf("task%sbackground_id has a too large rounded value. Please fix your tint2rc\n", j==0 ? "_" : j==1 ? "_active_" : j==2 ? "_iconified_" : "_urgent_");
			g_array_append_val(backgrounds, *panel->g_task.background[j]);
			panel->g_task.background[j] = &g_array_index(backgrounds, Background, backgrounds->len-1);
			panel->g_task.background[j]->border.rounded = panel->g_task.area.height/2;
		}
	}

	// compute vertical position : text and icon
	int height_ink, height;
	get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5);

	if (!panel->g_task.maximum_width && panel_horizontal)
		panel->g_task.maximum_width = server.monitor[panel->monitor].width;

	panel->g_task.text_posx = panel->g_task.background[0]->border.width + panel->g_task.area.paddingxlr;
	panel->g_task.text_height = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
	if (panel->g_task.icon) {
		panel->g_task.icon_size1 = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
		panel->g_task.text_posx += panel->g_task.icon_size1;
		panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
	}
	//printf("monitor %d, task_maximum_width %d\n", panel->monitor, panel->g_task.maximum_width);

	Taskbar *tskbar;
	panel->nb_desktop = server.nb_desktop;
	panel->taskbar = calloc(server.nb_desktop, sizeof(Taskbar));
	for (j=0 ; j < panel->nb_desktop ; j++) {
		tskbar = &panel->taskbar[j];
		memcpy(&tskbar->area, &panel->g_taskbar.area, sizeof(Area));
		tskbar->desktop = j;
		if (j == server.desktop)
			tskbar->area.bg = panel->g_taskbar.background[TASKBAR_ACTIVE];
		else
			tskbar->area.bg = panel->g_taskbar.background[TASKBAR_NORMAL];
	}
	init_taskbarname_panel(panel);
}
Example #18
0
static void
show_help (XtPointer data, XtIntervalId* id)
{
  int x, y;
  int shape;
  XPoint border[ 3 ];

  if (id == NULL || ((id && b_timer) && b_text))
    {
      b_timer = None;

      /* size */
      get_text_size (b_dpy, b_fontStruct, b_text, &b_width, &b_height);
      b_width  += 2 * MARGIN_WIDTH + 2 * BORDER_WIDTH;
      b_height += 2 * MARGIN_WIDTH + 2 * BORDER_WIDTH + CONE_HEIGHT;

      /* origin */
      get_pointer_xy (b_dpy, &x, &y);

      /* guess at shape */
      shape = get_shape(b_lastShape, x, y, b_width, b_height,
			b_screenWidth, b_screenHeight);

      x += (shape & SHAPE_CONE_LEFT) ? POINTER_OFFSET : -POINTER_OFFSET;
      y += (shape & SHAPE_CONE_TOP)  ? POINTER_OFFSET : -POINTER_OFFSET;

      /* make sure it is still ok with offset */
      shape = get_shape (shape, x, y, b_width, b_height, b_screenWidth, b_screenHeight);

      b_lastShape = shape;

      make_mask (shape, x, y, b_width, b_height);

      XShapeCombineMask (b_dpy, b_win, ShapeBounding, 0, 0, b_mask, ShapeSet);

      XMoveResizeWindow(b_dpy, b_win,
			(shape & SHAPE_CONE_LEFT) ? x : x - b_width,
			(shape & SHAPE_CONE_TOP)  ? y : y - b_height,
			b_width, b_height);

      XClearWindow (b_dpy, b_win);

      XMapRaised (b_dpy, b_win);
      b_winMapped = True;

      draw_text (b_dpy, b_win, b_gc, b_fontStruct,
		 BORDER_WIDTH + MARGIN_WIDTH,
		 BORDER_WIDTH + MARGIN_WIDTH + ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0),
               b_text);

      /* 3d border */
      /* shine- top left */
      border[0].x = 0 + BORDER_WIDTH_HALF;
      border[0].y = ((shape & SHAPE_CONE_TOP) ? b_height : b_height - CONE_HEIGHT) - BORDER_WIDTH_HALF;
      border[1].x = 0 + BORDER_WIDTH_HALF;
      border[1].y = ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0) + BORDER_WIDTH_HALF;
      border[2].x = b_width - BORDER_WIDTH_HALF;
      border[2].y = border[1].y;
      XDrawLines (b_dpy, b_win, b_shineGC, border, 3, CoordModeOrigin);

      /* shadow- bottom right */
      border[0].x = 0 + BORDER_WIDTH_HALF;
      border[0].y = ((shape & SHAPE_CONE_TOP) ? b_height : b_height - CONE_HEIGHT) - BORDER_WIDTH_HALF;
      border[1].x = b_width - BORDER_WIDTH_HALF;
      border[1].y = border[0].y;
      border[2].x = b_width - BORDER_WIDTH_HALF;
      border[2].y = ((shape & SHAPE_CONE_TOP) ? CONE_HEIGHT : 0) + BORDER_WIDTH_HALF;
      XDrawLines (b_dpy, b_win, b_shadowGC, border, 3, CoordModeOrigin);

      /* cone */
    if (SHAPE_CONE_TOP_LEFT == shape)
      {
	XClearArea (b_dpy, b_win,
		    CONE_WIDTH / 2 + BORDER_WIDTH,
		    CONE_HEIGHT,
		    CONE_WIDTH / 2 - BORDER_WIDTH,
		    BORDER_WIDTH, False);
	XDrawLine (b_dpy, b_win, b_shadowGC,
		   0,
		   0,
		   CONE_WIDTH / 2 + BORDER_WIDTH_HALF,
		   CONE_HEIGHT);
	XDrawLine (b_dpy, b_win, b_shineGC,
		   0,
		   0,
		   CONE_WIDTH - BORDER_WIDTH_HALF,
		   CONE_HEIGHT);
      }
    else if (SHAPE_CONE_TOP_RIGHT == shape)
      {
	XClearArea (b_dpy, b_win,
		    b_width - CONE_WIDTH + BORDER_WIDTH,
		    CONE_HEIGHT,
		    CONE_WIDTH / 2 - BORDER_WIDTH,
		    BORDER_WIDTH, False);
	XDrawLine (b_dpy, b_win, b_shadowGC,
		   b_width,
		   0,
		   b_width - CONE_WIDTH / 2 - BORDER_WIDTH_HALF,
		   CONE_HEIGHT);
	XDrawLine (b_dpy, b_win, b_shineGC,
		   b_width,
		   0,
		   b_width - CONE_WIDTH + BORDER_WIDTH_HALF,
		   CONE_HEIGHT);
      }
    else if (SHAPE_CONE_BOTTOM_LEFT == shape)
      {
	XClearArea (b_dpy, b_win,
		    CONE_WIDTH / 2 + BORDER_WIDTH,
		    b_height - CONE_HEIGHT - BORDER_WIDTH,
		    CONE_WIDTH / 2 - BORDER_WIDTH,
		    BORDER_WIDTH, False);
	XDrawLine (b_dpy, b_win, b_shadowGC,
		   0,
		   b_height - 1,
		   CONE_WIDTH,
		   b_height - 1 - CONE_HEIGHT);
	XDrawLine (b_dpy, b_win, b_shineGC,
		   0,
		   b_height - 1,
		   CONE_WIDTH / 2 + BORDER_WIDTH,
		   b_height - 1 - CONE_HEIGHT);
      }
    else if (SHAPE_CONE_BOTTOM_RIGHT == shape)
      {
	XClearArea (b_dpy, b_win,
		    b_width - 1 - CONE_WIDTH + BORDER_WIDTH,
		    b_height - CONE_HEIGHT - BORDER_WIDTH,
		    CONE_WIDTH / 2 - BORDER_WIDTH - 1,
		    BORDER_WIDTH, False);
	XDrawLine (b_dpy, b_win, b_shadowGC,
		   b_width - 1,
		   b_height - 1,
		   b_width - 1 - CONE_WIDTH,
		   b_height - 1 - CONE_HEIGHT);
	XDrawLine (b_dpy, b_win, b_shineGC,
		   b_width - 1,
		   b_height - 1,
		   b_width - 1 - CONE_WIDTH / 2 - BORDER_WIDTH,
		   b_height - 1 - CONE_HEIGHT);
      }
    }

}
Example #19
0
CSize hdc_with_font::get_text_size(const string& str)
{
	return get_text_size(to_wstring(str));
}
Example #20
0
int hdc_with_font::get_text_height(const wstring& str)
{
	return get_text_size(str).cy;
}
Example #21
0
int hdc_with_font::get_text_width(const wstring& str)
{
	return get_text_size(str).cx;
}
Example #22
0
std::pair<float,float> Text::get_text_size_ratio() {
    return window->get_ratio_from_pixels(get_text_size());
}