Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/OpenSHC/UI/Rendering/PencilRenderCore/dimHorizontalLine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/Rendering/ColorMode.hpp"

#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"
#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// Every bit but the lowest of each colour channel, so that halving a pixel shifts no bit into the channel
// below: red starts at bit 11 in RGB565 and at bit 10 in RGB555.
enum {
HALVING_MASK_RGB565 = 65535 & ~((1 << 11) | (1 << 5) | 1),
HALVING_MASK_RGB555 = 32767 & ~((1 << 10) | (1 << 5) | 1)
};

// FUNCTION: STRONGHOLDCRUSADER 0x00468EA0
void PencilRenderCore::dimHorizontalLine()
{
// The asm below names DAT_PencilRenderCore, which inline asm can only do once C++ code has instantiated
// it; sizeof does that without generating any code.
(void)sizeof(DAT_PencilRenderCore::instance);
int const startX = this->drawStartX;
int const startY = this->drawStartY;
int const endX = this->drawEndX;
int halvingMask;
if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_555) {
halvingMask = HALVING_MASK_RGB555;
} else {
halvingMask = HALVING_MASK_RGB565;
}
// Halves the brightness of row startY from startX to endX, on the global pencil's surface, not on this
// one's. Handwritten assembly in the original, transcribed from the binary.
__asm {
mov edi, DAT_PencilRenderCore::instance.surfacePtr
mov eax, startX
add eax, eax
add edi, eax
mov eax, startY
mov edx, DAT_PencilRenderCore::instance.horizontalByteSize
mul edx
add edi, eax
mov eax, startX
mov ebx, endX
mov dx, word ptr halvingMask
next_pixel:
cmp eax, ebx
jg done
mov cx, word ptr [edi]
and cx, dx
shr cx, 1
mov word ptr [edi], cx
add edi, 2
add eax, 1
jmp next_pixel
done:
}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp"
#include "OpenSHC/IO/Graphics/GmID.hpp"

#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// The border is drawn in tiles of 24 by 24 pixels. Each row of tiles has a left, a middle and a right picture
// in GID_INTERFACE_ICONS_3, followed by their three alpha masks; these are the rows' first pictures.
enum {
BORDER_TILE_SIZE = 24,
BORDER_TOP_PICTURES = 1,
BORDER_MIDDLE_PICTURES = 7,
BORDER_BOTTOM_PICTURES = 13
};

// FUNCTION: STRONGHOLDCRUSADER 0x00471340
void PencilRenderCore::drawBorderedBoxWithBlendedBackground(int xPos, int yPos, int width, int height)
{
// Rounded up to whole tiles
width = ((width - 1) / BORDER_TILE_SIZE + 1) * BORDER_TILE_SIZE;
height = ((height - 1) / BORDER_TILE_SIZE + 1) * BORDER_TILE_SIZE;
// The custom version's blends for blendStrength 0: 0 on the tiles, 16 (half-way to 32) on the background
for (int y = 0; y < height; y += BORDER_TILE_SIZE) {
int rowPictures;
if (y == 0) {
rowPictures = BORDER_TOP_PICTURES;
} else if (y == height - BORDER_TILE_SIZE) {
rowPictures = BORDER_BOTTOM_PICTURES;
} else {
rowPictures = BORDER_MIDDLE_PICTURES;
}
for (int x = 0; x < width; x += BORDER_TILE_SIZE) {
// The left picture first, replaced further in: a flat else-if chain doesn't match
int picture = rowPictures;
if (x != 0) {
if (x == width - BORDER_TILE_SIZE) {
picture = rowPictures + 2;
} else {
// The inside of the box is left to the blended background
if (rowPictures == BORDER_MIDDLE_PICTURES) {
continue;
}
picture = rowPictures + 1;
}
}
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask,
DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, picture,
x + xPos, y + yPos, OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, picture + 3, 0);
}
}
// The background always goes on the global pencil, not on this one.
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox,
DAT_PencilRenderCore::ptr)(xPos + BORDER_TILE_SIZE, yPos + BORDER_TILE_SIZE,
xPos + width - BORDER_TILE_SIZE - 1, yPos + height - BORDER_TILE_SIZE - 1, 16);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp"
#include "OpenSHC/IO/Graphics/GmID.hpp"

#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// The border is drawn in tiles of 24 by 24 pixels. Each row of tiles has a left, a middle and a right picture
// in GID_INTERFACE_ICONS_3, followed by their three alpha masks; these are the rows' first pictures.
enum {
BORDER_TILE_SIZE = 24,
BORDER_TOP_PICTURES = 1,
BORDER_MIDDLE_PICTURES = 7,
BORDER_BOTTOM_PICTURES = 13
};

// FUNCTION: STRONGHOLDCRUSADER 0x00471440
void PencilRenderCore::drawBorderedBoxWithCustomBlendedBackground(
int xPos, int yPos, int width, int height, int blendStrength)
{
// Rounded up to whole tiles
width = ((width - 1) / BORDER_TILE_SIZE + 1) * BORDER_TILE_SIZE;
height = ((height - 1) / BORDER_TILE_SIZE + 1) * BORDER_TILE_SIZE;
for (int y = 0; y < height; y += BORDER_TILE_SIZE) {
int rowPictures;
if (y == 0) {
rowPictures = BORDER_TOP_PICTURES;
} else if (y == height - BORDER_TILE_SIZE) {
rowPictures = BORDER_BOTTOM_PICTURES;
} else {
rowPictures = BORDER_MIDDLE_PICTURES;
}
for (int x = 0; x < width; x += BORDER_TILE_SIZE) {
// The left picture first, replaced further in: a flat else-if chain doesn't match
int picture = rowPictures;
if (x != 0) {
if (x == width - BORDER_TILE_SIZE) {
picture = rowPictures + 2;
} else {
// The inside of the box is left to the blended background
if (rowPictures == BORDER_MIDDLE_PICTURES) {
continue;
}
picture = rowPictures + 1;
}
}
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask,
DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, picture,
x + xPos, y + yPos, OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_3, picture + 3, blendStrength);
}
}
// The background always goes on the global pencil, not on this one.
// Half-way to full strength (32); * 16 / 32 gives the original's shl / sar, where / 2 doesn't.
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox,
DAT_PencilRenderCore::ptr)(xPos + BORDER_TILE_SIZE, yPos + BORDER_TILE_SIZE,
xPos + width - BORDER_TILE_SIZE - 1, yPos + height - BORDER_TILE_SIZE - 1,
(blendStrength - 32) * 16 / 32 + 32);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/Globals/DAT_TextInputDefinedData.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004710A0
void PencilRenderCore::drawBoxWithRoundedEdges(
int left, int top, int right, int bottom, RoundedBoxEdgeRoundingLevel roundingLevel)
{
// How far each of the first roundingLevel rows is indented at both ends, outermost row first.
int* rowIndents;
switch (roundingLevel) {
case OpenSHC::UI::Enums::RBERL_SLIGHT:
rowIndents = DAT_TextInputDefinedData::instance.field_0x0;
break;
case OpenSHC::UI::Enums::RBERL_STRONG:
rowIndents = DAT_TextInputDefinedData::instance.field_0x2c;
break;
default:
return;
}
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::setupPencilSurface, this)();
// Darkens the box instead of filling it: setupPencil's colour is not used.
if (!MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::setupPencil, this)(
left, top, right, bottom, 0)) {
return;
}
// Too low for both rounded ends
if (this->drawEndY - this->drawStartY < roundingLevel * 2) {
return;
}
int const startX = this->drawStartX;
int const endX = this->drawEndX;
for (int row = 0; row < roundingLevel && this->currentHeight_0x2c >= 0; ++row) {
this->drawStartX = rowIndents[row] + startX;
this->drawEndX = endX - rowIndents[row];
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::dimHorizontalLine, this)();
--this->currentHeight_0x2c;
++this->drawStartY;
}
this->drawStartX = startX;
this->drawEndX = endX;
for (; this->currentHeight_0x2c >= roundingLevel; --this->currentHeight_0x2c, ++this->drawStartY) {
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::dimHorizontalLine, this)();
}
for (int row = roundingLevel - 1; row >= 0 && this->currentHeight_0x2c >= 0; --row) {
this->drawStartX = rowIndents[row] + startX;
this->drawEndX = endX - rowIndents[row];
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::dimHorizontalLine, this)();
--this->currentHeight_0x2c;
++this->drawStartY;
}
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/Globals/DAT_TextInputDefinedData.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x00470EE0
void PencilRenderCore::drawBoxWithRoundedEdgesAndColor(
int left, int top, int right, int bottom, ushort color, RoundedBoxEdgeRoundingLevel roundingLevel)
{
// How far each of the first roundingLevel rows is indented at both ends, outermost row first.
int* rowIndents;
switch (roundingLevel) {
case OpenSHC::UI::Enums::RBERL_SLIGHT:
rowIndents = DAT_TextInputDefinedData::instance.field_0x0;
break;
case OpenSHC::UI::Enums::RBERL_STRONG:
rowIndents = DAT_TextInputDefinedData::instance.field_0x2c;
break;
default:
return;
}
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::setupPencilSurface, this)();
if (!MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::setupPencil, this)(
left, top, right, bottom, color)) {
return;
}
// Too low for both rounded ends
if (this->drawEndY - this->drawStartY < roundingLevel * 2) {
return;
}
int const startX = this->drawStartX;
int const endX = this->drawEndX;
for (int row = 0; row < roundingLevel && this->currentHeight_0x2c >= 0; ++row) {
this->drawStartX = rowIndents[row] + startX;
this->drawEndX = endX - rowIndents[row];
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawHorizontalLine, this)();
--this->currentHeight_0x2c;
++this->drawStartY;
}
this->drawStartX = startX;
this->drawEndX = endX;
for (; this->currentHeight_0x2c >= roundingLevel; --this->currentHeight_0x2c, ++this->drawStartY) {
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawHorizontalLine, this)();
}
for (int row = roundingLevel - 1; row >= 0 && this->currentHeight_0x2c >= 0; --row) {
this->drawStartX = rowIndents[row] + startX;
this->drawEndX = endX - rowIndents[row];
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawHorizontalLine, this)();
--this->currentHeight_0x2c;
++this->drawStartY;
}
}

}
}
}
36 changes: 36 additions & 0 deletions src/OpenSHC/UI/Rendering/PencilRenderCore/drawCurrentPixel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "../PencilRenderCore.func.hpp"

#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x00468F20
void PencilRenderCore::drawCurrentPixel()
{
// The asm below names DAT_PencilRenderCore, which inline asm can only do once C++ code has instantiated
// it; sizeof does that without generating any code.
(void)sizeof(DAT_PencilRenderCore::instance);
int const x = this->currentX;
int const y = this->currentY;
int const color = this->drawColor;
// Sets the pixel at (currentX, currentY) to the colour, on the global pencil's surface, not on this one's.
// Handwritten assembly in the original, transcribed from the binary.
__asm {
mov edi, DAT_PencilRenderCore::instance.surfacePtr
mov eax, x
add eax, eax
add edi, eax
mov eax, y
mov edx, DAT_PencilRenderCore::instance.horizontalByteSize
mul edx
add edi, eax
mov cx, word ptr color
mov word ptr [edi], cx
}
}

}
}
}
Loading
Loading