rdtk: Fixed warnings, added assertions
This commit is contained in:
parent
cbb39709b9
commit
0b0b716dd6
@ -19,14 +19,9 @@
|
||||
#ifndef RDTK_H
|
||||
#define RDTK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rdtk/api.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
#include <freerdp/codec/color.h>
|
||||
#include <freerdp/codec/region.h>
|
||||
|
||||
typedef struct rdtk_engine rdtkEngine;
|
||||
typedef struct rdtk_font rdtkFont;
|
||||
typedef struct rdtk_glyph rdtkGlyph;
|
||||
@ -43,38 +38,40 @@ extern "C"
|
||||
|
||||
/* Engine */
|
||||
|
||||
RDTK_EXPORT rdtkEngine* rdtk_engine_new();
|
||||
RDTK_EXPORT rdtkEngine* rdtk_engine_new(void);
|
||||
RDTK_EXPORT void rdtk_engine_free(rdtkEngine* engine);
|
||||
|
||||
/* Surface */
|
||||
|
||||
RDTK_EXPORT int rdtk_surface_fill(rdtkSurface* surface, int x, int y, int width, int height,
|
||||
UINT32 color);
|
||||
RDTK_EXPORT int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width,
|
||||
uint16_t height, uint32_t color);
|
||||
|
||||
RDTK_EXPORT rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int height,
|
||||
int scanline);
|
||||
RDTK_EXPORT rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width,
|
||||
uint16_t height, uint32_t scanline);
|
||||
RDTK_EXPORT void rdtk_surface_free(rdtkSurface* surface);
|
||||
|
||||
/* Font */
|
||||
|
||||
RDTK_EXPORT int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font,
|
||||
const char* text);
|
||||
RDTK_EXPORT int rdtk_font_draw_text(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
|
||||
rdtkFont* font, const char* text);
|
||||
|
||||
/* Button */
|
||||
|
||||
RDTK_EXPORT int rdtk_button_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
|
||||
int nHeight, rdtkButton* button, const char* text);
|
||||
RDTK_EXPORT int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
|
||||
uint16_t nWidth, uint16_t nHeight, rdtkButton* button,
|
||||
const char* text);
|
||||
|
||||
/* Label */
|
||||
|
||||
RDTK_EXPORT int rdtk_label_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
|
||||
int nHeight, rdtkLabel* label, const char* text, int hAlign,
|
||||
int vAlign);
|
||||
RDTK_EXPORT int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
|
||||
uint16_t nWidth, uint16_t nHeight, rdtkLabel* label,
|
||||
const char* text, uint16_t hAlign, uint16_t vAlign);
|
||||
|
||||
/* TextField */
|
||||
|
||||
RDTK_EXPORT int rdtk_text_field_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
|
||||
int nHeight, rdtkTextField* textField, const char* text);
|
||||
RDTK_EXPORT int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst,
|
||||
uint16_t nWidth, uint16_t nHeight,
|
||||
rdtkTextField* textField, const char* text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -24,15 +24,15 @@
|
||||
|
||||
#include "rdtk_button.h"
|
||||
|
||||
int rdtk_button_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight,
|
||||
rdtkButton* button, const char* text)
|
||||
int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
|
||||
uint16_t nHeight, rdtkButton* button, const char* text)
|
||||
{
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
int textWidth;
|
||||
int textHeight;
|
||||
int fillWidth;
|
||||
int fillHeight;
|
||||
uint16_t offsetX;
|
||||
uint16_t offsetY;
|
||||
uint16_t textWidth;
|
||||
uint16_t textHeight;
|
||||
uint16_t fillWidth;
|
||||
uint16_t fillHeight;
|
||||
rdtkFont* font;
|
||||
rdtkEngine* engine;
|
||||
rdtkNinePatch* ninePatch;
|
||||
|
@ -44,11 +44,11 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
|
||||
int nHeight;
|
||||
int nSrcStep;
|
||||
int nDstStep;
|
||||
BYTE* pSrcData;
|
||||
BYTE* pSrcPixel;
|
||||
BYTE* pDstData;
|
||||
BYTE* pDstPixel;
|
||||
BYTE A, R, G, B;
|
||||
uint8_t* pSrcData;
|
||||
uint8_t* pSrcPixel;
|
||||
uint8_t* pDstData;
|
||||
uint8_t* pDstPixel;
|
||||
uint8_t A, R, G, B;
|
||||
nXDst += glyph->offsetX;
|
||||
nYDst += glyph->offsetY;
|
||||
nXSrc = glyph->rectX;
|
||||
@ -105,7 +105,7 @@ static int rdtk_font_draw_glyph(rdtkSurface* surface, int nXDst, int nYDst, rdtk
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font,
|
||||
int rdtk_font_draw_text(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, rdtkFont* font,
|
||||
const char* text)
|
||||
{
|
||||
size_t index;
|
||||
@ -124,11 +124,11 @@ int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* fo
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char* text)
|
||||
int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height, const char* text)
|
||||
{
|
||||
size_t index;
|
||||
size_t length;
|
||||
int glyphIndex;
|
||||
size_t glyphIndex;
|
||||
rdtkGlyph* glyph;
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
@ -149,28 +149,32 @@ int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize)
|
||||
static char* rdtk_font_load_descriptor_file(const char* filename, size_t* pSize)
|
||||
{
|
||||
BYTE* buffer;
|
||||
uint8_t* buffer;
|
||||
FILE* fp = NULL;
|
||||
size_t readSize;
|
||||
size_t fileSize;
|
||||
union
|
||||
{
|
||||
size_t s;
|
||||
INT64 i64;
|
||||
} fileSize;
|
||||
fp = winpr_fopen(filename, "r");
|
||||
|
||||
if (!fp)
|
||||
return NULL;
|
||||
|
||||
_fseeki64(fp, 0, SEEK_END);
|
||||
fileSize = _ftelli64(fp);
|
||||
fileSize.i64 = _ftelli64(fp);
|
||||
_fseeki64(fp, 0, SEEK_SET);
|
||||
|
||||
if (fileSize < 1)
|
||||
if (fileSize.i64 < 1)
|
||||
{
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = (BYTE*)malloc(fileSize + 2);
|
||||
buffer = (uint8_t*)malloc(fileSize.s + 2);
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
@ -178,12 +182,12 @@ static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
readSize = fread(buffer, fileSize, 1, fp);
|
||||
readSize = fread(buffer, fileSize.s, 1, fp);
|
||||
|
||||
if (!readSize)
|
||||
if (readSize == 0)
|
||||
{
|
||||
if (!ferror(fp))
|
||||
readSize = fileSize;
|
||||
readSize = fileSize.s;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
@ -194,16 +198,16 @@ static char* rdtk_font_load_descriptor_file(const char* filename, int* pSize)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer[fileSize] = '\0';
|
||||
buffer[fileSize + 1] = '\0';
|
||||
*pSize = (int)fileSize;
|
||||
buffer[fileSize.s] = '\0';
|
||||
buffer[fileSize.s + 1] = '\0';
|
||||
*pSize = fileSize.s;
|
||||
return (char*)buffer;
|
||||
}
|
||||
|
||||
static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, BYTE* utf8)
|
||||
static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, uint8_t* utf8)
|
||||
{
|
||||
size_t len = strlen(str);
|
||||
*((UINT32*)utf8) = 0;
|
||||
*((uint32_t*)utf8) = 0;
|
||||
|
||||
if (len < 1)
|
||||
return 1;
|
||||
@ -235,7 +239,7 @@ static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, BYTE* utf8
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int size)
|
||||
static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, uint8_t* buffer, size_t size)
|
||||
{
|
||||
char* p;
|
||||
char* q;
|
||||
@ -576,15 +580,16 @@ static int rdtk_font_parse_descriptor_buffer(rdtkFont* font, BYTE* buffer, int s
|
||||
|
||||
static int rdtk_font_load_descriptor(rdtkFont* font, const char* filename)
|
||||
{
|
||||
int size;
|
||||
size_t size;
|
||||
char* buffer;
|
||||
buffer = rdtk_font_load_descriptor_file(filename, &size);
|
||||
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
return rdtk_font_parse_descriptor_buffer(font, (BYTE*)buffer, size);
|
||||
return rdtk_font_parse_descriptor_buffer(font, (uint8_t*)buffer, size);
|
||||
}
|
||||
|
||||
rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
|
||||
{
|
||||
int status;
|
||||
@ -658,12 +663,14 @@ cleanup:
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int imageSize,
|
||||
BYTE* descriptorData, int descriptorSize)
|
||||
|
||||
static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, const uint8_t* imageData,
|
||||
size_t imageSize, const uint8_t* descriptorData,
|
||||
size_t descriptorSize)
|
||||
{
|
||||
int size;
|
||||
size_t size;
|
||||
int status;
|
||||
BYTE* buffer;
|
||||
uint8_t* buffer;
|
||||
rdtkFont* font;
|
||||
font = (rdtkFont*)calloc(1, sizeof(rdtkFont));
|
||||
|
||||
@ -689,7 +696,7 @@ static rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int
|
||||
}
|
||||
|
||||
size = descriptorSize;
|
||||
buffer = (BYTE*)malloc(size);
|
||||
buffer = (uint8_t*)malloc(size);
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
@ -726,10 +733,10 @@ int rdtk_font_engine_init(rdtkEngine* engine)
|
||||
{
|
||||
if (!engine->font)
|
||||
{
|
||||
int imageSize;
|
||||
int descriptorSize;
|
||||
BYTE* imageData = NULL;
|
||||
BYTE* descriptorData = NULL;
|
||||
SSIZE_T imageSize;
|
||||
SSIZE_T descriptorSize;
|
||||
const uint8_t* imageData = NULL;
|
||||
const uint8_t* descriptorData = NULL;
|
||||
imageSize = rdtk_get_embedded_resource_file("source_serif_pro_regular_12.png", &imageData);
|
||||
descriptorSize =
|
||||
rdtk_get_embedded_resource_file("source_serif_pro_regular_12.xml", &descriptorData);
|
||||
@ -737,8 +744,8 @@ int rdtk_font_engine_init(rdtkEngine* engine)
|
||||
if ((imageSize < 0) || (descriptorSize < 0))
|
||||
return -1;
|
||||
|
||||
engine->font =
|
||||
rdtk_embedded_font_new(engine, imageData, imageSize, descriptorData, descriptorSize);
|
||||
engine->font = rdtk_embedded_font_new(engine, imageData, (size_t)imageSize, descriptorData,
|
||||
(size_t)descriptorSize);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef RDTK_FONT_PRIVATE_H
|
||||
#define RDTK_FONT_PRIVATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <rdtk/rdtk.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/image.h>
|
||||
|
||||
#include "rdtk_engine.h"
|
||||
@ -36,19 +36,19 @@ struct rdtk_glyph
|
||||
int rectY;
|
||||
int rectWidth;
|
||||
int rectHeight;
|
||||
BYTE code[4];
|
||||
uint8_t code[4];
|
||||
};
|
||||
|
||||
struct rdtk_font
|
||||
{
|
||||
rdtkEngine* engine;
|
||||
|
||||
int size;
|
||||
int height;
|
||||
uint32_t size;
|
||||
uint16_t height;
|
||||
char* family;
|
||||
char* style;
|
||||
wImage* image;
|
||||
int glyphCount;
|
||||
uint16_t glyphCount;
|
||||
rdtkGlyph* glyphs;
|
||||
};
|
||||
|
||||
@ -57,7 +57,8 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char* text);
|
||||
int rdtk_font_text_draw_size(rdtkFont* font, uint16_t* width, uint16_t* height,
|
||||
const char* text);
|
||||
|
||||
int rdtk_font_engine_init(rdtkEngine* engine);
|
||||
int rdtk_font_engine_uninit(rdtkEngine* engine);
|
||||
|
@ -24,13 +24,14 @@
|
||||
|
||||
#include "rdtk_label.h"
|
||||
|
||||
int rdtk_label_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight,
|
||||
rdtkLabel* label, const char* text, int hAlign, int vAlign)
|
||||
int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
|
||||
uint16_t nHeight, rdtkLabel* label, const char* text, uint16_t hAlign,
|
||||
uint16_t vAlign)
|
||||
{
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
int textWidth;
|
||||
int textHeight;
|
||||
uint16_t offsetX;
|
||||
uint16_t offsetY;
|
||||
uint16_t textWidth;
|
||||
uint16_t textHeight;
|
||||
rdtkFont* font;
|
||||
rdtkEngine* engine;
|
||||
|
||||
|
@ -20,23 +20,21 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <freerdp/codec/color.h>
|
||||
|
||||
#include "rdtk_resources.h"
|
||||
|
||||
#include "rdtk_nine_patch.h"
|
||||
|
||||
static int rdtk_image_copy_alpha_blend(BYTE* pDstData, int nDstStep, int nXDst, int nYDst,
|
||||
int nWidth, int nHeight, BYTE* pSrcData, int nSrcStep,
|
||||
static int rdtk_image_copy_alpha_blend(uint8_t* pDstData, int nDstStep, int nXDst, int nYDst,
|
||||
int nWidth, int nHeight, uint8_t* pSrcData, int nSrcStep,
|
||||
int nXSrc, int nYSrc)
|
||||
{
|
||||
int x, y;
|
||||
BYTE A, R, G, B;
|
||||
uint8_t A, R, G, B;
|
||||
|
||||
for (y = 0; y < nHeight; y++)
|
||||
{
|
||||
const BYTE* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)];
|
||||
BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)];
|
||||
const uint8_t* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (nXSrc * 4)];
|
||||
uint8_t* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)];
|
||||
|
||||
for (x = 0; x < nWidth; x++)
|
||||
{
|
||||
@ -80,8 +78,8 @@ int rdtk_nine_patch_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
|
||||
int nYSrc;
|
||||
int nSrcStep;
|
||||
int nDstStep;
|
||||
BYTE* pSrcData;
|
||||
BYTE* pDstData;
|
||||
uint8_t* pSrcData;
|
||||
uint8_t* pDstData;
|
||||
int scaleWidth;
|
||||
|
||||
if (nWidth < ninePatch->width)
|
||||
@ -206,10 +204,10 @@ int rdtk_nine_patch_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth,
|
||||
int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
{
|
||||
int x, y;
|
||||
BYTE* data;
|
||||
uint8_t* data;
|
||||
int beg, end;
|
||||
int scanline;
|
||||
UINT32* pixel;
|
||||
uint32_t* pixel;
|
||||
int width, height;
|
||||
ninePatch->image = image;
|
||||
width = image->width;
|
||||
@ -218,7 +216,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
data = image->data;
|
||||
/* parse scalable area */
|
||||
beg = end = -1;
|
||||
pixel = (UINT32*)&data[4]; /* (1, 0) */
|
||||
pixel = (uint32_t*)&data[4]; /* (1, 0) */
|
||||
|
||||
for (x = 1; x < width - 1; x++)
|
||||
{
|
||||
@ -245,7 +243,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
ninePatch->scaleRight = end - 1;
|
||||
ninePatch->scaleWidth = ninePatch->scaleRight - ninePatch->scaleLeft;
|
||||
beg = end = -1;
|
||||
pixel = (UINT32*)&data[scanline]; /* (0, 1) */
|
||||
pixel = (uint32_t*)&data[scanline]; /* (0, 1) */
|
||||
|
||||
for (y = 1; y < height - 1; y++)
|
||||
{
|
||||
@ -265,7 +263,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
}
|
||||
}
|
||||
|
||||
pixel = (UINT32*)&((BYTE*)pixel)[scanline];
|
||||
pixel = (uint32_t*)&((uint8_t*)pixel)[scanline];
|
||||
}
|
||||
|
||||
ninePatch->scaleTop = beg - 1;
|
||||
@ -273,7 +271,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
ninePatch->scaleHeight = ninePatch->scaleBottom - ninePatch->scaleTop;
|
||||
/* parse fillable area */
|
||||
beg = end = -1;
|
||||
pixel = (UINT32*)&data[((height - 1) * scanline) + 4]; /* (1, height - 1) */
|
||||
pixel = (uint32_t*)&data[((height - 1) * scanline) + 4]; /* (1, height - 1) */
|
||||
|
||||
for (x = 1; x < width - 1; x++)
|
||||
{
|
||||
@ -300,7 +298,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
ninePatch->fillRight = end - 1;
|
||||
ninePatch->fillWidth = ninePatch->fillRight - ninePatch->fillLeft;
|
||||
beg = end = -1;
|
||||
pixel = (UINT32*)&data[((width - 1) * 4) + scanline]; /* (width - 1, 1) */
|
||||
pixel = (uint32_t*)&data[((width - 1) * 4) + scanline]; /* (width - 1, 1) */
|
||||
|
||||
for (y = 1; y < height - 1; y++)
|
||||
{
|
||||
@ -320,7 +318,7 @@ int rdtk_nine_patch_set_image(rdtkNinePatch* ninePatch, wImage* image)
|
||||
}
|
||||
}
|
||||
|
||||
pixel = (UINT32*)&((BYTE*)pixel)[scanline];
|
||||
pixel = (uint32_t*)&((uint8_t*)pixel)[scanline];
|
||||
}
|
||||
|
||||
ninePatch->fillTop = beg - 1;
|
||||
@ -372,8 +370,8 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
|
||||
|
||||
if (!engine->button9patch)
|
||||
{
|
||||
int size;
|
||||
BYTE* data;
|
||||
SSIZE_T size;
|
||||
const uint8_t* data;
|
||||
status = -1;
|
||||
size = rdtk_get_embedded_resource_file("btn_default_normal.9.png", &data);
|
||||
|
||||
@ -382,7 +380,7 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
|
||||
image = winpr_image_new();
|
||||
|
||||
if (image)
|
||||
status = winpr_image_read_buffer(image, data, size);
|
||||
status = winpr_image_read_buffer(image, data, (size_t)size);
|
||||
}
|
||||
|
||||
if (status > 0)
|
||||
@ -400,8 +398,8 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
|
||||
|
||||
if (!engine->textField9patch)
|
||||
{
|
||||
int size;
|
||||
BYTE* data;
|
||||
SSIZE_T size;
|
||||
const uint8_t* data;
|
||||
status = -1;
|
||||
size = rdtk_get_embedded_resource_file("textfield_default.9.png", &data);
|
||||
image = NULL;
|
||||
@ -411,7 +409,7 @@ int rdtk_nine_patch_engine_init(rdtkEngine* engine)
|
||||
image = winpr_image_new();
|
||||
|
||||
if (image)
|
||||
status = winpr_image_read_buffer(image, data, size);
|
||||
status = winpr_image_read_buffer(image, data, (size_t)size);
|
||||
}
|
||||
|
||||
if (status > 0)
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef RDTK_NINE_PATCH_PRIVATE_H
|
||||
#define RDTK_NINE_PATCH_PRIVATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rdtk/rdtk.h>
|
||||
|
||||
#include <winpr/image.h>
|
||||
@ -36,7 +37,7 @@ struct rdtk_nine_patch
|
||||
int width;
|
||||
int height;
|
||||
int scanline;
|
||||
BYTE* data;
|
||||
uint8_t* data;
|
||||
|
||||
int scaleLeft;
|
||||
int scaleRight;
|
||||
|
@ -20,11 +20,13 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "rdtk_resources.h"
|
||||
|
||||
/* Nine Patches */
|
||||
|
||||
static BYTE btn_default_normal_9_png[] = {
|
||||
static const uint8_t btn_default_normal_9_png[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x42, 0xb5, 0xcb,
|
||||
0x95, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b,
|
||||
@ -69,9 +71,9 @@ static BYTE btn_default_normal_9_png[] = {
|
||||
0x26, 0xfe, 0xd3, 0x50, 0x44, 0xf0, 0x17, 0xa0, 0xb1, 0xe0, 0x73, 0xc3, 0xe6, 0x24, 0xdb, 0x00,
|
||||
0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
|
||||
};
|
||||
static int btn_default_normal_9_png_len = 683;
|
||||
static const int btn_default_normal_9_png_len = 683;
|
||||
|
||||
static BYTE textfield_default_9_png[] = {
|
||||
static const uint8_t textfield_default_9_png[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06, 0x00, 0x00, 0x00, 0x46, 0x40, 0x1b,
|
||||
0xa8, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x89, 0x00, 0x00, 0x0b,
|
||||
@ -100,11 +102,11 @@ static BYTE textfield_default_9_png[] = {
|
||||
0x71, 0x3a, 0x69, 0xd1, 0x87, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
|
||||
0x82
|
||||
};
|
||||
static int textfield_default_9_png_len = 417;
|
||||
static const int textfield_default_9_png_len = 417;
|
||||
|
||||
/* Fonts */
|
||||
|
||||
static BYTE source_serif_pro_regular_12_png[] = {
|
||||
static const uint8_t source_serif_pro_regular_12_png[] = {
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x02, 0xe7, 0x00, 0x00, 0x00, 0x11, 0x08, 0x06, 0x00, 0x00, 0x00, 0x7e, 0x53, 0x02,
|
||||
0xe5, 0x00, 0x00, 0x00, 0x04, 0x73, 0x42, 0x49, 0x54, 0x08, 0x08, 0x08, 0x08, 0x7c, 0x08, 0x64,
|
||||
@ -628,9 +630,9 @@ static BYTE source_serif_pro_regular_12_png[] = {
|
||||
0x1f, 0x5a, 0x3b, 0xf9, 0xfc, 0xc1, 0xff, 0x01, 0xf4, 0x4f, 0x9a, 0x26, 0x12, 0xca, 0xbf, 0xd8,
|
||||
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
|
||||
};
|
||||
static int source_serif_pro_regular_12_png_len = 8348;
|
||||
static const int source_serif_pro_regular_12_png_len = 8348;
|
||||
|
||||
static BYTE source_serif_pro_regular_12_xml[] = {
|
||||
static const uint8_t source_serif_pro_regular_12_xml[] = {
|
||||
0x3c, 0x3f, 0x78, 0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31,
|
||||
0x2e, 0x30, 0x22, 0x20, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3d, 0x22, 0x75, 0x74,
|
||||
0x66, 0x2d, 0x38, 0x22, 0x3f, 0x3e, 0x0a, 0x3c, 0x46, 0x6f, 0x6e, 0x74, 0x20, 0x73, 0x69, 0x7a,
|
||||
@ -992,7 +994,7 @@ static BYTE source_serif_pro_regular_12_xml[] = {
|
||||
0x37, 0x33, 0x36, 0x20, 0x36, 0x20, 0x37, 0x20, 0x33, 0x22, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x3d,
|
||||
0x22, 0x7e, 0x22, 0x2f, 0x3e, 0x0a, 0x3c, 0x2f, 0x46, 0x6f, 0x6e, 0x74, 0x3e, 0x0a
|
||||
};
|
||||
static int source_serif_pro_regular_12_xml_len = 5758;
|
||||
static const int source_serif_pro_regular_12_xml_len = 5758;
|
||||
|
||||
/**
|
||||
* Bitmap fonts were generated using FontBuilder on Windows with the following settings:
|
||||
@ -1006,7 +1008,7 @@ static int source_serif_pro_regular_12_xml_len = 5758;
|
||||
* These embedded resources were converted from binaries files to C arrays using "xxd -i"
|
||||
*/
|
||||
|
||||
int rdtk_get_embedded_resource_file(const char* filename, BYTE** pData)
|
||||
SSIZE_T rdtk_get_embedded_resource_file(const char* filename, const uint8_t** pData)
|
||||
{
|
||||
if (strcmp(filename, "source_serif_pro_regular_12.png") == 0)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef RDTK_RESOURCES_PRIVATE_H
|
||||
#define RDTK_RESOURCES_PRIVATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rdtk/rdtk.h>
|
||||
|
||||
#include "rdtk_engine.h"
|
||||
@ -28,7 +29,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int rdtk_get_embedded_resource_file(const char* filename, BYTE** pData);
|
||||
SSIZE_T rdtk_get_embedded_resource_file(const char* filename, const uint8_t** pData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -22,15 +22,28 @@
|
||||
|
||||
#include "rdtk_surface.h"
|
||||
|
||||
int rdtk_surface_fill(rdtkSurface* surface, int x, int y, int width, int height, UINT32 color)
|
||||
#include <string.h>
|
||||
|
||||
int rdtk_surface_fill(rdtkSurface* surface, uint16_t x, uint16_t y, uint16_t width, uint16_t height,
|
||||
uint32_t color)
|
||||
{
|
||||
freerdp_image_fill(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline, x, y, width, height,
|
||||
color);
|
||||
uint16_t i;
|
||||
for (i = y; x < y + height; i++)
|
||||
{
|
||||
uint16_t j;
|
||||
uint8_t* line = &surface->data[i * surface->scanline];
|
||||
for (j = x; j < x + width; x++)
|
||||
{
|
||||
uint32_t* pixel = (uint32_t*)&line[x + 4];
|
||||
*pixel = color;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int height, int scanline)
|
||||
rdtkSurface* rdtk_surface_new(rdtkEngine* engine, uint8_t* data, uint16_t width, uint16_t height,
|
||||
uint32_t scanline)
|
||||
{
|
||||
rdtkSurface* surface;
|
||||
|
||||
@ -50,13 +63,13 @@ rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int hei
|
||||
surface->scanline = scanline;
|
||||
|
||||
surface->data = data;
|
||||
surface->owner = FALSE;
|
||||
surface->owner = false;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
surface->scanline = (surface->width + (surface->width % 4)) * 4;
|
||||
|
||||
surface->data = (BYTE*)calloc(surface->height, surface->scanline);
|
||||
surface->data = (uint8_t*)calloc(surface->height, surface->scanline);
|
||||
|
||||
if (!surface->data)
|
||||
{
|
||||
@ -64,9 +77,9 @@ rdtkSurface* rdtk_surface_new(rdtkEngine* engine, BYTE* data, int width, int hei
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZeroMemory(surface->data, surface->scanline * surface->height);
|
||||
memset(surface->data, 0, surface->scanline * surface->height);
|
||||
|
||||
surface->owner = TRUE;
|
||||
surface->owner = true;
|
||||
}
|
||||
|
||||
return surface;
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef RDTK_SURFACE_PRIVATE_H
|
||||
#define RDTK_SURFACE_PRIVATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <rdtk/rdtk.h>
|
||||
|
||||
#include "rdtk_engine.h"
|
||||
@ -27,10 +29,10 @@ struct rdtk_surface
|
||||
{
|
||||
rdtkEngine* engine;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int scanline;
|
||||
BYTE* data;
|
||||
BOOL owner;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint32_t scanline;
|
||||
uint8_t* data;
|
||||
bool owner;
|
||||
};
|
||||
#endif /* RDTK_SURFACE_PRIVATE_H */
|
||||
|
@ -24,15 +24,15 @@
|
||||
|
||||
#include "rdtk_text_field.h"
|
||||
|
||||
int rdtk_text_field_draw(rdtkSurface* surface, int nXDst, int nYDst, int nWidth, int nHeight,
|
||||
rdtkTextField* textField, const char* text)
|
||||
int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
|
||||
uint16_t nHeight, rdtkTextField* textField, const char* text)
|
||||
{
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
int textWidth;
|
||||
int textHeight;
|
||||
int fillWidth;
|
||||
int fillHeight;
|
||||
uint16_t offsetX;
|
||||
uint16_t offsetY;
|
||||
uint16_t textWidth;
|
||||
uint16_t textHeight;
|
||||
uint16_t fillWidth;
|
||||
uint16_t fillHeight;
|
||||
rdtkFont* font;
|
||||
rdtkEngine* engine;
|
||||
rdtkNinePatch* ninePatch;
|
||||
|
@ -1,16 +1,22 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <rdtk/rdtk.h>
|
||||
#include <winpr/error.h>
|
||||
|
||||
int TestRdTkNinePatch(int argc, char* argv[])
|
||||
{
|
||||
rdtkEngine* engine = NULL;
|
||||
rdtkSurface* surface = NULL;
|
||||
DWORD scanline;
|
||||
DWORD width;
|
||||
DWORD height;
|
||||
BYTE* data = NULL;
|
||||
uint32_t scanline;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint8_t* data = NULL;
|
||||
int ret = -1;
|
||||
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
|
||||
if (!(engine = rdtk_engine_new()))
|
||||
{
|
||||
printf("%s: error creating rdtk engine (%" PRIu32 ")\n", __FUNCTION__, GetLastError());
|
||||
|
@ -20,7 +20,9 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include <rdtk/rdtk.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
@ -36,7 +38,7 @@ int main(int argc, char** argv)
|
||||
int x, y;
|
||||
int width;
|
||||
int height;
|
||||
BYTE* buffer;
|
||||
uint8_t* buffer;
|
||||
int scanline;
|
||||
int pf_count;
|
||||
XEvent event;
|
||||
@ -100,7 +102,7 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
|
||||
scanline = width * 4;
|
||||
buffer = (BYTE*)calloc(height, scanline);
|
||||
buffer = (uint8_t*)calloc(height, scanline);
|
||||
if (!buffer)
|
||||
return 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user