acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_canvas_1.c (1958B)

      1 #include "../../lv_examples.h"
      2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
      3 
      4 
      5 #define CANVAS_WIDTH  200
      6 #define CANVAS_HEIGHT  150
      7 
      8 void lv_example_canvas_1(void)
      9 {
     10     lv_draw_rect_dsc_t rect_dsc;
     11     lv_draw_rect_dsc_init(&rect_dsc);
     12     rect_dsc.radius = 10;
     13     rect_dsc.bg_opa = LV_OPA_COVER;
     14     rect_dsc.bg_grad.dir = LV_GRAD_DIR_HOR;
     15     rect_dsc.bg_grad.stops[0].color = lv_palette_main(LV_PALETTE_RED);
     16     rect_dsc.bg_grad.stops[1].color = lv_palette_main(LV_PALETTE_BLUE);
     17     rect_dsc.border_width = 2;
     18     rect_dsc.border_opa = LV_OPA_90;
     19     rect_dsc.border_color = lv_color_white();
     20     rect_dsc.shadow_width = 5;
     21     rect_dsc.shadow_ofs_x = 5;
     22     rect_dsc.shadow_ofs_y = 5;
     23 
     24     lv_draw_label_dsc_t label_dsc;
     25     lv_draw_label_dsc_init(&label_dsc);
     26     label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE);
     27 
     28     static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
     29 
     30     lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
     31     lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
     32     lv_obj_center(canvas);
     33     lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
     34 
     35     lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc);
     36 
     37     lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas");
     38 
     39     /*Test the rotation. It requires another buffer where the original image is stored.
     40      *So copy the current image to buffer and rotate it to the canvas*/
     41     static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
     42     memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
     43     lv_img_dsc_t img;
     44     img.data = (void *)cbuf_tmp;
     45     img.header.cf = LV_IMG_CF_TRUE_COLOR;
     46     img.header.w = CANVAS_WIDTH;
     47     img.header.h = CANVAS_HEIGHT;
     48 
     49     lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
     50     lv_canvas_transform(canvas, &img, 120, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
     51 }
     52 
     53 #endif