HelenOS sources
This source file includes following definitions.
- ui_image_create
- ui_image_destroy
- ui_image_ctl
- ui_image_set_rect
- ui_image_set_flags
- ui_image_paint
- ui_image_set_bmp
- ui_image_ctl_destroy
- ui_image_ctl_paint
- ui_image_ctl_pos_event
#include <errno.h>
#include <gfx/bitmap.h>
#include <gfx/context.h>
#include <gfx/render.h>
#include <gfx/text.h>
#include <stdlib.h>
#include <str.h>
#include <ui/control.h>
#include <ui/paint.h>
#include <ui/image.h>
#include "../private/image.h"
#include "../private/resource.h"
#include "../private/ui.h"
static void ui_image_ctl_destroy(void *);
static errno_t ui_image_ctl_paint(void *);
static ui_evclaim_t ui_image_ctl_pos_event(void *, pos_event_t *);
ui_control_ops_t ui_image_ops = {
.destroy = ui_image_ctl_destroy,
.paint = ui_image_ctl_paint,
.pos_event = ui_image_ctl_pos_event
};
errno_t ui_image_create(ui_resource_t *resource, gfx_bitmap_t *bitmap,
gfx_rect_t *brect, ui_image_t **rimage)
{
ui_image_t *image;
errno_t rc;
image = calloc(1, sizeof(ui_image_t));
if (image == NULL)
return ENOMEM;
rc = ui_control_new(&ui_image_ops, (void *) image, &image->control);
if (rc != EOK) {
free(image);
return rc;
}
image->bitmap = bitmap;
image->brect = *brect;
image->res = resource;
*rimage = image;
return EOK;
}
void ui_image_destroy(ui_image_t *image)
{
if (image == NULL)
return;
ui_control_delete(image->control);
if (image->bitmap != NULL)
gfx_bitmap_destroy(image->bitmap);
free(image);
}
ui_control_t *ui_image_ctl(ui_image_t *image)
{
return image->control;
}
void ui_image_set_rect(ui_image_t *image, gfx_rect_t *rect)
{
image->rect = *rect;
}
void ui_image_set_flags(ui_image_t *image, ui_image_flags_t flags)
{
image->flags = flags;
}
errno_t ui_image_paint(ui_image_t *image)
{
gfx_rect_t irect;
gfx_rect_t srect;
gfx_coord2_t offs;
errno_t rc;
if ((image->flags & ui_imgf_frame) != 0) {
rc = ui_paint_bevel(image->res->gc, &image->rect,
image->res->btn_frame_color, image->res->btn_frame_color,
1, NULL);
if (rc != EOK)
return rc;
}
if (image->bitmap == NULL)
return EOK;
irect = image->rect;
if ((image->flags & ui_imgf_frame) != 0) {
irect.p0.x++;
irect.p0.y++;
irect.p1.x--;
irect.p1.y--;
}
offs.x = irect.p0.x - image->brect.p0.x;
offs.y = irect.p0.y - image->brect.p0.y;
gfx_rect_rtranslate(&offs, &irect, &srect);
rc = gfx_bitmap_render(image->bitmap, &srect, &offs);
if (rc != EOK)
return rc;
return gfx_update(image->res->gc);
}
void ui_image_set_bmp(ui_image_t *image, gfx_bitmap_t *bitmap,
gfx_rect_t *brect)
{
image->bitmap = bitmap;
image->brect = *brect;
}
void ui_image_ctl_destroy(void *arg)
{
ui_image_t *image = (ui_image_t *) arg;
ui_image_destroy(image);
}
errno_t ui_image_ctl_paint(void *arg)
{
ui_image_t *image = (ui_image_t *) arg;
return ui_image_paint(image);
}
ui_evclaim_t ui_image_ctl_pos_event(void *arg, pos_event_t *event)
{
ui_image_t *image = (ui_image_t *) arg;
(void) image;
return ui_unclaimed;
}
HelenOS homepage, sources at GitHub