2017-12-06 21:43:47 +08:00
|
|
|
#include "../core_include/api.h"
|
2018-10-04 14:30:29 +08:00
|
|
|
#include "../core_include/resource.h"
|
2017-12-06 21:43:47 +08:00
|
|
|
#include "../core_include/rect.h"
|
|
|
|
#include "../core_include/bitmap.h"
|
|
|
|
#include "../core_include/surface.h"
|
|
|
|
|
2018-10-04 14:30:29 +08:00
|
|
|
void c_bitmap::draw_bitmap(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, int x, int y)
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
|
|
|
if (0 == pBitmap)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_bitmap_565(surface, z_order, x, y, pBitmap->XSize, pBitmap->YSize,
|
|
|
|
(unsigned char const *)pBitmap->pData);
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:30:29 +08:00
|
|
|
void c_bitmap::draw_bitmap_in_rect(c_surface* surface, int z_order, const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type)
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
|
|
|
if (0 == pBitmap)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int x, y;
|
|
|
|
get_bitmap_pos(pBitmap, rect, align_type, x, y);
|
2018-11-09 15:01:48 +08:00
|
|
|
draw_bitmap_565_in_rect(surface, z_order, rect.m_left + x, rect.m_top + y,
|
2017-12-06 21:43:47 +08:00
|
|
|
(rect.m_right - rect.m_left + 1), (rect.m_bottom - rect.m_top + 1),
|
|
|
|
pBitmap->XSize, pBitmap->YSize, (unsigned char const *)pBitmap->pData);
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:30:29 +08:00
|
|
|
void c_bitmap::get_bitmap_pos(const BITMAP_INFO *pBitmap, c_rect rect, unsigned int align_type, int &x, int &y)
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
|
|
|
int x_size = pBitmap->XSize;
|
|
|
|
int y_size = pBitmap->YSize;
|
|
|
|
|
|
|
|
int height = rect.m_bottom - rect.m_top + 1;
|
|
|
|
int width = rect.m_right - rect.m_left + 1;
|
|
|
|
|
|
|
|
x = y = 0;
|
|
|
|
|
|
|
|
switch (align_type & ALIGN_HMASK)
|
|
|
|
{
|
|
|
|
case ALIGN_HCENTER:
|
|
|
|
if (width > x_size)
|
|
|
|
{
|
|
|
|
x = (width - x_size)/2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ALIGN_LEFT:
|
|
|
|
x = 0;
|
|
|
|
break;
|
|
|
|
case ALIGN_RIGHT:
|
|
|
|
if (width > x_size)
|
|
|
|
{
|
|
|
|
x = width - x_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (align_type & ALIGN_VMASK)
|
|
|
|
{
|
|
|
|
case ALIGN_VCENTER:
|
|
|
|
if (height > y_size)
|
|
|
|
{
|
|
|
|
y = (height - y_size)/2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ALIGN_TOP:
|
|
|
|
y = 0;
|
|
|
|
break;
|
|
|
|
case ALIGN_BOTTOM:
|
|
|
|
if (height > y_size)
|
|
|
|
{
|
|
|
|
y = height - y_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_bitmap::draw_bitmap_565(c_surface* surface, int z_order, int x, int y, int xsize, int ysize, const unsigned char* pPixel)
|
|
|
|
{
|
2018-11-09 15:01:48 +08:00
|
|
|
const unsigned short* pData = (const unsigned short*)pPixel;
|
2017-12-06 21:43:47 +08:00
|
|
|
for (int j = 0; j < ysize; j++)
|
|
|
|
{
|
|
|
|
const unsigned short * p = pData;
|
|
|
|
for (int i = 0; i < xsize; i++)
|
|
|
|
{
|
2017-12-13 22:29:28 +08:00
|
|
|
unsigned int rgb = *p++;
|
2018-11-01 10:35:37 +08:00
|
|
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
2018-11-09 15:01:48 +08:00
|
|
|
pData += xsize;
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 15:01:48 +08:00
|
|
|
void c_bitmap::draw_bitmap_565_in_rect(c_surface* surface, int z_order, int x, int y, int width, int height, int xsize, int ysize, const unsigned char* pPixel)
|
2017-12-06 21:43:47 +08:00
|
|
|
{
|
2018-11-09 15:01:48 +08:00
|
|
|
const unsigned short* pData = (const unsigned short*)pPixel;
|
2017-12-06 21:43:47 +08:00
|
|
|
for (int j = 0; j < ysize; j++)
|
|
|
|
{
|
|
|
|
if(j >= height)break;
|
|
|
|
const unsigned short * p = pData;
|
|
|
|
for (int i = 0; i < xsize; i++)
|
|
|
|
{
|
2017-12-13 22:29:28 +08:00
|
|
|
if (i >= width)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int rgb = *p++;
|
2018-11-01 10:35:37 +08:00
|
|
|
surface->draw_pixel(x + i, y + j, GL_RGB_16_to_32(rgb), z_order);
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
2018-11-09 15:01:48 +08:00
|
|
|
pData += xsize;
|
2017-12-06 21:43:47 +08:00
|
|
|
}
|
|
|
|
}
|