diff --git a/ClassicalSharp/2D/Texture.cs b/ClassicalSharp/2D/Texture.cs index b0e719a71..305769e1e 100644 --- a/ClassicalSharp/2D/Texture.cs +++ b/ClassicalSharp/2D/Texture.cs @@ -5,6 +5,16 @@ using ClassicalSharp.GraphicsAPI; namespace ClassicalSharp { + /// Stores the four texture coordinates that describe a textured quad. + public struct TextureRec { + public float U1, V1, U2, V2; + + public TextureRec(float u, float v, float uWidth, float vHeight) { + U1 = u; V1 = v; + U2 = u + uWidth; V2 = v + vHeight; + } + } + /// Contains the information necessary to describe a 2D textured quad. public struct Texture { diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 076549b17..4dbfd5797 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -296,7 +296,6 @@ - diff --git a/ClassicalSharp/Utils/TextureRectangle.cs b/ClassicalSharp/Utils/TextureRectangle.cs deleted file mode 100644 index 9ac9a7ff6..000000000 --- a/ClassicalSharp/Utils/TextureRectangle.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 -using System; - -namespace ClassicalSharp { - - /// Stores the four texture coordinates that describe a textured quad. - public struct TextureRec { - public float U1, V1, U2, V2; - - public TextureRec(float u, float v, float uWidth, float vHeight) { - U1 = u; V1 = v; - U2 = u + uWidth; V2 = v + vHeight; - } - - public static TextureRec FromPoints(float u1, float v1, float u2, float v2) { - TextureRec rec; - rec.U1 = u1; rec.V1 = v1; - rec.U2 = u2; rec.V2 = v2; - return rec; - } - - public override string ToString() { - return String.Format("{0}, {1} : {2}, {3}", U1, V1, U2, V2); - } - - public void SwapU() { - float u2 = U2; U2 = U1; U1 = u2; - } - } -} \ No newline at end of file diff --git a/src/Client/2DStructs.c b/src/Client/2DStructs.c index 5784522df..2bce2ea4d 100644 --- a/src/Client/2DStructs.c +++ b/src/Client/2DStructs.c @@ -20,22 +20,4 @@ Size2D Size2D_Make(Int32 width, Int32 height) { Point2D Point2D_Make(Int32 x, Int32 y) { Point2D p; p.X = x; p.Y = y; return p; -} - -TextureRec TextureRec_FromRegion(Real32 u, Real32 v, Real32 uWidth, Real32 vHeight) { - TextureRec rec; - rec.U1 = u; rec.V1 = v; - rec.U2 = u + uWidth; rec.V2 = v + vHeight; - return rec; -} - -TextureRec TextureRec_FromPoints(Real32 u1, Real32 v1, Real32 u2, Real32 v2) { - TextureRec rec; - rec.U1 = u1; rec.V1 = v1; - rec.U2 = u2; rec.V2 = v2; - return rec; -} - -void TextureRec_SwapU(TextureRec* rec) { - Real32 u2 = rec->U2; rec->U2 = rec->U1; rec->U1 = u2; } \ No newline at end of file diff --git a/src/Client/2DStructs.h b/src/Client/2DStructs.h index 386bb596c..7debb3ef9 100644 --- a/src/Client/2DStructs.h +++ b/src/Client/2DStructs.h @@ -24,13 +24,5 @@ bool Rectangle2D_Equals(Rectangle2D a, Rectangle2D b); Size2D Size2D_Make(Int32 width, Int32 height); Point2D Point2D_Make(Int32 x, Int32 y); -/* Stores the four texture coordinates that describe a textured quad. */ typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec; - -/* Constructs a texture rectangle from origin and size. */ -TextureRec TextureRec_FromRegion(Real32 u, Real32 v, Real32 uWidth, Real32 vHeight); -/* Constructs a texture rectangle from four points. */ -TextureRec TextureRec_FromPoints(Real32 u1, Real32 v1, Real32 u2, Real32 v2); -/* Swaps U1 and U2 of a texture rectangle. */ -void TextureRec_SwapU(TextureRec* rec); #endif \ No newline at end of file diff --git a/src/Client/Chat.c b/src/Client/Chat.c index 2095c9c16..ab6fcada6 100644 --- a/src/Client/Chat.c +++ b/src/Client/Chat.c @@ -331,7 +331,8 @@ void ResolutionCommand_Execute(STRING_PURE String* args, UInt32 argsCount) { } else if (width <= 0 || height <= 0) { Chat_AddRaw(tmp, "&e/client: &cWidth and height must be above 0."); } else { - Window_SetClientSize(Size2D_Make(width, height)); + Size2D size = { width, height }; + Window_SetClientSize(size); Options_SetInt32(OPTION_WINDOW_WIDTH, width); Options_SetInt32(OPTION_WINDOW_HEIGHT, height); } diff --git a/src/Client/EntityComponents.c b/src/Client/EntityComponents.c index 7b798362f..a454e1bde 100644 --- a/src/Client/EntityComponents.c +++ b/src/Client/EntityComponents.c @@ -477,7 +477,7 @@ void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, Entity* entity, Shad void ShadowComponent_DrawSquareShadow(VertexP3fT2fC4b** vertices, Real32 y, Real32 x, Real32 z) { PackedCol col = PACKEDCOL_CONST(255, 255, 255, 220); - TextureRec rec = TextureRec_FromRegion(63.0f / 128.0f, 63.0f / 128.0f, 1.0f / 128.0f, 1.0f / 128.0f); + TextureRec rec = { 63.0f / 128.0f, 63.0f / 128.0f, 64.0f / 128.0f, 64.0f / 128.0f }; VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v; v.Y = y; v.Col = col; diff --git a/src/Client/TerrainAtlas.c b/src/Client/TerrainAtlas.c index c7d49b59a..aa88fa52f 100644 --- a/src/Client/TerrainAtlas.c +++ b/src/Client/TerrainAtlas.c @@ -50,10 +50,12 @@ TextureRec Atlas1D_TexRec(TextureLoc texLoc, Int32 uCount, Int32* index) { Int32 y = texLoc % Atlas1D_ElementsPerAtlas; /* Adjust coords to be slightly inside - fixes issues with AMD/ATI cards. */ - return TextureRec_FromRegion( - 0.0f, y * Atlas1D_InvElementSize, - (uCount - 1) + UV2_Scale, - UV2_Scale * Atlas1D_InvElementSize); + TextureRec rec; + rec.U1 = 0.0f; + rec.V1 = y * Atlas1D_InvElementSize; + rec.U2 = (uCount - 1) + UV2_Scale; + rec.V2 = rec.V1 + UV2_Scale * Atlas1D_InvElementSize; + return rec; } void Atlas1D_Make1DTexture(Int32 i, Int32 atlas1DHeight, Int32* index) { diff --git a/src/Client/Widgets.c b/src/Client/Widgets.c index c813cbe4e..0689a1b84 100644 --- a/src/Client/Widgets.c +++ b/src/Client/Widgets.c @@ -98,9 +98,6 @@ void TextWidget_SetText(TextWidget* widget, STRING_PURE String* text) { Texture Button_ShadowTex = { 0, 0, 0, 0, 0, 0.0f, 66.0f / 256.0f, 200.0f / 256.0f, 86.0f / 256.0f }; Texture Button_SelectedTex = { 0, 0, 0, 0, 0, 0.0f, 86.0f / 256.0f, 200.0f / 256.0f, 106.0f / 256.0f }; Texture Button_DisabledTex = { 0, 0, 0, 0, 0, 0.0f, 46.0f / 256.0f, 200.0f / 256.0f, 66.0f / 256.0f }; -PackedCol Button_NormCol = PACKEDCOL_CONST(224, 224, 244, 255); -PackedCol Button_ActiveCol = PACKEDCOL_CONST(255, 255, 160, 255); -PackedCol Button_DisabledCol = PACKEDCOL_CONST(160, 160, 160, 255); void ButtonWidget_Init(GuiElement* elem) { ButtonWidget* widget = (ButtonWidget*)elem; @@ -152,7 +149,10 @@ void ButtonWidget_Render(GuiElement* elem, Real64 delta) { GfxCommon_Draw2DTexture(&back, white); } - PackedCol col = elemW->Disabled ? Button_DisabledCol : (elemW->Active ? Button_ActiveCol : Button_NormCol); + PackedCol normCol = PACKEDCOL_CONST(224, 224, 244, 255); + PackedCol activeCol = PACKEDCOL_CONST(255, 255, 160, 255); + PackedCol disabledCol = PACKEDCOL_CONST(160, 160, 160, 255); + PackedCol col = elemW->Disabled ? disabledCol : (elemW->Active ? activeCol : normCol); Texture_RenderShaded(&widget->Texture, col); } @@ -350,7 +350,7 @@ void HotbarWidget_RenderHotbarBlocks(HotbarWidget* widget) { void HotbarWidget_RepositonBackgroundTexture(HotbarWidget* widget) { Widget* w = &widget->Base; - TextureRec rec = TextureRec_FromPoints(0.0f, 0.0f, 182.0f / 256.0f, 22.0f / 256.0f); + TextureRec rec = { 0.0f, 0.0f, 182.0f / 256.0f, 22.0f / 256.0f }; widget->BackTex = Texture_FromRec(0, w->X, w->Y, w->Width, w->Height, rec); } @@ -362,7 +362,7 @@ void HotbarWidget_RepositionSelectionTexture(HotbarWidget* widget) { Int32 vSize = (Int32)(22.0f * scale); Int32 y = w->Y + (w->Height - (Int32)(23.0f * scale)); - TextureRec rec = TextureRec_FromPoints(0.0f, 22.0f / 256.0f, 24.0f / 256.0f, 22.0f / 256.0f); + TextureRec rec = { 0.0f, 22.0f / 256.0f, 24.0f / 256.0f, 44.0f / 256.0f }; widget->SelTex = Texture_FromRec(0, 0, y, hSize, vSize, rec); } diff --git a/src/Client/WinWindow.c b/src/Client/WinWindow.c index b78a2ce8f..83790feba 100644 --- a/src/Client/WinWindow.c +++ b/src/Client/WinWindow.c @@ -527,12 +527,16 @@ void Window_SetBounds(Rectangle2D rect) { SetWindowPos(win_Handle, NULL, rect.X, rect.Y, rect.Width, rect.Height, 0); } -Point2D Window_GetLocation(void) { return Point2D_Make(win_Bounds.X, win_Bounds.Y); } +Point2D Window_GetLocation(void) { + Point2D point = { win_Bounds.X, win_Bounds.Y }; return point; +} void Window_SetLocation(Point2D point) { SetWindowPos(win_Handle, NULL, point.X, point.Y, 0, 0, SWP_NOSIZE); } -Size2D Window_GetSize(void) { return Size2D_Make(win_Bounds.Width, win_Bounds.Height); } +Size2D Window_GetSize(void) { + Size2D size = { win_Bounds.Width, win_Bounds.Height }; return size; +} void Window_SetSize(Size2D size) { SetWindowPos(win_Handle, NULL, 0, 0, size.Width, size.Height, SWP_NOMOVE); } @@ -544,7 +548,7 @@ void Window_SetClientRectangle(Rectangle2D rect) { } Size2D Window_GetClientSize(void) { - return Size2D_Make(win_ClientRect.Width, win_ClientRect.Height); + Size2D size = { win_ClientRect.Width, win_ClientRect.Height }; return size; } void Window_SetClientSize(Size2D size) { DWORD style = GetWindowLongA(win_Handle, GWL_STYLE); @@ -553,7 +557,8 @@ void Window_SetClientSize(Size2D size) { rect.right = size.Width; rect.bottom = size.Height; AdjustWindowRect(&rect, style, false); - Window_SetSize(Size2D_Make(RECT_WIDTH(rect), RECT_HEIGHT(rect))); + Size2D size = { RECT_WIDTH(rect), RECT_HEIGHT(rect) }; + Window_SetSize(size); } /* TODO: Set window icon