1
0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-25 04:02:30 +01:00

Added icon, textbox font.

TTextBox ready.
This commit is contained in:
oz 2020-12-11 19:03:13 +03:00
parent b412563ee3
commit fe254ef03c
11 changed files with 207 additions and 11 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

View File

@ -21,8 +21,7 @@ int main()
{ {
// Testing with UI // Testing with UI
char cmdLine[1]{}; char cmdLine[1]{};
pb::init(); WinMain(GetModuleHandleA(nullptr), 0, cmdLine, 10);
WinMain(winmain::hinst, 0, cmdLine, 10);
return 0; return 0;
} }

View File

@ -98,6 +98,24 @@ BEGIN
END END
/////////////////////////////////////////////////////////////////////////////
//
// RCDATA
//
PBMSG_FT RCDATA "PB_MSGFT.bin"
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
ICON_1 ICON "icon_1.ico"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// String Table // String Table

View File

@ -30,14 +30,14 @@
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>NotSet</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>NotSet</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
@ -288,6 +288,12 @@
<ItemGroup> <ItemGroup>
<ResourceCompile Include="SpaceCadetPinball.rc" /> <ResourceCompile Include="SpaceCadetPinball.rc" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="PB_MSGFT.bin" />
</ItemGroup>
<ItemGroup>
<Image Include="Icon_1.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -401,4 +401,14 @@
<Filter>Resource Files</Filter> <Filter>Resource Files</Filter>
</ResourceCompile> </ResourceCompile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="PB_MSGFT.bin">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Image Include="Icon_1.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project> </Project>

View File

@ -196,6 +196,65 @@ void TTextBox::Draw()
255); 255);
return; return;
} }
auto text = this2->Message1->Text;
for (auto y = this2->OffsetY; ; y += font->Height)
{
auto curChar = *text;
if (!curChar || y + font->Height > this2->OffsetY + this2->Height)
break;
auto totalWidth = 0;
char* textEndSpace = nullptr;
auto textEnd = text;
while (true)
{
auto maskedChar = curChar & 0x7F;
if (!maskedChar || maskedChar == '\n')
break;
auto charBmp = font->Chars[maskedChar];
if (charBmp)
{
auto width = charBmp->Width + font->GapWidth + totalWidth;
if (width > this2->Width)
{
if (textEndSpace)
textEnd = textEndSpace;
break;
}
if (*textEnd == ' ')
textEndSpace = textEnd;
curChar = *(textEnd + 1);
totalWidth = width;
++textEnd;
}
else
{
curChar = *textEnd;
}
}
auto offX = this2->OffsetX;
while (text < textEnd)
{
auto charBmp = font->Chars[*text++ & 0x7F];
if (charBmp)
{
auto height = charBmp->Height;
auto width = charBmp->Width;
if (render::background_bitmap)
gdrv::copy_bitmap_w_transparency(&render::vscreen, width, height, offX, y, charBmp, 0, 0);
else
gdrv::copy_bitmap(&render::vscreen, width, height, offX, y, charBmp, 0, 0);
font = this2->Font;
offX += charBmp->Width + font->GapWidth;
}
}
while ((*text & 0x7F) == ' ')
++text;
if ((*text & 0x7F) == '\n')
++text;
}
break;
} }
} }
else else

View File

@ -3,6 +3,7 @@
#include "loader.h" #include "loader.h"
#include "memory.h" #include "memory.h"
#include "partman.h" #include "partman.h"
#include "winmain.h"
score_msg_font_type* score::msg_fontp; score_msg_font_type* score::msg_fontp;
@ -44,17 +45,108 @@ scoreStruct* score::create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp)
scoreStruct* score::dup(scoreStruct* score, int scoreIndex) scoreStruct* score::dup(scoreStruct* score, int scoreIndex)
{ {
scoreStruct* result = (scoreStruct*)memory::allocate(sizeof(scoreStruct)); auto result = reinterpret_cast<scoreStruct*>(memory::allocate(sizeof(scoreStruct)));
if (result) if (result)
memcpy(result, score, sizeof(scoreStruct)); memcpy(result, score, sizeof(scoreStruct));
return result; return result;
} }
HRSRC score::load_msg_font(LPCSTR lpName) void score::load_msg_font(LPCSTR lpName)
{ {
return nullptr; auto resHandle = FindResourceA(winmain::hinst, lpName, RT_RCDATA);
if (!resHandle)
return;
auto resGlobal = LoadResource(winmain::hinst, resHandle);
if (!resGlobal)
return;
auto rcData = static_cast<__int16*>(LockResource(resGlobal));
auto fontp = reinterpret_cast<score_msg_font_type*>(memory::allocate(sizeof(score_msg_font_type)));
msg_fontp = fontp;
if (!fontp)
{
FreeResource(resGlobal);
return;
}
memset(fontp->Chars, 0, sizeof(fontp->Chars));
auto maxWidth = 0;
auto ptrToWidths = (char*)rcData + 6;
for (auto index = 128; index; index--)
{
if (*ptrToWidths > maxWidth)
maxWidth = *ptrToWidths;
++ptrToWidths;
}
auto height = rcData[2];
auto tmpCharBur = memory::allocate(maxWidth * height + 4);
if (!tmpCharBur)
{
memory::free(msg_fontp);
msg_fontp = nullptr;
FreeResource(resGlobal);
return;
}
msg_fontp->GapWidth = rcData[0];
msg_fontp->Height = height;
auto ptrToData = (char*)(rcData + 67);
int charInd;
for (charInd = 0; charInd < 128; charInd++)
{
auto width = *((char*)rcData + 6 + charInd);
if (!width)
continue;
auto bmp = reinterpret_cast<gdrv_bitmap8*>(memory::allocate(sizeof(gdrv_bitmap8)));
msg_fontp->Chars[charInd] = bmp;
if (!bmp)
{
break;
}
if (gdrv::create_raw_bitmap(bmp, width, height, 0))
{
memory::free(bmp);
msg_fontp->Chars[charInd] = nullptr;
break;
}
auto sizeInBytes = height * width + 1;
memcpy(tmpCharBur + 3, ptrToData, sizeInBytes);
ptrToData += sizeInBytes;
auto srcptr = tmpCharBur + 4;
auto dstPtr = &bmp->BmpBufPtr1[bmp->Stride * (bmp->Height - 1)];
for (auto y = 0; y < height; ++y)
{
memcpy(dstPtr, srcptr, width);
srcptr += width;
dstPtr -= bmp->Stride;
}
}
if (charInd != 128)
unload_msg_font();
FreeResource(resGlobal);
} }
void score::unload_msg_font() void score::unload_msg_font()
{ {
if (msg_fontp)
{
for (int i = 0; i < 128; i++)
{
if (msg_fontp->Chars[i])
{
gdrv::destroy_bitmap(msg_fontp->Chars[i]);
memory::free(msg_fontp->Chars[i]);
}
}
msg_fontp = nullptr;
}
} }

View File

@ -24,8 +24,20 @@ struct scoreStruct
struct score_msg_font_type struct score_msg_font_type
{ {
int GapWidth;
int Height;
gdrv_bitmap8* Chars[128];
}; };
struct score_font_rc
{
short Header0;
short Header1;
short Height;
char SomeLen[128];
};
class score class score
{ {
public: public:
@ -33,6 +45,6 @@ public:
static int init(); static int init();
static scoreStruct* create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp); static scoreStruct* create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp);
static scoreStruct* dup(scoreStruct* score, int scoreIndex); static scoreStruct* dup(scoreStruct* score, int scoreIndex);
static HRSRC load_msg_font(LPCSTR lpName); static void load_msg_font(LPCSTR lpName);
static void unload_msg_font(); static void unload_msg_font();
}; };

View File

@ -139,7 +139,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
WndClass.cbWndExtra = 0; WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance; WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIconA(hInstance, "ICON_1"); WndClass.hIcon = LoadIconA(hInstance, "ICON_1");
WndClass.hCursor = LoadCursorA(nullptr, (LPCSTR)0x7F00); WndClass.hCursor = LoadCursorA(nullptr, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)16; WndClass.hbrBackground = (HBRUSH)16;
WndClass.lpszMenuName = "MENU_1"; WndClass.lpszMenuName = "MENU_1";
WndClass.lpszClassName = windowClass; WndClass.lpszClassName = windowClass;
@ -354,7 +354,7 @@ LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LP
int height = rect.bottom - rect.top; int height = rect.bottom - rect.top;
pb::window_size(&width, &height); pb::window_size(&width, &height);
auto prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT)); auto prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
gdrv::init(hinst, hWnd); gdrv::init(hinst, hWnd);
auto voiceCount = options::get_int(nullptr, "Voices", 8); auto voiceCount = options::get_int(nullptr, "Voices", 8);
@ -747,7 +747,7 @@ void winmain::end_pause()
void winmain::new_game() void winmain::new_game()
{ {
end_pause(); end_pause();
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT)); HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
pb::replay_level(0); pb::replay_level(0);
SetCursor(prevCursor); SetCursor(prevCursor);
} }