mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 12:08:16 +08:00
improve guage
This commit is contained in:
parent
f0673cd7dc
commit
ed3eca5d26
@ -12,6 +12,7 @@
|
||||
#include "assets/inc/styles/default.data"
|
||||
#include "assets/inc/styles/big_font.data"
|
||||
#include "assets/inc/styles/tab_top_compact.data"
|
||||
#include "assets/inc/styles/guage.data"
|
||||
#include "assets/inc/styles/dialog.data"
|
||||
#include "assets/inc/styles/tab_top.data"
|
||||
#include "assets/inc/styles/button.data"
|
||||
@ -280,17 +281,17 @@
|
||||
#include "assets/inc/images/3.data"
|
||||
#include "assets/inc/images/arrow_left_n.data"
|
||||
#include "assets/inc/images/edit_clear_p.data"
|
||||
#endif/*WITH_STB_IMAGE*/
|
||||
#endif /*WITH_STB_IMAGE*/
|
||||
#ifdef WITH_STB_FONT
|
||||
#ifdef WITH_MINI_FONT
|
||||
#include "assets/inc/fonts/default.mini.res"
|
||||
#else/*WITH_MINI_FONT*/
|
||||
#else /*WITH_MINI_FONT*/
|
||||
#include "assets/inc/fonts/default.res"
|
||||
#endif/*WITH_MINI_FONT*/
|
||||
#else/*WITH_STB_FONT*/
|
||||
#endif /*WITH_MINI_FONT*/
|
||||
#else /*WITH_STB_FONT*/
|
||||
#include "assets/inc/fonts/default.data"
|
||||
#endif/*WITH_STB_FONT*/
|
||||
#endif/*WITH_FS_RES*/
|
||||
#endif /*WITH_STB_FONT*/
|
||||
#endif /*WITH_FS_RES*/
|
||||
|
||||
ret_t assets_init(void) {
|
||||
assets_manager_t* rm = assets_manager();
|
||||
@ -476,6 +477,7 @@ ret_t assets_init(void) {
|
||||
assets_manager_add(rm, style_default);
|
||||
assets_manager_add(rm, style_big_font);
|
||||
assets_manager_add(rm, style_tab_top_compact);
|
||||
assets_manager_add(rm, style_guage);
|
||||
assets_manager_add(rm, style_dialog);
|
||||
assets_manager_add(rm, style_tab_top);
|
||||
assets_manager_add(rm, style_button);
|
||||
|
9
demos/assets/inc/styles/guage.data
Normal file
9
demos/assets/inc/styles/guage.data
Normal file
@ -0,0 +1,9 @@
|
||||
const unsigned char style_guage[] = {
|
||||
0x03,0x00,0x00,0x01,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x75,0x61,0x67,0x65,0x00,0x64,0x61,
|
||||
0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0xfd,0xfc,0xfb,0xfa,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x54,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x75,0x61,0x67,
|
||||
0x65,0x5f,0x70,0x6f,0x69,0x6e,0x74,0x65,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xfe,0x17,0x00,0xff,
|
||||
0x02,0x00,0x00,0x00,0x3f,0x01,0x36,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*156*/
|
@ -1,5 +1,5 @@
|
||||
const unsigned char ui_guage[] = {
|
||||
0x04,0x00,0x01,0x01,0x9f,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x75,0x61,0x67,0x65,0x00,0x64,0x61,
|
||||
0x04,0x00,0x01,0x01,0x7c,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x75,0x61,0x67,0x65,0x00,0x64,0x61,
|
||||
0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x12,0x12,0x22,0x11,0x77,0x69,0x6e,0x64,0x6f,0x77,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
@ -7,7 +7,7 @@ const unsigned char ui_guage[] = {
|
||||
0x00,0x00,0x00,0x00,0x73,0x74,0x79,0x6c,0x65,0x00,0x64,0x61,0x72,0x6b,0x00,0x61,0x6e,0x69,0x6d,0x5f,
|
||||
0x68,0x69,0x6e,0x74,0x00,0x68,0x74,0x72,0x61,0x6e,0x73,0x6c,0x61,0x74,0x65,0x00,0x00,0x67,0x75,0x61,
|
||||
0x67,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,
|
||||
0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x67,
|
||||
0x75,0x61,0x67,0x65,0x5f,0x62,0x67,0x00,0x00,0x67,0x75,0x61,0x67,0x65,0x5f,0x70,0x6f,0x69,0x6e,0x74,
|
||||
0x65,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
@ -17,9 +17,20 @@ const unsigned char ui_guage[] = {
|
||||
0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x2d,0x31,0x32,
|
||||
0x38,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x32,0x38,0x2c,0x20,0x79,0x6f,0x79,0x6f,0x5f,0x74,0x69,0x6d,0x65,
|
||||
0x73,0x3d,0x31,0x30,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x33,0x30,0x30,
|
||||
0x30,0x2c,0x20,0x64,0x65,0x6c,0x61,0x79,0x3d,0x31,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x00,0x62,0x75,
|
||||
0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,
|
||||
0x00,0x00,0x19,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,
|
||||
0x6c,0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,};/*463*/
|
||||
0x30,0x2c,0x20,0x64,0x65,0x6c,0x61,0x79,0x3d,0x31,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x00,0x67,0x75,
|
||||
0x61,0x67,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,
|
||||
0x00,0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,
|
||||
0x67,0x75,0x61,0x67,0x65,0x5f,0x62,0x67,0x00,0x00,0x67,0x75,0x61,0x67,0x65,0x5f,0x70,0x6f,0x69,0x6e,
|
||||
0x74,0x65,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x8c,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x2d,0x31,0x32,0x38,0x00,0x61,0x6e,0x69,
|
||||
0x6d,0x61,0x74,0x69,0x6f,0x6e,0x00,0x76,0x61,0x6c,0x75,0x65,0x28,0x66,0x72,0x6f,0x6d,0x3d,0x2d,0x31,
|
||||
0x32,0x38,0x2c,0x20,0x74,0x6f,0x3d,0x31,0x32,0x38,0x2c,0x20,0x79,0x6f,0x79,0x6f,0x5f,0x74,0x69,0x6d,
|
||||
0x65,0x73,0x3d,0x31,0x30,0x30,0x30,0x2c,0x20,0x64,0x75,0x72,0x61,0x74,0x69,0x6f,0x6e,0x3d,0x33,0x30,
|
||||
0x30,0x30,0x2c,0x20,0x64,0x65,0x6c,0x61,0x79,0x3d,0x31,0x30,0x30,0x30,0x29,0x00,0x00,0x00,0x00,0x62,
|
||||
0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x0a,
|
||||
0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,
|
||||
0x63,0x6c,0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,};/*684*/
|
||||
|
BIN
demos/assets/raw/styles/guage.bin
Normal file
BIN
demos/assets/raw/styles/guage.bin
Normal file
Binary file not shown.
5
demos/assets/raw/styles/guage.xml
Normal file
5
demos/assets/raw/styles/guage.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<guage_pointer>
|
||||
<style name="default">
|
||||
<normal bg_color="#fe1700" fg_color="#3f0136"/>
|
||||
</style>
|
||||
</guage_pointer>
|
Binary file not shown.
@ -1,7 +1,12 @@
|
||||
<window style="dark" anim_hint="htranslate" >
|
||||
<guage x="c" y="m" w="240" h="240" image="guage_bg" >
|
||||
<guage x="c" y="10" w="240" h="240" image="guage_bg" >
|
||||
<guage_pointer x="c" y="50" w="24" h="140" value="-128" image="guage_pointer"
|
||||
animation="value(from=-128, to=128, yoyo_times=1000, duration=3000, delay=1000)"/>
|
||||
</guage>
|
||||
</guage>
|
||||
|
||||
<guage x="c" y="bottom:60" w="240" h="240" image="guage_bg" >
|
||||
<guage_pointer x="c" y="50" w="12" h="140" value="-128"
|
||||
animation="value(from=-128, to=128, yoyo_times=1000, duration=3000, delay=1000)"/>
|
||||
</guage>
|
||||
<button name="close" x="center" y="bottom:10" w="25%" h="30" text="Close"/>
|
||||
</window>
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "base/mem.h"
|
||||
#include "base/utils.h"
|
||||
#include "base/matrix.h"
|
||||
#include "base/widget_vtable.h"
|
||||
#include "guage/guage_pointer.h"
|
||||
#include "base/image_manager.h"
|
||||
|
||||
@ -85,30 +86,59 @@ static ret_t guage_pointer_destroy(widget_t* widget) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t guage_pointer_paint_default(widget_t* widget, vgcanvas_t* vg) {
|
||||
float_t w = widget->w;
|
||||
float_t h = widget->h;
|
||||
float_t cx = w * 0.5f;
|
||||
float_t cy = h * 0.5f;
|
||||
style_t* style = widget->astyle;
|
||||
color_t black = color_init(0, 0, 0, 0xff);
|
||||
color_t bg = style_get_color(style, STYLE_ID_BG_COLOR, black);
|
||||
color_t fg = style_get_color(style, STYLE_ID_FG_COLOR, black);
|
||||
|
||||
vgcanvas_begin_path(vg);
|
||||
vgcanvas_move_to(vg, cx, 0);
|
||||
vgcanvas_line_to(vg, cx, cx + h * 0.6);
|
||||
vgcanvas_set_line_width(vg, 2);
|
||||
vgcanvas_set_stroke_color(vg, bg);
|
||||
vgcanvas_stroke(vg);
|
||||
|
||||
vgcanvas_begin_path(vg);
|
||||
vgcanvas_set_fill_color(vg, fg);
|
||||
vgcanvas_arc(vg, cx, cy, cx, 0, M_PI * 2, FALSE);
|
||||
vgcanvas_fill(vg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t guage_pointer_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
bitmap_t bitmap;
|
||||
float_t rotation = 0;
|
||||
float_t anchor_x = 0;
|
||||
float_t anchor_y = 0;
|
||||
matrix_t matrix;
|
||||
matrix_t* m = matrix_init(&matrix);
|
||||
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
|
||||
guage_pointer_t* guage_pointer = GUAGE_POINTER(widget);
|
||||
rect_t dst = rect_init(0, 0, widget->w, widget->h);
|
||||
return_value_if_fail(guage_pointer->image != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (widget_load_image(widget, guage_pointer->image, &bitmap) == RET_OK) {
|
||||
anchor_x = dst.w * 0.5f;
|
||||
anchor_y = dst.h * 0.5f;
|
||||
rotation = TK_D2R(guage_pointer->angle);
|
||||
anchor_x = dst.w * 0.5f;
|
||||
anchor_y = dst.h * 0.5f;
|
||||
rotation = TK_D2R(guage_pointer->angle);
|
||||
|
||||
matrix_identity(m);
|
||||
matrix_translate(m, c->ox, c->oy);
|
||||
matrix_translate(m, anchor_x, anchor_y);
|
||||
matrix_rotate(m, rotation);
|
||||
matrix_translate(m, -anchor_x, -anchor_y);
|
||||
vgcanvas_save(vg);
|
||||
vgcanvas_translate(vg, c->ox, c->oy);
|
||||
vgcanvas_translate(vg, anchor_x, anchor_y);
|
||||
vgcanvas_rotate(vg, rotation);
|
||||
vgcanvas_translate(vg, -anchor_x, -anchor_y);
|
||||
|
||||
canvas_draw_image_matrix(c, &bitmap, &matrix);
|
||||
if (guage_pointer->image != NULL &&
|
||||
widget_load_image(widget, guage_pointer->image, &bitmap) == RET_OK) {
|
||||
float_t w = bitmap.w;
|
||||
float_t h = bitmap.h;
|
||||
vgcanvas_draw_image(vg, &bitmap, 0, 0, w, h, 0, 0, w, h);
|
||||
} else {
|
||||
guage_pointer_paint_default(widget, vg);
|
||||
}
|
||||
vgcanvas_restore(vg);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -123,6 +153,7 @@ static const widget_vtable_t s_guage_pointer_vtable = {
|
||||
.persistent_properties = s_guage_pointer_properties,
|
||||
.create = guage_pointer_create,
|
||||
.on_paint_self = guage_pointer_on_paint_self,
|
||||
.on_paint_background = widget_on_paint_null,
|
||||
.set_prop = guage_pointer_set_prop,
|
||||
.get_prop = guage_pointer_get_prop,
|
||||
.destroy = guage_pointer_destroy};
|
||||
|
@ -29,27 +29,19 @@ static ret_t vgcanvas_nanovg_end_frame(vgcanvas_t* vgcanvas) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
BEGIN_IDX = 1,
|
||||
MAX_VIEW_COUNT = 256
|
||||
};
|
||||
enum { BEGIN_IDX = 1, MAX_VIEW_COUNT = 256 };
|
||||
static bool_t arrayViewId[MAX_VIEW_COUNT] = {0};
|
||||
|
||||
static int32_t getFreeViewId(void)
|
||||
{
|
||||
|
||||
int32_t index = BEGIN_IDX;
|
||||
for (int32_t i = BEGIN_IDX; i < MAX_VIEW_COUNT; ++i)
|
||||
{
|
||||
if (!arrayViewId[i])
|
||||
{
|
||||
index = i;
|
||||
arrayViewId[i] = true;
|
||||
break;
|
||||
}
|
||||
static int32_t getFreeViewId(void) {
|
||||
int32_t index = BEGIN_IDX;
|
||||
for (int32_t i = BEGIN_IDX; i < MAX_VIEW_COUNT; ++i) {
|
||||
if (!arrayViewId[i]) {
|
||||
index = i;
|
||||
arrayViewId[i] = true;
|
||||
break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_create_fbo(vgcanvas_t* vgcanvas, framebuffer_object_t* fbo) {
|
||||
@ -57,7 +49,7 @@ static ret_t vgcanvas_nanovg_create_fbo(vgcanvas_t* vgcanvas, framebuffer_object
|
||||
NVGcontext* vg = ((vgcanvas_nanovg_t*)vgcanvas)->vg;
|
||||
|
||||
handle = nvgluCreateFramebufferByViewId(vg, (int)(vgcanvas->w * vgcanvas->ratio),
|
||||
(int)(vgcanvas->h * vgcanvas->ratio), 0, getFreeViewId());
|
||||
(int)(vgcanvas->h * vgcanvas->ratio), 0, getFreeViewId());
|
||||
return_value_if_fail(handle != NULL, RET_FAIL);
|
||||
fbo->w = vgcanvas->w;
|
||||
fbo->h = vgcanvas->h;
|
||||
@ -68,9 +60,9 @@ static ret_t vgcanvas_nanovg_create_fbo(vgcanvas_t* vgcanvas, framebuffer_object
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_destroy_fbo(vgcanvas_t* vgcanvas, framebuffer_object_t* fbo) {
|
||||
NVGLUframebuffer_bgfx* handle = (NVGLUframebuffer_bgfx*)fbo->handle;
|
||||
nvgluDeleteFramebuffer(handle);
|
||||
resetBGFX(fbo->w, fbo->h, 0);
|
||||
NVGLUframebuffer_bgfx* handle = (NVGLUframebuffer_bgfx*)fbo->handle;
|
||||
nvgluDeleteFramebuffer(handle);
|
||||
resetBGFX(fbo->w, fbo->h, 0);
|
||||
arrayViewId[handle->viewId] = false;
|
||||
(void)vgcanvas;
|
||||
return RET_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user