C client: Minor code cleanup

This commit is contained in:
UnknownShadow200 2018-09-12 07:36:37 +10:00
parent ab8a35f7c7
commit 6eb08b70e2
48 changed files with 334 additions and 392 deletions

View File

@ -1,19 +0,0 @@
#include "2DStructs.h"
struct Rectangle2D Rectangle2D_Make(Int32 x, Int32 y, Int32 width, Int32 height) {
struct Rectangle2D r;
r.X = x; r.Y = y; r.Width = width; r.Height = height;
return r;
}
bool Rectangle2D_Equals(struct Rectangle2D a, struct Rectangle2D b) {
return a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;
}
struct Size2D Size2D_Make(Int32 width, Int32 height) {
struct Size2D s; s.Width = width; s.Height = height; return s;
}
struct Point2D Point2D_Make(Int32 x, Int32 y) {
struct Point2D p; p.X = x; p.Y = y; return p;
}

View File

@ -1,24 +0,0 @@
#ifndef CC_2DSTRUCTS_H
#define CC_2DSTRUCTS_H
#include "Core.h"
/* Represents simple structures useful for 2D operations.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
struct Rectangle2D { Int32 X, Y, Width, Height; };
struct Rectangle2D Rectangle2D_Empty;
struct Point2D { Int32 X, Y; };
struct Point2D Point2D_Empty;
struct Size2D { Int32 Width, Height; };
struct Size2D Size2D_Empty;
struct Rectangle2D Rectangle2D_Make(Int32 x, Int32 y, Int32 width, Int32 height);
bool Rectangle2D_Equals(struct Rectangle2D a, struct Rectangle2D b);
struct Size2D Size2D_Make(Int32 width, Int32 height);
struct Point2D Point2D_Make(Int32 x, Int32 y);
struct TextureRec { Real32 U1, V1, U2, V2; };
#endif

View File

@ -11,6 +11,7 @@
#include "ErrorHandler.h"
#include "Errors.h"
#include "Stream.h"
#include "Bitmap.h"
#define LIQUID_ANIM_MAX 64
/*########################################################################################################################*
@ -142,7 +143,7 @@ struct AnimationData {
Int16 Tick, TickDelay;
};
struct Bitmap anims_bmp;
Bitmap anims_bmp;
struct AnimationData anims_list[ATLAS1D_MAX_ATLASES];
Int32 anims_count;
bool anims_validated, anims_useLavaAnim, anims_useWaterAnim;
@ -215,7 +216,7 @@ static void Animations_Draw(struct AnimationData* data, TextureLoc texLoc, Int32
Int32 index_1D = Atlas1D_Index(texLoc);
Int32 rowId_1D = Atlas1D_RowId(texLoc);
struct Bitmap animPart; Bitmap_Create(&animPart, size, size, buffer);
Bitmap animPart; Bitmap_Create(&animPart, size, size, buffer);
if (!data) {
if (texLoc == 30) {

View File

@ -2,7 +2,6 @@
#define CC_ASYNCDOWNLOADER_H
#include "Constants.h"
#include "Utils.h"
#include "Bitmap.h"
/* Downloads images, texture packs, skins, etc in async manner.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/

View File

@ -7,11 +7,11 @@
#include "Stream.h"
#include "Errors.h"
void Bitmap_Create(struct Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
bmp->Width = width; bmp->Height = height; bmp->Scan0 = scan0;
}
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bitmap* src, struct Bitmap* dst, Int32 size) {
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size) {
Int32 x, y;
for (y = 0; y < size; y++) {
UInt32* srcRow = Bitmap_GetRow(src, srcY + y);
@ -22,12 +22,12 @@ void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bit
}
}
void Bitmap_Allocate(struct Bitmap* bmp, Int32 width, Int32 height) {
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height) {
bmp->Width = width; bmp->Height = height;
bmp->Scan0 = Mem_Alloc(width * height, BITMAP_SIZEOF_PIXEL, "bitmap data");
}
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, Int32 width, Int32 height) {
void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height) {
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);
@ -308,7 +308,7 @@ Png_RowExpander Png_GetExpander(UInt8 col, UInt8 bitsPerSample) {
return NULL;
}
static void Png_ComputeTransparency(struct Bitmap* bmp, UInt32 transparentCol) {
static void Png_ComputeTransparency(Bitmap* bmp, UInt32 transparentCol) {
UInt32 trnsRGB = transparentCol & PNG_RGB_MASK;
Int32 x, y, width = bmp->Width, height = bmp->Height;
@ -324,7 +324,7 @@ static void Png_ComputeTransparency(struct Bitmap* bmp, UInt32 transparentCol) {
/* Most bits per sample is 16. Most samples per pixel is 4. Add 1 for filter byte. */
#define PNG_BUFFER_SIZE ((PNG_MAX_DIMS * 2 * 4 + 1) * 2)
/* TODO: Test a lot of .png files and ensure output is right */
ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream) {
ReturnCode Bitmap_DecodePng(Bitmap* bmp, struct Stream* stream) {
Bitmap_Create(bmp, 0, 0, NULL);
UInt8 tmp[PNG_PALETTE * 3];
ReturnCode res;
@ -607,7 +607,7 @@ static void Png_EncodeRow(UInt8* src, UInt8* cur, UInt8* prior, UInt8* best, Int
best[0] = bestFilter;
}
ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
ReturnCode Bitmap_EncodePng(Bitmap* bmp, struct Stream* stream) {
ReturnCode res;
UInt8 tmp[32];
if ((res = Stream_Write(stream, png_sig, PNG_SIG_SIZE))) return res;

View File

@ -5,7 +5,6 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct Stream;
struct Bitmap { UInt8* Scan0; Int32 Width, Height; };
#define PNG_MAX_DIMS 0x8000L
#define BITMAP_SIZEOF_PIXEL 4 /* 32 bit ARGB */
@ -13,12 +12,12 @@ struct Bitmap { UInt8* Scan0; Int32 Width, Height; };
#define Bitmap_GetRow(bmp, y) ((UInt32*)((bmp)->Scan0 + ((y) * ((bmp)->Width << 2))))
#define Bitmap_GetPixel(bmp, x, y) (Bitmap_GetRow(bmp, y)[x])
void Bitmap_Create(struct Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bitmap* src, struct Bitmap* dst, Int32 size);
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size);
/* Allocates a new bitmap of the given dimensions. You are responsible for freeing its memory! */
void Bitmap_Allocate(struct Bitmap* bmp, Int32 width, Int32 height);
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height);
/* Allocates a power-of-2 sized bitmap larger or equal to to the given size, and clears it to 0. You are responsible for freeing its memory! */
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, Int32 width, Int32 height);
void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height);
bool Bitmap_DetectPng(UInt8* data, UInt32 len);
/*
@ -26,6 +25,6 @@ bool Bitmap_DetectPng(UInt8* data, UInt32 len);
https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way
https://github.com/nothings/stb/blob/master/stb_image.h
*/
ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_DecodePng(Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_EncodePng(Bitmap* bmp, struct Stream* stream);
#endif

View File

@ -7,6 +7,7 @@
#include "Inventory.h"
#include "Event.h"
#include "Platform.h"
#include "Bitmap.h"
const char* Sound_Names[SOUND_COUNT] = {
"none", "wood", "gravel", "grass", "stone",
@ -275,7 +276,7 @@ void Block_RecalculateSpriteBB(void) {
}
}
static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (x = 0; x < size; x++) {
for (y = 0; y < size; y++) {
@ -288,7 +289,7 @@ static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, struc
return 1.0f;
}
static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (y = size - 1; y >= 0; y--) {
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
@ -301,7 +302,7 @@ static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, struc
return 1.0f;
}
static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (x = size - 1; x >= 0; x--) {
for (y = 0; y < size; y++) {
@ -314,7 +315,7 @@ static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, struc
return 0.0f;
}
static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (y = 0; y < size; y++) {
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
@ -328,7 +329,7 @@ static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, struc
}
void Block_RecalculateBB(BlockID block) {
struct Bitmap* bmp = &Atlas2D_Bitmap;
Bitmap* bmp = &Atlas2D_Bitmap;
Int32 tileSize = Atlas2D_TileSize;
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMAX);
Int32 x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);

View File

@ -34,20 +34,20 @@ static void PerspectiveCamera_GetPickedBlock(struct PickedPos* pos) {
Picking_CalculatePickedBlock(eyePos, dir, reach, pos);
}
struct Point2D cam_prev, cam_delta;
Point2D cam_prev, cam_delta;
static void PerspectiveCamera_CentreMousePosition(void) {
struct Point2D topLeft = Window_PointToScreen(Point2D_Empty);
Point2D topLeft = Window_PointToScreen(0, 0);
Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenY = topLeft.Y + Game_Height / 2;
Window_SetDesktopCursorPos(Point2D_Make(cenX, cenY));
Window_SetDesktopCursorPos(cenX, cenY);
/* Fixes issues with large DPI displays on Windows >= 8.0. */
cam_prev = Window_GetDesktopCursorPos();
}
static void PerspectiveCamera_RegrabMouse(void) {
if (!Window_Exists) return;
cam_delta = Point2D_Empty;
cam_delta.X = 0; cam_delta.Y = 0;
PerspectiveCamera_CentreMousePosition();
}
@ -99,10 +99,10 @@ static void PerspectiveCamera_UpdateMouseRotation(void) {
static void PerspectiveCamera_UpdateMouse(void) {
struct Screen* screen = Gui_GetActiveScreen();
if (screen->HandlesAllInput) {
cam_delta = Point2D_Empty;
cam_delta.X = 0; cam_delta.Y = 0;
} else if (Window_Focused) {
struct Point2D pos = Window_GetDesktopCursorPos();
cam_delta = Point2D_Make(pos.X - cam_prev.X, pos.Y - cam_prev.Y);
Point2D pos = Window_GetDesktopCursorPos();
cam_delta.X = pos.X - cam_prev.X; cam_delta.Y = pos.Y - cam_prev.Y;
PerspectiveCamera_CentreMousePosition();
}
PerspectiveCamera_UpdateMouseRotation();

View File

@ -389,8 +389,7 @@ static void ResolutionCommand_Execute(STRING_PURE String* args, Int32 argsCount)
} else if (width <= 0 || height <= 0) {
Chat_AddRaw("&e/client: &cWidth and height must be above 0.");
} else {
struct Size2D size = { width, height };
Window_SetClientSize(size);
Window_SetClientSize(width, height);
Options_SetInt(OPT_WINDOW_WIDTH, width);
Options_SetInt(OPT_WINDOW_HEIGHT, height);
}

View File

@ -187,7 +187,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="2DStructs.h" />
<ClInclude Include="AsyncDownloader.h" />
<ClInclude Include="Audio.h" />
<ClInclude Include="AxisLinesRenderer.h" />
@ -255,7 +254,6 @@
<ClInclude Include="World.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="2DStructs.c" />
<ClCompile Include="AsyncDownloader.c" />
<ClCompile Include="Audio.c" />
<ClCompile Include="Camera.c" />

View File

@ -19,9 +19,6 @@
<Filter Include="Header Files\Generator">
<UniqueIdentifier>{6acee9ab-36de-4f0d-b434-b915b4b52c02}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Defines">
<UniqueIdentifier>{405d40c2-3d05-4d42-8ccb-415189b379a4}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Platform">
<UniqueIdentifier>{eab38ecc-57ac-48f4-9ed2-7cbd40effb24}</UniqueIdentifier>
</Filter>
@ -216,12 +213,6 @@
<ClInclude Include="MapRenderer.h">
<Filter>Header Files\Rendering\Map</Filter>
</ClInclude>
<ClInclude Include="Constants.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="2DStructs.h">
<Filter>Header Files\2D\Utils</Filter>
</ClInclude>
<ClInclude Include="MapGenerator.h">
<Filter>Header Files\Generator</Filter>
</ClInclude>
@ -336,12 +327,15 @@
<ClInclude Include="Errors.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
<ClInclude Include="Core.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="Model.h">
<Filter>Header Files\Entities\Model</Filter>
</ClInclude>
<ClInclude Include="Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Core.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="String.c">
@ -386,9 +380,6 @@
<ClCompile Include="MapRenderer.c">
<Filter>Source Files\Rendering\Map</Filter>
</ClCompile>
<ClCompile Include="2DStructs.c">
<Filter>Source Files\2D\Utils</Filter>
</ClCompile>
<ClCompile Include="AxisLinesRenderer.c">
<Filter>Source Files\SelectionBox</Filter>
</ClCompile>

View File

@ -47,14 +47,14 @@
/* Number of faces on a cube. */
#define FACE_COUNT 6
#define SKIN_TYPE_64x32 0
#define SKIN_TYPE_64x64 1
#define SKIN_TYPE_64x64_SLIM 2
#define SKIN_TYPE_INVALID 3
#define FONT_STYLE_NORMAL 0
#define FONT_STYLE_BOLD 1
#define FONT_STYLE_UNDERLINE 2
enum SKIN_TYPE { SKIN_64x32, SKIN_64x64, SKIN_64x64_SLIM, SKIN_INVALID };
enum FONT_STYLE { FONT_STYLE_NORMAL, FONT_STYLE_BOLD, FONT_STYLE_UNDERLINE };
#define DRAWER2D_MAX_COLS 256
#define UInt8_MaxValue ((UInt8)255)
#define Int16_MinValue ((Int16)-32768)
#define Int16_MaxValue ((Int16)32767)
#define UInt16_MaxValue ((UInt16)65535)
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
#define Int32_MaxValue ((Int32)2147483647L)
#endif

View File

@ -1,6 +1,6 @@
#ifndef CC_TYPEDEFS_H
#define CC_TYPEDEFS_H
/* Ensures variables are of a fixed size.
#ifndef CC_CORE_H
#define CC_CORE_H
/* Core fixed-size integer and floating point types, and common small structs.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
@ -49,15 +49,12 @@ typedef UInt16 TextureLoc;
typedef UInt8 Face;
typedef UInt32 ReturnCode;
struct FontDesc { void* Handle; UInt16 Size, Style; };
#define UInt8_MaxValue ((UInt8)255)
#define Int16_MinValue ((Int16)-32768)
#define Int16_MaxValue ((Int16)32767)
#define UInt16_MaxValue ((UInt16)65535)
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
#define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL)
typedef struct Rect2D_ { Int32 X, Y, Width, Height; } Rect2D;
typedef struct Point2D_ { Int32 X, Y; } Point2D;
typedef struct Size2D_ { Int32 Width, Height; } Size2D;
typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec;
typedef struct Bitmap_ { UInt8* Scan0; Int32 Width, Height; } Bitmap;
#define CC_BUILD_GL11 false
#define CC_BUILD_D3D9 true

View File

@ -7,6 +7,7 @@
#include "Funcs.h"
#include "Game.h"
#include "ExtMath.h"
#include "Bitmap.h"
//#define D3D_DISABLE_9EX causes compile errors
#if CC_BUILD_WIN
@ -163,7 +164,7 @@ void Gfx_Free(void) {
D3D9_FreeResource(&d3d);
}
static void D3D9_SetTextureData(IDirect3DTexture9* texture, struct Bitmap* bmp, Int32 lvl) {
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, Int32 lvl) {
D3DLOCKED_RECT rect;
ReturnCode hresult = IDirect3DTexture9_LockRect(texture, lvl, &rect, NULL, 0);
ErrorHandler_CheckOrFail(hresult, "D3D9_SetTextureData - Lock");
@ -175,7 +176,7 @@ static void D3D9_SetTextureData(IDirect3DTexture9* texture, struct Bitmap* bmp,
ErrorHandler_CheckOrFail(hresult, "D3D9_SetTextureData - Unlock");
}
static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, Int32 x, Int32 y, struct Bitmap* bmp, Int32 lvl) {
static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, Int32 x, Int32 y, Bitmap* bmp, Int32 lvl) {
RECT part;
part.left = x; part.right = x + bmp->Width;
part.top = y; part.bottom = y + bmp->Height;
@ -200,7 +201,7 @@ static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, Int32 x, Int32 y
ErrorHandler_CheckOrFail(hresult, "D3D9_SetTexturePartData - Unlock");
}
static void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, struct Bitmap* bmp, bool partial) {
static void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, Bitmap* bmp, bool partial) {
UInt8* prev = bmp->Scan0;
Int32 lvls = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
Int32 lvl, width = bmp->Width, height = bmp->Height;
@ -213,7 +214,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, struct
UInt8* cur = Mem_Alloc(width * height, BITMAP_SIZEOF_PIXEL, "mipmaps");
GfxCommon_GenMipmaps(width, height, cur, prev);
struct Bitmap mipmap;
Bitmap mipmap;
Bitmap_Create(&mipmap, width, height, cur);
if (partial) {
D3D9_SetTexturePartData(texture, x, y, &mipmap, lvl);
@ -227,7 +228,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, Int32 x, Int32 y, struct
if (prev != bmp->Scan0) Mem_Free(prev);
}
GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, bool managedPool, bool mipmaps) {
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
IDirect3DTexture9* texture;
ReturnCode hresult;
Int32 mipmapsLevels = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
@ -262,7 +263,7 @@ GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, bool managedPool, bool mipma
return texture;
}
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, struct Bitmap* part, bool mipmaps) {
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, Bitmap* part, bool mipmaps) {
IDirect3DTexture9* texture = (IDirect3DTexture9*)texId;
D3D9_SetTexturePartData(texture, x, y, part, 0);
if (mipmaps) D3D9_DoMipmaps(texture, x, y, part, true);
@ -592,7 +593,7 @@ ReturnCode Gfx_TakeScreenshot(struct Stream* output, Int32 width, Int32 height)
res = IDirect3DSurface9_LockRect(temp, &rect, NULL, D3DLOCK_READONLY | D3DLOCK_NO_DIRTY_UPDATE);
if (res) goto finished;
{
struct Bitmap bmp; Bitmap_Create(&bmp, width, height, rect.pBits);
Bitmap bmp; Bitmap_Create(&bmp, width, height, rect.pBits);
res = Bitmap_EncodePng(&bmp, output);
if (res) { IDirect3DSurface9_UnlockRect(temp); goto finished; }
}

View File

@ -1,7 +1,6 @@
#ifndef CC_DISPLAYDEVICE_H
#define CC_DISPLAYDEVICE_H
#include "Core.h"
#include "2DStructs.h"
/* Contains structs related to monitor displays.
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based originally on OpenTK
*/
@ -12,7 +11,7 @@
* See license.txt for licensing detailed licensing details.
*/
struct DisplayDevice { Int32 BitsPerPixel; struct Rectangle2D Bounds; };
struct DisplayDevice { Int32 BitsPerPixel; Rect2D Bounds; };
struct DisplayDevice DisplayDevice_Default;
void* DisplayDevice_Meta[3];

View File

@ -5,21 +5,22 @@
#include "ExtMath.h"
#include "ErrorHandler.h"
#include "GraphicsCommon.h"
#include "Bitmap.h"
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF String* text, struct FontDesc* font, bool useShadow) {
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow) {
args->Text = *text;
args->Font = *font;
args->UseShadow = useShadow;
}
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, bool useShadow) {
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow) {
args->Text = String_MakeNull();
args->Font = *font;
args->UseShadow = useShadow;
}
struct Bitmap Drawer2D_FontBitmap;
struct Bitmap* Drawer2D_Cur;
Bitmap Drawer2D_FontBitmap;
Bitmap* Drawer2D_Cur;
Int32 Drawer2D_BoxSize = 8; /* avoid divide by 0 if default.png missing */
/* So really 16 characters per row */
#define DRAWER2D_LOG2_CHARS_PER_ROW 4
@ -60,7 +61,7 @@ static void Drawer2D_FreeFontBitmap(void) {
Drawer2D_FontBitmap.Scan0 = NULL;
}
void Drawer2D_SetFontBitmap(struct Bitmap* bmp) {
void Drawer2D_SetFontBitmap(Bitmap* bmp) {
Drawer2D_FreeFontBitmap();
Drawer2D_FontBitmap = *bmp;
Drawer2D_BoxSize = bmp->Width >> DRAWER2D_LOG2_CHARS_PER_ROW;
@ -96,7 +97,7 @@ void Drawer2D_Free(void) {
Drawer2D_FreeFontBitmap();
}
void Drawer2D_Begin(struct Bitmap* bmp) {
void Drawer2D_Begin(Bitmap* bmp) {
if (!Drawer2D_UseBitmappedChat) Platform_SetBitmap(bmp);
Drawer2D_Cur = bmp;
}
@ -107,9 +108,9 @@ void Drawer2D_End(void) {
}
/* Draws a 2D flat rectangle. */
void Drawer2D_Rect(struct Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
void Drawer2D_Rect(Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
void Drawer2D_Clear(struct Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height) {
void Drawer2D_Clear(Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height) {
if (x < 0 || y < 0 || (x + width) > bmp->Width || (y + height) > bmp->Height) {
ErrorHandler_Fail("Drawer2D_Clear - tried to clear at invalid coords");
}
@ -122,7 +123,7 @@ void Drawer2D_Clear(struct Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 w
}
}
Int32 Drawer2D_FontHeight(struct FontDesc* font, bool useShadow) {
Int32 Drawer2D_FontHeight(FontDesc* font, bool useShadow) {
struct DrawTextArgs args;
String text = String_FromConst("I");
DrawTextArgs_Make(&args, &text, font, useShadow);
@ -130,13 +131,13 @@ Int32 Drawer2D_FontHeight(struct FontDesc* font, bool useShadow) {
}
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, Int32 X, Int32 Y) {
struct Size2D size = Drawer2D_MeasureText(args);
Size2D size = Drawer2D_MeasureText(args);
if (size.Width == 0 && size.Height == 0) {
struct Texture empty = { NULL, TEX_RECT(X,Y, 0,0), TEX_UV(0,0, 1,1) };
*tex = empty; return;
}
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Drawer2D_Begin(&bmp);
{
Drawer2D_DrawText(args, 0, 0);
@ -147,7 +148,7 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, In
Mem_Free(bmp.Scan0);
}
void Drawer2D_Make2DTexture(struct Texture* tex, struct Bitmap* bmp, struct Size2D used, Int32 X, Int32 Y) {
void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used, Int32 X, Int32 Y) {
GfxResourceID texId = Gfx_CreateTexture(bmp, false, false);
Real32 u2 = (Real32)used.Width / (Real32)bmp->Width;
Real32 v2 = (Real32)used.Height / (Real32)bmp->Height;
@ -315,7 +316,7 @@ static void Drawer2D_DrawUnderline(struct DrawTextArgs* args, Int32 x, Int32 y,
}
}
void Drawer2D_DrawBitmapText(struct DrawTextArgs* args, Int32 x, Int32 y) {
static void Drawer2D_DrawBitmapText(struct DrawTextArgs* args, Int32 x, Int32 y) {
bool ul = args->Font.Style == FONT_STYLE_UNDERLINE;
Int32 offset = Drawer2D_ShadowOffset(args->Font.Size);
@ -328,11 +329,11 @@ void Drawer2D_DrawBitmapText(struct DrawTextArgs* args, Int32 x, Int32 y) {
if (ul) Drawer2D_DrawUnderline(args, x, y, false);
}
struct Size2D Drawer2D_MeasureBitmapText(struct DrawTextArgs* args) {
static Size2D Drawer2D_MeasureBitmapText(struct DrawTextArgs* args) {
Int32 point = args->Font.Size;
/* adjust coords to make drawn text match GDI fonts */
Int32 xPadding = Drawer2D_XPadding(point), i;
struct Size2D total = { 0, Drawer2D_AdjHeight(point) };
Size2D total = { 0, Drawer2D_AdjHeight(point) };
String text = args->Text;
for (i = 0; i < text.length; i++) {
@ -388,26 +389,26 @@ void Drawer2D_DrawText(struct DrawTextArgs* args, Int32 x, Int32 y) {
Platform_TextDraw(args, x + DRAWER2D_OFFSET, y + DRAWER2D_OFFSET, backCol);
}
struct Size2D partSize = Platform_TextDraw(args, x, y, col);
Size2D partSize = Platform_TextDraw(args, x, y, col);
x += partSize.Width;
}
args->Text = value;
}
struct Size2D Drawer2D_MeasureText(struct DrawTextArgs* args) {
if (Drawer2D_IsEmptyText(&args->Text)) return Size2D_Empty;
Size2D Drawer2D_MeasureText(struct DrawTextArgs* args) {
Size2D size = { 0, 0 };
if (Drawer2D_IsEmptyText(&args->Text)) return size;
if (Drawer2D_UseBitmappedChat) return Drawer2D_MeasureBitmapText(args);
String value = args->Text;
char nextCol = 'f';
Int32 i = 0;
struct Size2D size = { 0, 0 };
Int32 i = 0;
while (i < value.length) {
i = Drawer2D_NextPart(i, &value, &args->Text, &nextCol);
if (!args->Text.length) continue;
struct Size2D partSize = Platform_TextMeasure(args);
Size2D partSize = Platform_TextMeasure(args);
size.Width += partSize.Width;
size.Height = max(size.Height, partSize.Height);
}

View File

@ -1,18 +1,16 @@
#ifndef CC_DRAWER2D_H
#define CC_DRAWER2D_H
#include "2DStructs.h"
#include "PackedCol.h"
#include "Constants.h"
/* Responsible for performing drawing operations on bitmaps, and for converting bitmaps into textures.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
struct DrawTextArgs { String Text; struct FontDesc Font; bool UseShadow; };
struct Bitmap;
struct DrawTextArgs { String Text; FontDesc Font; bool UseShadow; };
struct Texture;
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF String* text, struct FontDesc* font, bool useShadow);
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, struct FontDesc* font, bool useShadow);
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow);
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow);
/* Whether chat text should be drawn and measuring using the currently bitmapped font,
false uses the font supplied as the DrawTextArgs argument supplied to the function. */
@ -26,20 +24,20 @@ void Drawer2D_Init(void);
void Drawer2D_Free(void);
/* Sets the underlying bitmap that text operations are performed on. */
void Drawer2D_Begin(struct Bitmap* bmp);
void Drawer2D_Begin(Bitmap* bmp);
/* Frees any resources associated with the underlying bitmap. */
void Drawer2D_End(void);
/* Draws a 2D flat rectangle. */
void Drawer2D_Rect(struct Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
void Drawer2D_Rect(Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
/* Clears the entire given area to the specified colour. */
void Drawer2D_Clear(struct Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
void Drawer2D_Clear(Bitmap* bmp, PackedCol col, Int32 x, Int32 y, Int32 width, Int32 height);
void Drawer2D_DrawText(struct DrawTextArgs* args, Int32 x, Int32 y);
struct Size2D Drawer2D_MeasureText(struct DrawTextArgs* args);
Int32 Drawer2D_FontHeight(struct FontDesc* font, bool useShadow);
Size2D Drawer2D_MeasureText(struct DrawTextArgs* args);
Int32 Drawer2D_FontHeight(FontDesc* font, bool useShadow);
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args, Int32 X, Int32 Y);
void Drawer2D_Make2DTexture(struct Texture* tex, struct Bitmap* bmp, struct Size2D used, Int32 X, Int32 Y);
void Drawer2D_Make2DTexture(struct Texture* tex, Bitmap* bmp, Size2D used, Int32 X, Int32 Y);
bool Drawer2D_ValidColCodeAt(STRING_PURE String* text, Int32 i);
bool Drawer2D_ValidColCode(char c);
@ -50,5 +48,5 @@ bool Drawer2D_IsWhiteCol(char c);
void Drawer2D_ReducePadding_Tex(struct Texture* tex, Int32 point, Int32 scale);
void Drawer2D_ReducePadding_Height(Int32* height, Int32 point, Int32 scale);
void Drawer2D_SetFontBitmap(struct Bitmap* bmp);
void Drawer2D_SetFontBitmap(Bitmap* bmp);
#endif

View File

@ -19,6 +19,7 @@
#include "Input.h"
#include "Gui.h"
#include "Stream.h"
#include "Bitmap.h"
const char* NameMode_Names[NAME_MODE_COUNT] = { "None", "Hovered", "All", "AllHovered", "AllUnscaled" };
const char* ShadowMode_Names[SHADOW_MODE_COUNT] = { "None", "SnapToBlock", "Circle", "CircleAll" };
@ -452,7 +453,7 @@ void TabList_MakeComponent(struct IGameComponent* comp) {
*#########################################################################################################################*/
#define PLAYER_NAME_EMPTY_TEX -30000
static void Player_MakeNameTexture(struct Player* player) {
struct FontDesc font;
FontDesc font;
Font_Make(&font, &Game_FontName, 24, FONT_STYLE_NORMAL);
String displayName = String_FromRawArray(player->DisplayNameRaw);
@ -462,7 +463,7 @@ static void Player_MakeNameTexture(struct Player* player) {
/* we want names to always be drawn not using the system font */
bool bitmapped = Drawer2D_UseBitmappedChat;
Drawer2D_UseBitmappedChat = true;
struct Size2D size = Drawer2D_MeasureText(&args);
Size2D size = Drawer2D_MeasureText(&args);
if (size.Width == 0) {
player->NameTex.ID = NULL;
@ -472,7 +473,7 @@ static void Player_MakeNameTexture(struct Player* player) {
String shadowName = String_FromArray(buffer);
size.Width += 3; size.Height += 3;
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Drawer2D_Begin(&bmp);
{
PackedCol origWhiteCol = Drawer2D_Cols['f'];
@ -527,7 +528,7 @@ static void Player_DrawName(struct Player* player) {
}
VertexP3fT2fC4b vertices[4];
struct TextureRec rec = { 0.0f, 0.0f, player->NameTex.U2, player->NameTex.V2 };
TextureRec rec = { 0.0f, 0.0f, player->NameTex.U2, player->NameTex.V2 };
PackedCol col = PACKEDCOL_WHITE;
Particle_DoRender(&size, &pos, &rec, col, vertices);
@ -587,7 +588,7 @@ void Player_ResetSkin(struct Player* player) {
entity->uScale = 1.0f; entity->vScale = 1.0f;
entity->MobTextureId = NULL;
entity->TextureId = NULL;
entity->SkinType = SKIN_TYPE_64x32;
entity->SkinType = SKIN_64x32;
}
/* Apply or reset skin, for all players with same skin */
@ -610,9 +611,9 @@ static void Player_SetSkinAll(struct Player* player, bool reset) {
}
}
static void Player_ClearHat(struct Bitmap* bmp, UInt8 skinType) {
static void Player_ClearHat(Bitmap* bmp, UInt8 skinType) {
Int32 sizeX = (bmp->Width / 64) * 32;
Int32 yScale = skinType == SKIN_TYPE_64x32 ? 32 : 64;
Int32 yScale = skinType == SKIN_64x32 ? 32 : 64;
Int32 sizeY = (bmp->Height / yScale) * 16;
Int32 x, y;
@ -639,12 +640,12 @@ static void Player_ClearHat(struct Bitmap* bmp, UInt8 skinType) {
}
}
static void Player_EnsurePow2(struct Player* player, struct Bitmap* bmp) {
static void Player_EnsurePow2(struct Player* player, Bitmap* bmp) {
Int32 width = Math_NextPowOf2(bmp->Width);
Int32 height = Math_NextPowOf2(bmp->Height);
if (width == bmp->Width && height == bmp->Height) return;
struct Bitmap scaled; Bitmap_Allocate(&scaled, width, height);
Bitmap scaled; Bitmap_Allocate(&scaled, width, height);
Int32 y;
UInt32 stride = (UInt32)(bmp->Width) * BITMAP_SIZEOF_PIXEL;
for (y = 0; y < bmp->Height; y++) {
@ -680,7 +681,7 @@ static void Player_CheckSkin(struct Player* player) {
if (!item.ResultData) { Player_SetSkinAll(player, true); return; }
String url = String_FromRawArray(item.URL);
struct Stream mem; struct Bitmap bmp;
struct Stream mem; Bitmap bmp;
Stream_ReadonlyMemory(&mem, item.ResultData, item.ResultSize);
ReturnCode res = Bitmap_DecodePng(&bmp, &mem);
@ -694,7 +695,7 @@ static void Player_CheckSkin(struct Player* player) {
Player_EnsurePow2(player, &bmp);
entity->SkinType = Utils_GetSkinType(&bmp);
if (entity->SkinType == SKIN_TYPE_INVALID) {
if (entity->SkinType == SKIN_INVALID) {
Player_SetSkinAll(player, true);
} else {
if (entity->Model->UsesHumanSkin) {

View File

@ -15,6 +15,7 @@
#include "Physics.h"
#include "Model.h"
#include "Audio.h"
#include "Bitmap.h"
/*########################################################################################################################*
*----------------------------------------------------AnimatedComponent----------------------------------------------------*
@ -589,7 +590,7 @@ static bool ShadowComponent_GetBlocks(struct Entity* entity, Int32 x, Int32 y, I
#define sh_half (sh_size / 2)
static void ShadowComponent_MakeTex(void) {
UInt8 pixels[Bitmap_DataSize(sh_size, sh_size)];
struct Bitmap bmp; Bitmap_Create(&bmp, sh_size, sh_size, pixels);
Bitmap bmp; Bitmap_Create(&bmp, sh_size, sh_size, pixels);
UInt32 inPix = PackedCol_ARGB(0, 0, 0, 200);
UInt32 outPix = PackedCol_ARGB(0, 0, 0, 0);

View File

@ -534,13 +534,17 @@ static void EnvRenderer_MakeBorderTex(GfxResourceID* texId, BlockID block) {
*texId = Atlas2D_LoadTile(texLoc);
}
static void EnvRenderer_CalcBorderRects(struct Rectangle2D* rects) {
Int32 extent = Utils_AdjViewDist(Game_ViewDistance);
rects[0] = Rectangle2D_Make(-extent, -extent, extent + World_Width + extent, extent);
rects[1] = Rectangle2D_Make(-extent, World_Length, extent + World_Width + extent, extent);
static Rect2D EnvRenderer_Rect(Int32 x, Int32 y, Int32 width, Int32 height) {
Rect2D r; r.X = x; r.Y = y; r.Width = width; r.Height = height; return r;
}
rects[2] = Rectangle2D_Make(-extent, 0, extent, World_Length);
rects[3] = Rectangle2D_Make(World_Width, 0, extent, World_Length);
static void EnvRenderer_CalcBorderRects(Rect2D* rects) {
Int32 extent = Utils_AdjViewDist(Game_ViewDistance);
rects[0] = EnvRenderer_Rect(-extent, -extent, extent + World_Width + extent, extent);
rects[1] = EnvRenderer_Rect(-extent, World_Length, extent + World_Width + extent, extent);
rects[2] = EnvRenderer_Rect(-extent, 0, extent, World_Length);
rects[3] = EnvRenderer_Rect(World_Width, 0, extent, World_Length);
}
static void EnvRenderer_UpdateBorderTextures(void) {
@ -629,12 +633,12 @@ static void EnvRenderer_UpdateMapSides(void) {
BlockID block = WorldEnv_SidesBlock;
if (Block_Draw[block] == DRAW_GAS) return;
struct Rectangle2D rects[4];
Rect2D rects[4];
EnvRenderer_CalcBorderRects(rects);
Int32 i; sides_vertices = 0;
for (i = 0; i < 4; i++) {
struct Rectangle2D r = rects[i];
Rect2D r = rects[i];
sides_vertices += EnvRenderer_Vertices(r.Width, r.Height); /* YQuads outside */
}
@ -656,7 +660,7 @@ static void EnvRenderer_UpdateMapSides(void) {
Block_Tint(col, block)
for (i = 0; i < 4; i++) {
struct Rectangle2D r = rects[i];
Rect2D r = rects[i];
EnvRenderer_DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, (Real32)y, col,
0, borders_YOffset(block), &temp);
}
@ -680,12 +684,12 @@ static void EnvRenderer_UpdateMapEdges(void) {
BlockID block = WorldEnv_EdgeBlock;
if (Block_Draw[block] == DRAW_GAS) return;
struct Rectangle2D rects[4];
Rect2D rects[4];
EnvRenderer_CalcBorderRects(rects);
Int32 i; edges_vertices = 0;
for (i = 0; i < 4; i++) {
struct Rectangle2D r = rects[i];
Rect2D r = rects[i];
edges_vertices += EnvRenderer_Vertices(r.Width, r.Height); /* YPlanes outside */
}
@ -703,7 +707,7 @@ static void EnvRenderer_UpdateMapEdges(void) {
Real32 y = (Real32)WorldEnv_EdgeHeight;
for (i = 0; i < 4; i++) {
struct Rectangle2D r = rects[i];
Rect2D r = rects[i];
EnvRenderer_DrawBorderY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, col,
borders_HorOffset(block), borders_YOffset(block), &temp);
}

View File

@ -36,6 +36,7 @@
#include "Audio.h"
#include "DisplayDevice.h"
#include "Stream.h"
#include "Bitmap.h"
struct IGameComponent Game_Components[26];
Int32 Game_ComponentsCount;
@ -121,7 +122,7 @@ void Game_SetDefaultTexturePack(STRING_PURE String* texPack) {
Options_Set(OPT_DEFAULT_TEX_PACK, texPack);
}
bool Game_ChangeTerrainAtlas(struct Bitmap* atlas) {
bool Game_ChangeTerrainAtlas(Bitmap* atlas) {
String terrain = String_FromConst("terrain.png");
if (!Game_ValidateBitmap(&terrain, atlas)) return false;
@ -206,7 +207,7 @@ bool Game_CanPick(BlockID block) {
}
bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, STRING_PURE String* file, UInt8* skinType) {
struct Bitmap bmp;
Bitmap bmp;
ReturnCode res = Bitmap_DecodePng(&bmp, src);
if (res) { Chat_LogError(res, "decoding", file); }
@ -221,7 +222,7 @@ bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, STRING_PURE St
return success;
}
bool Game_ValidateBitmap(STRING_PURE String* file, struct Bitmap* bmp) {
bool Game_ValidateBitmap(STRING_PURE String* file, Bitmap* bmp) {
if (!bmp->Scan0) {
Chat_Add1("&cError loading %s from the texture pack.", file);
return false;
@ -260,7 +261,7 @@ Int32 Game_CalcRenderType(STRING_PURE String* type) {
}
static void Game_UpdateClientSize(void) {
struct Size2D size = Window_ClientSize;
Size2D size = Window_ClientSize;
Game_Width = max(size.Width, 1);
Game_Height = max(size.Height, 1);
}
@ -287,7 +288,7 @@ static void Game_OnNewMapLoadedCore(void* obj) {
}
static void Game_TextureChangedCore(void* obj, struct Stream* src, String* name) {
struct Bitmap bmp;
Bitmap bmp;
if (String_CaselessEqualsConst(name, "terrain.png")) {
ReturnCode res = Bitmap_DecodePng(&bmp, src);
@ -751,11 +752,11 @@ void Game_Run(Int32 width, Int32 height, STRING_PURE String* title, struct Displ
#include "Builder.h"
void AdvLightingBuilder_SetActive(void) { NormalBuilder_SetActive(); }
#if CC_BUILD_NIX
void Font_Make(struct FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style) { desc->Size = size; desc->Style = style; }
void Font_Free(struct FontDesc* desc) { }
void Font_Make(FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style) { desc->Size = size; desc->Style = style; }
void Font_Free(FontDesc* desc) { }
void Font_GetNames(StringsBuffer* buffer) { }
struct Size2D Platform_TextMeasure(struct DrawTextArgs* args) { }
void Platform_SetBitmap(struct Bitmap* bmp) { }
struct Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col) { }
Size2D Platform_TextMeasure(struct DrawTextArgs* args) { }
void Platform_SetBitmap(Bitmap* bmp) { }
Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col) { }
void Platform_ReleaseBitmap(void) { }
#endif

View File

@ -6,7 +6,6 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct Bitmap;
struct DisplayDevice;
struct Stream;
@ -79,14 +78,14 @@ Real32 Game_GetChatScale(void);
void Game_GetDefaultTexturePack(STRING_TRANSIENT String* texPack);
void Game_SetDefaultTexturePack(STRING_PURE String* texPack);
bool Game_ChangeTerrainAtlas(struct Bitmap* atlas);
bool Game_ChangeTerrainAtlas(Bitmap* atlas);
void Game_SetViewDistance(Int32 distance, bool userDist);
void Game_UpdateProjection(void);
void Game_Disconnect(STRING_PURE String* title, STRING_PURE String* reason);
void Game_UpdateBlock(Int32 x, Int32 y, Int32 z, BlockID block);
bool Game_CanPick(BlockID block);
bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, STRING_PURE String* file, UInt8* skinType);
bool Game_ValidateBitmap(STRING_PURE String* file, struct Bitmap* bmp);
bool Game_ValidateBitmap(STRING_PURE String* file, Bitmap* bmp);
Int32 Game_CalcRenderType(STRING_PURE String* type);
void Game_SetFpsLimit(FpsLimit method);
Real32 Game_CalcLimitMillis(FpsLimit method);

View File

@ -1,6 +1,5 @@
#ifndef CC_GFXAPI_H
#define CC_GFXAPI_H
#include "Bitmap.h"
#include "PackedCol.h"
#include "Vectors.h"
#include "GameStructs.h"
@ -44,8 +43,8 @@ struct Matrix Gfx_View, Gfx_Projection;
/* Callback invoked when the current context is lost, and is repeatedly invoked until the context can be retrieved. */
ScheduledTaskCallback Gfx_LostContextFunction;
GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, bool managedPool, bool mipmaps);
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, struct Bitmap* part, bool mipmaps);
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps);
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, Bitmap* part, bool mipmaps);
void Gfx_BindTexture(GfxResourceID texId);
void Gfx_DeleteTexture(GfxResourceID* texId);
void Gfx_SetTexturing(bool enabled);

View File

@ -11,6 +11,7 @@
#include "InputHandler.h"
#include "ErrorHandler.h"
#include "Platform.h"
#include "Bitmap.h"
struct Screen* Gui_Status;
void Gui_DefaultRecreate(void* elem) {
@ -226,15 +227,15 @@ void Gui_CalcCursorVisible(void) {
}
void TextAtlas_Make(struct TextAtlas* atlas, STRING_PURE String* chars, struct FontDesc* font, STRING_PURE String* prefix) {
void TextAtlas_Make(struct TextAtlas* atlas, STRING_PURE String* chars, FontDesc* font, STRING_PURE String* prefix) {
struct DrawTextArgs args; DrawTextArgs_Make(&args, prefix, font, true);
struct Size2D size = Drawer2D_MeasureText(&args);
Size2D size = Drawer2D_MeasureText(&args);
atlas->Offset = size.Width;
atlas->FontSize = font->Size;
size.Width += 16 * chars->length;
Mem_Set(atlas->Widths, 0, sizeof(atlas->Widths));
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Drawer2D_Begin(&bmp);
{
Drawer2D_DrawText(&args, 0, 0);

View File

@ -110,7 +110,7 @@ struct TextAtlas {
Real32 uScale;
Int32 Widths[TEXTATLAS_MAX_WIDTHS];
};
void TextAtlas_Make(struct TextAtlas* atlas, STRING_PURE String* chars, struct FontDesc* font, STRING_PURE String* prefix);
void TextAtlas_Make(struct TextAtlas* atlas, STRING_PURE String* chars, FontDesc* font, STRING_PURE String* prefix);
void TextAtlas_Free(struct TextAtlas* atlas);
void TextAtlas_Add(struct TextAtlas* atlas, Int32 charI, VertexP3fT2fC4b** vertices);
void TextAtlas_AddInt(struct TextAtlas* atlas, Int32 value, VertexP3fT2fC4b** vertices);

View File

@ -70,7 +70,7 @@ static TextureLoc IsometricDrawer_GetTexLoc(BlockID block, Face face) {
#define AddVertex *iso_vertices = v; iso_vertices++;
static void IsometricDrawer_SpriteZQuad(BlockID block, bool firstPart) {
TextureLoc texLoc = Block_GetTexLoc(block, FACE_ZMAX);
struct TextureRec rec = Atlas1D_TexRec(texLoc, 1, &iso_texIndex);
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &iso_texIndex);
if (iso_lastTexIndex != iso_texIndex) IsometricDrawer_Flush();
VertexP3fT2fC4b v;
@ -95,7 +95,7 @@ static void IsometricDrawer_SpriteZQuad(BlockID block, bool firstPart) {
static void IsometricDrawer_SpriteXQuad(BlockID block, bool firstPart) {
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMAX);
struct TextureRec rec = Atlas1D_TexRec(texLoc, 1, &iso_texIndex);
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &iso_texIndex);
if (iso_lastTexIndex != iso_texIndex) IsometricDrawer_Flush();
VertexP3fT2fC4b v;

View File

@ -39,7 +39,7 @@ struct ListScreen;
struct ListScreen {
MenuBase_Layout
struct ButtonWidget Buttons[LIST_SCREEN_BUTTONS];
struct FontDesc Font;
FontDesc Font;
Real32 WheelAcc;
Int32 CurrentIndex;
Widget_LeftClick EntryClick;
@ -50,7 +50,7 @@ struct ListScreen {
StringsBuffer Entries; /* NOTE: this is the last member so we can avoid memsetting it to 0 */
};
#define MenuScreen_Layout MenuBase_Layout struct FontDesc TitleFont, TextFont;
#define MenuScreen_Layout MenuBase_Layout FontDesc TitleFont, TextFont;
struct MenuScreen { MenuScreen_Layout };
struct PauseScreen {
@ -161,7 +161,7 @@ struct TexPackOverlay {
/*########################################################################################################################*
*--------------------------------------------------------Menu base--------------------------------------------------------*
*#########################################################################################################################*/
static void Menu_Button(void* s, Int32 i, struct ButtonWidget* btn, Int32 width, String* text, struct FontDesc* font, Widget_LeftClick onClick, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
static void Menu_Button(void* s, Int32 i, struct ButtonWidget* btn, Int32 width, String* text, FontDesc* font, Widget_LeftClick onClick, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
struct Menu* menu = (struct Menu*)s;
ButtonWidget_Create(btn, width, text, font, onClick);
@ -169,7 +169,7 @@ static void Menu_Button(void* s, Int32 i, struct ButtonWidget* btn, Int32 width,
Widget_SetLocation(menu->Widgets[i], horAnchor, verAnchor, x, y);
}
static void Menu_Label(void* s, Int32 i, struct TextWidget* label, String* text, struct FontDesc* font, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
static void Menu_Label(void* s, Int32 i, struct TextWidget* label, String* text, FontDesc* font, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
struct Menu* menu = (struct Menu*)s;
TextWidget_Create(label, text, font);
@ -177,7 +177,7 @@ static void Menu_Label(void* s, Int32 i, struct TextWidget* label, String* text,
Widget_SetLocation(menu->Widgets[i], horAnchor, verAnchor, x, y);
}
static void Menu_Input(void* s, Int32 i, struct MenuInputWidget* input, Int32 width, String* text, struct FontDesc* font, struct MenuInputValidator* v, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
static void Menu_Input(void* s, Int32 i, struct MenuInputWidget* input, Int32 width, String* text, FontDesc* font, struct MenuInputValidator* v, UInt8 horAnchor, UInt8 verAnchor, Int32 x, Int32 y) {
struct Menu* menu = (struct Menu*)s;
MenuInputWidget_Create(input, width, 30, text, font, v);
@ -186,7 +186,7 @@ static void Menu_Input(void* s, Int32 i, struct MenuInputWidget* input, Int32 wi
input->Base.ShowCaret = true;
}
static void Menu_Back(void* s, Int32 i, struct ButtonWidget* btn, const char* label, struct FontDesc* font, Widget_LeftClick onClick) {
static void Menu_Back(void* s, Int32 i, struct ButtonWidget* btn, const char* label, FontDesc* font, Widget_LeftClick onClick) {
Int32 width = Game_UseClassicOptions ? 400 : 200;
String msg = String_FromReadonly(label);
Menu_Button(s, i, btn, width, &msg, font, onClick, ANCHOR_CENTRE, ANCHOR_MAX, 0, 25);
@ -613,7 +613,7 @@ static void PauseScreen_CheckHacksAllowed(void* screen) {
static void PauseScreen_ContextRecreated(void* screen) {
struct PauseScreen* s = screen;
struct FontDesc* font = &s->TitleFont;
FontDesc* font = &s->TitleFont;
if (Game_UseClassicOptions) {
PauseScreen_MakeClassic(s, 0, -100, "Options...", Menu_SwitchClassicOptions);
@ -1436,7 +1436,7 @@ static void FontListScreen_EntryClick(void* screen, void* widget) {
}
static void FontListScreen_UpdateEntry(struct ListScreen* s, struct ButtonWidget* button, STRING_PURE String* text) {
struct FontDesc font = { 0 };
FontDesc font = { 0 };
Font_Make(&font, text, 16, FONT_STYLE_NORMAL);
ButtonWidget_Set(button, text, &font);
Font_Free(&font);

View File

@ -108,7 +108,7 @@ void Model_SetupState(struct Model* model, struct Entity* entity) {
model->index = 0;
PackedCol col = entity->VTABLE->GetCol(entity);
bool _64x64 = entity->SkinType != SKIN_TYPE_64x32;
bool _64x64 = entity->SkinType != SKIN_64x32;
/* only apply when using humanoid skins */
_64x64 &= model->UsesHumanSkin || entity->MobTextureId;
@ -150,7 +150,7 @@ void Model_ApplyTexture(struct Entity* entity) {
}
Gfx_BindTexture(tex);
bool _64x64 = Model_skinType != SKIN_TYPE_64x32;
bool _64x64 = Model_skinType != SKIN_64x32;
Model_uScale = entity->uScale * 0.015625f;
Model_vScale = entity->vScale * (_64x64 ? 0.015625f : 0.03125f);
}

View File

@ -807,7 +807,7 @@ static void HumanModel_DrawModel(struct Entity* entity, struct ModelSet* model)
Gfx_SetAlphaTest(false);
UInt8 type = Model_skinType;
struct ModelLimbs* set = &model->Limbs[type == SKIN_TYPE_64x64_SLIM ? 2 : (type == SKIN_TYPE_64x64 ? 1 : 0)];
struct ModelLimbs* set = &model->Limbs[type == SKIN_64x64_SLIM ? 2 : (type == SKIN_64x64 ? 1 : 0)];
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &model->Head, true);
Model_DrawPart(&model->Torso);
@ -821,7 +821,7 @@ static void HumanModel_DrawModel(struct Entity* entity, struct ModelSet* model)
Model_UpdateVB();
Gfx_SetAlphaTest(true);
if (type != SKIN_TYPE_64x32) {
if (type != SKIN_64x32) {
Model_DrawPart(&model->TorsoLayer);
Model_DrawRotate(entity->Anim.LeftLegX, 0, entity->Anim.LeftLegZ, &set->LeftLegLayer, false);
Model_DrawRotate(entity->Anim.RightLegX, 0, entity->Anim.RightLegZ, &set->RightLegLayer, false);
@ -837,10 +837,10 @@ static void HumanModel_DrawModel(struct Entity* entity, struct ModelSet* model)
static void HumanModel_DrawArm(struct Entity* entity, struct ModelSet* model) {
UInt8 type = Model_skinType;
struct ModelLimbs* set = &model->Limbs[type == SKIN_TYPE_64x64_SLIM ? 2 : (type == SKIN_TYPE_64x64 ? 1 : 0)];
struct ModelLimbs* set = &model->Limbs[type == SKIN_64x64_SLIM ? 2 : (type == SKIN_64x64 ? 1 : 0)];
Model_DrawArmPart(&set->RightArm);
if (type != SKIN_TYPE_64x32) {
if (type != SKIN_64x32) {
Model_DrawArmPart(&set->RightArmLayer);
}
Model_UpdateVB();
@ -1166,7 +1166,7 @@ if (Block_Tinted[block]) {\
static void BlockModel_SpriteZQuad(bool firstPart, bool mirror) {
TextureLoc texLoc = Block_GetTexLoc(BlockModel_block, FACE_ZMAX);
struct TextureRec rec = Atlas1D_TexRec(texLoc, 1, &BlockModel_texIndex);
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &BlockModel_texIndex);
BlockModel_FlushIfNotSame;
PackedCol col = Model_Cols[0];
@ -1193,7 +1193,7 @@ static void BlockModel_SpriteZQuad(bool firstPart, bool mirror) {
static void BlockModel_SpriteXQuad(bool firstPart, bool mirror) {
TextureLoc texLoc = Block_GetTexLoc(BlockModel_block, FACE_XMAX);
struct TextureRec rec = Atlas1D_TexRec(texLoc, 1, &BlockModel_texIndex);
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &BlockModel_texIndex);
BlockModel_FlushIfNotSame;
PackedCol col = Model_Cols[0];

View File

@ -165,7 +165,7 @@ static void Window_RefreshBorders(void) {
static void Window_RefreshBounds(XEvent* e) {
Window_RefreshBorders();
struct Point2D loc = { e->xconfigure.x - borderLeft, e->xconfigure.y - borderTop };
Point2D loc = { e->xconfigure.x - borderLeft, e->xconfigure.y - borderTop };
if (loc.X != Window_Bounds.X || loc.Y != Window_Bounds.Y) {
Window_Bounds.X = loc.X; Window_Bounds.Y = loc.Y;
Event_RaiseVoid(&WindowEvents_Moved);
@ -173,14 +173,14 @@ static void Window_RefreshBounds(XEvent* e) {
/* Note: width and height denote the internal (client) size.
To get the external (window) size, we need to add the border size. */
struct Size2D size = {
Size2D size = {
e->xconfigure.width + borderLeft + borderRight,
e->xconfigure.height + borderTop + borderBottom
};
if (size.Width != Window_Bounds.Width || size.Height != Window_Bounds.Height) {
Window_Bounds.Width = size.Width; Window_Bounds.Height = size.Height;
Window_ClientSize = Size2D_Make(e->xconfigure.width, e->xconfigure.height);
if (size.Width != Window_Bounds.Width || size.Height != Window_Bounds.Height) {
Window_ClientSize.Width = e->xconfigure.width; Window_Bounds.Width = size.Width;
Window_ClientSize.Height = e->xconfigure.height; Window_Bounds.Height = size.Height;
Event_RaiseVoid(&WindowEvents_Resized);
}
}
@ -380,7 +380,7 @@ void Window_SetWindowState(UInt8 state) {
Window_ProcessEvents();
}
void Window_SetBounds(struct Rectangle2D rect) {
void Window_SetBounds(Rect2D rect) {
Int32 width = rect.Width - borderLeft - borderRight;
Int32 height = rect.Height - borderTop - borderBottom;
XMoveResizeWindow(win_display, win_handle, rect.X, rect.Y,
@ -388,21 +388,20 @@ void Window_SetBounds(struct Rectangle2D rect) {
Window_ProcessEvents();
}
void Window_SetLocation(struct Point2D point) {
XMoveWindow(win_display, win_handle, point.X, point.Y);
void Window_SetLocation(Int32 x, Int32 y) {
XMoveWindow(win_display, win_handle, x, y);
Window_ProcessEvents();
}
void Window_SetSize(struct Size2D size) {
Int32 width = size.Width - borderLeft - borderRight;
Int32 height = size.Height - borderTop - borderBottom;
XResizeWindow(win_display, win_handle,
max(width, 1), max(height, 1));
void Window_SetSize(Int32 width, Int32 height) {
Int32 adjWidth = width - borderLeft - borderRight;
Int32 adjHeight = height - borderTop - borderBottom;
XResizeWindow(win_display, win_handle, adjWidth, adjHeight);
Window_ProcessEvents();
}
void Window_SetClientSize(struct Size2D size) {
XResizeWindow(win_display, win_handle, size.Width, size.Height);
void Window_SetClientSize(Int32 width, Int32 height) {
XResizeWindow(win_display, win_handle, width, height);
Window_ProcessEvents();
}
@ -618,29 +617,29 @@ void Window_ProcessEvents(void) {
}
}
struct Point2D Window_PointToClient(struct Point2D point) {
Point2D Window_PointToClient(Int32 x, Int32 y) {
int ox, oy;
Window child;
XTranslateCoordinates(win_display, win_rootWin, win_handle, point.X, point.Y, &ox, &oy, &child);
return Point2D_Make(ox, oy);
XTranslateCoordinates(win_display, win_rootWin, win_handle, x, y, &ox, &oy, &child);
Point2D p = { ox, oy }; return p;
}
struct Point2D Window_PointToScreen(struct Point2D point) {
Point2D Window_PointToScreen(Int32 x, Int32 y) {
int ox, oy;
Window child;
XTranslateCoordinates(win_display, win_handle, win_rootWin, point.X, point.Y, &ox, &oy, &child);
return Point2D_Make(ox, oy);
XTranslateCoordinates(win_display, win_handle, win_rootWin, x, y, &ox, &oy, &child);
Point2D p = { ox, oy }; return p;
}
struct Point2D Window_GetDesktopCursorPos(void) {
Point2D Window_GetDesktopCursorPos(void) {
Window root, child;
int rootX, rootY, childX, childY, mask;
XQueryPointer(win_display, win_rootWin, &root, &child, &rootX, &rootY, &childX, &childY, &mask);
return Point2D_Make(rootX, rootY);
Point2D p = { rootX, rootY }; return p;
}
void Window_SetDesktopCursorPos(struct Point2D point) {
XWarpPointer(win_display, NULL, win_rootWin, 0, 0, 0, 0, point.X, point.Y);
void Window_SetDesktopCursorPos(Int32 x, Int32 y) {
XWarpPointer(win_display, NULL, win_rootWin, 0, 0, 0, 0, x, y);
XFlush(win_display); /* TODO: not sure if XFlush call is necessary */
}

View File

@ -8,6 +8,7 @@
#include "Chat.h"
#include "Game.h"
#include "ExtMath.h"
#include "Bitmap.h"
#if CC_BUILD_WIN
#define WIN32_LEAN_AND_MEAN
@ -115,7 +116,7 @@ void Gfx_Free(void) {
#define gl_Toggle(cap) if (enabled) { glEnable(cap); } else { glDisable(cap); }
static void GL_DoMipmaps(GfxResourceID texId, Int32 x, Int32 y, struct Bitmap* bmp, bool partial) {
static void GL_DoMipmaps(GfxResourceID texId, Int32 x, Int32 y, Bitmap* bmp, bool partial) {
UInt8* prev = bmp->Scan0;
Int32 lvls = GfxCommon_MipmapsLevels(bmp->Width, bmp->Height);
Int32 lvl, width = bmp->Width, height = bmp->Height;
@ -140,7 +141,7 @@ static void GL_DoMipmaps(GfxResourceID texId, Int32 x, Int32 y, struct Bitmap* b
if (prev != bmp->Scan0) Mem_Free(prev);
}
GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, bool managedPool, bool mipmaps) {
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps) {
UInt32 texId;
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);
@ -166,7 +167,7 @@ GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, bool managedPool, bool mipma
return texId;
}
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, struct Bitmap* part, bool mipmaps) {
void Gfx_UpdateTexturePart(GfxResourceID texId, Int32 x, Int32 y, Bitmap* part, bool mipmaps) {
glBindTexture(GL_TEXTURE_2D, texId);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, part->Width, part->Height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, part->Scan0);
if (mipmaps) GL_DoMipmaps(texId, x, y, part, true);
@ -523,7 +524,7 @@ void Gfx_CalcPerspectiveMatrix(Real32 fov, Real32 aspect, Real32 zNear, Real32 z
ReturnCode Gfx_TakeScreenshot(struct Stream* output, Int32 width, Int32 height) {
struct Bitmap bmp; Bitmap_Allocate(&bmp, width, height);
Bitmap bmp; Bitmap_Allocate(&bmp, width, height);
glReadPixels(0, 0, width, height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bmp.Scan0);
UInt8 tmp[PNG_MAX_DIMS * BITMAP_SIZEOF_PIXEL];

View File

@ -21,7 +21,7 @@ GfxResourceID Particles_TexId, Particles_VB;
Random rnd;
bool particle_hitTerrain;
void Particle_DoRender(Vector2* size, Vector3* pos, struct TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices) {
void Particle_DoRender(Vector2* size, Vector3* pos, TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices) {
Real32 sX = size->X * 0.5f, sY = size->Y * 0.5f;
Vector3 centre = *pos; centre.Y += sY;
@ -141,7 +141,7 @@ static bool RainParticle_Tick(struct RainParticle* p, Real64 delta) {
return Particle_PhysicsTick(&p->Base, 3.5f, false, delta) || particle_hitTerrain;
}
struct TextureRec Rain_Rec = { 2.0f / 128.0f, 14.0f / 128.0f, 5.0f / 128.0f, 16.0f / 128.0f };
TextureRec Rain_Rec = { 2.0f / 128.0f, 14.0f / 128.0f, 5.0f / 128.0f, 16.0f / 128.0f };
static void RainParticle_Render(struct RainParticle* p, Real32 t, VertexP3fT2fC4b* vertices) {
Vector3 pos;
Vector3_Lerp(&pos, &p->Base.LastPos, &p->Base.NextPos, t);
@ -191,7 +191,7 @@ static void Rain_Tick(Real64 delta) {
*#########################################################################################################################*/
struct TerrainParticle {
struct Particle Base;
struct TextureRec Rec;
TextureRec Rec;
TextureLoc TexLoc;
BlockID Block;
};
@ -360,7 +360,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID old, BlockID now) {
Vector3I_ToVector3(&worldPos, &coords);
TextureLoc texLoc = Block_GetTexLoc(old, FACE_XMIN);
Int32 texIndex;
struct TextureRec baseRec = Atlas1D_TexRec(texLoc, 1, &texIndex);
TextureRec baseRec = Atlas1D_TexRec(texLoc, 1, &texIndex);
Real32 uScale = (1.0f / 16.0f), vScale = (1.0f / 16.0f) * Atlas1D_InvTileSize;
Vector3 minBB = Block_MinBB[old];
@ -395,7 +395,7 @@ void Particles_BreakBlockEffect(Vector3I coords, BlockID old, BlockID now) {
velocity.Y = CELL_CENTRE + (cellY - 0.0f) + (Random_Float(&rnd) * 0.4f - 0.2f);
velocity.Z = CELL_CENTRE + (cellZ - 0.5f) + (Random_Float(&rnd) * 0.4f - 0.2f);
struct TextureRec rec = baseRec;
TextureRec rec = baseRec;
rec.U1 = baseRec.U1 + Random_Range(&rnd, minU, maxUsedU) * uScale;
rec.V1 = baseRec.V1 + Random_Range(&rnd, minV, maxUsedV) * vScale;
rec.U2 = rec.U1 + 4 * uScale;

View File

@ -2,7 +2,6 @@
#define CC_PARTICLE_H
#include "Vectors.h"
#include "VertexStructs.h"
#include "2DStructs.h"
/* Represents particle effects, and manages rendering and spawning particles.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
@ -17,7 +16,7 @@ struct Particle {
};
/* http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/ */
void Particle_DoRender(Vector2* size, Vector3* pos, struct TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices);
void Particle_DoRender(Vector2* size, Vector3* pos, TextureRec* rec, PackedCol col, VertexP3fT2fC4b* vertices);
void Particles_MakeComponent(struct IGameComponent* comp);
void Particles_Render(Real64 delta, Real32 t);
void Particles_Tick(struct ScheduledTask* task);

View File

@ -7,6 +7,7 @@
#include "Drawer2D.h"
#include "Funcs.h"
#include "AsyncDownloader.h"
#include "Bitmap.h"
#if CC_BUILD_WIN
#define WIN32_LEAN_AND_MEAN
@ -681,7 +682,7 @@ void Font_GetNames(StringsBuffer* buffer) {
EnumFontFamiliesW(hdc, NULL, Font_GetNamesCallback, buffer);
}
void Font_Make(struct FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style) {
void Font_Make(FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style) {
desc->Size = size;
desc->Style = style;
LOGFONTA font = { 0 };
@ -697,33 +698,33 @@ void Font_Make(struct FontDesc* desc, STRING_PURE String* fontName, UInt16 size,
if (!desc->Handle) ErrorHandler_Fail("Creating font handle failed");
}
void Font_Free(struct FontDesc* desc) {
void Font_Free(FontDesc* desc) {
if (!DeleteObject(desc->Handle)) ErrorHandler_Fail("Deleting font handle failed");
desc->Handle = NULL;
}
/* TODO: not associate font with device so much */
struct Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
WCHAR str[300]; Platform_ConvertString(str, &args->Text);
HGDIOBJ oldFont = SelectObject(hdc, args->Font.Handle);
SIZE area; GetTextExtentPointW(hdc, str, args->Text.length, &area);
SelectObject(hdc, oldFont);
return Size2D_Make(area.cx, area.cy);
Size2D s = { area.cx, area.cy }; return s;
}
HBITMAP platform_dib;
HBITMAP platform_oldBmp;
struct Bitmap* platform_bmp;
Bitmap* platform_bmp;
void* platform_bits;
void Platform_SetBitmap(struct Bitmap* bmp) {
void Platform_SetBitmap(Bitmap* bmp) {
platform_bmp = bmp;
platform_bits = NULL;
BITMAPINFO bmi = { 0 };
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bmp->Width;
bmi.bmiHeader.biWidth = bmp->Width;
bmi.bmiHeader.biHeight = -bmp->Height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
@ -737,7 +738,7 @@ void Platform_SetBitmap(struct Bitmap* bmp) {
/* TODO: check return codes and stuff */
/* TODO: make text prettier.. somehow? */
/* TODO: Do we need to / 255 instead of >> 8 ? */
struct Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col) {
Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col) {
WCHAR str[300]; Platform_ConvertString(str, &args->Text);
HGDIOBJ oldFont = (HFONT)SelectObject(hdc, (HFONT)args->Font.Handle);
@ -745,7 +746,7 @@ struct Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, Pac
TextOutW(hdc, 0, 0, str, args->Text.length);
Int32 xx, yy;
struct Bitmap* bmp = platform_bmp;
Bitmap* bmp = platform_bmp;
for (yy = 0; yy < area.cy; yy++) {
UInt8* src = (UInt8*)platform_bits + (yy * (bmp->Width << 2));
UInt8* dst = (UInt8*)Bitmap_GetRow(bmp, y + yy); dst += x * BITMAP_SIZEOF_PIXEL;
@ -764,7 +765,7 @@ struct Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, Pac
SelectObject(hdc, oldFont);
//DrawTextA(hdc, args->Text.buffer, args->Text.length,
// &r, DT_NOPREFIX | DT_SINGLELINE | DT_NOCLIP);
return Size2D_Make(area.cx, area.cy);
Size2D s = { area.cx, area.cy }; return s;
}
void Platform_ReleaseBitmap(void) {

View File

@ -1,14 +1,11 @@
#ifndef CC_PLATFORM_H
#define CC_PLATFORM_H
#include "Utils.h"
#include "2DStructs.h"
#include "PackedCol.h"
/* Abstracts platform specific memory management, I/O, etc.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
struct DrawTextArgs;
struct FontDesc;
struct Bitmap;
struct AsyncRequest;
enum SOCKET_SELECT { SOCKET_SELECT_READ, SOCKET_SELECT_WRITE };
@ -89,11 +86,11 @@ void Waitable_Wait(void* handle);
void Waitable_WaitFor(void* handle, UInt32 milliseconds);
void Font_GetNames(StringsBuffer* buffer);
void Font_Make(struct FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style);
void Font_Free(struct FontDesc* desc);
struct Size2D Platform_TextMeasure(struct DrawTextArgs* args);
void Platform_SetBitmap(struct Bitmap* bmp);
struct Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col);
void Font_Make(FontDesc* desc, STRING_PURE String* fontName, UInt16 size, UInt16 style);
void Font_Free(FontDesc* desc);
Size2D Platform_TextMeasure(struct DrawTextArgs* args);
void Platform_SetBitmap(Bitmap* bmp);
Size2D Platform_TextDraw(struct DrawTextArgs* args, Int32 x, Int32 y, PackedCol col);
void Platform_ReleaseBitmap(void);
void Socket_Create(SocketPtr* socket);

View File

@ -23,14 +23,14 @@
struct InventoryScreen {
Screen_Layout
struct FontDesc Font;
FontDesc Font;
struct TableWidget Table;
bool ReleasedInv, DeferredSelect;
};
struct StatusScreen {
Screen_Layout
struct FontDesc Font;
FontDesc Font;
struct TextWidget Status, HackStates;
struct TextAtlas PosAtlas;
Real64 Accumulator;
@ -44,13 +44,13 @@ struct HUDScreen {
struct Screen* Chat;
struct HotbarWidget Hotbar;
struct PlayerListWidget PlayerList;
struct FontDesc PlayerFont;
FontDesc PlayerFont;
bool ShowingList, WasShowingList;
};
struct LoadingScreen {
Screen_Layout
struct FontDesc Font;
FontDesc Font;
Real32 Progress;
struct TextWidget Title, Message;
@ -71,7 +71,7 @@ struct ChatScreen {
bool SuppressNextPress;
Int32 ChatIndex;
Int32 LastDownloadStatus;
struct FontDesc ChatFont, ChatUrlFont, AnnouncementFont;
FontDesc ChatFont, ChatUrlFont, AnnouncementFont;
struct TextWidget Announcement;
struct ChatInputWidget Input;
struct TextGroupWidget Status, BottomRight, Chat, ClientStatus;
@ -98,7 +98,7 @@ struct DisconnectScreen {
Int32 LastSecsLeft;
struct ButtonWidget Reconnect;
struct FontDesc TitleFont, MessageFont;
FontDesc TitleFont, MessageFont;
struct TextWidget Title, Message;
char __TitleBuffer[STRING_SIZE];
char __MessageBuffer[STRING_SIZE];
@ -523,7 +523,7 @@ static void LoadingScreen_DrawBackground(void) {
PackedCol col = PACKEDCOL_CONST(64, 64, 64, 255);
TextureLoc texLoc = Block_GetTexLoc(BLOCK_DIRT, FACE_YMAX);
struct TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex);
TextureRec rec = Atlas1D_TexRec(texLoc, 1, &atlasIndex);
Real32 u2 = (Real32)Game_Width / (Real32)LOADING_TILE_SIZE;
struct Texture tex = { NULL, TEX_RECT(0,0, Game_Width,LOADING_TILE_SIZE), TEX_UV(0,rec.V1, u2,rec.V2) };
@ -618,7 +618,6 @@ static void GeneratingScreen_Init(void* screen) {
Gen_Done = false;
LoadingScreen_Init(screen);
void* threadHandle;
if (Gen_Vanilla) {
Thread_Start(&NotchyGen_Generate, true);
} else {

View File

@ -6,7 +6,7 @@
#include "GraphicsAPI.h"
#include "Platform.h"
void Atlas2D_UpdateState(struct Bitmap* bmp) {
void Atlas2D_UpdateState(Bitmap* bmp) {
Atlas2D_Bitmap = *bmp;
Atlas2D_TileSize = bmp->Width / ATLAS2D_TILES_PER_ROW;
Atlas2D_RowsCount = bmp->Height / Atlas2D_TileSize;
@ -14,7 +14,7 @@ void Atlas2D_UpdateState(struct Bitmap* bmp) {
Block_RecalculateSpriteBB();
}
static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, struct Bitmap* element) {
static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) {
Int32 size = Atlas2D_TileSize;
Int32 x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
if (y >= Atlas2D_RowsCount) return NULL;
@ -25,7 +25,7 @@ static GfxResourceID Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, struct Bi
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) {
Int32 size = Atlas2D_TileSize;
struct Bitmap tile;
Bitmap tile;
/* Try to allocate bitmap on stack if possible */
if (size > 64) {
@ -46,12 +46,12 @@ void Atlas2D_Free(void) {
}
struct TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index) {
TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index) {
*index = Atlas1D_Index(texLoc);
Int32 y = Atlas1D_RowId(texLoc);
/* Adjust coords to be slightly inside - fixes issues with AMD/ATI cards. */
struct TextureRec rec;
TextureRec rec;
rec.U1 = 0.0f;
rec.V1 = y * Atlas1D_InvTileSize;
rec.U2 = (uCount - 1) + UV2_Scale;
@ -61,7 +61,7 @@ struct TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index)
static void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) {
Int32 tileSize = Atlas2D_TileSize;
struct Bitmap atlas1D;
Bitmap atlas1D;
Bitmap_Allocate(&atlas1D, tileSize, atlas1DHeight);
Int32 index1D;

View File

@ -1,7 +1,6 @@
#ifndef CC_TERRAINATLAS_H
#define CC_TERRAINATLAS_H
#include "Bitmap.h"
#include "2DStructs.h"
#include "Core.h"
/* Represents the 2D texture atlas of terrain.png, and converted into an array of 1D textures.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
@ -12,7 +11,7 @@
#define ATLAS2D_MAX_ROWS_COUNT 32
#define ATLAS1D_MAX_ATLASES (ATLAS2D_TILES_PER_ROW * ATLAS2D_MAX_ROWS_COUNT)
struct Bitmap Atlas2D_Bitmap;
Bitmap Atlas2D_Bitmap;
Int32 Atlas2D_TileSize, Atlas2D_RowsCount;
Int32 Atlas1D_Count, Atlas1D_TilesPerAtlas;
Int32 Atlas1D_Mask, Atlas1D_Shift;
@ -26,10 +25,10 @@ GfxResourceID Atlas1D_TexIds[ATLAS1D_MAX_ATLASES];
/* Returns the index of the 1D atlas within the array of 1D atlases that contains the given tile id */
#define Atlas1D_Index(texLoc) ((texLoc) >> Atlas1D_Shift) /* texLoc / Atlas1D_TilesPerAtlas */
void Atlas2D_UpdateState(struct Bitmap* bmp);
void Atlas2D_UpdateState(Bitmap* bmp);
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc);
void Atlas2D_Free(void);
struct TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index);
TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index);
void Atlas1D_UpdateState(void);
Int32 Atlas1D_UsedAtlasesCount(void);
void Atlas1D_Free(void);

View File

@ -440,7 +440,7 @@ void TexturePack_ExtractZip_File(STRING_PURE String* filename) {
}
ReturnCode TexturePack_ExtractTerrainPng(struct Stream* stream) {
struct Bitmap bmp;
Bitmap bmp;
ReturnCode res = Bitmap_DecodePng(&bmp, stream);
if (!res) {

View File

@ -6,7 +6,6 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct Stream;
struct Bitmap;
struct AsyncRequest;
struct ZipEntry { UInt32 CompressedSize, UncompressedSize, LocalHeaderOffset, Crc32; };

View File

@ -145,15 +145,15 @@ Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta) {
return steps;
}
UInt8 Utils_GetSkinType(struct Bitmap* bmp) {
if (bmp->Width == bmp->Height * 2) return SKIN_TYPE_64x32;
if (bmp->Width != bmp->Height) return SKIN_TYPE_INVALID;
UInt8 Utils_GetSkinType(Bitmap* bmp) {
if (bmp->Width == bmp->Height * 2) return SKIN_64x32;
if (bmp->Width != bmp->Height) return SKIN_INVALID;
/* Minecraft alex skins have this particular pixel with alpha of 0 */
Int32 scale = bmp->Width / 64;
UInt32 pixel = Bitmap_GetPixel(bmp, 54 * scale, 20 * scale);
UInt8 alpha = PackedCol_ARGB_A(pixel);
return alpha >= 127 ? SKIN_TYPE_64x64 : SKIN_TYPE_64x64_SLIM;
return alpha >= 127 ? SKIN_64x64 : SKIN_64x64_SLIM;
}
UInt32 Utils_CRC32(UInt8* data, UInt32 length) {

View File

@ -15,7 +15,6 @@ typedef struct DateTime_ {
UInt8 Second; /* Second, ranges from 0 to 59 */
UInt16 Milli; /* Milliseconds, ranges from 0 to 999 */
} DateTime;
struct Bitmap;
#define DATETIME_MILLIS_PER_SEC 1000
UInt64 DateTime_TotalMs(DateTime* time);
@ -31,7 +30,7 @@ void Utils_UNSAFE_GetFilename(STRING_TRANSIENT String* str);
Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta);
#define Utils_AdjViewDist(value) ((Int32)(1.4142135f * (value)))
UInt8 Utils_GetSkinType(struct Bitmap* bmp);
UInt8 Utils_GetSkinType(Bitmap* bmp);
UInt32 Utils_CRC32(UInt8* data, UInt32 length);
extern UInt32 Utils_Crc32Table[256];
void Utils_Resize(void** buffer, UInt32* maxElems, UInt32 elemSize, UInt32 defElems, UInt32 expandElems);

View File

@ -1,6 +1,7 @@
#include "Vectors.h"
#include "ExtMath.h"
#include "Funcs.h"
#include "Constants.h"
Vector3 Vector3_Create1(Real32 value) {
Vector3 v; v.X = value; v.Y = value; v.Z = value; return v;

View File

@ -188,6 +188,7 @@ static UInt32 Codebook_Lookup1Values(UInt32 entries, UInt32 dimensions) {
return 0;
}
#define CODEWORD_UNUSED UInt8_MaxValue
static bool Codebook_CalcCodewords(struct Codebook* c, UInt8* len) {
c->Codewords = Mem_Alloc(c->NumCodewords, sizeof(UInt32), "codewords");
c->CodewordLens = Mem_Alloc(c->NumCodewords, sizeof(UInt8), "raw codeword lens");
@ -199,7 +200,7 @@ static bool Codebook_CalcCodewords(struct Codebook* c, UInt8* len) {
/* add codeword 0 to tree */
for (i = 0; i < c->Entries; i++) {
if (len[i] == UInt8_MaxValue) continue;
if (len[i] == CODEWORD_UNUSED) continue;
c->Codewords[0] = 0;
c->CodewordLens[0] = len[i];
@ -215,7 +216,7 @@ static bool Codebook_CalcCodewords(struct Codebook* c, UInt8* len) {
i++; /* first codeword was already handled */
for (j = 1; i < c->Entries; i++) {
UInt32 root = len[i];
if (root == UInt8_MaxValue) continue;
if (root == CODEWORD_UNUSED) continue;
/* per spec, find lowest possible value (leftmost) */
while (root && next_codewords[root] == 0) root--;
@ -251,7 +252,7 @@ static ReturnCode Codebook_DecodeSetup(struct VorbisState* ctx, struct Codebook*
if (sparse) {
Int32 flag = Vorbis_ReadBits(ctx, 1);
if (!flag) {
codewordLens[i] = UInt8_MaxValue;
codewordLens[i] = CODEWORD_UNUSED;
continue; /* unused entry */
}
}

View File

@ -16,9 +16,12 @@
#include "Chat.h"
#include "Game.h"
#include "ErrorHandler.h"
#include "Bitmap.h"
#define WIDGET_UV(u1,v1, u2,v2) u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f
static void Widget_NullFunc(void* widget) { }
Size2D Size2D_Empty;
static bool Widget_Mouse(void* elem, Int32 x, Int32 y, MouseButton btn) { return false; }
static bool Widget_Key(void* elem, Key key) { return false; }
static bool Widget_KeyPress(void* elem, char keyChar) { return false; }
@ -59,12 +62,12 @@ void TextWidget_Make(struct TextWidget* w) {
PackedCol col = PACKEDCOL_WHITE; w->Col = col;
}
void TextWidget_Create(struct TextWidget* w, STRING_PURE String* text, struct FontDesc* font) {
void TextWidget_Create(struct TextWidget* w, STRING_PURE String* text, FontDesc* font) {
TextWidget_Make(w);
TextWidget_Set(w, text, font);
}
void TextWidget_Set(struct TextWidget* w, STRING_PURE String* text, struct FontDesc* font) {
void TextWidget_Set(struct TextWidget* w, STRING_PURE String* text, FontDesc* font) {
Gfx_DeleteTexture(&w->Texture.ID);
if (Drawer2D_IsEmptyText(text)) {
w->Texture.Width = 0;
@ -151,7 +154,7 @@ struct WidgetVTABLE ButtonWidget_VTABLE = {
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
ButtonWidget_Reposition,
};
void ButtonWidget_Create(struct ButtonWidget* w, Int32 minWidth, STRING_PURE String* text, struct FontDesc* font, Widget_LeftClick onClick) {
void ButtonWidget_Create(struct ButtonWidget* w, Int32 minWidth, STRING_PURE String* text, FontDesc* font, Widget_LeftClick onClick) {
Widget_Reset(w);
w->VTABLE = &ButtonWidget_VTABLE;
w->OptName = NULL;
@ -160,7 +163,7 @@ void ButtonWidget_Create(struct ButtonWidget* w, Int32 minWidth, STRING_PURE Str
ButtonWidget_Set(w, text, font);
}
void ButtonWidget_Set(struct ButtonWidget* w, STRING_PURE String* text, struct FontDesc* font) {
void ButtonWidget_Set(struct ButtonWidget* w, STRING_PURE String* text, FontDesc* font) {
Gfx_DeleteTexture(&w->Texture.ID);
if (Drawer2D_IsEmptyText(text)) {
w->Texture.Width = 0;
@ -514,9 +517,9 @@ static void TableWidget_MoveCursorToSelected(struct TableWidget* w) {
TableWidget_GetCoords(w, i, &x, &y);
x += w->BlockSize / 2; y += w->BlockSize / 2;
struct Point2D topLeft = Window_PointToScreen(Point2D_Empty);
Point2D topLeft = Window_PointToScreen(0, 0);
x += topLeft.X; y += topLeft.Y;
Window_SetDesktopCursorPos(Point2D_Make(x, y));
Window_SetDesktopCursorPos(x, y);
}
static void TableWidget_MakeBlockDesc(STRING_TRANSIENT String* desc, BlockID block) {
@ -887,7 +890,7 @@ static void InputWidget_CalculateLineSizes(struct InputWidget* w) {
InputWidget_FormatLine(w, y, &line);
args.Text = line;
struct Size2D textSize = Drawer2D_MeasureText(&args);
Size2D textSize = Drawer2D_MeasureText(&args);
w->LineSizes[y].Width += textSize.Width;
w->LineSizes[y].Height = textSize.Height;
}
@ -931,7 +934,7 @@ static void InputWidget_UpdateCaret(struct InputWidget* w) {
InputWidget_FormatLine(w, w->CaretY, &line);
args.Text = String_UNSAFE_Substring(&line, 0, w->CaretX);
struct Size2D trimmedSize = Drawer2D_MeasureText(&args);
Size2D trimmedSize = Drawer2D_MeasureText(&args);
if (w->CaretY == 0) { trimmedSize.Width += w->PrefixWidth; }
w->CaretTex.X = w->X + w->Padding + trimmedSize.Width;
@ -1246,7 +1249,7 @@ static bool InputWidget_MouseDown(void* widget, Int32 x, Int32 y, MouseButton bu
return true;
}
NOINLINE_ static void InputWidget_Create(struct InputWidget* w, struct FontDesc* font, STRING_REF String* prefix) {
NOINLINE_ static void InputWidget_Create(struct InputWidget* w, FontDesc* font, STRING_REF String* prefix) {
Widget_Reset(w);
w->Font = *font;
w->Prefix = *prefix;
@ -1262,7 +1265,7 @@ NOINLINE_ static void InputWidget_Create(struct InputWidget* w, struct FontDesc*
if (!prefix->length) return;
DrawTextArgs_Make(&args, prefix, font, true);
struct Size2D size = Drawer2D_MeasureText(&args);
Size2D size = Drawer2D_MeasureText(&args);
w->PrefixWidth = size.Width; w->Width = size.Width;
w->PrefixHeight = size.Height; w->Height = size.Height;
}
@ -1442,7 +1445,7 @@ static void MenuInputWidget_RemakeTexture(void* widget) {
struct MenuInputWidget* w = widget;
struct DrawTextArgs args;
DrawTextArgs_Make(&args, &w->Base.Lines[0], &w->Base.Font, false);
struct Size2D size = Drawer2D_MeasureText(&args);
Size2D size = Drawer2D_MeasureText(&args);
w->Base.CaretAccumulator = 0.0;
char rangeBuffer[STRING_SIZE];
@ -1459,15 +1462,15 @@ static void MenuInputWidget_RemakeTexture(void* widget) {
w->Base.Width = max(size.Width, w->MinWidth);
w->Base.Height = max(size.Height, w->MinHeight);
struct Size2D adjSize = size; adjSize.Width = w->Base.Width;
Size2D adjSize = size; adjSize.Width = w->Base.Width;
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, adjSize.Width, adjSize.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, adjSize.Width, adjSize.Height);
Drawer2D_Begin(&bmp);
{
Drawer2D_DrawText(&args, w->Base.Padding, 0);
args.Text = range;
struct Size2D hintSize = Drawer2D_MeasureText(&args);
Size2D hintSize = Drawer2D_MeasureText(&args);
Int32 hintX = adjSize.Width - hintSize.Width;
if (size.Width + 3 < hintX) {
Drawer2D_DrawText(&args, hintX, 0);
@ -1509,7 +1512,7 @@ struct WidgetVTABLE MenuInputWidget_VTABLE = {
InputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
InputWidget_Reposition,
};
void MenuInputWidget_Create(struct MenuInputWidget* w, Int32 width, Int32 height, STRING_PURE String* text, struct FontDesc* font, struct MenuInputValidator* validator) {
void MenuInputWidget_Create(struct MenuInputWidget* w, Int32 width, Int32 height, STRING_PURE String* text, FontDesc* font, struct MenuInputValidator* validator) {
String empty = String_MakeNull();
InputWidget_Create(&w->Base, font, &empty);
w->Base.VTABLE = &MenuInputWidget_VTABLE;
@ -1544,10 +1547,10 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
totalHeight += w->LineSizes[i].Height;
maxWidth = max(maxWidth, w->LineSizes[i].Width);
}
struct Size2D size = { maxWidth, totalHeight };
Size2D size = { maxWidth, totalHeight };
Int32 realHeight = 0;
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Drawer2D_Begin(&bmp);
struct DrawTextArgs args; DrawTextArgs_MakeEmpty(&args, &w->Font, true);
@ -1758,7 +1761,7 @@ struct WidgetVTABLE ChatInputWidget_VTABLE = {
InputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
InputWidget_Reposition,
};
void ChatInputWidget_Create(struct ChatInputWidget* w, struct FontDesc* font) {
void ChatInputWidget_Create(struct ChatInputWidget* w, FontDesc* font) {
String prefix = String_FromConst("> ");
InputWidget_Create(&w->Base, font, &prefix);
w->TypingLogPos = Chat_InputLog.Count; /* Index of newest entry + 1. */
@ -2136,7 +2139,7 @@ struct WidgetVTABLE PlayerListWidget_VTABLE = {
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
PlayerListWidget_Reposition,
};
void PlayerListWidget_Create(struct PlayerListWidget* w, struct FontDesc* font, bool classic) {
void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic) {
Widget_Reset(w);
w->VTABLE = &PlayerListWidget_VTABLE;
w->HorAnchor = ANCHOR_CENTRE;
@ -2447,8 +2450,8 @@ void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Texture* tex
struct Portion portions[2 * (TEXTGROUPWIDGET_LEN / TEXTGROUPWIDGET_HTTP_LEN)];
Int32 i, x, portionsCount = TextGroupWidget_Reduce(w, chars, index, portions);
struct Size2D total = Size2D_Empty;
struct Size2D partSizes[Array_Elems(portions)];
Size2D total = { 0, 0 };
Size2D partSizes[Array_Elems(portions)];
for (i = 0; i < portionsCount; i++) {
struct Portion bit = portions[i];
@ -2460,7 +2463,7 @@ void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Texture* tex
total.Width += partSizes[i].Width;
}
struct Bitmap bmp;
Bitmap bmp;
Bitmap_AllocateClearedPow2(&bmp, total.Width, total.Height);
Drawer2D_Begin(&bmp);
{
@ -2548,7 +2551,7 @@ struct WidgetVTABLE TextGroupWidget_VTABLE = {
Widget_Mouse, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
TextGroupWidget_Reposition,
};
void TextGroupWidget_Create(struct TextGroupWidget* w, Int32 linesCount, struct FontDesc* font, struct FontDesc* underlineFont, STRING_REF struct Texture* textures, STRING_REF char* buffer) {
void TextGroupWidget_Create(struct TextGroupWidget* w, Int32 linesCount, FontDesc* font, FontDesc* underlineFont, STRING_REF struct Texture* textures, STRING_REF char* buffer) {
Widget_Reset(w);
w->VTABLE = &TextGroupWidget_VTABLE;
@ -2583,7 +2586,7 @@ static void SpecialInputWidget_UpdateColString(struct SpecialInputWidget* w) {
static bool SpecialInputWidget_IntersectsHeader(struct SpecialInputWidget* w, Int32 x, Int32 y) {
Int32 titleX = 0, i;
for (i = 0; i < Array_Elems(w->Tabs); i++) {
struct Size2D size = w->Tabs[i].TitleSize;
Size2D size = w->Tabs[i].TitleSize;
if (Gui_Contains(titleX, 0, size.Width, size.Height, x, y)) {
w->SelectedIndex = i;
return true;
@ -2655,7 +2658,7 @@ static Int32 SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) {
return totalWidth;
}
static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct Bitmap* bmp) {
static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, Bitmap* bmp) {
Int32 x = 0;
struct DrawTextArgs args; DrawTextArgs_MakeEmpty(&args, &w->Font, false);
@ -2665,7 +2668,7 @@ static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct B
for (i = 0; i < Array_Elems(w->Tabs); i++) {
args.Text = w->Tabs[i].Title;
PackedCol col = i == w->SelectedIndex ? col_selected : col_inactive;
struct Size2D size = w->Tabs[i].TitleSize;
Size2D size = w->Tabs[i].TitleSize;
Drawer2D_Clear(bmp, col, x, 0, size.Width, size.Height);
Drawer2D_DrawText(&args, x + SPECIAL_TITLE_SPACING / 2, 0);
@ -2673,7 +2676,7 @@ static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct B
}
}
static struct Size2D SpecialInputWidget_CalculateContentSize(struct SpecialInputTab* tab, struct Size2D* sizes, struct Size2D* elemSize) {
static Size2D SpecialInputWidget_CalculateContentSize(struct SpecialInputTab* tab, Size2D* sizes, Size2D* elemSize) {
*elemSize = Size2D_Empty;
Int32 i;
for (i = 0; i < tab->Contents.length; i += tab->CharsPerItem) {
@ -2683,10 +2686,10 @@ static struct Size2D SpecialInputWidget_CalculateContentSize(struct SpecialInput
elemSize->Width += SPECIAL_CONTENT_SPACING;
elemSize->Height = sizes[0].Height + SPECIAL_CONTENT_SPACING;
Int32 rows = Math_CeilDiv(tab->Contents.length / tab->CharsPerItem, tab->ItemsPerRow);
return Size2D_Make(elemSize->Width * tab->ItemsPerRow, elemSize->Height * rows);
Size2D s = { elemSize->Width * tab->ItemsPerRow, elemSize->Height * rows }; return s;
}
static void SpecialInputWidget_MeasureContentSizes(struct SpecialInputWidget* w, struct SpecialInputTab* tab, struct Size2D* sizes) {
static void SpecialInputWidget_MeasureContentSizes(struct SpecialInputWidget* w, struct SpecialInputTab* tab, Size2D* sizes) {
char buffer[STRING_SIZE];
String s = String_FromArray(buffer);
s.length = tab->CharsPerItem;
@ -2721,15 +2724,16 @@ static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct
}
static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct SpecialInputTab* tab) {
struct Size2D sizes[DRAWER2D_MAX_COLS];
Size2D sizes[DRAWER2D_MAX_COLS];
SpecialInputWidget_MeasureContentSizes(w, tab, sizes);
struct Size2D bodySize = SpecialInputWidget_CalculateContentSize(tab, sizes, &w->ElementSize);
Int32 titleWidth = SpecialInputWidget_MeasureTitles(w);
Size2D bodySize = SpecialInputWidget_CalculateContentSize(tab, sizes, &w->ElementSize);
Int32 titleWidth = SpecialInputWidget_MeasureTitles(w);
Int32 titleHeight = w->Tabs[0].TitleSize.Height;
struct Size2D size = Size2D_Make(max(bodySize.Width, titleWidth), bodySize.Height + titleHeight);
Size2D size = { max(bodySize.Width, titleWidth), bodySize.Height + titleHeight };
Gfx_DeleteTexture(&w->Tex.ID);
struct Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Bitmap bmp; Bitmap_AllocateClearedPow2(&bmp, size.Width, size.Height);
Drawer2D_Begin(&bmp);
{
SpecialInputWidget_DrawTitles(w, &bmp);
@ -2798,7 +2802,7 @@ struct WidgetVTABLE SpecialInputWidget_VTABLE = {
SpecialInputWidget_MouseDown, Widget_Mouse, Widget_MouseMove, Widget_MouseScroll,
Widget_CalcPosition,
};
void SpecialInputWidget_Create(struct SpecialInputWidget* w, struct FontDesc* font, struct InputWidget* appendObj) {
void SpecialInputWidget_Create(struct SpecialInputWidget* w, FontDesc* font, struct InputWidget* appendObj) {
Widget_Reset(w);
w->VTABLE = &SpecialInputWidget_VTABLE;
w->VerAnchor = ANCHOR_MAX;

View File

@ -4,7 +4,6 @@
#include "BlockID.h"
#include "Constants.h"
#include "Entity.h"
#include "2DStructs.h"
/* Contains all 2D widget implementations.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
@ -17,8 +16,8 @@ struct TextWidget {
PackedCol Col;
};
NOINLINE_ void TextWidget_Make(struct TextWidget* w);
NOINLINE_ void TextWidget_Create(struct TextWidget* w, STRING_PURE String* text, struct FontDesc* font);
NOINLINE_ void TextWidget_Set(struct TextWidget* w, STRING_PURE String* text, struct FontDesc* font);
NOINLINE_ void TextWidget_Create(struct TextWidget* w, STRING_PURE String* text, FontDesc* font);
NOINLINE_ void TextWidget_Set(struct TextWidget* w, STRING_PURE String* text, FontDesc* font);
typedef void (*Button_Get)(STRING_TRANSIENT String* raw);
@ -32,8 +31,8 @@ struct ButtonWidget {
Button_Get GetValue;
Button_Set SetValue;
};
NOINLINE_ void ButtonWidget_Create(struct ButtonWidget* w, Int32 minWidth, STRING_PURE String* text, struct FontDesc* font, Widget_LeftClick onClick);
NOINLINE_ void ButtonWidget_Set(struct ButtonWidget* w, STRING_PURE String* text, struct FontDesc* font);
NOINLINE_ void ButtonWidget_Create(struct ButtonWidget* w, Int32 minWidth, STRING_PURE String* text, FontDesc* font, Widget_LeftClick onClick);
NOINLINE_ void ButtonWidget_Set(struct ButtonWidget* w, STRING_PURE String* text, FontDesc* font);
struct ScrollbarWidget {
@ -61,7 +60,7 @@ struct TableWidget {
Widget_Layout
Int32 ElementsCount, ElementsPerRow, RowsCount;
Int32 LastCreatedIndex;
struct FontDesc Font;
FontDesc Font;
Int32 SelectedIndex, BlockSize;
Real32 SelBlockExpand;
GfxResourceID VB;
@ -83,7 +82,7 @@ NOINLINE_ void TableWidget_MakeDescTex(struct TableWidget* w, BlockID block);
#define INPUTWIDGET_LEN STRING_SIZE
struct InputWidget {
Widget_Layout
struct FontDesc Font;
FontDesc Font;
Int32 (*GetMaxLines)(void);
void (*RemakeTexture)(void* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */
void (*OnPressedEnter)(void* elem); /* Invoked when the user presses enter. */
@ -91,7 +90,7 @@ struct InputWidget {
String Text;
String Lines[INPUTWIDGET_MAX_LINES]; /* raw text of each line */
struct Size2D LineSizes[INPUTWIDGET_MAX_LINES]; /* size of each line in pixels */
Size2D LineSizes[INPUTWIDGET_MAX_LINES]; /* size of each line in pixels */
struct Texture InputTex;
String Prefix;
UInt16 PrefixWidth, PrefixHeight;
@ -143,7 +142,7 @@ struct MenuInputWidget {
struct MenuInputValidator Validator;
char __TextBuffer[INPUTWIDGET_LEN];
};
NOINLINE_ void MenuInputWidget_Create(struct MenuInputWidget* w, Int32 width, Int32 height, STRING_PURE String* text, struct FontDesc* font, struct MenuInputValidator* v);
NOINLINE_ void MenuInputWidget_Create(struct MenuInputWidget* w, Int32 width, Int32 height, STRING_PURE String* text, FontDesc* font, struct MenuInputValidator* v);
struct ChatInputWidget {
@ -154,7 +153,7 @@ struct ChatInputWidget {
String OrigStr;
};
NOINLINE_ void ChatInputWidget_Create(struct ChatInputWidget* w, struct FontDesc* font);
NOINLINE_ void ChatInputWidget_Create(struct ChatInputWidget* w, FontDesc* font);
#define TEXTGROUPWIDGET_MAX_LINES 30
@ -162,14 +161,14 @@ NOINLINE_ void ChatInputWidget_Create(struct ChatInputWidget* w, struct FontDesc
struct TextGroupWidget {
Widget_Layout
Int32 LinesCount, DefaultHeight;
struct FontDesc Font, UnderlineFont;
FontDesc Font, UnderlineFont;
bool PlaceholderHeight[TEXTGROUPWIDGET_MAX_LINES];
UInt8 LineLengths[TEXTGROUPWIDGET_MAX_LINES];
struct Texture* Textures;
char* Buffer;
};
NOINLINE_ void TextGroupWidget_Create(struct TextGroupWidget* w, Int32 linesCount, struct FontDesc* font, struct FontDesc* underlineFont, STRING_REF struct Texture* textures, STRING_REF char* buffer);
NOINLINE_ void TextGroupWidget_Create(struct TextGroupWidget* w, Int32 linesCount, FontDesc* font, FontDesc* underlineFont, STRING_REF struct Texture* textures, STRING_REF char* buffer);
NOINLINE_ void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, Int32 index, bool placeHolder);
NOINLINE_ void TextGroupWidget_PushUpAndReplaceLast(struct TextGroupWidget* w, STRING_PURE String* text);
NOINLINE_ Int32 TextGroupWidget_UsedHeight(struct TextGroupWidget* w);
@ -180,7 +179,7 @@ NOINLINE_ void TextGroupWidget_SetText(struct TextGroupWidget* w, Int32 index, S
struct PlayerListWidget {
Widget_Layout
struct FontDesc Font;
FontDesc Font;
UInt16 NamesCount, ElementOffset;
Int32 XMin, XMax, YHeight;
bool Classic;
@ -188,30 +187,30 @@ struct PlayerListWidget {
UInt16 IDs[TABLIST_MAX_NAMES * 2];
struct Texture Textures[TABLIST_MAX_NAMES * 2];
};
NOINLINE_ void PlayerListWidget_Create(struct PlayerListWidget* w, struct FontDesc* font, bool classic);
NOINLINE_ void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic);
NOINLINE_ void PlayerListWidget_GetNameUnder(struct PlayerListWidget* w, Int32 mouseX, Int32 mouseY, STRING_TRANSIENT String* name);
typedef void (*SpecialInputAppendFunc)(void* userData, char c);
struct SpecialInputTab {
Int32 ItemsPerRow, CharsPerItem;
struct Size2D TitleSize;
Size2D TitleSize;
String Title, Contents;
};
struct SpecialInputWidget {
Widget_Layout
struct Size2D ElementSize;
Size2D ElementSize;
Int32 SelectedIndex;
struct InputWidget* AppendObj;
struct Texture Tex;
struct FontDesc Font;
FontDesc Font;
struct SpecialInputTab Tabs[5];
String ColString;
char __ColBuffer[DRAWER2D_MAX_COLS * 4];
};
NOINLINE_ void SpecialInputWidget_Create(struct SpecialInputWidget* w, struct FontDesc* font, struct InputWidget* appendObj);
NOINLINE_ void SpecialInputWidget_Create(struct SpecialInputWidget* w, FontDesc* font, struct InputWidget* appendObj);
NOINLINE_ void SpecialInputWidget_UpdateCols(struct SpecialInputWidget* w);
NOINLINE_ void SpecialInputWidget_SetActive(struct SpecialInputWidget* w, bool active);
#endif

View File

@ -25,12 +25,12 @@ HDC win_DC;
UInt8 win_State = WINDOW_STATE_NORMAL;
bool invisible_since_creation; /* Set by WindowsMessage.CREATE and consumed by Visible = true (calls BringWindowToFront) */
Int32 suppress_resize; /* Used in WindowBorder and WindowState in order to avoid rapid, consecutive resize events */
struct Rectangle2D previous_bounds; /* Used to restore previous size when leaving fullscreen mode */
Rect2D prev_bounds; /* Used to restore previous size when leaving fullscreen mode */
static struct Rectangle2D Window_FromRect(RECT rect) {
struct Rectangle2D r;
static Rect2D Window_FromRect(RECT rect) {
Rect2D r;
r.X = rect.left; r.Y = rect.top;
r.Width = RECT_WIDTH(rect);
r.Width = RECT_WIDTH(rect);
r.Height = RECT_HEIGHT(rect);
return r;
}
@ -395,8 +395,7 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_PURE Stri
/* TODO: UngroupFromTaskbar(); */
/* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */
RECT rect; rect.left = x; rect.top = y;
rect.right = x + width; rect.bottom = y + height;
RECT rect = { x, y, x + width, y + height };
AdjustWindowRect(&rect, win_Style, false);
WNDCLASSEXW wc = { 0 };
@ -494,27 +493,25 @@ void Window_SetClipboardText(STRING_PURE String* value) {
}
void Window_SetBounds(struct Rectangle2D rect) {
void Window_SetBounds(Rect2D rect) {
/* Note: the bounds variable is updated when the resize/move message arrives.*/
SetWindowPos(win_Handle, NULL, rect.X, rect.Y, rect.Width, rect.Height, 0);
}
void Window_SetLocation(struct Point2D point) {
SetWindowPos(win_Handle, NULL, point.X, point.Y, 0, 0, SWP_NOSIZE);
void Window_SetLocation(Int32 x, Int32 y) {
SetWindowPos(win_Handle, NULL, x, y, 0, 0, SWP_NOSIZE);
}
void Window_SetSize(struct Size2D size) {
SetWindowPos(win_Handle, NULL, 0, 0, size.Width, size.Height, SWP_NOMOVE);
void Window_SetSize(Int32 width, Int32 height) {
SetWindowPos(win_Handle, NULL, 0, 0, width, height, SWP_NOMOVE);
}
void Window_SetClientSize(struct Size2D size) {
void Window_SetClientSize(Int32 width, Int32 height) {
DWORD style = GetWindowLongW(win_Handle, GWL_STYLE);
RECT rect; rect.left = 0; rect.top = 0;
rect.right = size.Width; rect.bottom = size.Height;
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, style, false);
struct Size2D adjSize = { RECT_WIDTH(rect), RECT_HEIGHT(rect) };
Window_SetSize(adjSize);
Window_SetSize(RECT_WIDTH(rect), RECT_HEIGHT(rect));
}
void* Window_GetWindowHandle(void) { return win_Handle; }
@ -570,7 +567,7 @@ void Window_SetWindowState(UInt8 state) {
/* Reset state to avoid strange side-effects from maximized/minimized windows. */
Window_ResetWindowState();
previous_bounds = Window_Bounds;
prev_bounds = Window_Bounds;
Window_SetHiddenBorder(true);
command = SW_MAXIMIZE;
@ -584,20 +581,22 @@ void Window_SetWindowState(UInt8 state) {
if (exiting_fullscreen) Window_SetHiddenBorder(false);
/* Restore previous window size/location if necessary */
if (command == SW_RESTORE && !Rectangle2D_Equals(previous_bounds, Rectangle2D_Empty)) {
Window_SetBounds(previous_bounds);
previous_bounds = Rectangle2D_Empty;
if (command == SW_RESTORE && (prev_bounds.Width || prev_bounds.Height)) {
Window_SetBounds(prev_bounds);
prev_bounds.Width = 0; prev_bounds.Height = 0;
}
}
struct Point2D Window_PointToClient(struct Point2D point) {
Point2D Window_PointToClient(Int32 x, Int32 y) {
Point2D point = { x, y };
if (!ScreenToClient(win_Handle, &point)) {
ErrorHandler_FailWithCode(GetLastError(), "Converting point from client to screen coordinates");
}
return point;
}
struct Point2D Window_PointToScreen(struct Point2D point) {
Point2D Window_PointToScreen(Int32 x, Int32 y) {
Point2D point = { x, y };
if (!ClientToScreen(win_Handle, &point)) {
ErrorHandler_FailWithCode(GetLastError(), "Converting point from screen to client coordinates");
}
@ -617,12 +616,12 @@ void Window_ProcessEvents(void) {
}
}
struct Point2D Window_GetDesktopCursorPos(void) {
POINT p; GetCursorPos(&p);
return Point2D_Make(p.x, p.y);
Point2D Window_GetDesktopCursorPos(void) {
POINT point; GetCursorPos(&point);
Point2D p = { point.x, point.y }; return p;
}
void Window_SetDesktopCursorPos(struct Point2D point) {
SetCursorPos(point.X, point.Y);
void Window_SetDesktopCursorPos(Int32 x, Int32 y) {
SetCursorPos(x, y);
}
bool win_cursorVisible = true;

View File

@ -1,8 +1,6 @@
#ifndef CC_WINDOW_H
#define CC_WINDOW_H
#include "String.h"
#include "Bitmap.h"
#include "2DStructs.h"
#include "DisplayDevice.h"
/* Abstracts creating and managing a native window.
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
@ -51,23 +49,23 @@ void* Window_GetWindowHandle(void);
UInt8 Window_GetWindowState(void);
void Window_SetWindowState(UInt8 value);
struct Rectangle2D Window_Bounds;
struct Size2D Window_ClientSize;
Rect2D Window_Bounds;
Size2D Window_ClientSize;
void Window_SetBounds(struct Rectangle2D rect);
void Window_SetLocation(struct Point2D point);
void Window_SetSize(struct Size2D size);
void Window_SetClientSize(struct Size2D size);
void Window_SetBounds(Rect2D rect);
void Window_SetLocation(Int32 x, Int32 y);
void Window_SetSize(Int32 width, Int32 height);
void Window_SetClientSize(Int32 width, Int32 height);
void Window_Close(void);
void Window_ProcessEvents(void);
/* Transforms the specified point from screen to client coordinates. */
struct Point2D Window_PointToClient(struct Point2D point);
Point2D Window_PointToClient(Int32 x, Int32 y);
/* Transforms the specified point from client to screen coordinates. */
struct Point2D Window_PointToScreen(struct Point2D point);
Point2D Window_PointToScreen(Int32 x, Int32 y);
struct Point2D Window_GetDesktopCursorPos(void);
void Window_SetDesktopCursorPos(struct Point2D point);
Point2D Window_GetDesktopCursorPos(void);
void Window_SetDesktopCursorPos(Int32 x, Int32 y);
bool Window_GetCursorVisible(void);
void Window_SetCursorVisible(bool visible);