本文整理汇总了C++中rtgui_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ rtgui_malloc函数的具体用法?C++ rtgui_malloc怎么用?C++ rtgui_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rtgui_malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rtgui_font_default
struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w, int h)
{
struct rtgui_dc_buffer *dc;
dc = (struct rtgui_dc_buffer *)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
dc->parent.type = RTGUI_DC_BUFFER;
dc->parent.engine = &dc_buffer_engine;
dc->gc.foreground = default_foreground;
dc->gc.background = default_background;
dc->gc.font = rtgui_font_default();
dc->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
dc->pixel_format = pixel_format;
dc->width = w;
dc->height = h;
dc->pitch = w * rtgui_color_get_bpp(pixel_format);
dc->pixel = rtgui_malloc(h * dc->pitch);
if (!dc->pixel)
{
rtgui_free(dc);
return RT_NULL;
}
rt_memset(dc->pixel, 0, h * dc->pitch);
return &(dc->parent);
}
示例2: rtgui_xml_create
rtgui_xml_t* rtgui_xml_create(rt_size_t buffer_size, rtgui_xml_event_handler_t handler,
void* user)
{
rtgui_xml_t* xml = (rtgui_xml_t*) rtgui_malloc(sizeof(struct rtgui_xml));
rt_memset(xml, 0, sizeof(rtgui_xml_t));
xml->event_handler = handler;
xml->user = user;
/* create buffer */
xml->buffer_size = buffer_size;
xml->buffer = (char*)rtgui_malloc(xml->buffer_size);
return xml;
}
示例3: rtgui_image_hdc_load
static rt_bool_t rtgui_image_hdc_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
{
rt_uint32_t header[5];
struct rtgui_image_hdc *hdc;
hdc = (struct rtgui_image_hdc *) rtgui_malloc(sizeof(struct rtgui_image_hdc));
if (hdc == RT_NULL) return RT_FALSE;
hdc->hw_driver = rtgui_graphic_driver_get_default();
if (hdc->hw_driver == RT_NULL)
{
rtgui_free(hdc);
return RT_FALSE;
}
rtgui_filerw_read(file, (char *)&header, 1, sizeof(header));
/* set image information */
image->w = (rt_uint16_t)header[1];
image->h = (rt_uint16_t)header[2];
image->engine = &rtgui_image_hdc_engine;
image->data = hdc;
hdc->filerw = file;
hdc->byte_per_pixel = hdc->hw_driver->bits_per_pixel / 8;
hdc->pitch = image->w * hdc->byte_per_pixel;
hdc->pixel_offset = rtgui_filerw_tell(file);
if (load == RT_TRUE)
{
/* load all pixels */
hdc->pixels = rtgui_malloc(image->h * hdc->pitch);
if (hdc->pixels == RT_NULL)
{
/* release data */
rtgui_free(hdc);
return RT_FALSE;
}
rtgui_filerw_read(hdc->filerw, hdc->pixels, 1, image->h * hdc->pitch);
rtgui_filerw_close(hdc->filerw);
hdc->filerw = RT_NULL;
hdc->pixel_offset = 0;
}
else
{
hdc->pixels = RT_NULL;
}
return RT_TRUE;
}
示例4: rtgui_textbox_set_value
void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text)
{
if (box->text != RT_NULL)
{
if (box->line_length > rt_strlen(text) + 1)
{
rt_memcpy(box->text, text, rt_strlen(text) + 1);
/* set current position */
box->position = 0;
return;
}
else
{
/* free the old text */
rtgui_free(box->text);
box->text = RT_NULL;
}
}
box->line_length = RTGUI_TEXTBOX_LINE_MAX > rt_strlen(text) + 1 ?
RTGUI_TEXTBOX_LINE_MAX : rt_strlen(text) + 1;
/* allocate line buffer */
box->text = rtgui_malloc(box->line_length);
rt_memset(box->text, 0, box->line_length);
/* copy text */
rt_memcpy(box->text, text, rt_strlen(text) + 1);
/* set current position */
box->position = 0;
}
示例5:
struct rtgui_dc *rtgui_img_dc_create_pixformat(rt_uint8_t pixel_format,
rt_uint8_t *pixel, struct rtgui_image_item *image_item)
{
struct rtgui_dc_buffer *dc;
dc = (struct rtgui_dc_buffer *)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
if (dc)
{
dc->parent.type = RTGUI_DC_BUFFER;
dc->parent.engine = &dc_buffer_engine;
dc->gc.foreground = default_foreground;
dc->gc.background = default_background;
dc->gc.font = rtgui_font_default();
dc->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
dc->pixel_format = pixel_format;
dc->pixel_alpha = 255;
dc->width = image_item->image->w;
dc->height = image_item->image->h;
dc->pitch = image_item->image->w * rtgui_color_get_bpp(pixel_format);
dc->image_item = image_item;
dc->pixel = pixel;
return &(dc->parent);
}
return RT_NULL;
}
示例6: rtgui_edit_init_caret
static void rtgui_edit_init_caret(struct rtgui_edit *edit, rtgui_point_t visual)
{
struct rtgui_gdev *grp = rtgui_gdev_get();
int x, y;
rtgui_color_t color;
rtgui_rect_t rect;
int ofs=0;
RT_ASSERT(edit != RT_NULL);
if(!RTGUI_WIDGET_IS_FOCUSED(edit)) return;
rtgui_edit_get_caret_rect(edit, &edit->caret_rect, visual);
rect = edit->caret_rect;
rtgui_widget_rect_to_device(RTGUI_WIDGET(edit), &rect);
if(edit->caret == RT_NULL)
edit->caret = (rtgui_color_t*)rtgui_malloc(RC_W(rect) * RC_H(rect)*sizeof(rtgui_color_t));
rtgui_timer_stop(edit->caret_timer);
for(x=rect.x1; x<rect.x2; x++)
{
for(y=rect.y1; y<rect.y2; y++)
{
grp->ops->get_pixel(&color,x,y);
*(edit->caret + ofs++) = color;
}
}
rtgui_timer_start(edit->caret_timer);
}
示例7: rtgui_filerw_create_file
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{
int fd;
struct rtgui_filerw_stdio *rw;
RT_ASSERT(filename != RT_NULL);
rw = RT_NULL;
fd = open(filename, parse_mode(mode), 0);
if ( fd >= 0 ) {
rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
if (rw != RT_NULL) {
rw->parent.seek = stdio_seek;
rw->parent.read = stdio_read;
rw->parent.write = stdio_write;
rw->parent.tell = stdio_tell;
rw->parent.close = stdio_close;
rw->parent.eof = stdio_eof;
rw->fd = fd;
rw->eof = RT_FALSE;
}
}
return &(rw->parent);
}
示例8: rtgui_textbox_init_caret
static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
{
int x, y;
rtgui_color_t color;
rtgui_rect_t rect;
int ofs = 0;
RT_ASSERT(box != RT_NULL);
if (!RTGUI_WIDGET_IS_FOCUSED(box))
return;
rtgui_textbox_get_caret_rect(box, &box->caret_rect, position);
rect = box->caret_rect;
rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);
if (box->caret == RT_NULL)
box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));
for (x = rect.x1; x < rect.x2; x++)
{
for (y = rect.y1; y < rect.y2; y++)
{
rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
*(box->caret + ofs) = color;
ofs++;
}
}
}
示例9: rtgui_anim_create
struct rtgui_animation* rtgui_anim_create(struct rtgui_widget *parent,
int interval)
{
struct rtgui_animation *anim = rtgui_malloc(sizeof(*anim));
if (anim == RT_NULL)
return RT_NULL;
anim->timer = rtgui_timer_create(interval, RT_TIMER_FLAG_PERIODIC,
_anim_timeout, anim);
if (anim->timer == RT_NULL)
{
rtgui_free(anim);
return RT_NULL;
}
anim->parent = parent;
anim->fg_buf = RT_NULL;
anim->dc_cnt = 0;
anim->tick = 0;
anim->tick_interval = interval;
anim->max_tick = 0;
/* Set default handlers. */
anim->motion = rtgui_anim_motion_linear;
anim->engine = RT_NULL;
anim->eng_ctx = RT_NULL;
anim->on_finish = _animation_default_finish;
anim->state = _ANIM_STOPPED;
return anim;
}
示例10: rtgui_textbox_ondraw
void rtgui_textbox_ondraw(rtgui_textbox_t *box)
{
/* draw button */
rtgui_rect_t rect;
struct rtgui_dc *dc;
rtgui_color_t fc;
RT_ASSERT(box != RT_NULL);
/* begin drawing */
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
if (dc == RT_NULL)
return;
/* get widget rect */
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
fc = RTGUI_WIDGET_FOREGROUND(box);
rtgui_rect_inflate(&rect, -1);
/* fill widget rect with white color */
RTGUI_WIDGET_BACKGROUND(box) = white;
rtgui_dc_fill_rect(dc, &rect);
rtgui_rect_inflate(&rect, 1);
/* draw border */
RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
rtgui_dc_draw_rect(dc, &rect);
/* draw text */
RTGUI_WIDGET_FOREGROUND(box) = fc;
if (box->text != RT_NULL)
{
rect.x1 += RTGUI_WIDGET_DEFAULT_MARGIN;
/* draw single text */
if (box->flag & RTGUI_TEXTBOX_MASK)
{
/* draw mask char */
rt_size_t len = rt_strlen(box->text);
if (len > 0)
{
char *text_mask = rtgui_malloc(len + 1);
rt_memset(text_mask, box->mask_char, len + 1);
text_mask[len] = 0;
rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect);
rtgui_free(text_mask);
}
}
else
{
rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect);
}
}
rtgui_dc_end_drawing(dc);
}
示例11: load_img_test
void load_img_test(char *fname)
{
struct rtgui_filerw *filerw;
struct rtgui_image image;
struct rtgui_rect rect;
struct rtgui_dc_hw *dc;
struct rtgui_image_engine *img_eng;
printf_syn("fun:%s, line:%d, fn:%s\n", __FUNCTION__, __LINE__, fname);
filerw = rtgui_filerw_create_file(fname, "rb");
if (NULL == filerw) {
printf_syn("fun:%s, line:%d, fn:%s\n", __FUNCTION__, __LINE__, fname);
return;
}
img_eng = &rtgui_image_hdc_engine;
if (RT_TRUE != img_eng->image_check(filerw)) {
printf_syn("fun:%s, line:%d\n", __FUNCTION__, __LINE__);
return;
}
if (RT_TRUE != img_eng->image_load(&image, filerw, RT_FALSE)) {
printf_syn("fun:%s, line:%d\n", __FUNCTION__, __LINE__);
return;
}
dc = (struct rtgui_dc_hw*) rtgui_malloc(sizeof(struct rtgui_dc_hw));
dc->parent.type = RTGUI_DC_HW;
dc->parent.engine = &dc_hw_engine;
dc->owner = NULL;
dc->hw_driver = rtgui_graphic_driver_get_default();
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = rtgui_graphic_driver_get_default()->width;
rect.y2 = rtgui_graphic_driver_get_default()->height;
printf_syn("fun:%s, line:%d, 0x%x\n", __FUNCTION__, __LINE__, img_eng->image_blit);
img_eng->image_blit(&image, (struct rtgui_dc*)dc, &rect);
rt_thread_delay(get_ticks_of_ms(5000));
printf_syn("fun:%s, line:%d, fn:%s\n", __FUNCTION__, __LINE__, fname);
img_eng->image_unload(&image);
printf_syn("fun:%s, line:%d, fn:%s\n", __FUNCTION__, __LINE__, fname);
//rect.x1 = rtgui_filerw_close(filerw); /* unload 已close */
printf_syn("fun:%s, line:%d, ret:%d, fn:%s\n", __FUNCTION__, __LINE__, rect.x1, fname);
rtgui_free(dc);
return;
}
示例12: rtgui_image_hdc_blit
static void rtgui_image_hdc_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
{
rt_uint16_t y, w, h;
struct rtgui_image_hdc *hdc;
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
/* this dc is not visible */
if (rtgui_dc_get_visible(dc) != RT_TRUE) return;
hdc = (struct rtgui_image_hdc *) image->data;
RT_ASSERT(hdc != RT_NULL);
/* the minimum rect */
if (image->w < rtgui_rect_width(*dst_rect)) w = image->w;
else w = rtgui_rect_width(*dst_rect);
if (image->h < rtgui_rect_height(*dst_rect)) h = image->h;
else h = rtgui_rect_height(*dst_rect);
if (hdc->pixels != RT_NULL)
{
rt_uint8_t *ptr;
/* get pixel pointer */
ptr = hdc->pixels;
for (y = 0; y < h; y ++)
{
dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
ptr += hdc->pitch;
}
}
else
{
rt_uint8_t *ptr;
ptr = rtgui_malloc(hdc->pitch);
if (ptr == RT_NULL) return; /* no memory */
/* seek to the begin of pixel data */
rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET);
for (y = 0; y < h; y ++)
{
/* read pixel data */
if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch)
break; /* read data failed */
dc->engine->blit_line(dc, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y, ptr);
}
rtgui_free(ptr);
}
}
示例13: rtgui_edit_readin_file
rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
{
int fd, num=0, read_bytes, size ,len=0;
char *text ,ch;
fd = open(filename, O_RDONLY, 0);
if (fd < 0)
{
return RT_FALSE;
}
while(edit->max_rows > 0)
rtgui_edit_delete_line(edit, edit->head);
edit->max_rows = 0;
size = edit->bzsize;
text = rtgui_malloc(size);
if(text == RT_NULL) return RT_FALSE;
do {
if ( (read_bytes = read(fd, &ch, 1)) > 0 )
{
if(num >= size - 1)
text = rt_realloc(text, rtgui_edit_alloc_len(size, num));
if(ch == 0x09)
{
len = edit->tabsize - num%edit->tabsize;
while(len--)
*(text + num++) = ' ';
}
else
*(text + num++) = ch;
if(ch == 0x0A)
{
rtgui_edit_append_line(edit, text);
num = 0;
}
}
else if(num > 0)
{ /* last line does not exist the end operator */
*(text + num) = '\0';
rtgui_edit_append_line(edit, text);
}
} while(read_bytes);
close(fd);
rtgui_free(text);
rtgui_edit_ondraw(edit);
return RT_TRUE;
}
示例14: rtgui_edit_append_line
rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text)
{
rt_size_t len;
struct edit_line *line, *node;
RT_ASSERT(edit != RT_NULL);
line = rtgui_malloc(sizeof(struct edit_line));
if(line == RT_NULL) return RT_FALSE;
len = rtgui_edit_line_strlen(text);
line->zsize = rtgui_edit_alloc_len(edit->bzsize, len+1);
line->text = rtgui_malloc(line->zsize);
rt_memcpy(line->text, text, len);
*(line->text+len) = '\0';
line->len = rtgui_edit_line_strlen(line->text);
line->next = RT_NULL;
edit->max_rows++;
if(edit->max_cols < len) edit->max_cols = len;
node = edit->head;
if(node == RT_NULL)
{
edit->head = line;
edit->tail = line;
line->prev = RT_NULL;
edit->first_line = line;
return RT_TRUE;
}
while(node->next != RT_NULL) node = node->next;
/* to tail item on to queue */
node->next = line;
line->prev = node;
/* re-fixed position tail */
edit->tail = line;
return RT_TRUE;
}
示例15: rtgui_edit_insert_line
rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text)
{
rt_size_t len;
struct edit_line *line;
RT_ASSERT(edit != RT_NULL);
RT_ASSERT(p != RT_NULL);
if(p->next == RT_NULL)
{
rtgui_edit_append_line(edit, text);
return RT_TRUE;
}
line = rtgui_malloc(sizeof(struct edit_line));
if(line == RT_NULL) return RT_FALSE;
line->prev = p;
line->next = p->next;
p->next = line;
if(line->next != RT_NULL)
{
line->next->prev = line;
}
len = rtgui_edit_line_strlen(text);
line->zsize = rtgui_edit_alloc_len(edit->bzsize, len+1);
line->text = rtgui_malloc(line->zsize);
rt_memset(line->text, 0, line->zsize);
rt_memcpy(line->text, text, len);
*(line->text+len) = '\0';
edit->max_rows ++;
line->len = rtgui_edit_line_strlen(line->text);
return RT_TRUE;
}