looper/backends/ui/haiku/aboutwindow.cpp
Zachary Hall 1756fb40a1
Some checks failed
Build / build-appimage (push) Successful in 3m21s
Build / build-android (push) Failing after 2m52s
Build / build-gentoo (push) Failing after 1m14s
Build / download-system-deps (push) Successful in 3m29s
Build / get-source-code (push) Successful in 7m1s
Build / build-windows (push) Failing after 6m40s
Fix Haiku backend build
2024-11-21 10:43:50 -08:00

74 lines
3.2 KiB
C++

#include "aboutwindow.h"
#include <SplitView.h>
#include <license.hpp>
#include <GroupLayout.h>
#include <SplitView.h>
#include <StringView.h>
#include <ScrollView.h>
#include "main_window.h"
#define CMD_LOAD_LICENSE 0x40
HaikuLicenseItem::HaikuLicenseItem(const LicenseData license) : BStringItem("") {
SetText(fmt::format("{} ({})", license.Project, license.Spdx).c_str());
this->license_text = license.LicenseContents;
}
HaikuAboutWindow::HaikuAboutWindow() : BWindow(BRect(100, 100, 600, 400), "About Looper", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) {
BGroupLayout *root_layout = new BGroupLayout(B_VERTICAL);
float minW, minH, maxW, maxH;
GetSizeLimits(&minW, &maxW, &minH, &maxH);
SetLayout(root_layout);
root_layout->SetSpacing(0.0);
BFont *title_font = new BFont();
title_font->SetSize(title_font->Size() * 4.0);
BStringView *looper_title = new BStringView("about:title", "Looper");
looper_title->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
looper_title->SetFont(title_font);
float title_height, version_height;
looper_title->GetPreferredSize(NULL, &title_height);
looper_title->SetExplicitMaxSize(BSize(maxW, title_height));
looper_title->ResizeToPreferred();
BStringView *version_text = new BStringView("about:version_text", fmt::format("Version {}", TAG).c_str());
version_text->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
version_text->GetPreferredSize(NULL, &version_height);
version_text->SetExplicitMaxSize(BSize(maxW, version_height));
version_text->ResizeToPreferred();
BLayoutItem *title_item = root_layout->AddView(looper_title);
BLayoutItem *version_item = root_layout->AddView(version_text);
title_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
version_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
BSplitView *view = new BSplitView();
view->SetExplicitMaxSize(BSize(maxW, maxH));
root_layout->AddView(view);
license_list = new BListView();
license_list->SetTarget(this);
for (auto &license : get_license_data()) {
license_list->AddItem(new HaikuLicenseItem(license));
}
license_list->SetSelectionMessage(new BMessage(CMD_LOAD_LICENSE));
BScrollView *license_list_scroller = new BScrollView("about:license-list-scroller", license_list, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
license_text = new BTextView("about:license-text");
license_text->MakeEditable(false);
BScrollView *license_text_scroller = new BScrollView("about:license-text-scroller", license_text, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
view->AddChild(license_list_scroller);
view->AddChild(license_text_scroller);
license_list->Select(0);
InvalidateLayout(true);
UpdateIfNeeded();
}
void HaikuAboutWindow::Show() {
BWindow::Show();
}
bool HaikuAboutWindow::QuitRequested() {
Hide();
return quitting;
}
void HaikuAboutWindow::MessageReceived(BMessage *msg) {
if (msg->IsSystem()) return;
if (msg->what == CMD_LOAD_LICENSE) {
auto selection = license_list->ItemAt(msg->GetInt32("index", 0));
std::string str = ((HaikuLicenseItem*)selection)->license_text;
license_text->SetText(str.c_str());
}
}