Skip to content

Commit

Permalink
Add interface bar side panels
Browse files Browse the repository at this point in the history
See #3
  • Loading branch information
alexbatalov committed Nov 7, 2022
1 parent b2420bd commit fa058f2
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
136 changes: 136 additions & 0 deletions src/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ static bool indicatorBarAdd(int indicator);
static void customInterfaceBarInit();
static void customInterfaceBarExit();

static void sidePanelsInit();
static void sidePanelsExit();
static void sidePanelsHide();
static void sidePanelsShow();
static void sidePanelsDraw(const char* path, int win, bool isLeading);

// 0x518F08
static bool gInterfaceBarInitialized = false;

Expand Down Expand Up @@ -288,6 +294,11 @@ int gInterfaceBarWidth = -1;
bool gInterfaceBarIsCustom = false;
static Art* gCustomInterfaceBarBackground = nullptr;

int gInterfaceSidePanelsImageId = 2;
bool gInterfaceSidePanelsExtendFromScreenEdge = false;
static int gInterfaceSidePanelsLeadingWindow = -1;
static int gInterfaceSidePanelsTrailingWindow = -1;

// intface_init
// 0x45D880
int interfaceInit()
Expand Down Expand Up @@ -566,6 +577,9 @@ int interfaceInit()

displayMonitorInit();

// SFALL
sidePanelsInit();

gInterfaceBarEnabled = true;
gInterfaceBarInitialized = false;
_intfaceHidden = 1;
Expand Down Expand Up @@ -594,6 +608,9 @@ void interfaceReset()
void interfaceFree()
{
if (gInterfaceBarWindow != -1) {
// SFALL
sidePanelsExit();

displayMonitorExit();

_redLightFrmImage.unlock();
Expand Down Expand Up @@ -765,6 +782,10 @@ void intface_hide()
_intfaceHidden = 1;
}
}

// SFALL
sidePanelsHide();

indicatorBarRefresh();
}

Expand All @@ -777,9 +798,14 @@ void _intface_show()
interfaceRenderHitPoints(false);
interfaceRenderArmorClass(false);
windowUnhide(gInterfaceBarWindow);
sidePanelsShow();
_intfaceHidden = false;
}
}

// SFALL
sidePanelsShow();

indicatorBarRefresh();
}

Expand Down Expand Up @@ -2496,4 +2522,114 @@ unsigned char* customInterfaceBarGetBackgroundImageData()
return artGetFrameData(gCustomInterfaceBarBackground, 0, 0);
}

static void sidePanelsInit()
{
if (gInterfaceBarMode) {
return;
}

if (gInterfaceSidePanelsImageId == 0) {
return;
}

if (gInterfaceBarWidth >= screenGetWidth()) {
return;
}

Rect windowRect;
windowGetRect(gInterfaceBarWindow, &windowRect);

gInterfaceSidePanelsLeadingWindow = windowCreate(0, windowRect.top, windowRect.left, windowRect.bottom - windowRect.top + 1, 0, WINDOW_HIDDEN | WINDOW_FLAG_0x02);
gInterfaceSidePanelsTrailingWindow = windowCreate(windowRect.right + 1, windowRect.top, screenGetWidth() - windowRect.right - 1, windowRect.bottom - windowRect.top + 1, 0, WINDOW_HIDDEN | WINDOW_FLAG_0x02);

char path[COMPAT_MAX_PATH];
sprintf(path, "art\\intrface\\HR_IFACELFT%d.frm", gInterfaceSidePanelsImageId);
sidePanelsDraw(path, gInterfaceSidePanelsLeadingWindow, true);

sprintf(path, "art\\intrface\\HR_IFACERHT%d.frm", gInterfaceSidePanelsImageId);
sidePanelsDraw(path, gInterfaceSidePanelsTrailingWindow, false);
}

static void sidePanelsExit()
{
if (gInterfaceSidePanelsTrailingWindow != -1) {
windowDestroy(gInterfaceSidePanelsTrailingWindow);
gInterfaceSidePanelsTrailingWindow = -1;
}

if (gInterfaceSidePanelsLeadingWindow != -1) {
windowDestroy(gInterfaceSidePanelsLeadingWindow);
gInterfaceSidePanelsLeadingWindow = -1;
}
}

static void sidePanelsHide()
{
if (gInterfaceSidePanelsLeadingWindow != -1) {
windowHide(gInterfaceSidePanelsLeadingWindow);
}

if (gInterfaceSidePanelsTrailingWindow != -1) {
windowHide(gInterfaceSidePanelsTrailingWindow);
}
}

static void sidePanelsShow()
{
if (gInterfaceSidePanelsLeadingWindow != -1) {
windowUnhide(gInterfaceSidePanelsLeadingWindow);
}

if (gInterfaceSidePanelsTrailingWindow != -1) {
windowUnhide(gInterfaceSidePanelsTrailingWindow);
}
}

static void sidePanelsDraw(const char* path, int win, bool isLeading)
{
int size;
if (dbGetFileSize(path, &size) != 0) {
return;
}

Art* image = reinterpret_cast<Art*>(internal_malloc(size));
if (image == nullptr) {
return;
}

if (artRead(path, reinterpret_cast<unsigned char*>(image)) != 0) {
internal_free(image);
return;
}

unsigned char* imageData = artGetFrameData(image, 0, 0);

int imageWidth = artGetWidth(image, 0, 0);
int imageHeight = artGetHeight(image, 0, 0);

int windowWidth = windowGetWidth(win);
int windowHeight = windowGetHeight(win);

int width = std::min(imageWidth, windowWidth);

if (!gInterfaceSidePanelsExtendFromScreenEdge && isLeading) {
imageData += imageWidth - width;
}

if (gInterfaceSidePanelsExtendFromScreenEdge && !isLeading) {
imageData += imageWidth - width;
}

blitBufferToBufferStretch(imageData,
width,
imageHeight,
imageWidth,
windowGetBuffer(win),
windowWidth,
windowHeight,
windowWidth);

internal_free(image);
}

} // namespace fallout
2 changes: 2 additions & 0 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern bool gInterfaceBarMode;
extern int gInterfaceBarWidth;
extern bool gInterfaceBarIsCustom;
extern int gInterfaceBarContentOffset;
extern int gInterfaceSidePanelsImageId;
extern bool gInterfaceSidePanelsExtendFromScreenEdge;

int interfaceInit();
void interfaceReset();
Expand Down
2 changes: 2 additions & 0 deletions src/svga.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ int _GNW95_init_mode_ex(int width, int height, int bpp)

configGetBool(&resolutionConfig, "IFACE", "IFACE_BAR_MODE", &gInterfaceBarMode);
configGetInt(&resolutionConfig, "IFACE", "IFACE_BAR_WIDTH", &gInterfaceBarWidth);
configGetInt(&resolutionConfig, "IFACE", "IFACE_BAR_SIDE_ART", &gInterfaceSidePanelsImageId);
configGetBool(&resolutionConfig, "IFACE", "IFACE_BAR_SIDES_ORI", &gInterfaceSidePanelsExtendFromScreenEdge);
}
configFree(&resolutionConfig);
}
Expand Down

0 comments on commit fa058f2

Please sign in to comment.