Changeset d8ddf7a in mainline for uspace/lib


Ignore:
Timestamp:
2020-11-22T17:52:37Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2d879f7
Parents:
4f64b7b8
Message:

UI demo should demonstrate image and entry controls

We also add the ability to draw a frame around image control, use
in UI demo and in launcher.

Location:
uspace/lib/ui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/types/ui/image.h

    r4f64b7b8 rd8ddf7a  
    4040typedef struct ui_image ui_image_t;
    4141
     42/** UI image flags */
     43typedef enum {
     44        /** Draw a frame around the image */
     45        ui_imgf_frame = 0x1
     46} ui_image_flags_t;
     47
    4248#endif
    4349
  • uspace/lib/ui/include/ui/image.h

    r4f64b7b8 rd8ddf7a  
    5050extern void ui_image_set_bmp(ui_image_t *, gfx_bitmap_t *, gfx_rect_t *);
    5151extern void ui_image_set_rect(ui_image_t *, gfx_rect_t *);
     52extern void ui_image_set_flags(ui_image_t *, ui_image_flags_t);
    5253extern errno_t ui_image_paint(ui_image_t *);
    5354
  • uspace/lib/ui/private/image.h

    r4f64b7b8 rd8ddf7a  
    5252        /** Image rectangle */
    5353        gfx_rect_t rect;
     54        /** Flags */
     55        ui_image_flags_t flags;
    5456        /** Bitmap */
    5557        gfx_bitmap_t *bitmap;
     58        /** Bitmap rectangle */
    5659        gfx_rect_t brect;
    5760};
  • uspace/lib/ui/src/image.c

    r4f64b7b8 rd8ddf7a  
    124124}
    125125
     126/** Set image flags.
     127 *
     128 * @param image Image
     129 * @param flags Flags
     130 */
     131void ui_image_set_flags(ui_image_t *image, ui_image_flags_t flags)
     132{
     133        image->flags = flags;
     134}
     135
    126136/** Paint image.
    127137 *
     
    131141errno_t ui_image_paint(ui_image_t *image)
    132142{
     143        gfx_rect_t irect;
    133144        gfx_rect_t srect;
    134145        gfx_coord2_t offs;
     146        errno_t rc;
     147
     148        if ((image->flags & ui_imgf_frame) != 0) {
     149                rc = ui_paint_bevel(image->res->gc, &image->rect,
     150                    image->res->btn_frame_color, image->res->btn_frame_color,
     151                    1, NULL);
     152                if (rc != EOK)
     153                        return rc;
     154        }
    135155
    136156        if (image->bitmap == NULL)
    137157                return EOK;
     158
     159        irect = image->rect;
     160        if ((image->flags & ui_imgf_frame) != 0) {
     161                irect.p0.x++;
     162                irect.p0.y++;
     163                irect.p1.x--;
     164                irect.p1.y--;
     165        }
    138166
    139167        /*
     
    141169         * we need to subtract it.
    142170         */
    143         offs.x = image->rect.p0.x - image->brect.p0.x;
    144         offs.y = image->rect.p0.y - image->brect.p0.y;
     171        offs.x = irect.p0.x - image->brect.p0.x;
     172        offs.y = irect.p0.y - image->brect.p0.y;
    145173
    146174        /*
    147          * Transalte image rectangle back to bitmap coordinate space.
     175         * Translate image rectangle back to bitmap coordinate space.
    148176         * Thus the bitmap will be clipped to the image rectangle.
    149177         */
    150         gfx_rect_rtranslate(&offs, &image->rect, &srect);
     178        gfx_rect_rtranslate(&offs, &irect, &srect);
    151179        return gfx_bitmap_render(image->bitmap, &srect, &offs);
     180
    152181}
    153182
  • uspace/lib/ui/test/image.c

    r4f64b7b8 rd8ddf7a  
    110110}
    111111
     112/** Set image flags sets internal field */
     113PCUT_TEST(set_flags)
     114{
     115        ui_image_t *image = NULL;
     116        gfx_rect_t brect;
     117        errno_t rc;
     118
     119        rc = ui_image_create(NULL, NULL, &brect, &image);
     120        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     121        PCUT_ASSERT_NOT_NULL(image);
     122
     123        PCUT_ASSERT_INT_EQUALS(0, image->flags);
     124
     125        ui_image_set_flags(image, ui_imgf_frame);
     126        PCUT_ASSERT_INT_EQUALS(ui_imgf_frame, image->flags);
     127
     128        ui_image_destroy(image);
     129}
     130
    112131/** Set image bitmap */
    113132PCUT_TEST(set_bmp)
Note: See TracChangeset for help on using the changeset viewer.