diff --git a/GuiLite.h b/GuiLite.h index 8f36e48..c4fc88a 100644 --- a/GuiLite.h +++ b/GuiLite.h @@ -123,10 +123,6 @@ typedef struct struct_lattice_font_info unsigned int count; LATTICE* lattice_array; } LATTICE_FONT_INFO; -typedef struct struct_font_info -{ - const void* font; //could be LATTICE_FONT_INFO or TTF -} FONT_INFO; //Rebuild gui library once you change this file enum FONT_LIST { @@ -140,15 +136,15 @@ enum FONT_LIST FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_LIST +enum IMAGE_LIST { - BITMAP_CUSTOM1, - BITMAP_CUSTOM2, - BITMAP_CUSTOM3, - BITMAP_CUSTOM4, - BITMAP_CUSTOM5, - BITMAP_CUSTOM6, - BITMAP_MAX + IMAGE_CUSTOM1, + IMAGE_CUSTOM2, + IMAGE_CUSTOM3, + IMAGE_CUSTOM4, + IMAGE_CUSTOM5, + IMAGE_CUSTOM6, + IMAGE_MAX }; enum COLOR_LIST { @@ -175,7 +171,7 @@ public: ASSERT(false); return -1; } - s_font_map[index].font = font; + s_font_map[index] = font; return 0; } static const void* get_font(FONT_LIST index) @@ -185,27 +181,28 @@ public: ASSERT(false); return 0; } - return s_font_map[index].font; + return s_font_map[index]; } - static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) + static int add_image(IMAGE_LIST index, const void* image_info) { - if (index >= BITMAP_MAX) + if (index >= IMAGE_MAX) { ASSERT(false); return -1; } - s_bmp_map[index] = bmp; + s_image_map[index] = image_info; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_LIST index) + static const void* get_image(IMAGE_LIST index) { - if (index >= BITMAP_MAX) + if (index >= IMAGE_MAX) { ASSERT(false); return 0; } - return s_bmp_map[index]; + return s_image_map[index]; } + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) @@ -226,8 +223,8 @@ public: return s_color_map[index]; } private: - static FONT_INFO s_font_map[FONT_MAX]; - static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; + static const void* s_font_map[FONT_MAX]; + static const void* s_image_map[IMAGE_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; #include @@ -318,7 +315,7 @@ public: c_rect rect; //framebuffer area }; class c_surface { - friend class c_display; friend class c_bitmap; + friend class c_display; friend class c_bitmap_operator; public: c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) { @@ -883,7 +880,7 @@ public: } } }; -class c_lattice_font_op: public c_font_operator +class c_lattice_font_op : public c_font_operator { public: void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) @@ -1131,12 +1128,19 @@ public: }; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; -class c_bitmap +class c_image_operator { public: - static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0; + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0; +}; +class c_bitmap_operator : public c_image_operator +{ +public: + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) { - ASSERT(pBitmap); + ASSERT(image_info); + BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info; unsigned short* lower_fb_16 = 0; unsigned int* lower_fb_32 = 0; int lower_fb_width = 0; @@ -1172,8 +1176,10 @@ public: } } } - static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO* pBitmap, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) { + ASSERT(image_info); + BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info; if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height)) { return; @@ -1213,6 +1219,20 @@ public: } } }; +class c_image +{ +public: + static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + { + image_operator->draw_image(surface, z_order, image_info, x, y, mask_rgb); + } + static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + { + image_operator->draw_image(surface, z_order, image_info, x, y, src_x, src_y, width, height, mask_rgb); + } + + static c_image_operator* image_operator; +}; class c_wnd; class c_surface; typedef enum @@ -3384,11 +3404,15 @@ private: unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; +#ifdef GUILITE_ON +c_bitmap_operator the_bitmap_op = c_bitmap_operator(); +c_image_operator* c_image::image_operator = &the_bitmap_op; +#endif #ifdef GUILITE_ON -FONT_INFO c_theme::s_font_map[FONT_MAX]; -const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; #endif diff --git a/README.md b/README.md index 2b8b16e..eb1a210 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,10 @@ Even a C beginner could master GuiLite quickly. The source code only uses basic
Layout GUI
-
Video: GuiLite + FFmpeg
+
Render JPG file quickly
+ + +
Play video with FFmpeg
diff --git a/README_zh.md b/README_zh.md index f0e6059..9b52b42 100644 --- a/README_zh.md +++ b/README_zh.md @@ -108,7 +108,10 @@
Layout GUI
-
Video: GuiLite + FFmpeg
+
Render JPG file quickly
+ + +
Play video with FFmpeg
diff --git a/documents/HelloJPG.gif b/documents/HelloJPG.gif new file mode 100644 index 0000000..8a767b7 Binary files /dev/null and b/documents/HelloJPG.gif differ diff --git a/workspace/.sync.sh b/workspace/.sync.sh index 368cba8..49cff5b 100755 --- a/workspace/.sync.sh +++ b/workspace/.sync.sh @@ -42,5 +42,5 @@ curl --include --request POST --header "Content-Type: application/json" --data-b \"city\" :\"$city\", \"org\" :\"$org\", \"log\" :\"$build_time\", -\"version\" :\"v2.1\" +\"version\" :\"v2.2\" }]" $url > /dev/null diff --git a/workspace/GuiLite.vcxproj b/workspace/GuiLite.vcxproj index be50834..161a405 100644 --- a/workspace/GuiLite.vcxproj +++ b/workspace/GuiLite.vcxproj @@ -389,8 +389,8 @@ - + diff --git a/workspace/GuiLite.vcxproj.filters b/workspace/GuiLite.vcxproj.filters index 858241b..f78d165 100644 --- a/workspace/GuiLite.vcxproj.filters +++ b/workspace/GuiLite.vcxproj.filters @@ -34,9 +34,6 @@ widgets - - core - core @@ -52,6 +49,9 @@ core\adapter + + core + diff --git a/workspace/core/bitmap.cpp b/workspace/core/bitmap.cpp deleted file mode 100644 index 9bbaaf5..0000000 --- a/workspace/core/bitmap.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "../core_include/bitmap.h" diff --git a/workspace/core/image.cpp b/workspace/core/image.cpp new file mode 100644 index 0000000..a778ad1 --- /dev/null +++ b/workspace/core/image.cpp @@ -0,0 +1,8 @@ +#include "../core_include/image.h" + +#ifdef GUILITE_ON + +c_bitmap_operator the_bitmap_op = c_bitmap_operator(); +c_image_operator* c_image::image_operator = &the_bitmap_op; + +#endif diff --git a/workspace/core/theme.cpp b/workspace/core/theme.cpp index 44feb1d..ca21ff3 100644 --- a/workspace/core/theme.cpp +++ b/workspace/core/theme.cpp @@ -2,8 +2,8 @@ #ifdef GUILITE_ON -FONT_INFO c_theme::s_font_map[FONT_MAX]; -const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; +const void* c_theme::s_font_map[FONT_MAX]; +const void* c_theme::s_image_map[IMAGE_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; #endif diff --git a/workspace/core_include/display.h b/workspace/core_include/display.h index 2a9db69..dad6889 100644 --- a/workspace/core_include/display.h +++ b/workspace/core_include/display.h @@ -103,7 +103,7 @@ public: }; class c_surface { - friend class c_display; friend class c_bitmap; + friend class c_display; friend class c_bitmap_operator; public: c_surface(unsigned int width, unsigned int height, unsigned int color_bytes, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0, c_rect overlpa_rect = c_rect()) : m_width(width), m_height(height), m_color_bytes(color_bytes), m_fb(0), m_is_active(false), m_top_zorder(Z_ORDER_LEVEL_0), m_phy_fb(0), m_phy_write_index(0), m_display(0) { diff --git a/workspace/core_include/bitmap.h b/workspace/core_include/image.h similarity index 65% rename from workspace/core_include/bitmap.h rename to workspace/core_include/image.h index 5abb10f..cf5c07a 100644 --- a/workspace/core_include/bitmap.h +++ b/workspace/core_include/image.h @@ -6,12 +6,21 @@ #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; -class c_bitmap + +class c_image_operator { public: - static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0; + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) = 0; +}; + +class c_bitmap_operator : public c_image_operator +{ +public: + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) { - ASSERT(pBitmap); + ASSERT(image_info); + BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info; unsigned short* lower_fb_16 = 0; unsigned int* lower_fb_32 = 0; int lower_fb_width = 0; @@ -48,8 +57,10 @@ public: } } - static void draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO* pBitmap, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + virtual void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) { + ASSERT(image_info); + BITMAP_INFO* pBitmap = (BITMAP_INFO*)image_info; if (0 == pBitmap || (src_x + width > pBitmap->width) || (src_y + height > pBitmap->height)) { return; @@ -89,5 +100,20 @@ public: } } } - +}; + +class c_image +{ +public: + static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + { + image_operator->draw_image(surface, z_order, image_info, x, y, mask_rgb); + } + + static void draw_image(c_surface* surface, int z_order, const void* image_info, int x, int y, int src_x, int src_y, int width, int height, unsigned int mask_rgb = DEFAULT_MASK_COLOR) + { + image_operator->draw_image(surface, z_order, image_info, x, y, src_x, src_y, width, height, mask_rgb); + } + + static c_image_operator* image_operator; }; diff --git a/workspace/core_include/resource.h b/workspace/core_include/resource.h index aeaf200..7eb6cab 100644 --- a/workspace/core_include/resource.h +++ b/workspace/core_include/resource.h @@ -23,8 +23,3 @@ typedef struct struct_lattice_font_info unsigned int count; LATTICE* lattice_array; } LATTICE_FONT_INFO; - -typedef struct struct_font_info -{ - const void* font; //could be LATTICE_FONT_INFO or TTF -} FONT_INFO; diff --git a/workspace/core_include/theme.h b/workspace/core_include/theme.h index 6a00412..663e9fd 100644 --- a/workspace/core_include/theme.h +++ b/workspace/core_include/theme.h @@ -18,16 +18,16 @@ enum FONT_LIST FONT_MAX }; -enum BITMAP_LIST +enum IMAGE_LIST { - BITMAP_CUSTOM1, - BITMAP_CUSTOM2, - BITMAP_CUSTOM3, - BITMAP_CUSTOM4, - BITMAP_CUSTOM5, - BITMAP_CUSTOM6, + IMAGE_CUSTOM1, + IMAGE_CUSTOM2, + IMAGE_CUSTOM3, + IMAGE_CUSTOM4, + IMAGE_CUSTOM5, + IMAGE_CUSTOM6, - BITMAP_MAX + IMAGE_MAX }; enum COLOR_LIST @@ -58,9 +58,10 @@ public: ASSERT(false); return -1; } - s_font_map[index].font = font; + s_font_map[index] = font; return 0; } + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) @@ -68,27 +69,30 @@ public: ASSERT(false); return 0; } - return s_font_map[index].font; + return s_font_map[index]; } - static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) + + static int add_image(IMAGE_LIST index, const void* image_info) { - if (index >= BITMAP_MAX) + if (index >= IMAGE_MAX) { ASSERT(false); return -1; } - s_bmp_map[index] = bmp; + s_image_map[index] = image_info; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_LIST index) + + static const void* get_image(IMAGE_LIST index) { - if (index >= BITMAP_MAX) + if (index >= IMAGE_MAX) { ASSERT(false); return 0; } - return s_bmp_map[index]; + return s_image_map[index]; } + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) @@ -99,6 +103,7 @@ public: s_color_map[index] = color; return 0; } + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) @@ -108,8 +113,9 @@ public: } return s_color_map[index]; } + private: - static FONT_INFO s_font_map[FONT_MAX]; - static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; + static const void* s_font_map[FONT_MAX]; + static const void* s_image_map[IMAGE_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; diff --git a/workspace/core_include/wnd.h b/workspace/core_include/wnd.h index 53a3b1c..da74dfa 100644 --- a/workspace/core_include/wnd.h +++ b/workspace/core_include/wnd.h @@ -2,7 +2,6 @@ #include "../core_include/api.h" #include "../core_include/resource.h" -#include "../core_include/bitmap.h" #include "../core_include/display.h" class c_wnd; diff --git a/workspace/core_include/word.h b/workspace/core_include/word.h index 18055f1..444e739 100644 --- a/workspace/core_include/word.h +++ b/workspace/core_include/word.h @@ -74,7 +74,7 @@ public: } }; -class c_lattice_font_op: public c_font_operator +class c_lattice_font_op : public c_font_operator { public: void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) diff --git a/workspace/header-only.sh b/workspace/header-only.sh index ba1e995..14808c5 100644 --- a/workspace/header-only.sh +++ b/workspace/header-only.sh @@ -2,7 +2,7 @@ echo "Build header-only library: GuiLite.h" # build GuiLiteRaw.h cd core_include -cat api.h resource.h theme.h display.h word.h bitmap.h wnd.h > core.h +cat api.h resource.h theme.h display.h word.h image.h wnd.h > core.h mv core.h ../ cd ../widgets_include diff --git a/workspace/sync_build.bat b/workspace/sync_build.bat index 2a978cc..2a5bf34 100644 --- a/workspace/sync_build.bat +++ b/workspace/sync_build.bat @@ -66,7 +66,7 @@ set raw_data=[{^ \"city\" :\"%city%\",^ \"org\" :\"%org%\",^ \"log\" :\"%datetime%\",^ -\"version\" :\"v2.1\"^ +\"version\" :\"v2.2\"^ }] curl.exe --include --request POST --header "Content-Type: application/json" --data-binary "%raw_data%" "%url%" diff --git a/workspace/widgets_include/button.h b/workspace/widgets_include/button.h index 5673cfb..ab28f4e 100644 --- a/workspace/widgets_include/button.h +++ b/workspace/widgets_include/button.h @@ -3,7 +3,6 @@ #include "../core_include/api.h" #include "../core_include/wnd.h" #include "../core_include/resource.h" -#include "../core_include/bitmap.h" #include "../core_include/word.h" #include "../core_include/display.h" #include "../core_include/theme.h" diff --git a/workspace/widgets_include/label.h b/workspace/widgets_include/label.h index 2383161..de8c4de 100644 --- a/workspace/widgets_include/label.h +++ b/workspace/widgets_include/label.h @@ -4,7 +4,6 @@ #include "../core_include/wnd.h" #include "../core_include/display.h" #include "../core_include/resource.h" -#include "../core_include/bitmap.h" #include "../core_include/theme.h" #include "../core_include/word.h" diff --git a/workspace/widgets_include/list_box.h b/workspace/widgets_include/list_box.h index c3fbc39..fd8d866 100644 --- a/workspace/widgets_include/list_box.h +++ b/workspace/widgets_include/list_box.h @@ -4,7 +4,6 @@ #include "../core_include/resource.h" #include "../core_include/wnd.h" #include "../core_include/display.h" -#include "../core_include/bitmap.h" #include "../core_include/word.h" #include "../core_include/theme.h" #include "../widgets_include/button.h"