Skip to content

Commit

Permalink
Moving class method declarations into class seems to decrease program…
Browse files Browse the repository at this point in the history
… size
  • Loading branch information
keelimeguy committed Jun 25, 2017
1 parent 347e76c commit 9be6f9a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 114 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CFLAGS = -Wall -Wextra -Wpedantic -O1 -Wchkp -Wformat=2 -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused-parameter -fno-rtti
CFLAGS = -Wall -Wextra -Wpedantic -Os -Wchkp -Wformat=2 -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wno-unused-parameter -fno-rtti
CFLAGS += `pkg-config --cflags freetype2` `pkg-config --cflags libpng` -isystem lib/litehtml/include/
LDFLAGS = -Llib/litehtml/ -llitehtml `pkg-config --libs freetype2` `pkg-config --libs libpng`

Expand Down
102 changes: 0 additions & 102 deletions uxmux_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,6 @@

/* See https://github.com/litehtml/litehtml/wiki/document_container */

uxmux_container::uxmux_container(std::string prefix, struct fb_fix_screeninfo* finfo, struct fb_var_screeninfo* vinfo) :
m_finfo(finfo), m_vinfo(vinfo), m_default_font({0, false}), m_cursor(false), m_new_page(""), m_new_page_alt("")
{
// printf("ctor uxmux_container\n");

if (strcmp(prefix.c_str(),"")!=0)
m_directory = prefix+"/";
else
m_directory = "";
m_back_buffer = static_cast<uint32_t*>(mmap(0, vinfo->yres_virtual * finfo->line_length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, off_t(0)));

/* Setup Font Library */
FT_Init_FreeType(&m_library);

litehtml::font_metrics fm;
create_font(get_default_font_name(), get_default_font_size(), 400, litehtml::font_style(0), 0, &fm);

/* Clear the screen to white */
draw_rect(m_back_buffer, 0, 0, m_vinfo->xres, m_vinfo->yres, litehtml::web_color(0xff, 0xff, 0xff));
}

uxmux_container::~uxmux_container(void) {
// printf("dtor ~uxmux_container\n");
if (!m_fonts.empty()) {
std::unordered_map<std::string, font_structure_t>::iterator it;
for (it=m_fonts.begin(); it!=m_fonts.end(); ++it){
// printf(" delete_font: %s\n", it->first.c_str());
if (it->second.valid && it->second.font) {
FT_Done_Face(it->second.font);
it->second.valid = false;
it->second.font = 0;
}
}
m_fonts.clear();
}
FT_Done_FreeType(m_library);
}

void uxmux_container::swap_buffer(litehtml::uint_ptr hdc) {
int i;
for (i=0; i<(m_vinfo->yres_virtual * m_finfo->line_length)/4; i++) {
(reinterpret_cast<uint32_t*>(hdc))[i] = m_back_buffer[i];
}
}

void uxmux_container::swap_buffer(litehtml::uint_ptr src_hdc, litehtml::uint_ptr dest_hdc, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo) {
int i;
for (i=0; i<(vinfo->yres_virtual * finfo->line_length)/4; i++) {
(reinterpret_cast<uint32_t*>(dest_hdc))[i] = reinterpret_cast<uint32_t*>(src_hdc)[i];
}
}

void uxmux_container::draw_mouse(litehtml::uint_ptr hdc, int xpos, int ypos, unsigned char click) {
// printf("draw_mouse, at (%d, %d)\n", xpos, ypos);
if (m_cursor) {
draw_rect(hdc, xpos-1, ypos-4, 3, 9, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
draw_rect(hdc, xpos-4, ypos-1, 9, 3, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
} else {
draw_rect(hdc, xpos-1, ypos-2, 3, 5, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
draw_rect(hdc, xpos-2, ypos-1, 5, 3, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
}
}

void uxmux_container::draw_rect(litehtml::uint_ptr hdc, const litehtml::position& rect, const litehtml::web_color& color) {
draw_rect(hdc, rect.x, rect.y, rect.width, rect.height, color);
}

void uxmux_container::draw_rect(litehtml::uint_ptr hdc, int xpos, int ypos, int width, int height, const litehtml::web_color& color) {
// printf(" draw_rect, at (%d, %d), size (%d, %d), color (%d, %d, %d)\n", xpos, ypos, width, height, static_cast<int>(color.red), static_cast<int>(color.green), static_cast<int>(color.blue));

long x, y;
for (x = xpos; x < xpos + width; x++) {
for (y = ypos; y < ypos + height; y++) {
if (x < 0 || y < 0 || x >= m_vinfo->xres || y >= m_vinfo->yres)
continue;
long location = (x+m_vinfo->xoffset)*(m_vinfo->bits_per_pixel/8) + (y+m_vinfo->yoffset)*m_finfo->line_length;
*(reinterpret_cast<uint32_t*>(hdc+location)) = static_cast<uint32_t>(color.red<<m_vinfo->red.offset | color.green<<m_vinfo->green.offset | color.blue<<m_vinfo->blue.offset);
}
}
}

void uxmux_container::load_font(litehtml::uint_ptr hFont) {
font_structure_t* font_struct = reinterpret_cast<font_structure_t*>(hFont);
load_font(*font_struct);
}

void uxmux_container::load_font(font_structure_t font_struct) {
m_face = font_struct.font;
if (!font_struct.valid || !m_face) {
font_struct.valid = false;
if (m_default_font.valid)
m_face = m_default_font.font;
else {
m_face = 0;
return;
}
}
if (!m_face)
return;
m_slot = m_face->glyph;
}

litehtml::uint_ptr uxmux_container::create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) {
// printf("create_font: %s, size=%d, weight=%d, style=%d, decoration=%d\n", faceName, size, weight, italic, decoration);

Expand Down
112 changes: 101 additions & 11 deletions uxmux_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,107 @@ class uxmux_container : public litehtml::document_container {
uint32_t* m_back_buffer;

public:
// uxmux_container(void);
uxmux_container(std::string prefix, struct fb_fix_screeninfo* finfo, struct fb_var_screeninfo* vinfo);
~uxmux_container(void);

void draw_rect(litehtml::uint_ptr hdc, const litehtml::position& rect, const litehtml::web_color& color);
void draw_rect(litehtml::uint_ptr hdc, int xpos, int ypos, int width, int height, const litehtml::web_color& color);
void draw_mouse(litehtml::uint_ptr hdc, int xpos, int ypos, unsigned char click);
void swap_buffer(litehtml::uint_ptr src_hdc, litehtml::uint_ptr dest_hdc, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo);
void swap_buffer(litehtml::uint_ptr hdc);
void load_font(litehtml::uint_ptr hFont);
void load_font(font_structure_t font_struct);
uxmux_container(std::string prefix, struct fb_fix_screeninfo* finfo, struct fb_var_screeninfo* vinfo) :
m_finfo(finfo), m_vinfo(vinfo), m_default_font({0, false}), m_cursor(false), m_new_page(""), m_new_page_alt("")
{
// printf("ctor uxmux_container\n");

if (strcmp(prefix.c_str(),"")!=0)
m_directory = prefix+"/";
else
m_directory = "";
m_back_buffer = static_cast<uint32_t*>(mmap(0, vinfo->yres_virtual * finfo->line_length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, off_t(0)));

/* Setup Font Library */
FT_Init_FreeType(&m_library);

litehtml::font_metrics fm;
create_font(get_default_font_name(), get_default_font_size(), 400, litehtml::font_style(0), 0, &fm);

/* Clear the screen to white */
draw_rect(m_back_buffer, 0, 0, m_vinfo->xres, m_vinfo->yres, litehtml::web_color(0xff, 0xff, 0xff));
}

~uxmux_container(void) {
// printf("dtor ~uxmux_container\n");
if (!m_fonts.empty()) {
std::unordered_map<std::string, font_structure_t>::iterator it;
for (it=m_fonts.begin(); it!=m_fonts.end(); ++it){
// printf(" delete_font: %s\n", it->first.c_str());
if (it->second.valid && it->second.font) {
FT_Done_Face(it->second.font);
it->second.valid = false;
it->second.font = 0;
}
}
m_fonts.clear();
}
FT_Done_FreeType(m_library);
}

void swap_buffer(litehtml::uint_ptr hdc) {
int i;
for (i=0; i<(m_vinfo->yres_virtual * m_finfo->line_length)/4; i++) {
(reinterpret_cast<uint32_t*>(hdc))[i] = m_back_buffer[i];
}
}

void swap_buffer(litehtml::uint_ptr src_hdc, litehtml::uint_ptr dest_hdc, struct fb_var_screeninfo *vinfo, struct fb_fix_screeninfo *finfo) {
int i;
for (i=0; i<(vinfo->yres_virtual * finfo->line_length)/4; i++) {
(reinterpret_cast<uint32_t*>(dest_hdc))[i] = reinterpret_cast<uint32_t*>(src_hdc)[i];
}
}

void draw_mouse(litehtml::uint_ptr hdc, int xpos, int ypos, unsigned char click) {
// printf("draw_mouse, at (%d, %d)\n", xpos, ypos);
if (m_cursor) {
draw_rect(hdc, xpos-1, ypos-4, 3, 9, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
draw_rect(hdc, xpos-4, ypos-1, 9, 3, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
} else {
draw_rect(hdc, xpos-1, ypos-2, 3, 5, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
draw_rect(hdc, xpos-2, ypos-1, 5, 3, litehtml::web_color(click&0x4?0xff:0, click&0x2?0xff:0, click&0x1?0xff:0));
}
}

void draw_rect(litehtml::uint_ptr hdc, const litehtml::position& rect, const litehtml::web_color& color) {
draw_rect(hdc, rect.x, rect.y, rect.width, rect.height, color);
}

void draw_rect(litehtml::uint_ptr hdc, int xpos, int ypos, int width, int height, const litehtml::web_color& color) {
// printf(" draw_rect, at (%d, %d), size (%d, %d), color (%d, %d, %d)\n", xpos, ypos, width, height, static_cast<int>(color.red), static_cast<int>(color.green), static_cast<int>(color.blue));

long x, y;
for (x = xpos; x < xpos + width; x++) {
for (y = ypos; y < ypos + height; y++) {
if (x < 0 || y < 0 || x >= m_vinfo->xres || y >= m_vinfo->yres)
continue;
long location = (x+m_vinfo->xoffset)*(m_vinfo->bits_per_pixel/8) + (y+m_vinfo->yoffset)*m_finfo->line_length;
*(reinterpret_cast<uint32_t*>(hdc+location)) = static_cast<uint32_t>(color.red<<m_vinfo->red.offset | color.green<<m_vinfo->green.offset | color.blue<<m_vinfo->blue.offset);
}
}
}

void load_font(litehtml::uint_ptr hFont) {
font_structure_t* font_struct = reinterpret_cast<font_structure_t*>(hFont);
load_font(*font_struct);
}

void load_font(font_structure_t font_struct) {
m_face = font_struct.font;
if (!font_struct.valid || !m_face) {
font_struct.valid = false;
if (m_default_font.valid)
m_face = m_default_font.font;
else {
m_face = 0;
return;
}
}
if (!m_face)
return;
m_slot = m_face->glyph;
}

std::string get_new_page() {
// printf("get_new_page\n");
Expand Down

0 comments on commit 9be6f9a

Please sign in to comment.