mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-09-02 11:59:39 +02:00
Added icon, textbox font.
TTextBox ready.
This commit is contained in:
parent
b412563ee3
commit
fe254ef03c
Binary file not shown.
BIN
SpaceCadetPinball/Icon_1.ico
Normal file
BIN
SpaceCadetPinball/Icon_1.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
SpaceCadetPinball/PB_MSGFT.bin
Normal file
BIN
SpaceCadetPinball/PB_MSGFT.bin
Normal file
Binary file not shown.
@ -21,8 +21,7 @@ int main()
|
||||
{
|
||||
// Testing with UI
|
||||
char cmdLine[1]{};
|
||||
pb::init();
|
||||
WinMain(winmain::hinst, 0, cmdLine, 10);
|
||||
WinMain(GetModuleHandleA(nullptr), 0, cmdLine, 10);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,24 @@ BEGIN
|
||||
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
|
||||
|
@ -30,14 +30,14 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
@ -288,6 +288,12 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="SpaceCadetPinball.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="PB_MSGFT.bin" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="Icon_1.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -401,4 +401,14 @@
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</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>
|
@ -196,6 +196,65 @@ void TTextBox::Draw()
|
||||
255);
|
||||
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
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "loader.h"
|
||||
#include "memory.h"
|
||||
#include "partman.h"
|
||||
#include "winmain.h"
|
||||
|
||||
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* result = (scoreStruct*)memory::allocate(sizeof(scoreStruct));
|
||||
auto result = reinterpret_cast<scoreStruct*>(memory::allocate(sizeof(scoreStruct)));
|
||||
if (result)
|
||||
memcpy(result, score, sizeof(scoreStruct));
|
||||
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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,20 @@ struct scoreStruct
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
@ -33,6 +45,6 @@ public:
|
||||
static int init();
|
||||
static scoreStruct* create(LPCSTR fieldName, gdrv_bitmap8* renderBgBmp);
|
||||
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();
|
||||
};
|
||||
|
@ -139,7 +139,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
||||
WndClass.cbWndExtra = 0;
|
||||
WndClass.hInstance = hInstance;
|
||||
WndClass.hIcon = LoadIconA(hInstance, "ICON_1");
|
||||
WndClass.hCursor = LoadCursorA(nullptr, (LPCSTR)0x7F00);
|
||||
WndClass.hCursor = LoadCursorA(nullptr, IDC_ARROW);
|
||||
WndClass.hbrBackground = (HBRUSH)16;
|
||||
WndClass.lpszMenuName = "MENU_1";
|
||||
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;
|
||||
pb::window_size(&width, &height);
|
||||
|
||||
auto prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT));
|
||||
auto prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
||||
gdrv::init(hinst, hWnd);
|
||||
|
||||
auto voiceCount = options::get_int(nullptr, "Voices", 8);
|
||||
@ -747,7 +747,7 @@ void winmain::end_pause()
|
||||
void winmain::new_game()
|
||||
{
|
||||
end_pause();
|
||||
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT));
|
||||
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
||||
pb::replay_level(0);
|
||||
SetCursor(prevCursor);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user