Changeset 66a2becf in mainline for uspace/lib/ui/src/window.c


Ignore:
Timestamp:
2020-11-11T18:05:01Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b93ec7c0
Parents:
d942ca4
Message:

Application area GC / port font editor

Font editor and other 'non-GUI' applications typically assume that
0,0 is the top left of the 'screen'/application area. We provide
a special GC that meets this requirement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/window.c

    rd942ca4 r66a2becf  
    3636#include <display.h>
    3737#include <errno.h>
     38#include <gfx/bitmap.h>
    3839#include <gfx/context.h>
    3940#include <gfx/render.h>
     
    4142#include <io/pos_event.h>
    4243#include <mem.h>
     44#include <memgfx/memgc.h>
    4345#include <stdlib.h>
    4446#include <ui/control.h>
     
    7476        .move = wd_move
    7577};
     78
     79static void ui_window_app_update(void *, gfx_rect_t *);
    7680
    7781/** Initialize window parameters structure.
     
    223227}
    224228
     229/** Get UI resource from window.
     230 *
     231 * @param window Window
     232 * @return UI resource
     233 */
    225234ui_resource_t *ui_window_get_res(ui_window_t *window)
    226235{
     
    228237}
    229238
     239/** Get window GC.
     240 *
     241 * @param window Window
     242 * @return GC (relative to window)
     243 */
    230244gfx_context_t *ui_window_get_gc(ui_window_t *window)
    231245{
     
    233247}
    234248
     249/** Get window application area GC
     250 *
     251 * @param window Window
     252 * @param rgc Place to store GC (relative to application area)
     253 * @return EOK on success or an error code
     254 */
     255errno_t ui_window_get_app_gc(ui_window_t *window, gfx_context_t **rgc)
     256{
     257        gfx_bitmap_params_t params;
     258        gfx_bitmap_alloc_t alloc;
     259        gfx_rect_t rect;
     260        mem_gc_t *memgc;
     261        errno_t rc;
     262
     263        if (window->app_gc == NULL) {
     264                assert(window->app_bmp == NULL);
     265
     266                gfx_bitmap_params_init(&params);
     267
     268                /*
     269                 * The bitmap will have the same dimensions as the
     270                 * application rectangle, but start at 0,0.
     271                 */
     272                ui_window_get_app_rect(window, &rect);
     273                gfx_rect_rtranslate(&rect.p0, &rect, &params.rect);
     274
     275                rc = gfx_bitmap_create(window->gc, &params, NULL,
     276                    &window->app_bmp);
     277                if (rc != EOK)
     278                        return rc;
     279
     280                rc = gfx_bitmap_get_alloc(window->app_bmp, &alloc);
     281                if (rc != EOK) {
     282                        gfx_bitmap_destroy(window->app_bmp);
     283                        return rc;
     284                }
     285
     286                rc = mem_gc_create(&params.rect, &alloc, ui_window_app_update,
     287                    (void *) window, &memgc);
     288                if (rc != EOK) {
     289                        gfx_bitmap_destroy(window->app_bmp);
     290                        return rc;
     291                }
     292
     293                window->app_gc = mem_gc_get_ctx(memgc);
     294        }
     295
     296        *rgc = window->app_gc;
     297        return EOK;
     298}
     299
     300/** Get window application rectangle
     301 *
     302 * @param window Window
     303 * @param rect Place to store application rectangle
     304 */
    235305void ui_window_get_app_rect(ui_window_t *window, gfx_rect_t *rect)
    236306{
     
    241311}
    242312
     313/** Paint window
     314 *
     315 * @param window Window
     316 * @return EOK on success or an error code
     317 */
    243318errno_t ui_window_paint(ui_window_t *window)
    244319{
     
    428503}
    429504
     505/** Application area update callback
     506 *
     507 * @param arg Argument (ui_window_t *)
     508 * @param rect Rectangle to update
     509 */
     510static void ui_window_app_update(void *arg, gfx_rect_t *rect)
     511{
     512        ui_window_t *window = (ui_window_t *) arg;
     513        gfx_rect_t arect;
     514
     515        ui_window_get_app_rect(window, &arect);
     516
     517        /* Render bitmap rectangle inside the application area */
     518        (void) gfx_bitmap_render(window->app_bmp, rect, &arect.p0);
     519}
     520
    430521/** @}
    431522 */
Note: See TracChangeset for help on using the changeset viewer.