void Font::Reset() { assert(!IsDefined() || IsScreenInitialized()); if (font != NULL) { assert(IsScreenInitialized()); TTF_CloseFont(font); font = NULL; } }
void Window::set(ContainerWindow *parent, const TCHAR *cls, const TCHAR *text, PixelScalar left, PixelScalar top, UPixelScalar width, UPixelScalar height, const WindowStyle window_style) { assert(IsScreenInitialized()); assert(width > 0); assert(width < 0x1000000); assert(height > 0); assert(height < 0x1000000); double_clicks = window_style.double_clicks; DWORD style = window_style.style, ex_style = window_style.ex_style; if (window_style.custom_painting) EnableCustomPainting(); hWnd = ::CreateWindowEx(ex_style, cls, text, style, left, top, width, height, parent != NULL ? parent->hWnd : NULL, NULL, NULL, this); /* this isn't good error handling, but this only happens if out-of-memory (we can't do anything useful) or if we passed wrong arguments - which is a bug */ assert(hWnd != NULL); }
void UnitSymbol::Load(ResourceId id) { #ifdef USE_MEMORY_CANVAS assert(IsScreenInitialized()); assert(buffer.data == nullptr); ResourceLoader::Data data = ResourceLoader::Load(id); assert(!data.IsNull()); const UncompressedImage uncompressed = LoadPNG(data.data, data.size); assert(uncompressed.GetFormat() == UncompressedImage::Format::GRAY); const size_t size = uncompressed.GetPitch() * uncompressed.GetHeight(); buffer.data = new Luminosity8[size]; memcpy(buffer.data, uncompressed.GetData(), size); buffer.pitch = uncompressed.GetPitch(); buffer.width = uncompressed.GetWidth(); buffer.height = uncompressed.GetHeight(); #else bitmap.Load(id, Bitmap::Type::MONO); size = bitmap.GetSize(); #endif }
bool Font::Load(const LOGFONT &log_font) { assert(IsScreenInitialized()); bool bold = log_font.lfWeight >= 700; bool italic = log_font.lfItalic; const char *path = nullptr; /* check for presence of "real" font and clear the bold or italic * flags if found so that freetype does not apply them again to * produce a "synthetic" bold or italic version of the font */ if (italic && bold && bold_italic_font_path != nullptr) { path = bold_italic_font_path; bold = false; italic = false; } else if (italic && italic_font_path != nullptr) { path = italic_font_path; italic = false; } else if ((log_font.lfPitchAndFamily & 0x03) == FIXED_PITCH && monospace_font_path != nullptr) { path = monospace_font_path; } else if (bold && bold_font_path != nullptr) { path = bold_font_path; bold = false; } else { path = font_path; } if (path == nullptr) return false; return LoadFile(path, log_font.lfHeight > 0 ? log_font.lfHeight : 10, bold, italic); }
bool Font::Load(const FontDescription &d) { assert(IsScreenInitialized()); bool bold = d.IsBold(); bool italic = d.IsItalic(); const char *path = nullptr; /* check for presence of "real" font and clear the bold or italic * flags if found so that freetype does not apply them again to * produce a "synthetic" bold or italic version of the font */ if (italic && bold && bold_italic_font_path != nullptr) { path = bold_italic_font_path; bold = false; italic = false; } else if (italic && italic_font_path != nullptr) { path = italic_font_path; italic = false; } else if (d.IsMonospace() && monospace_font_path != nullptr) { path = monospace_font_path; } else if (bold && bold_font_path != nullptr) { path = bold_font_path; bold = false; } else { path = font_path; } if (path == nullptr) return false; return LoadFile(path, d.GetHeight(), bold, italic); }
void Window::set(ContainerWindow *parent, PixelScalar left, PixelScalar top, UPixelScalar width, UPixelScalar height, const WindowStyle window_style) { assert(IsScreenInitialized()); assert(width < 0x8000); assert(height < 0x8000); double_clicks = window_style.double_clicks; this->parent = parent; this->left = left; this->top = top; this->width = width; this->height = height; tab_stop = window_style.tab_stop; control_parent = window_style.control_parent; visible = window_style.visible; enabled = window_style.enabled; has_border = window_style.has_border; text_style = window_style.text_style; if (parent != NULL) parent->AddChild(*this); OnCreate(); OnResize(width, height); }
void Bitmap::Reset() { assert(!IsDefined() || IsScreenInitialized()); buffer.Free(); }
bool Font::LoadFile(const char *file, unsigned ptsize, bool bold, bool italic) { assert(IsScreenInitialized()); Destroy(); FT_Face new_face = FreeType::Load(file); if (new_face == nullptr) return false; FT_Error error = ::FT_Set_Pixel_Sizes(new_face, 0, ptsize); if (error) { ::FT_Done_Face(new_face); return false; } const FT_Fixed y_scale = new_face->size->metrics.y_scale; height = FT_CEIL(FT_MulFix(new_face->height, y_scale)); ascent_height = FT_CEIL(FT_MulFix(new_face->ascender, y_scale)); capital_height = ::GetCapitalHeight(new_face); if (capital_height == 0) capital_height = height; // TODO: handle bold/italic face = new_face; return true; }
inline void Brush::Reset() { assert(!IsDefined() || IsScreenInitialized()); color = Color::Transparent(); }
inline void Brush::Set(const Color c) { assert(IsScreenInitialized()); color = c; }
void Window::Create(ContainerWindow *parent, const TCHAR *cls, const TCHAR *text, PixelRect rc, const WindowStyle window_style) { assert(IsScreenInitialized()); assert(rc.left <= rc.right); assert(rc.right - rc.left < 0x1000000); assert(rc.top <= rc.bottom); assert(rc.bottom - rc.top < 0x1000000); double_clicks = window_style.double_clicks; DWORD style = window_style.style, ex_style = window_style.ex_style; if (window_style.custom_painting) EnableCustomPainting(); hWnd = ::CreateWindowEx(ex_style, cls, text, style, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, parent != NULL ? parent->hWnd : NULL, NULL, NULL, this); /* this isn't good error handling, but this only happens if out-of-memory (we can't do anything useful) or if we passed wrong arguments - which is a bug */ assert(hWnd != NULL); }
void Window::Create(ContainerWindow *parent, PixelRect rc, const WindowStyle window_style) { assert(IsScreenInitialized()); assert(rc.left <= rc.right); assert(rc.right - rc.left < 0x8000); assert(rc.top <= rc.bottom); assert(rc.bottom - rc.top < 0x8000); double_clicks = window_style.double_clicks; this->parent = parent; position = rc.GetOrigin(); size = rc.GetSize(); tab_stop = window_style.tab_stop; control_parent = window_style.control_parent; visible = window_style.visible; enabled = window_style.enabled; has_border = window_style.has_border; text_style = window_style.text_style; if (parent != NULL) parent->AddChild(*this); OnCreate(); OnResize(size); }
void Window::reset() { if (!IsDefined()) return; assert(IsScreenInitialized()); AssertThread(); #ifndef USE_GDI OnDestroy(); width = 0; height = 0; #else /* USE_GDI */ ::DestroyWindow(hWnd); /* the OnDestroy() method must have cleared the variable by now */ assert(prev_wndproc == NULL || hWnd == NULL); hWnd = NULL; prev_wndproc = NULL; #endif /* USE_GDI */ }
bool Bitmap::Load(unsigned id, Type type) { assert(IsScreenInitialized()); Reset(); ResourceLoader::Data data = ResourceLoader::Load(id); if (data.first == NULL) return false; #ifdef WIN32 const BITMAPINFO *info = (const BITMAPINFO *)data.first; if (data.second < sizeof(*info)) return false; int pitch = (((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 7) / 8 - 1) | 3) + 1; int data_size = pitch * info->bmiHeader.biHeight; /* duplicate the BMP file and re-insert the BITMAPFILEHEADER which is not included in this .EXE file */ size_t size = data.second; BITMAPFILEHEADER *header = (BITMAPFILEHEADER *)malloc(sizeof(*header) + size); if (header == NULL) /* out of memory */ return false; /* byte order? this constant is correct according to MSDN */ header->bfType = 0x4D42; header->bfSize = sizeof(*header) + size; header->bfReserved1 = 0; header->bfReserved2 = 0; header->bfOffBits = sizeof(BITMAPFILEHEADER) + size - data_size; memcpy(header + 1, data.first, data.second); const void *bmp_data = header; size_t bmp_size = sizeof(*header) + size; #else const void *bmp_data = data.first; size_t bmp_size = data.second; #endif SDL_RWops *rw = SDL_RWFromConstMem(bmp_data, bmp_size); #ifdef WIN32 SDL_Surface *original = ::SDL_LoadBMP_RW(rw, 1); free(header); #else SDL_Surface *original = ::IMG_LoadPNG_RW(rw); SDL_RWclose(rw); #endif if (original == NULL) return false; Load(original, type); return true; }
void Font::reset() { assert(!defined() || IsScreenInitialized()); delete textUtilObject; textUtilObject = NULL; }
void Pen::Set(Style Style, unsigned width, const Color c) { assert(IsScreenInitialized()); Reset(); pen = ::CreatePen(Style, width, c); }
void Brush::Set(const Color c) { assert(IsScreenInitialized()); Reset(); brush = ::CreateSolidBrush(c); }
void Pen::set(enum style style, unsigned _width, const Color c) { assert(IsScreenInitialized()); width = _width; color = c; }
void Font::Destroy() { assert(!IsDefined() || IsScreenInitialized()); delete text_util_object; text_util_object = nullptr; }
void Pen::set(enum style style, unsigned width, const Color c) { assert(IsScreenInitialized()); reset(); pen = ::CreatePen(style, width, c); }
void Pen::reset() { assert(!defined() || IsScreenInitialized()); #ifndef NDEBUG width = 0; #endif }
void Bitmap::Reset() { assert(!IsDefined() || IsScreenInitialized()); assert(!IsDefined() || pthread_equal(pthread_self(), OpenGL::thread)); delete texture; texture = NULL; }
inline void Pen::Destroy() { assert(!IsDefined() || IsScreenInitialized()); #ifndef NDEBUG width = 0; #endif }
void Bitmap::Reset() { assert(!IsDefined() || IsScreenInitialized()); if (surface != NULL) { SDL_FreeSurface(surface); surface = NULL; } }
void Pen::reset() { assert(!defined() || IsScreenInitialized()); if (pen != NULL) { ::DeleteObject(pen); pen = NULL; } }
void Font::reset() { if (font != NULL) { assert(IsScreenInitialized()); ::DeleteObject(font); font = NULL; } }
void Bitmap::Reset() { if (bitmap != NULL) { assert(IsScreenInitialized()); DeleteObject(bitmap); bitmap = NULL; } }
bool Bitmap::Load(const UncompressedImage &uncompressed, Type type) { assert(IsScreenInitialized()); assert(uncompressed.IsVisible()); Reset(); ImportSurface(buffer, uncompressed); return true; }
void Font::Destroy() { if (!IsDefined()) return; assert(IsScreenInitialized()); ::FT_Done_Face(face); face = nullptr; }
void Pen::Create(Style _style, unsigned _width, const Color c) { assert(IsScreenInitialized()); width = _width; color = c; #if defined(USE_MEMORY_CANVAS) || (defined(ENABLE_OPENGL) && !defined(HAVE_GLES)) style = _style; #endif }