コード例 #1
0
void _ttk_draw_button_select(cairo_t * cr, int x, int y, int width, int height, char * title) {
	cairo_save(cr);

	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 134.0/255.0, 173.0/255.0, 201.0/255.0, 1.0);
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 202.0/255.0, 211.0/255.0, 232.0/255.0, 1.0);
	cairo_fill(cr);

	{
		cairo_surface_t * surface = cairo_get_target(cr);
		gfx_context_t fake_context = {
			.width = cairo_image_surface_get_width(surface),
			.height = cairo_image_surface_get_height(surface),
			.depth = 32,
			.buffer = NULL,
			.backbuffer = cairo_image_surface_get_data(surface)
		};

		set_font_face(FONT_SANS_SERIF);
		set_font_size(13);

		int str_width = draw_string_width(title);
		draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title);
	}

	cairo_restore(cr);
	
}
コード例 #2
0
ファイル: ttk-core.c プロジェクト: ijustcode/toaruos
void _ttk_draw_button_hover(cairo_t * cr, int x, int y, int width, int height) {
	cairo_save(cr);

	cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 44.0/255.0, 71.0/255.0, 91.0/255.0, 29.0/255.0);
	cairo_set_line_width(cr, 4);
	cairo_stroke(cr);

	cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
	cairo_set_source_rgba(cr, 158.0/255.0, 169.0/255.0, 177.0/255.0, 1.0);
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(2 + x, 2 + y, 2 + x, 2 + y + height - 4);
		cairo_pattern_add_color_stop_rgba(pat, 0, 1, 1, 1, 1);
		cairo_pattern_add_color_stop_rgba(pat, 1, 229.0/255.0, 229.0/255.0, 246.0/255.0, 1);
		cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(3 + x, 3 + y, 3 + x, 3 + y + height - 4);
		cairo_pattern_add_color_stop_rgba(pat, 0, 252.0/255.0, 252.0/255.0, 254.0/255.0, 1);
		cairo_pattern_add_color_stop_rgba(pat, 1, 212.0/255.0, 223.0/255.0, 251.0/255.0, 1);
		cairo_rounded_rectangle(cr, 3 + x, 3 + y, width - 5, height - 5, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	{
		cairo_surface_t * surface = cairo_get_target(cr);
		gfx_context_t fake_context = {
			.width = cairo_image_surface_get_width(surface),
			.height = cairo_image_surface_get_height(surface),
			.depth = 32,
			.buffer = NULL,
			.backbuffer = cairo_image_surface_get_data(surface)
		};

		set_font_face(FONT_SANS_SERIF);
		set_font_size(13);

		char * title = "Button with Hover Highlight";
		int str_width = draw_string_width(title);
		draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title);
	}

	cairo_restore(cr);
	
}
コード例 #3
0
void draw_text_box(cairo_t * cr, struct text_box * tb) {
	int x = tb->parent->x + tb->x;
	int y = tb->parent->y + tb->y;

	set_font_size(13);
	int text_offset = 15;

	cairo_rounded_rectangle(cr, 1 + x, 1 + y, tb->width - 2, tb->height - 2, 2.0);
	if (tb->is_focused) {
		cairo_set_source_rgba(cr, 8.0/255.0, 193.0/255.0, 236.0/255.0, 1.0);
	} else {
		cairo_set_source_rgba(cr, 158.0/255.0, 169.0/255.0, 177.0/255.0, 1.0);
	}
	cairo_set_line_width(cr, 2);
	cairo_stroke(cr);

	{
		cairo_pattern_t * pat = cairo_pattern_create_linear(1 + x, 1 + y, 1 + x, 1 + y + tb->height - 2);
		if (tb->is_focused) {
			cairo_pattern_add_color_stop_rgba(pat, 0, 241.0/255.0, 241.0/255.0, 244.0/255.0, 1.0);
			cairo_pattern_add_color_stop_rgba(pat, 1, 1, 1, 1, 1.0);
		} else {
			cairo_pattern_add_color_stop_rgba(pat, 0, 241.0/255.0, 241.0/255.0, 244.0/255.0, 0.9);
			cairo_pattern_add_color_stop_rgba(pat, 1, 1, 1, 1, 0.9);
		}
		cairo_rounded_rectangle(cr, 1 + x, 1 + y, tb->width - 2, tb->height - 2, 2.0);
		cairo_set_source(cr, pat);
		cairo_fill(cr);
		cairo_pattern_destroy(pat);
	}

	char * text = tb->buffer;
	char password_circles[512];
	uint32_t color = tb->text_color;

	if (strlen(tb->buffer) == 0 && !tb->is_focused) {
		text = tb->placeholder;
		color = rgba(0,0,0,127);
	} else if (tb->is_password) {
		strcpy(password_circles, "");
		for (int i = 0; i < strlen(tb->buffer); ++i) {
			strcat(password_circles, "⚫");
		}
		text = password_circles;
	}

	draw_string(ctx, x + TEXTBOX_INTERIOR_LEFT, y + text_offset, color, text);

	if (tb->is_focused) {
		int width = draw_string_width(text);
		draw_line(ctx, x + TEXTBOX_INTERIOR_LEFT + width, x + TEXTBOX_INTERIOR_LEFT + width, y + 2, y + text_offset + 1, tb->text_color);
	}

}
コード例 #4
0
void draw_login_container(cairo_t * cr, struct login_container * lc) {

	/* Draw rounded rectangle */
	cairo_rounded_rectangle(cr, lc->x, lc->y, lc->width, lc->height, (float)BOX_ROUNDNESS);
	cairo_set_source_rgba(cr, (float)(BOX_COLOR_R)/255.0, (float)(BOX_COLOR_G)/255.0, (float)(BOX_COLOR_B)/255.0, (float)(BOX_COLOR_A)/255.0);
	cairo_fill(cr);

	/* Draw labels */
	if (lc->show_error) {
		char * error_message = "Incorrect username or password.";

		set_font_size(11);
		draw_string(ctx, lc->x + (lc->width - draw_string_width(error_message)) / 2, lc->y + 6 + EXTRA_TEXT_OFFSET, rgb(240, 20, 20), error_message);
	}

	draw_text_box(cr, lc->username_box);
	draw_text_box(cr, lc->password_box);

}