| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | /******************************************************************************
|
| 2 | *(C) Copyright 2014 Marvell International Ltd.
|
| 3 | * All Rights Reserved
|
| 4 | ******************************************************************************/
|
| 5 | /*******************************************************************************
|
| 6 | *
|
| 7 | * Filename: Line.c
|
| 8 | *
|
| 9 | * Authors: Boaz Sommer
|
| 10 | *
|
| 11 | * Description: A Line class
|
| 12 | *
|
| 13 | * HISTORY:
|
| 14 | *
|
| 15 | *
|
| 16 | *
|
| 17 | * Notes:
|
| 18 | *
|
| 19 | ******************************************************************************/
|
| 20 | #include <stdarg.h>
|
| 21 | #include <stdlib.h>
|
| 22 | #include <string.h>
|
| 23 |
|
| 24 | #include "mgui_utils.h"
|
| 25 | #include "Image.h"
|
| 26 |
|
| 27 | typedef struct _IMAGE_ARRAY
|
| 28 | {
|
| 29 | int num_items;
|
| 30 | int image_index_to_display;
|
| 31 | int image_index_last_display;
|
| 32 | IMAGE_ARRAY_ITEM *image_array_items;
|
| 33 | }IMAGE_ARRAY;
|
| 34 |
|
| 35 | typedef struct S_IMAGE_PRIV
|
| 36 | {
|
| 37 | void *dfb;
|
| 38 | IMAGE_ARRAY image_array;
|
| 39 | IMAGE_ARRAY_ITEM single_image_path;
|
| 40 | OBJECT_RECT region;
|
| 41 | }IMAGE_PRIV;
|
| 42 |
|
| 43 | static char *_ImageGetPath(IMAGE_PRIV *image)
|
| 44 | {
|
| 45 | char *path = NULL;
|
| 46 |
|
| 47 | if (image->single_image_path.path)
|
| 48 | path = image->single_image_path.path;
|
| 49 | else if (image->image_array.image_index_to_display != -1)
|
| 50 | path = image->image_array.image_array_items[image->image_array.image_index_to_display].path;
|
| 51 |
|
| 52 | return path;
|
| 53 | }
|
| 54 |
|
| 55 | static void _ImageFreeArray (IMAGE_PRIV *image)
|
| 56 | {
|
| 57 | int i, num = image->image_array.num_items;
|
| 58 |
|
| 59 | for (i = 0; i < num; i++)
|
| 60 | {
|
| 61 | if (image->image_array.image_array_items[i].path != NULL)
|
| 62 | {
|
| 63 | free (image->image_array.image_array_items[i].path);
|
| 64 | GuiReleaseImageSurface(image->dfb, image->image_array.image_array_items[i].image_surface);
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | free(image->image_array.image_array_items);
|
| 69 | image->image_array.image_array_items = NULL;
|
| 70 | image->image_array.num_items = 0;
|
| 71 | image->image_array.image_index_to_display = -1;
|
| 72 | image->image_array.image_index_last_display = -1;
|
| 73 | }
|
| 74 |
|
| 75 |
|
| 76 | IMAGE ImageInit (void *dfb)
|
| 77 | {
|
| 78 | IMAGE_PRIV *image = calloc(1, sizeof(*image));
|
| 79 |
|
| 80 | image->dfb = dfb;
|
| 81 | GuiAddObject(image->dfb, image, (ObjectDrawFunc)ImageDraw);
|
| 82 | image->image_array.image_index_to_display = -1;
|
| 83 | image->image_array.image_index_last_display = -1;
|
| 84 | image->single_image_path.path = NULL;
|
| 85 | image->image_array.num_items = 0;
|
| 86 |
|
| 87 | return (IMAGE)image;
|
| 88 | }
|
| 89 |
|
| 90 | void ImageDeinit (IMAGE pt)
|
| 91 | {
|
| 92 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 93 |
|
| 94 | if (image)
|
| 95 | {
|
| 96 | _ImageFreeArray(image);
|
| 97 | if (image->single_image_path.path)
|
| 98 | {
|
| 99 | GuiReleaseImageSurface(image->dfb, image->single_image_path.image_surface);
|
| 100 | free (image->single_image_path.path);
|
| 101 | }
|
| 102 | GuiRemoveObject(image->dfb, image);
|
| 103 | free (image);
|
| 104 | image = NULL;
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 |
|
| 109 | void ImageDraw (IMAGE pt)
|
| 110 | {
|
| 111 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 112 | IMAGE_ARRAY_ITEM *image_array_item = NULL;
|
| 113 | if (image)
|
| 114 | {
|
| 115 | //MGUI_DMSG("image_index_to_display = %d\n", image->image_array.image_index_to_display);
|
| 116 | if (image->image_array.image_index_to_display >= 0) {
|
| 117 | image_array_item = &image->image_array.image_array_items[image->image_array.image_index_to_display];
|
| 118 | if (image->image_array.image_index_last_display != image->image_array.image_index_to_display &&
|
| 119 | image->image_array.image_index_last_display >= 0)
|
| 120 | lvgl_image_hide(image->image_array.image_array_items[image->image_array.image_index_last_display].image_surface);
|
| 121 | } else if (image->single_image_path.path)
|
| 122 | image_array_item = &image->single_image_path;
|
| 123 | //MGUI_DMSG("image_array_item = %04X\n", (unsigned long)image_array_item);
|
| 124 | if (image_array_item) {
|
| 125 | //DirectFbDrawImageFromSurface (image->dfb, image_array_item->image_surface, image->region.lx, image->region.ly);
|
| 126 | MGUI_DMSG("ptr=%p, key=%d, path=%s, surface=%p, flags=0x%08x, region=[h:%d w:%d:, lx:%d, ly:%d,\n",
|
| 127 | image_array_item,
|
| 128 | image_array_item->key, image_array_item->path,
|
| 129 | image_array_item->image_surface,
|
| 130 | image_array_item->image_blitting_flags,
|
| 131 | image->region.h, image->region.w, image->region.lx, image->region.ly);
|
| 132 |
|
| 133 | GuiDrawResizeImageFromSurface(image->dfb,
|
| 134 | image_array_item->image_surface,
|
| 135 | &image_array_item->image_blitting_flags,
|
| 136 | &image->region);
|
| 137 | }
|
| 138 | }
|
| 139 |
|
| 140 | #if 0
|
| 141 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 142 | char *path = NULL;
|
| 143 | if (image)
|
| 144 | {
|
| 145 | path = _ImageGetPath(image);
|
| 146 | if (path)
|
| 147 | {
|
| 148 | MGUI_DMSG("path = %s\n", path);
|
| 149 | DirectFbDrawImage(image->dfb, path, &image->region);
|
| 150 | }
|
| 151 | }
|
| 152 | #endif
|
| 153 | }
|
| 154 |
|
| 155 |
|
| 156 | void ImageSetup2(IMAGE pt, OBJECT_RECT rect)
|
| 157 | {
|
| 158 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 159 | if (image) {
|
| 160 | image->region = rect;
|
| 161 | }
|
| 162 | }
|
| 163 |
|
| 164 | void ImageSetup (IMAGE pt, int lx, int ly, int w, int h)
|
| 165 | {
|
| 166 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 167 | if (image)
|
| 168 | {
|
| 169 | image->region.lx = lx;
|
| 170 | image->region.ly = ly;
|
| 171 | image->region.w = w;
|
| 172 | image->region.h = h;
|
| 173 | }
|
| 174 | }
|
| 175 |
|
| 176 | void ImageSetFromPath (IMAGE pt, char *resPath)
|
| 177 | {
|
| 178 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 179 |
|
| 180 | if (image && resPath)
|
| 181 | {
|
| 182 | MGUI_DMSG("image path = %s\n", resPath);
|
| 183 | image->single_image_path.path = strdup(resPath);
|
| 184 | GuiCreateImageSurface(image->dfb, resPath,
|
| 185 | &image->single_image_path.image_surface,
|
| 186 | &image->single_image_path.image_blitting_flags);
|
| 187 |
|
| 188 | GuiGetImageGeometry(image->dfb, resPath, &image->region);
|
| 189 | MGUI_DMSG("image Width x Height = %d x %d\n", image->region.w, image->region.h);
|
| 190 | }
|
| 191 | }
|
| 192 |
|
| 193 | void ImageGetGeometry (IMAGE pt, OBJECT_RECT *rect)
|
| 194 | {
|
| 195 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 196 | char *path;
|
| 197 | if (image)
|
| 198 | {
|
| 199 | path = _ImageGetPath(image);
|
| 200 | if (path)
|
| 201 | {
|
| 202 | GuiGetImageGeometry(image->dfb, path, rect);
|
| 203 | }
|
| 204 | }
|
| 205 | }
|
| 206 |
|
| 207 | void ImageSetFromArray (IMAGE pt, int key)
|
| 208 | {
|
| 209 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 210 | int i;
|
| 211 |
|
| 212 | if (image)
|
| 213 | {
|
| 214 | for (i = 0; i < image->image_array.num_items; i++)
|
| 215 | {
|
| 216 | if (key == image->image_array.image_array_items[i].key)
|
| 217 | {
|
| 218 | image->image_array.image_index_last_display = image->image_array.image_index_to_display;
|
| 219 | image->image_array.image_index_to_display = i;
|
| 220 | break;
|
| 221 | }
|
| 222 | }
|
| 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | void ImageSetArray (IMAGE pt, const IMAGE_ARRAY_ITEM *array, int size)
|
| 227 | {
|
| 228 | IMAGE_PRIV *image = (IMAGE_PRIV *)pt;
|
| 229 | int i;
|
| 230 |
|
| 231 | MGUI_DMSG("image = %08X\n", (unsigned long )image);
|
| 232 |
|
| 233 | if (image)
|
| 234 | {
|
| 235 | if (image->image_array.image_array_items != NULL)
|
| 236 | {
|
| 237 | MGUI_DMSG("Freeing image array\n");
|
| 238 | _ImageFreeArray(image);
|
| 239 | }
|
| 240 |
|
| 241 | image->image_array.image_array_items = calloc(size, sizeof(IMAGE_ARRAY_ITEM));
|
| 242 | MGUI_DMSG("image_array_items allocated, address = %08X, size = %d\n", (unsigned long)image->image_array.image_array_items,
|
| 243 | size);
|
| 244 | for (i = 0; i < size; i++)
|
| 245 | {
|
| 246 | image->image_array.image_array_items[i].key = array[i].key;
|
| 247 | image->image_array.image_array_items[i].path = strdup(array[i].path);
|
| 248 | GuiCreateImageSurface(image->dfb,
|
| 249 | image->image_array.image_array_items[i].path,
|
| 250 | &image->image_array.image_array_items[i].image_surface,
|
| 251 | &image->image_array.image_array_items[i].image_blitting_flags);
|
| 252 | }
|
| 253 | image->image_array.num_items = size;
|
| 254 | }
|
| 255 |
|
| 256 | MGUI_DMSG("Done.\n");
|
| 257 | }
|
| 258 |
|