rename some functions

This commit is contained in:
xianjimli 2018-05-26 17:48:14 +08:00
parent 82a14f788c
commit 0ab8949aba
11 changed files with 82 additions and 82 deletions

View File

@ -182,8 +182,8 @@ static ret_t canvas_draw_hline_impl(canvas_t* c, xy_t x, xy_t y, wh_t w) {
return RET_OK;
}
x = ftk_max(x, c->clip_left);
x2 = ftk_min(x2, c->clip_right);
x = tk_max(x, c->clip_left);
x2 = tk_min(x2, c->clip_right);
w = x2 - x;
return lcd_draw_hline(c->lcd, x, y, w);
@ -202,8 +202,8 @@ static ret_t canvas_draw_vline_impl(canvas_t* c, xy_t x, xy_t y, wh_t h) {
return RET_OK;
}
y = ftk_max(y, c->clip_top);
y2 = ftk_min(y2, c->clip_bottom);
y = tk_max(y, c->clip_top);
y2 = tk_min(y2, c->clip_bottom);
h = y2 - y;
return lcd_draw_vline(c->lcd, x, y, h);
@ -222,9 +222,9 @@ static ret_t canvas_draw_line_impl(canvas_t* c, xy_t x1, xy_t y1, xy_t x2, xy_t
}
if (x1 == x2) {
return canvas_draw_vline_impl(c, x1, y1, ftk_abs(y2 - y1) + 1);
return canvas_draw_vline_impl(c, x1, y1, tk_abs(y2 - y1) + 1);
} else if (y1 == y2) {
return canvas_draw_hline_impl(c, x1, y1, ftk_abs(x2 - x1) + 1);
return canvas_draw_hline_impl(c, x1, y1, tk_abs(x2 - x1) + 1);
} else {
draw_line(c, x1, y1, x2, y2);
return RET_OK;
@ -317,10 +317,10 @@ static ret_t canvas_fill_rect_impl(canvas_t* c, xy_t x, xy_t y, wh_t w, wh_t h)
return RET_OK;
}
x = ftk_max(x, c->clip_left);
y = ftk_max(y, c->clip_top);
x2 = ftk_min(x2, c->clip_right);
y2 = ftk_min(y2, c->clip_bottom);
x = tk_max(x, c->clip_left);
y = tk_max(y, c->clip_top);
x2 = tk_min(x2, c->clip_right);
y2 = tk_min(y2, c->clip_bottom);
w = x2 - x;
h = y2 - y;
@ -364,10 +364,10 @@ static ret_t canvas_draw_glyph(canvas_t* c, glyph_t* g, xy_t x, xy_t y) {
return RET_OK;
}
dst.x = ftk_max(x, c->clip_left);
dst.y = ftk_max(y, c->clip_top);
dst.w = ftk_min(x2, c->clip_right) - dst.x;
dst.h = ftk_min(y2, c->clip_bottom) - dst.y;
dst.x = tk_max(x, c->clip_left);
dst.y = tk_max(y, c->clip_top);
dst.w = tk_min(x2, c->clip_right) - dst.x;
dst.h = tk_min(y2, c->clip_bottom) - dst.y;
src.x = dst.x - x;
src.y = dst.y - y;
@ -454,10 +454,10 @@ static ret_t canvas_do_draw_image(canvas_t* c, bitmap_t* img, rect_t* s, rect_t*
return RET_OK;
}
dst.x = ftk_max(x, c->clip_left);
dst.y = ftk_max(y, c->clip_top);
dst.w = ftk_min(x2, c->clip_right) - dst.x;
dst.h = ftk_min(y2, c->clip_bottom) - dst.y;
dst.x = tk_max(x, c->clip_left);
dst.y = tk_max(y, c->clip_top);
dst.w = tk_min(x2, c->clip_right) - dst.x;
dst.h = tk_min(y2, c->clip_bottom) - dst.y;
src.x = s->x + (dst.x - x) * s->w / d->w;
src.y = s->y + (dst.y - y) * s->h / d->h;
@ -468,8 +468,8 @@ static ret_t canvas_do_draw_image(canvas_t* c, bitmap_t* img, rect_t* s, rect_t*
return RET_OK;
}
src.w = ftk_min((img->w - src.x), src.w);
src.h = ftk_min((img->h - src.y), src.h);
src.w = tk_min((img->w - src.x), src.w);
src.h = tk_min((img->h - src.y), src.h);
if (src.w == 0 || src.h == 0 || dst.w == 0 || dst.h == 0) {
return RET_OK;
@ -507,9 +507,9 @@ ret_t canvas_draw_image_repeat(canvas_t* c, bitmap_t* img, rect_t* dst) {
d = *dst;
while (y < dst->h) {
h = ftk_min(img->h, dst->h - y);
h = tk_min(img->h, dst->h - y);
while (x < dst->w) {
w = ftk_min(img->w, dst->w - x);
w = tk_min(img->w, dst->w - x);
s.w = w;
s.h = h;
@ -542,7 +542,7 @@ ret_t canvas_draw_image_repeat_x(canvas_t* c, bitmap_t* img, rect_t* dst) {
d = *dst;
while (x < dst->w) {
w = ftk_min(img->w, dst->w - x);
w = tk_min(img->w, dst->w - x);
s.w = w;
d.x = x;
d.w = w;
@ -568,7 +568,7 @@ ret_t canvas_draw_image_repeat_y(canvas_t* c, bitmap_t* img, rect_t* dst) {
d = *dst;
while (y < dst->h) {
h = ftk_min(img->h, dst->h - y);
h = tk_min(img->h, dst->h - y);
s.h = h;
d.y = y;
d.h = h;
@ -598,7 +598,7 @@ ret_t canvas_draw_image_3patch_y_scale_x(canvas_t* c, bitmap_t* img, rect_t* dst
canvas_translate(c, dst->x, dst->y);
h = ftk_min(img_h, dst_h) / 3;
h = tk_min(img_h, dst_h) / 3;
h_h = dst_h - h * 2;
/*top*/
@ -641,7 +641,7 @@ ret_t canvas_draw_image_3patch_y(canvas_t* c, bitmap_t* img, rect_t* dst) {
canvas_translate(c, dst->x, dst->y);
h = ftk_min(img_h, dst_h) / 3;
h = tk_min(img_h, dst_h) / 3;
h_h = dst_h - h * 2;
x = (dst->w - img->w) >> 1;
@ -685,7 +685,7 @@ ret_t canvas_draw_image_3patch_x_scale_y(canvas_t* c, bitmap_t* img, rect_t* dst
canvas_translate(c, dst->x, dst->y);
w = ftk_min(img_w, dst_w) / 3;
w = tk_min(img_w, dst_w) / 3;
w_w = dst_w - w * 2;
/*left*/
@ -728,7 +728,7 @@ ret_t canvas_draw_image_3patch_x(canvas_t* c, bitmap_t* img, rect_t* dst) {
canvas_translate(c, dst->x, dst->y);
w = ftk_min(img_w, dst_w) / 3;
w = tk_min(img_w, dst_w) / 3;
w_w = dst_w - w * 2;
y = (dst_h - img_h) >> 1;
@ -775,8 +775,8 @@ ret_t canvas_draw_image_9patch(canvas_t* c, bitmap_t* img, rect_t* dst) {
canvas_translate(c, dst->x, dst->y);
w = ftk_min(img_w, dst_w) / 3;
h = ftk_min(img_h, dst_h) / 3;
w = tk_min(img_w, dst_w) / 3;
h = tk_min(img_h, dst_h) / 3;
w_w = dst_w - w * 2;
h_h = dst_h - h * 2;
@ -886,8 +886,8 @@ ret_t canvas_draw_image_scale_w(canvas_t* c, bitmap_t* img, rect_t* dst) {
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS);
scale = (float)(dst->w) / img->w;
dst_h = ftk_min(img->h * scale, dst->h);
src_h = ftk_min(img->h, dst_h / scale);
dst_h = tk_min(img->h * scale, dst->h);
src_h = tk_min(img->h, dst_h / scale);
s.x = 0;
s.y = 0;
@ -909,8 +909,8 @@ ret_t canvas_draw_image_scale_h(canvas_t* c, bitmap_t* img, rect_t* dst) {
return_value_if_fail(c != NULL && img != NULL && dst != NULL, RET_BAD_PARAMS);
scale = (float)(dst->h) / img->h;
dst_w = ftk_min(img->w * scale, dst->w);
src_w = ftk_min(img->w, dst_w / scale);
dst_w = tk_min(img->w * scale, dst->w);
src_w = tk_min(img->w, dst_w / scale);
s.x = 0;
s.y = 0;
@ -938,7 +938,7 @@ ret_t canvas_draw_image_scale(canvas_t* c, bitmap_t* img, rect_t* dst) {
scalex = (float)(dst->w) / img->w;
scaley = (float)(dst->h) / img->h;
scale = ftk_min(scalex, scaley);
scale = tk_min(scalex, scaley);
d.w = img->w * scale;
d.h = img->h * scale;

View File

@ -112,7 +112,7 @@ static ret_t progress_bar_on_paint_self(widget_t* widget, canvas_t* c) {
uint16_t font_size = style_get_int(style, STYLE_ID_FONT_SIZE, 20);
const char* font_name = style_get_str(style, STYLE_ID_FONT_NAME, NULL);
ftk_itoa(s, sizeof(s), progress_bar->value);
tk_itoa(s, sizeof(s), progress_bar->value);
len = strlen(s);
s[len] = '%';
s[len + 1] = '\0';

View File

@ -25,10 +25,10 @@ ret_t rect_merge(rect_t* dr, rect_t* r) {
if (r->w > 0 && r->h > 0) {
if (dr->w > 0 && dr->h > 0) {
xy_t x = ftk_min(dr->x, r->x);
xy_t y = ftk_min(dr->y, r->y);
wh_t right = ftk_max((r->x + r->w), (dr->x + dr->w));
wh_t bottom = ftk_max((r->y + r->h), (dr->y + dr->h));
xy_t x = tk_min(dr->x, r->x);
xy_t y = tk_min(dr->y, r->y);
wh_t right = tk_max((r->x + r->w), (dr->x + dr->w));
wh_t bottom = tk_max((r->y + r->h), (dr->y + dr->h));
dr->x = x;
dr->y = y;

View File

@ -35,7 +35,7 @@ static ret_t slider_get_dragger_rect(widget_t* widget, rect_t* r) {
float fvalue = (float)value / (float)range;
return_value_if_fail(r != NULL, RET_BAD_PARAMS);
r->w = ftk_min(widget->w, widget->h);
r->w = tk_min(widget->w, widget->h);
r->h = r->w;
if (slider->vertical) {
r->x = 0;
@ -229,7 +229,7 @@ static ret_t slider_set_value_internal(widget_t* widget, uint16_t value, event_t
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
step = slider->step;
value = ftk_max(ftk_min(value, slider->max), slider->min);
value = tk_max(tk_min(value, slider->max), slider->min);
if (step > 1) {
offset = value - slider->min;

View File

@ -98,14 +98,14 @@ ret_t str_from_int(str_t* str, int32_t v) {
char buff[32];
return_value_if_fail(str != NULL, RET_BAD_PARAMS);
return str_set(str, ftk_itoa(buff, sizeof(buff), v));
return str_set(str, tk_itoa(buff, sizeof(buff), v));
}
ret_t str_from_float(str_t* str, float v) {
char buff[32];
return_value_if_fail(str != NULL, RET_BAD_PARAMS);
return str_set(str, ftk_ftoa(buff, sizeof(buff), v));
return str_set(str, tk_ftoa(buff, sizeof(buff), v));
}
ret_t str_from_value(str_t* str, const value_t* v) {
@ -125,14 +125,14 @@ ret_t str_from_value(str_t* str, const value_t* v) {
ret_t str_to_int(str_t* str, int32_t* v) {
return_value_if_fail(str != NULL && v != NULL, RET_BAD_PARAMS);
*v = ftk_atoi(str->str);
*v = tk_atoi(str->str);
return RET_OK;
}
ret_t str_to_float(str_t* str, float* v) {
return_value_if_fail(str != NULL && v != NULL, RET_BAD_PARAMS);
*v = ftk_atof(str->str);
*v = tk_atof(str->str);
return RET_OK;
}

View File

@ -168,17 +168,17 @@ typedef enum _ret_t {
typedef void* pointer_t;
#ifndef ftk_min
#define ftk_min(a, b) ((a) < (b) ? (a) : (b))
#endif /*ftk_min*/
#ifndef tk_min
#define tk_min(a, b) ((a) < (b) ? (a) : (b))
#endif /*tk_min*/
#ifndef ftk_abs
#define ftk_abs(a) ((a) < (0) ? (-a) : (a))
#endif /*ftk_abs*/
#ifndef tk_abs
#define tk_abs(a) ((a) < (0) ? (-a) : (a))
#endif /*tk_abs*/
#ifndef ftk_max
#define ftk_max(a, b) ((a) > (b) ? (a) : (b))
#endif /*ftk_max*/
#ifndef tk_max
#define tk_max(a, b) ((a) > (b) ? (a) : (b))
#endif /*tk_max*/
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))

View File

@ -21,7 +21,7 @@
#include "base/utils.h"
int ftk_str2bool(const char* str) {
int tk_str2bool(const char* str) {
if (str == NULL || str[0] == '0' || strcmp(str, "false") == 0 || strcmp(str, "no") == 0) {
return 0;
}
@ -29,7 +29,7 @@ int ftk_str2bool(const char* str) {
return 1;
}
static long ftk_strtol_internal(const char* str, const char** end, int base) {
static long tk_strtol_internal(const char* str, const char** end, int base) {
int i = 0;
long n = 0;
char c = 0;
@ -80,7 +80,7 @@ static long ftk_strtol_internal(const char* str, const char** end, int base) {
return n;
}
long ftk_strtol(const char* str, const char** end, int base) {
long tk_strtol(const char* str, const char** end, int base) {
long n = 0;
int neg = 0;
return_value_if_fail(str != NULL, 0);
@ -92,14 +92,14 @@ long ftk_strtol(const char* str, const char** end, int base) {
str++;
}
n = ftk_strtol_internal(str, end, base);
n = tk_strtol_internal(str, end, base);
return neg ? -n : n;
}
int ftk_atoi(const char* str) { return ftk_strtol(str, NULL, 10); }
int tk_atoi(const char* str) { return tk_strtol(str, NULL, 10); }
float_t ftk_atof(const char* str) {
float_t tk_atof(const char* str) {
int n = 0;
unsigned int f = 0;
int neg = 0;
@ -112,10 +112,10 @@ float_t ftk_atof(const char* str) {
str++;
}
n = ftk_strtol_internal(str, &p, 10);
n = tk_strtol_internal(str, &p, 10);
if (p != NULL && *p == '.') {
f = ftk_strtol_internal(p + 1, NULL, 10);
f = tk_strtol_internal(p + 1, NULL, 10);
}
result = f;
@ -128,7 +128,7 @@ float_t ftk_atof(const char* str) {
return neg ? -result : result;
}
static const char* ftk_itoa_simple(char* str, int len, int n, const char** end) {
static const char* tk_itoa_simple(char* str, int len, int n, const char** end) {
int i = 0;
int value = n;
int need_len = 0;
@ -175,17 +175,17 @@ static const char* ftk_itoa_simple(char* str, int len, int n, const char** end)
return str;
}
const char* ftk_itoa(char* str, int len, int n) { return ftk_itoa_simple(str, len, n, NULL); }
const char* tk_itoa(char* str, int len, int n) { return tk_itoa_simple(str, len, n, NULL); }
const char* ftk_ftoa(char* str, int len, float_t value) {
const char* tk_ftoa(char* str, int len, float_t value) {
int i = 0;
char str_n[32] = {0};
char str_f[32] = {0};
int n = (int)value;
int f = (int)((value - n) * 1000000000);
ftk_itoa(str_n, sizeof(str_n), n);
ftk_itoa(str_f, sizeof(str_f), f > 0 ? f : -f);
tk_itoa(str_n, sizeof(str_n), n);
tk_itoa(str_f, sizeof(str_f), f > 0 ? f : -f);
if (f == 0) {
strncpy(str, str_n, len);
@ -216,7 +216,7 @@ const char* ftk_ftoa(char* str, int len, float_t value) {
return NULL;
}
char* ftk_strcpy(char* dst, const char* src) { return strcpy(dst, src); }
char* tk_strcpy(char* dst, const char* src) { return strcpy(dst, src); }
uint16_t* tk_memset16(uint16_t* buff, uint16_t val, uint32_t size) {
return_value_if_fail(buff != NULL, NULL);

View File

@ -26,11 +26,11 @@
BEGIN_C_DECLS
int ftk_atoi(const char* str);
float_t ftk_atof(const char* str);
const char* ftk_itoa(char* str, int len, int n);
const char* ftk_ftoa(char* str, int len, float_t f);
long ftk_strtol(const char* str, const char** end, int base);
int tk_atoi(const char* str);
float_t tk_atof(const char* str);
const char* tk_itoa(char* str, int len, int n);
const char* tk_ftoa(char* str, int len, float_t f);
long tk_strtol(const char* str, const char** end, int base);
uint16_t* tk_memset16(uint16_t* buff, uint16_t val, uint32_t size);

View File

@ -255,7 +255,7 @@ float value_float(const value_t* v) {
return (float)v->value.f64;
}
case VALUE_TYPE_STRING: {
return ftk_atof(v->value.str);
return tk_atof(v->value.str);
}
default:
break;
@ -354,7 +354,7 @@ int value_int(const value_t* v) {
return (int)v->value.f64;
}
case VALUE_TYPE_STRING: {
return ftk_atoi(v->value.str);
return tk_atoi(v->value.str);
}
default:
break;

View File

@ -142,14 +142,14 @@ ret_t wstr_from_int(wstr_t* str, int32_t v) {
char buff[32];
return_value_if_fail(str != NULL, RET_BAD_PARAMS);
return wstr_set_utf8(str, ftk_itoa(buff, sizeof(buff), v));
return wstr_set_utf8(str, tk_itoa(buff, sizeof(buff), v));
}
ret_t wstr_from_float(wstr_t* str, float v) {
char buff[32];
return_value_if_fail(str != NULL, RET_BAD_PARAMS);
return wstr_set_utf8(str, ftk_ftoa(buff, sizeof(buff), v));
return wstr_set_utf8(str, tk_ftoa(buff, sizeof(buff), v));
}
ret_t wstr_from_value(wstr_t* str, const value_t* v) {
@ -170,7 +170,7 @@ ret_t wstr_to_int(wstr_t* str, int32_t* v) {
char buff[32];
return_value_if_fail(str != NULL && v != NULL, RET_BAD_PARAMS);
wstr_get_utf8(str, buff, sizeof(buff));
*v = ftk_atoi(buff);
*v = tk_atoi(buff);
return RET_OK;
}
@ -179,7 +179,7 @@ ret_t wstr_to_float(wstr_t* str, float* v) {
char buff[32];
return_value_if_fail(str != NULL && v != NULL, RET_BAD_PARAMS);
wstr_get_utf8(str, buff, sizeof(buff));
*v = ftk_atof(buff);
*v = tk_atof(buff);
return RET_OK;
}

View File

@ -4,8 +4,8 @@
TEST(Utils, basic) {
char str[32];
ASSERT_EQ(ftk_atoi("100"), 100);
ASSERT_EQ(strcmp(ftk_itoa(str, sizeof(str), ftk_atoi("100")), "100"), 0);
ASSERT_EQ(tk_atoi("100"), 100);
ASSERT_EQ(strcmp(tk_itoa(str, sizeof(str), tk_atoi("100")), "100"), 0);
}
static void check_buff(uint16_t* buff, uint16_t val, uint32_t size) {