gfxSurface_p Surface_New(uint16_t width, uint16_t heigth) { const uint8_t bitsDepth = 4; uint16_t i; gfxSurface_p surface = malloc(sizeof(gfxSurface_t)); if (surface) { memset(surface, 0, sizeof(gfxSurface_t)); surface->bytesPerLine = width*8/bitsDepth + width%2; surface->line = malloc(heigth*sizeof(*surface->line)); if (surface->line) { memset(surface->line, 0, heigth*sizeof(*surface->line)); for (i = 0; i < heigth; i++) { surface->line[i] = malloc(surface->bytesPerLine); if (!surface->line[i]) break; } if (i != heigth) { Surface_Delete(surface); return NULL; } surface->width = width; surface->heigth = heigth; } else { free(surface); surface = NULL; } } return surface; }
static void LCUIDisplay_CleanSurfaces( void ) { SurfaceRecord *sr; LinkedListNode *node; for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; Surface_Delete( sr->surface ); LinkedList_DeleteNode( &display.surfaces, node ); } }
/** 解除 widget 与 sruface 的绑定 */ static void LCUIDisplay_UnbindSurface( LCUI_Widget widget ) { SurfaceRecord *sr; LinkedListNode *node; for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; if( sr && sr->widget == widget ) { Surface_Delete( sr->surface ); LinkedList_DeleteNode( &display.surfaces, node ); break; } } }
static void LCUIDisplay_CleanSurfaces( void ) { int i, n; SurfaceRecord *p_sr; n = LinkedList_GetTotal( &display.surfaces ); for( i=0; i<n; ++i ) { LinkedList_Goto( &display.surfaces, 0 ); p_sr = (SurfaceRecord*) LinkedList_Get( &display.surfaces ); Surface_Delete( p_sr->surface ); LinkedList_Delete( &display.surfaces ); } }
/** 解除 widget 与 sruface 的绑定 */ static void LCUIDisplay_UnbindSurface( LCUI_Widget widget ) { int i, n; SurfaceRecord *p_sr; n = LinkedList_GetTotal( &display.surfaces ); for( i=0; i<n; ++i ) { LinkedList_Goto( &display.surfaces, i ); p_sr = (SurfaceRecord*) LinkedList_Get( &display.surfaces ); if( p_sr->widget != widget ) { continue; } Surface_Delete( p_sr->surface ); LinkedList_Delete( &display.surfaces ); break; } }
void Surface_SetGenericSurface(gfxSurface_p srf) { if (s_genericSurface) Surface_Delete(s_genericSurface); s_genericSurface = srf; }