Index: uspace/lib/ui/src/paint.c
===================================================================
--- uspace/lib/ui/src/paint.c	(revision de9992c5dcfe392011d18f6d641c7151c514607a)
+++ uspace/lib/ui/src/paint.c	(revision de9992c5dcfe392011d18f6d641c7151c514607a)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2020 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libui
+ * @{
+ */
+/**
+ * @file Painting routines
+ */
+
+#include <errno.h>
+#include <gfx/color.h>
+#include <gfx/context.h>
+#include <gfx/render.h>
+#include <ui/paint.h>
+
+/** Paint bevel.
+ *
+ * @param gc Graphic context
+ * @param rect Rectangle to paint into
+ * @param tlcolor Top-left color
+ * @param brcolor Bottom-right color
+ * @param thickness Bevel thickness in pixels
+ * @param inside Place to store rectangle of the interior or @c NULL
+ * @reutrn EOK on success or an error code
+ */
+errno_t ui_paint_bevel(gfx_context_t *gc, gfx_rect_t *rect,
+    gfx_color_t *tlcolor, gfx_color_t *brcolor, gfx_coord_t thickness,
+    gfx_rect_t *inside)
+{
+	gfx_rect_t frect;
+	gfx_coord_t i;
+	errno_t rc;
+
+	/* Top left */
+
+	rc = gfx_set_color(gc, tlcolor);
+	if (rc != EOK)
+		goto error;
+
+	for (i = 0; i < thickness; i++) {
+		frect.p0.x = rect->p0.x + i;
+		frect.p0.y = rect->p0.y + i;
+		frect.p1.x = rect->p1.x - i - 1;
+		frect.p1.y = rect->p0.y + i + 1;
+		rc = gfx_fill_rect(gc, &frect);
+		if (rc != EOK)
+			goto error;
+
+		frect.p0.x = rect->p0.x + i;
+		frect.p0.y = rect->p0.y + i + 1;
+		frect.p1.x = rect->p0.x + i + 1;
+		frect.p1.y = rect->p1.y - i - 1;
+		rc = gfx_fill_rect(gc, &frect);
+		if (rc != EOK)
+			goto error;
+	}
+
+	/* Bottom right */
+
+	rc = gfx_set_color(gc, brcolor);
+	if (rc != EOK)
+		goto error;
+
+	for (i = 0; i < thickness; i++) {
+		frect.p0.x = rect->p0.x + i;
+		frect.p0.y = rect->p1.y - i - 1;
+		frect.p1.x = rect->p1.x - i - 1;
+		frect.p1.y = rect->p1.y - i;
+		rc = gfx_fill_rect(gc, &frect);
+		if (rc != EOK)
+			goto error;
+
+		frect.p0.x = rect->p1.x - i - 1;
+		frect.p0.y = rect->p0.y + i;
+		frect.p1.x = rect->p1.x - i;
+		frect.p1.y = rect->p1.y - i;
+		rc = gfx_fill_rect(gc, &frect);
+		if (rc != EOK)
+			goto error;
+	}
+
+	if (inside != NULL) {
+		inside->p0.x = rect->p0.x + thickness;
+		inside->p0.y = rect->p0.y + thickness;
+		inside->p1.x = rect->p1.x - thickness;
+		inside->p1.y = rect->p1.y - thickness;
+	}
+
+	return EOK;
+error:
+	return rc;
+}
+
+/** @}
+ */
Index: uspace/lib/ui/src/pbutton.c
===================================================================
--- uspace/lib/ui/src/pbutton.c	(revision 8ef48ece717476a9d162affd18ffa54f6f946249)
+++ uspace/lib/ui/src/pbutton.c	(revision de9992c5dcfe392011d18f6d641c7151c514607a)
@@ -42,4 +42,5 @@
 #include <stdlib.h>
 #include <str.h>
+#include <ui/paint.h>
 #include <ui/pbutton.h>
 #include "../private/pbutton.h"
@@ -133,5 +134,4 @@
 static errno_t ui_pbutton_paint_frame(ui_pbutton_t *pbutton)
 {
-	gfx_color_t *color = NULL;
 	gfx_rect_t rect;
 	gfx_coord_t thickness;
@@ -140,9 +140,5 @@
 	thickness = pbutton->isdefault ? 2 : 1;
 
-	rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
+	rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_frame_color);
 	if (rc != EOK)
 		goto error;
@@ -180,9 +176,6 @@
 		goto error;
 
-	gfx_color_delete(color);
 	return EOK;
 error:
-	if (color != NULL)
-		gfx_color_delete(color);
 	return rc;
 }
@@ -196,75 +189,7 @@
     gfx_rect_t *rect)
 {
-	gfx_color_t *color = NULL;
-	gfx_rect_t frect;
-	gfx_coord_t i;
-	errno_t rc;
-
-	/* Highlight */
-
-	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
-	if (rc != EOK)
-		goto error;
-
-	for (i = 0; i < 2; i++) {
-		frect.p0.x = rect->p0.x + i;
-		frect.p0.y = rect->p0.y + i;
-		frect.p1.x = rect->p1.x - i - 1;
-		frect.p1.y = rect->p0.y + i + 1;
-		rc = gfx_fill_rect(pbutton->res->gc, &frect);
-		if (rc != EOK)
-			goto error;
-
-		frect.p0.x = rect->p0.x + i;
-		frect.p0.y = rect->p0.y + i + 1;
-		frect.p1.x = rect->p0.x + i + 1;
-		frect.p1.y = rect->p1.y - i - 1;
-		rc = gfx_fill_rect(pbutton->res->gc, &frect);
-		if (rc != EOK)
-			goto error;
-	}
-
-	gfx_color_delete(color);
-	color = NULL;
-
-	/* Shadow */
-
-	rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
-	if (rc != EOK)
-		goto error;
-
-	for (i = 0; i < 2; i++) {
-		frect.p0.x = rect->p0.x + i;
-		frect.p0.y = rect->p1.y - i - 1;
-		frect.p1.x = rect->p1.x - i - 1;
-		frect.p1.y = rect->p1.y - i;
-		rc = gfx_fill_rect(pbutton->res->gc, &frect);
-		if (rc != EOK)
-			goto error;
-
-		frect.p0.x = rect->p1.x - i - 1;
-		frect.p0.y = rect->p0.y + i;
-		frect.p1.x = rect->p1.x - i;
-		frect.p1.y = rect->p1.y - i;
-		rc = gfx_fill_rect(pbutton->res->gc, &frect);
-		if (rc != EOK)
-			goto error;
-	}
-
-	gfx_color_delete(color);
-
-	return EOK;
-error:
-	if (color != NULL)
-		gfx_color_delete(color);
-	return rc;
+	return ui_paint_bevel(pbutton->res->gc, rect,
+	    pbutton->res->btn_highlight_color,
+	    pbutton->res->btn_shadow_color, 2, NULL);
 }
 
@@ -277,39 +202,7 @@
     gfx_rect_t *rect)
 {
-	gfx_color_t *color = NULL;
-	gfx_rect_t frect;
-	errno_t rc;
-
-	rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
-	if (rc != EOK)
-		goto error;
-
-	frect.p0.x = rect->p0.x;
-	frect.p0.y = rect->p0.y;
-	frect.p1.x = rect->p1.x;
-	frect.p1.y = rect->p0.y + 2;
-	rc = gfx_fill_rect(pbutton->res->gc, &frect);
-	if (rc != EOK)
-		goto error;
-
-	frect.p0.x = rect->p0.x;
-	frect.p0.y = rect->p0.y + 2;
-	frect.p1.x = rect->p0.x + 2;
-	frect.p1.y = rect->p1.y;
-	rc = gfx_fill_rect(pbutton->res->gc, &frect);
-	if (rc != EOK)
-		goto error;
-
-	gfx_color_delete(color);
-
-	return EOK;
-error:
-	if (color != NULL)
-		gfx_color_delete(color);
-	return rc;
+	return ui_paint_bevel(pbutton->res->gc, rect,
+	    pbutton->res->btn_shadow_color,
+	    pbutton->res->btn_face_color, 2, NULL);
 }
 
@@ -321,5 +214,4 @@
 errno_t ui_pbutton_paint(ui_pbutton_t *pbutton)
 {
-	gfx_color_t *color = NULL;
 	gfx_coord2_t pos;
 	gfx_text_fmt_t fmt;
@@ -337,24 +229,13 @@
 	rect.p1.y = pbutton->rect.p1.y - thickness;
 
-	rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_fill_rect(pbutton->res->gc, &rect);
-	if (rc != EOK)
-		goto error;
-
-	gfx_color_delete(color);
-	color = NULL;
-
-	rc = gfx_color_new_rgb_i16(0, 0, 0, &color);
-	if (rc != EOK)
-		goto error;
-
-	rc = gfx_set_color(pbutton->res->gc, color);
+	rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_fill_rect(pbutton->res->gc, &rect);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color);
 	if (rc != EOK)
 		goto error;
@@ -376,7 +257,4 @@
 	if (rc != EOK)
 		goto error;
-
-	gfx_color_delete(color);
-	color = NULL;
 
 	rc = ui_pbutton_paint_frame(pbutton);
@@ -396,6 +274,4 @@
 	return EOK;
 error:
-	if (color != NULL)
-		gfx_color_delete(color);
 	return rc;
 }
Index: uspace/lib/ui/src/resource.c
===================================================================
--- uspace/lib/ui/src/resource.c	(revision 8ef48ece717476a9d162affd18ffa54f6f946249)
+++ uspace/lib/ui/src/resource.c	(revision de9992c5dcfe392011d18f6d641c7151c514607a)
@@ -59,4 +59,9 @@
 	gfx_font_t *font = NULL;
 	gfx_font_info_t *finfo;
+	gfx_color_t *btn_frame_color = NULL;
+	gfx_color_t *btn_face_color = NULL;
+	gfx_color_t *btn_text_color = NULL;
+	gfx_color_t *btn_highlight_color = NULL;
+	gfx_color_t *btn_shadow_color = NULL;
 	errno_t rc;
 
@@ -79,10 +84,46 @@
 		goto error;
 
+	rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &btn_face_color);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_text_color);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
+	    &btn_highlight_color);
+	if (rc != EOK)
+		goto error;
+
+	rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &btn_shadow_color);
+	if (rc != EOK)
+		goto error;
+
 	resource->gc = gc;
 	resource->tface = tface;
 	resource->font = font;
+	resource->btn_frame_color = btn_frame_color;
+	resource->btn_face_color = btn_face_color;
+	resource->btn_text_color = btn_text_color;
+	resource->btn_highlight_color = btn_highlight_color;
+	resource->btn_shadow_color = btn_shadow_color;
 	*rresource = resource;
 	return EOK;
 error:
+	if (btn_frame_color != NULL)
+		gfx_color_delete(btn_frame_color);
+	if (btn_face_color != NULL)
+		gfx_color_delete(btn_face_color);
+	if (btn_text_color != NULL)
+		gfx_color_delete(btn_text_color);
+	if (btn_highlight_color != NULL)
+		gfx_color_delete(btn_highlight_color);
+	if (btn_shadow_color != NULL)
+		gfx_color_delete(btn_shadow_color);
 	if (tface != NULL)
 		gfx_typeface_destroy(tface);
@@ -100,4 +141,10 @@
 		return;
 
+	gfx_color_delete(resource->btn_frame_color);
+	gfx_color_delete(resource->btn_face_color);
+	gfx_color_delete(resource->btn_text_color);
+	gfx_color_delete(resource->btn_highlight_color);
+	gfx_color_delete(resource->btn_shadow_color);
+
 	gfx_font_close(resource->font);
 	gfx_typeface_destroy(resource->tface);
