Permalink
Browse files

Font bitmap doesn't need to be public

  • Loading branch information...
UnknownShadow200 committed Jun 6, 2018
1 parent 623e7df commit d48ed236b366a08f43a8330d585b31397faf518b
@@ -68,7 +68,7 @@ public sealed class CanvasDrawer2D : IDrawer2D {
pair.Value.Dispose();
DisposeText();
DisposeBitmappedText();
DisposeFontBitmap();
}
Paint GetOrCreateBrush(Color color) {
@@ -86,7 +86,7 @@ struct CachedBrush { public int ARGB; public SolidBrush Brush; }
}
DisposeText();
DisposeBitmappedText();
DisposeFontBitmap();
}
SolidBrush GetOrCreateBrush(FastColour col) {
@@ -12,18 +12,17 @@ namespace ClassicalSharp {
/// <remarks> Uses GDI+ on Windows, uses Cairo on Mono. </remarks>
unsafe partial class IDrawer2D {
public Bitmap FontBitmap;
/// <summary> Sets the bitmap that contains the bitmapped font characters as an atlas. </summary>
public void SetFontBitmap(Bitmap bmp) {
DisposeBitmappedText();
DisposeFontBitmap();
FontBitmap = bmp;
boxSize = FontBitmap.Width / 16;
fontPixels = new FastBitmap(FontBitmap, true, true);
fontBitmap = bmp;
boxSize = fontBitmap.Width / 16;
fontPixels = new FastBitmap(fontBitmap, true, true);
CalculateTextWidths();
}
protected Bitmap fontBitmap;
protected FastBitmap fontPixels;
protected int boxSize;
protected int[] widths = new int[256];
@@ -238,10 +237,10 @@ unsafe partial class IDrawer2D {
return Utils.CeilDiv(point * 3, 2);
}
protected void DisposeBitmappedText() {
if (FontBitmap == null) return;
protected void DisposeFontBitmap() {
if (fontBitmap == null) return;
fontPixels.Dispose();
FontBitmap.Dispose();
fontBitmap.Dispose();
}
}
}
@@ -19,9 +19,7 @@ Vector3I ChunkUpdater_ChunkPos;
UInt32* ChunkUpdater_Distances;
void ChunkInfo_Reset(ChunkInfo* chunk, Int32 x, Int32 y, Int32 z) {
chunk->CentreX = (UInt16)(x + 8);
chunk->CentreY = (UInt16)(y + 8);
chunk->CentreZ = (UInt16)(z + 8);
chunk->CentreX = x + 8; chunk->CentreY = y + 8; chunk->CentreZ = z + 8;
#if !CC_BUILD_GL11
chunk->Vb = NULL;
#endif
@@ -58,10 +58,10 @@ static void Drawer2D_FreeFontBitmap(void) {
Platform_MemFree(&Drawer2D_FontBitmap.Scan0);
}
void Drawer2D_SetFontBitmap(Bitmap bmp) {
void Drawer2D_SetFontBitmap(Bitmap* bmp) {
Drawer2D_FreeFontBitmap();
Drawer2D_FontBitmap = bmp;
Drawer2D_BoxSize = bmp.Width >> DRAWER2D_LOG2_CHARS_PER_ROW;
Drawer2D_FontBitmap = *bmp;
Drawer2D_BoxSize = bmp->Width >> DRAWER2D_LOG2_CHARS_PER_ROW;
Drawer2D_CalculateTextWidths();
}
@@ -1,14 +1,13 @@
#ifndef CC_DRAWER2D_H
#define CC_DRAWER2D_H
#include "Platform.h"
#include "Bitmap.h"
#include "Texture.h"
#include "Constants.h"
/* Responsible for performing drawing operations on bitmaps, and for converting bitmaps into textures.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
typedef struct DrawTextArgs_ { String Text; FontDesc Font; bool UseShadow; } DrawTextArgs;
typedef struct Bitmap_ Bitmap;
void DrawTextArgs_Make(DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow);
void DrawTextArgs_MakeEmpty(DrawTextArgs* args, FontDesc* font, bool useShadow);
@@ -48,6 +47,5 @@ bool Drawer2D_IsWhiteCol(UInt8 c);
void Drawer2D_ReducePadding_Tex(Texture* tex, Int32 point, Int32 scale);
void Drawer2D_ReducePadding_Height(Int32* height, Int32 point, Int32 scale);
Bitmap Drawer2D_FontBitmap;
void Drawer2D_SetFontBitmap(Bitmap bmp);
void Drawer2D_SetFontBitmap(Bitmap* bmp);
#endif
@@ -25,7 +25,7 @@ static void Map_ReadBlocks(Stream* stream) {
*--------------------------------------------------MCSharp level Format---------------------------------------------------*
*#########################################################################################################################*/
#define LVL_VERSION 1874
#define LVL_CUSTOMTILE ((BlockID)163)
#define LVL_CUSTOMTILE 163
#define LVL_CHUNKSIZE 16
UInt8 Lvl_table[256 - BLOCK_CPE_COUNT] = { 0, 0, 0, 0, 39, 36, 36, 10, 46, 21, 22,
22, 22, 22, 4, 0, 22, 21, 0, 22, 23, 24, 22, 26, 27, 28, 30, 31, 32, 33,
@@ -314,7 +314,7 @@ static void Game_TextureChangedCore(void* obj, Stream* src) {
Platform_MemFree(&atlas.Scan0);
} else if (String_CaselessEqualsConst(&src->Name, "default.png")) {
Bitmap bmp; Bitmap_DecodePng(&bmp, src);
Drawer2D_SetFontBitmap(bmp);
Drawer2D_SetFontBitmap(&bmp);
Event_RaiseVoid(&ChatEvents_FontChanged);
}
}
@@ -59,8 +59,8 @@ void PackedCol_ToHex(STRING_TRANSIENT String* str, PackedCol value) {
for (i = 0; i < 3; i++) {
Int32 value = input[i], hi = value >> 4, lo = value & 0x0F;
/* 48 = index of 0, 55 = index of (A - 10) */
hex[i * 2 + 0] = hi < 10 ? (UInt8)(hi + 48) : (UInt8)(hi + 55);
hex[i * 2 + 1] = lo < 10 ? (UInt8)(lo + 48) : (UInt8)(lo + 55);
hex[i * 2 + 0] = hi < 10 ? (hi + 48) : (hi + 55);
hex[i * 2 + 1] = lo < 10 ? (lo + 48) : (lo + 55);
}
hex[6] = NULL; /* Null terminate hex characters */
@@ -81,9 +81,9 @@ bool PackedCol_TryParseHex(STRING_PURE String* str, PackedCol* value) {
if (!PackedCol_Unhex(buffer[2], &gH) || !PackedCol_Unhex(buffer[3], &gL)) return false;
if (!PackedCol_Unhex(buffer[4], &bH) || !PackedCol_Unhex(buffer[5], &bL)) return false;
value->R = (UInt8)((rH << 4) | rL);
value->G = (UInt8)((gH << 4) | gL);
value->B = (UInt8)((bH << 4) | bL);
value->R = ((rH << 4) | rL);
value->G = ((gH << 4) | gL);
value->B = ((bH << 4) | bL);
value->A = UInt8_MaxValue;
return true;
}
@@ -27,7 +27,7 @@ void SelectionBox_Render(SelectionBox* box, VertexP3fC4b** vertices, VertexP3fC4
SelectionBox_VerQuad(vertices, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p2.Z);
SelectionBox_VerQuad(vertices, col, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z);
col.R = (UInt8)~col.R; col.G = (UInt8)~col.G; col.B = (UInt8)~col.B;
col.R = ~col.R; col.G = ~col.G; col.B = ~col.B;
/* bottom face */
SelectionBox_Line(lineVertices, col, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z);
SelectionBox_Line(lineVertices, col, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z);
@@ -19,6 +19,7 @@
#include "ErrorHandler.h"
#include "PacketHandlers.h"
#include "Inventory.h"
#include "Platform.h"
/*########################################################################################################################*
*-----------------------------------------------------Common handlers-----------------------------------------------------*
@@ -399,16 +399,16 @@ bool Stream_ReadLine(Stream* stream, STRING_TRANSIENT String* text) {
Int32 Stream_WriteUtf8(UInt8* buffer, UInt16 codepoint) {
if (codepoint <= 0x7F) {
buffer[0] = (UInt8)codepoint;
buffer[0] = codepoint;
return 1;
} else if (codepoint >= 0x80 && codepoint <= 0x7FF) {
buffer[0] = (UInt8)(0xC0 | (codepoint >> 6) & 0x1F);
buffer[1] = (UInt8)(0x80 | (codepoint) & 0x3F);
buffer[0] = 0xC0 | ((codepoint >> 6) & 0x1F);
buffer[1] = 0x80 | ((codepoint) & 0x3F);
return 2;
} else {
buffer[0] = (UInt8)(0xE0 | (codepoint >> 12) & 0x0F);
buffer[1] = (UInt8)(0x80 | (codepoint >> 6) & 0x3F);
buffer[2] = (UInt8)(0x80 | (codepoint) & 0x3F);
buffer[0] = 0xE0 | ((codepoint >> 12) & 0x0F);
buffer[1] = 0x80 | ((codepoint >> 6) & 0x3F);
buffer[2] = 0x80 | ((codepoint) & 0x3F);
return 3;
}
}
@@ -503,14 +503,14 @@ UInt8 Convert_UnicodeToCP437(UInt16 c) {
}
bool Convert_TryUnicodeToCP437(UInt16 c, UInt8* value) {
if (c >= 0x20 && c < 0x7F) { *value = (UInt8)c; return true; }
if (c >= 0x20 && c < 0x7F) { *value = c; return true; }
UInt32 i;
for (i = 0; i < Array_Elems(Convert_ControlChars); i++) {
if (Convert_ControlChars[i] == c) { *value = (UInt8)i; return true; }
if (Convert_ControlChars[i] == c) { *value = i; return true; }
}
for (i = 0; i < Array_Elems(Convert_ExtendedChars); i++) {
if (Convert_ExtendedChars[i] == c) { *value = (UInt8)(i + 0x7F); return true; }
if (Convert_ExtendedChars[i] == c) { *value = i + 0x7F; return true; }
}
*value = '?'; return false;

0 comments on commit d48ed23

Please sign in to comment.