From da9b7322f2718a5af1f8a737798a807d315b25ce Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Thu, 21 Nov 2024 10:22:34 -0800 Subject: [PATCH] Fix combined Haiku/Qt backend build --- backends/ui/haiku/aboutwindow.cpp | 10 +++--- backends/ui/haiku/aboutwindow.h | 9 ++--- backends/ui/haiku/main_window.cpp | 36 +++++++++---------- backends/ui/haiku/main_window.h | 24 ++++++------- backends/ui/haiku/prefs.cpp | 10 +++--- backends/ui/haiku/prefs.h | 4 +-- backends/ui/haiku/slider.cpp | 60 +++++++++++++++---------------- backends/ui/haiku/slider.h | 6 ++-- backends/ui/haiku/utils.h | 2 ++ 9 files changed, 82 insertions(+), 79 deletions(-) diff --git a/backends/ui/haiku/aboutwindow.cpp b/backends/ui/haiku/aboutwindow.cpp index a751d82..34e5930 100644 --- a/backends/ui/haiku/aboutwindow.cpp +++ b/backends/ui/haiku/aboutwindow.cpp @@ -7,12 +7,12 @@ #include #include "main_window.h" #define CMD_LOAD_LICENSE 0x40 -LicenseItem::LicenseItem(const LicenseData license) : BStringItem("") { +HaikuLicenseItem::HaikuLicenseItem(const LicenseData license) : BStringItem("") { SetText(fmt::format("{} ({})", license.Project, license.Spdx).c_str()); this->license_text = license.LicenseContents; } -AboutWindow::AboutWindow() : BWindow(BRect(100, 100, 600, 400), "About Looper", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) { +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); @@ -55,14 +55,14 @@ AboutWindow::AboutWindow() : BWindow(BRect(100, 100, 600, 400), "About Looper", InvalidateLayout(true); UpdateIfNeeded(); } -void AboutWindow::Show() { +void HaikuAboutWindow::Show() { BWindow::Show(); } -bool AboutWindow::QuitRequested() { +bool HaikuAboutWindow::QuitRequested() { Hide(); return quitting; } -void AboutWindow::MessageReceived(BMessage *msg) { +void HaikuAboutWindow::MessageReceived(BMessage *msg) { if (msg->IsSystem()) return; if (msg->what == CMD_LOAD_LICENSE) { auto selection = license_list->ItemAt(msg->GetInt32("index", 0)); diff --git a/backends/ui/haiku/aboutwindow.h b/backends/ui/haiku/aboutwindow.h index b1d1944..b69b051 100644 --- a/backends/ui/haiku/aboutwindow.h +++ b/backends/ui/haiku/aboutwindow.h @@ -7,12 +7,13 @@ #include #include #include -class LicenseItem : public BStringItem { +#include "utils.h" +class HaikuLicenseItem : public BStringItem { public: std::string license_text; - LicenseItem(const LicenseData license); + HaikuLicenseItem(const LicenseData license); }; -class AboutWindow : public BWindow +class HaikuAboutWindow : public BWindow { BListView *license_list; BTextView *license_text; @@ -20,5 +21,5 @@ class AboutWindow : public BWindow bool QuitRequested() override; void Show() override; void MessageReceived(BMessage *msg) override; - AboutWindow(); + HaikuAboutWindow(); }; diff --git a/backends/ui/haiku/main_window.cpp b/backends/ui/haiku/main_window.cpp index d62ead1..4a59c5b 100644 --- a/backends/ui/haiku/main_window.cpp +++ b/backends/ui/haiku/main_window.cpp @@ -37,20 +37,20 @@ #define SLIDER_SCALE 1000 #define D(x) ((double)(x)) std::vector Subwindow::windows; -BMessage *make_slider_msg(uint32_t what, bool down) { +static BMessage *make_slider_msg(uint32_t what, bool down) { BMessage *msg = new BMessage(what); msg->SetBool(CMD_MOUSE_DOWN_KEY, down); return msg; } -bool is_slider_down_msg(BMessage *msg) { +static bool is_slider_down_msg(BMessage *msg) { return msg->HasBool(CMD_MOUSE_DOWN_KEY) && msg->GetBool(CMD_MOUSE_DOWN_KEY); } -void LooperWindow::UpdateViewFlags(BView *view) { +void HaikuLooperWindow::UpdateViewFlags(BView *view) { if (view == NULL) return; view->SetFlags(view->Flags()|B_SUPPORTS_LAYOUT|B_FRAME_EVENTS); view->SetResizingMode(B_FOLLOW_ALL_SIDES); } -void LooperWindow::UpdateViewFlags(BLayout *layout) { +void HaikuLooperWindow::UpdateViewFlags(BLayout *layout) { BView *owner = layout->Owner(); if (owner == NULL) { owner = layout->View(); @@ -60,12 +60,12 @@ void LooperWindow::UpdateViewFlags(BLayout *layout) { } UpdateViewFlags(owner); } -LooperWindow::LooperWindow(Playback *playback) : BWindow(BRect(100, 100, 500, 100), "Looper", B_TITLED_WINDOW, 0) { +HaikuLooperWindow::HaikuLooperWindow(Playback *playback) : BWindow(BRect(100, 100, 500, 100), "Looper", B_TITLED_WINDOW, 0) { pause_bitmap = load_icon(ICON_PAUSE); resume_bitmap = load_icon(ICON_PLAY); stop_bitmap = load_icon(ICON_STOP); refresh_bitmap = load_icon(ICON_REFRESH); - ref_handler = new LooperRefHandler(this); + ref_handler = new HaikuLooperRefHandler(this); this->playback = playback; float minW, minH, maxW, maxH; GetSizeLimits(&minW, &maxW, &minH, &maxH); @@ -113,24 +113,24 @@ LooperWindow::LooperWindow(Playback *playback) : BWindow(BRect(100, 100, 500, 10 stop_btn = new BButton(NULL, new BMessage(CMD_STOP)); stop_btn->SetTarget(this); top_row->AddChild(stop_btn); - volume_slider = new LooperSlider("volume", "Volume", new BMessage(CMD_VOLUME), 0, 0, 100, 1, false); + volume_slider = new HaikuLooperSlider("volume", "Volume", new BMessage(CMD_VOLUME), 0, 0, 100, 1, false); volume_slider->SetLimitLabels("Muted", "Full Volume"); volume_slider->SetTarget(this); top_row->AddChild(volume_slider); - speed_slider = new LooperSlider("speed", "Speed", new BMessage(CMD_SPEED), 0, 0.25, 4.0, 0.01, true); + speed_slider = new HaikuLooperSlider("speed", "Speed", new BMessage(CMD_SPEED), 0, 0.25, 4.0, 0.01, true); speed_slider->SetLimitLabels("0.25x", "4.00x"); speed_slider->SetTarget(this); bottom_row->AddChild(speed_slider); - tempo_slider = new LooperSlider("tempo", "Tempo", new BMessage(CMD_TEMPO), 0, 0.25, 4.0, 0.01, true); + tempo_slider = new HaikuLooperSlider("tempo", "Tempo", new BMessage(CMD_TEMPO), 0, 0.25, 4.0, 0.01, true); tempo_slider->SetLimitLabels("0.25x", "4.00x"); tempo_slider->SetTarget(this); bottom_row->AddChild(tempo_slider); - pitch_slider = new LooperSlider("pitch", "Pitch", new BMessage(CMD_PITCH), 0, 0.25, 4.0, 0.01, true); + pitch_slider = new HaikuLooperSlider("pitch", "Pitch", new BMessage(CMD_PITCH), 0, 0.25, 4.0, 0.01, true); pitch_slider->SetLimitLabels("0.25x", "4.00x"); pitch_slider->SetTarget(this); bottom_row->AddChild(pitch_slider); file_panel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this)); - auto prefs_window = new PrefsWindow(this); + auto prefs_window = new HaikuPrefsWindow(this); prefs_subwindow = Subwindow::Add(prefs_window); about_subwindow = Subwindow::Add(about_window); EnableUpdates(); @@ -147,7 +147,7 @@ LooperWindow::LooperWindow(Playback *playback) : BWindow(BRect(100, 100, 500, 10 MessageReceived(msg); delete msg; } -LooperWindow::~LooperWindow() { +HaikuLooperWindow::~HaikuLooperWindow() { delete ref_handler; delete pause_bitmap; delete resume_bitmap; @@ -158,7 +158,7 @@ LooperWindow::~LooperWindow() { update_thread->join(); delete update_thread; } -void LooperWindow::MessageReceived(BMessage *msg) { +void HaikuLooperWindow::MessageReceived(BMessage *msg) { SDL_Event ev; while (SDL_PollEvent(&ev)) { if (ev.type == SDL_DROPFILE) { @@ -279,7 +279,7 @@ void LooperWindow::MessageReceived(BMessage *msg) { } break; }; } -void LooperWindow::Pulse() { +void HaikuLooperWindow::Pulse() { auto len = playback->GetLength(); auto pos = playback->GetPosition(); auto pos_milliseconds = pos * 1000.0; @@ -316,12 +316,12 @@ void LooperWindow::Pulse() { tempo_slider->SetLabel(fmt::format("Tempo: {:.02f}x", tempo).c_str()); UpdateIfNeeded(); } -void LooperWindow::FrameResized(float newWidth, float newHeight) { +void HaikuLooperWindow::FrameResized(float newWidth, float newHeight) { InvalidateLayout(true); Layout(true); layout->SetExplicitSize(BSize(newWidth, newHeight)); } -void LooperWindow::ThreadFunc() { +void HaikuLooperWindow::ThreadFunc() { while (true) { if (done) return; if (Lock()) { @@ -349,7 +349,7 @@ void LooperWindow::ThreadFunc() { std::this_thread::sleep_for(1s / 60.0); } } -LooperRefHandler::LooperRefHandler(LooperWindow *win) { +HaikuLooperRefHandler::HaikuLooperRefHandler(LooperWindow *win) { this->win = win; be_app->Lock(); this->next_handler = be_app->PreferredHandler(); @@ -361,7 +361,7 @@ LooperRefHandler::LooperRefHandler(LooperWindow *win) { AddFilter(new BMessageFilter(B_REFS_RECEIVED)); be_app->Unlock(); } -void LooperRefHandler::MessageReceived(BMessage *msg) { +void HaikuLooperRefHandler::MessageReceived(BMessage *msg) { if (msg->what == B_REFS_RECEIVED) { win->PostMessage(msg); } diff --git a/backends/ui/haiku/main_window.h b/backends/ui/haiku/main_window.h index d1b7966..ac6cc6b 100644 --- a/backends/ui/haiku/main_window.h +++ b/backends/ui/haiku/main_window.h @@ -39,8 +39,8 @@ class Subwindow { Showing.store(true); } }; -class LooperRefHandler; -class LooperWindow : public BWindow { +class HaikuLooperRefHandler; +class HaikuLooperWindow : public BWindow { BSlider *slider; BBitmap *pause_bitmap; BBitmap *resume_bitmap; @@ -64,12 +64,12 @@ class LooperWindow : public BWindow { bool seek_clicked = false; void UpdateViewFlags(BView *view); void UpdateViewFlags(BLayout *layout); - LooperSlider *volume_slider; - LooperSlider *speed_slider; + HaikuLooperSlider *volume_slider; + HaikuLooperSlider *speed_slider; BFilePanel *file_panel; - LooperSlider *pitch_slider; - LooperSlider *tempo_slider; - LooperRefHandler *ref_handler; + HaikuLooperSlider *pitch_slider; + HaikuLooperSlider *tempo_slider; + HaikuLooperRefHandler *ref_handler; std::thread *update_thread = nullptr; bool done = false; void Pulse(); @@ -80,13 +80,13 @@ public: Subwindow *prefs_subwindow; void FrameResized(float newWidth, float newHeight) override; void MessageReceived(BMessage *msg) override; - LooperWindow(Playback *playback); - ~LooperWindow(); + HaikuLooperWindow(Playback *playback); + ~HaikuLooperWindow(); }; -class LooperRefHandler : public BHandler { - LooperWindow *win; +class HaikuLooperRefHandler : public BHandler { + HaikuLooperWindow *win; BHandler *next_handler; public: void MessageReceived(BMessage *msg) override; - LooperRefHandler(LooperWindow *win); + HaikuLooperRefHandler(HaikuLooperWindow *win); }; diff --git a/backends/ui/haiku/prefs.cpp b/backends/ui/haiku/prefs.cpp index 2e629f9..8677fc2 100644 --- a/backends/ui/haiku/prefs.cpp +++ b/backends/ui/haiku/prefs.cpp @@ -15,7 +15,7 @@ using namespace Looper::Options; #define CMD_APPLY 0x1004 bool show_icons, show_labels; -PrefsWindow::PrefsWindow(BLooper *next_handler) : BWindow(BRect(100, 100, 0, 0), "Preferences", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) { +HaikuPrefsWindow::HaikuPrefsWindow(BLooper *next_handler) : BWindow(BRect(100, 100, 0, 0), "Preferences", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) { this->next_handler = next_handler; auto *root_layout = new BGroupLayout(B_VERTICAL); SetLayout(root_layout); @@ -72,15 +72,15 @@ PrefsWindow::PrefsWindow(BLooper *next_handler) : BWindow(BRect(100, 100, 0, 0), } } -bool PrefsWindow::QuitRequested() { +bool HaikuPrefsWindow::QuitRequested() { Hide(); return quitting; } -void PrefsWindow::set_options_changed(bool changed) { +void HaikuPrefsWindow::set_options_changed(bool changed) { revert_btn->SetEnabled(changed); apply_btn->SetEnabled(changed); } -void PrefsWindow::update_label_setting() { +void HaikuPrefsWindow::update_label_setting() { std::map label_settings_map({{"labels", labels_only}, {"icons", icons_only}, {"both", both_labels_icons}}); auto cur_radio_btn = labels_only; @@ -92,7 +92,7 @@ void PrefsWindow::update_label_setting() { show_labels = new_label_setting != "icons"; cur_radio_btn->SetValue(B_CONTROL_ON); } -void PrefsWindow::MessageReceived(BMessage *msg) { +void HaikuPrefsWindow::MessageReceived(BMessage *msg) { if (msg->IsSystem()) return; switch (msg->what) { case CMD_APPLY: { diff --git a/backends/ui/haiku/prefs.h b/backends/ui/haiku/prefs.h index 29de9de..eaa8fd4 100644 --- a/backends/ui/haiku/prefs.h +++ b/backends/ui/haiku/prefs.h @@ -13,7 +13,7 @@ #include #include #include -class PrefsWindow : public BWindow { +class HaikuPrefsWindow : public BWindow { std::vector backend_ids; int32 cur_option = 0; BLooper *next_handler; @@ -32,5 +32,5 @@ class PrefsWindow : public BWindow { public: bool QuitRequested() override; void MessageReceived(BMessage *msg) override; - PrefsWindow(BLooper *next_handler); + HaikuPrefsWindow(BLooper *next_handler); }; diff --git a/backends/ui/haiku/slider.cpp b/backends/ui/haiku/slider.cpp index be8bf47..c7a1495 100644 --- a/backends/ui/haiku/slider.cpp +++ b/backends/ui/haiku/slider.cpp @@ -14,10 +14,10 @@ #define CMD_SLIDER_CHANGED 0x92 #define CMD_CHANGE_MODE 0x93 using namespace BPrivate; -void LooperSlider::UpdateLogScaler() { +void HaikuLooperSlider::UpdateLogScaler() { scaler->update_min_max(min, max); } -void LooperSlider::UpdateSlider(bool update_value) { +void HaikuLooperSlider::UpdateSlider(bool update_value) { if (recreate_slider) { if (slider != NULL) { if (!text_edit_mode) text_layout->RemoveView(slider); @@ -53,39 +53,39 @@ void LooperSlider::UpdateSlider(bool update_value) { } recreate_slider = false; } -void LooperSlider::set_min(double min) { +void HaikuLooperSlider::set_min(double min) { this->min = min; recreate_slider = true; } -void LooperSlider::set_max(double max) { +void HaikuLooperSlider::set_max(double max) { this->max = max; recreate_slider = true; } -void LooperSlider::SetMinLabel(const char *label) { +void HaikuLooperSlider::SetMinLabel(const char *label) { if (min_label != NULL) free((void*)min_label); min_label = label == NULL ? NULL : strdup(label); UpdateSlider(); } -void LooperSlider::SetMaxLabel(const char *label) { +void HaikuLooperSlider::SetMaxLabel(const char *label) { if (max_label != NULL) free((void*)max_label); max_label = label == NULL ? NULL : strdup(label); UpdateSlider(); } -void LooperSlider::set_tick(double value) { +void HaikuLooperSlider::set_tick(double value) { this->tick = value; recreate_slider = true; } -const char *LooperSlider::MinLabel() { +const char *HaikuLooperSlider::MinLabel() { return min_label; } -const char *LooperSlider::MaxLabel() { +const char *HaikuLooperSlider::MaxLabel() { return max_label; } -void LooperSlider::SetLimitLabels(const char *min, const char *max) { +void HaikuLooperSlider::SetLimitLabels(const char *min, const char *max) { SetMinLabel(min); SetMaxLabel(max); } -LooperSlider::~LooperSlider() { +HaikuLooperSlider::~LooperSlider() { if (min_label != NULL) free((void*)min_label); if (max_label != NULL) free((void*)max_label); delete slider; @@ -95,41 +95,41 @@ LooperSlider::~LooperSlider() { delete text_mode_bitmap; delete slider_mode_bitmap; } -void LooperSlider::SetMin(double min) { +void HaikuLooperSlider::SetMin(double min) { set_min(min); UpdateSlider(); } -void LooperSlider::SetMax(double max) { +void HaikuLooperSlider::SetMax(double max) { set_max(max); UpdateSlider(); } -double LooperSlider::Min() { +double HaikuLooperSlider::Min() { return min; } -double LooperSlider::Max() { +double HaikuLooperSlider::Max() { return max; } -void LooperSlider::SetLimits(double min, double max) { +void HaikuLooperSlider::SetLimits(double min, double max) { set_min(min); set_max(max); UpdateSlider(); } -void LooperSlider::SetTick(double value) { +void HaikuLooperSlider::SetTick(double value) { set_tick(value); UpdateSlider(); } -double LooperSlider::Tick() { +double HaikuLooperSlider::Tick() { return tick; } -void LooperSlider::SetLogarithmic(bool logarithmic) { +void HaikuLooperSlider::SetLogarithmic(bool logarithmic) { this->logarithmic = logarithmic; recreate_slider = true; UpdateSlider(true); } -bool LooperSlider::IsLogarithmic() { +bool HaikuLooperSlider::IsLogarithmic() { return this->logarithmic; } -void LooperSlider::MessageReceived(BMessage *msg) { +void HaikuLooperSlider::MessageReceived(BMessage *msg) { switch (msg->what) { case CMD_SLIDER_MOVED: case CMD_SLIDER_CHANGED: { @@ -193,35 +193,35 @@ void LooperSlider::MessageReceived(BMessage *msg) { } break; } } -void LooperSlider::SendChangeMsg() { +void HaikuLooperSlider::SendChangeMsg() { BMessage *msg = change_msg; msg->SetDouble("be:value", this->value); msg->SetBool("catmeow:pressed", pressed); Invoke(msg); } -void LooperSlider::SetValue(int32 value) { +void HaikuLooperSlider::SetValue(int32 value) { SetValueDouble(value * tick); } -void LooperSlider::SetValueDouble(double value) { +void HaikuLooperSlider::SetValueDouble(double value) { this->value = value; BControl::SetValue(std::round(value / tick)); UpdateSlider(true); } -double LooperSlider::ValueDouble() { +double HaikuLooperSlider::ValueDouble() { return this->value; } -void LooperSlider::SetLabel(const char *label) { +void HaikuLooperSlider::SetLabel(const char *label) { this->label = label; text_label->SetText(label); } -void LooperSlider::set_logarithmic(bool logarithmic) { +void HaikuLooperSlider::set_logarithmic(bool logarithmic) { this->logarithmic = logarithmic; recreate_slider = true; } -void LooperSlider::SetValueChangedMsg(BMessage *msg) { +void HaikuLooperSlider::SetValueChangedMsg(BMessage *msg) { this->change_msg = msg; } -LooperSlider::LooperSlider(const char *name, const char *label, BMessage *msg, uint32_t flags, double min, double max, double tick, bool logarithmic) : BControl(name, label, msg, flags) { +HaikuLooperSlider::HaikuLooperSlider(const char *name, const char *label, BMessage *msg, uint32_t flags, double min, double max, double tick, bool logarithmic) : BControl(name, label, msg, flags) { scaler = new LooperLogScaler(min, max); text_mode_bitmap = load_icon(ICON_EDIT_TEXT); slider_mode_bitmap = load_icon(ICON_EDIT_SLIDER); @@ -263,7 +263,7 @@ LooperSlider::LooperSlider(const char *name, const char *label, BMessage *msg, u SetLabel(label); InvalidateLayout(true); } -void LooperSlider::AttachedToWindow() { +void HaikuLooperSlider::AttachedToWindow() { { BMessage *msg = make_self_msg(CMD_CHANGE_MODE); MessageReceived(msg); diff --git a/backends/ui/haiku/slider.h b/backends/ui/haiku/slider.h index 286ddf0..5b7f52f 100644 --- a/backends/ui/haiku/slider.h +++ b/backends/ui/haiku/slider.h @@ -10,7 +10,7 @@ #include #include class LooperLogScaler; -class LooperSlider : public BControl { +class HaikuLooperSlider : public BControl { inline BMessage *make_self_msg(int32 what) { auto output = new BMessage(what); output->AddPointer("catmeow:target", this); @@ -70,6 +70,6 @@ class LooperSlider : public BControl { void SetValueChangedMsg(BMessage *msg); void MessageReceived(BMessage *msg) override; void AttachedToWindow() override; - LooperSlider(const char *name, const char *label, BMessage *msg, uint32_t flags, double min, double max, double tick = 0.0001, bool logarithmic = false); - ~LooperSlider(); + HaikuLooperSlider(const char *name, const char *label, BMessage *msg, uint32_t flags, double min, double max, double tick = 0.0001, bool logarithmic = false); + ~HaikuLooperSlider(); }; diff --git a/backends/ui/haiku/utils.h b/backends/ui/haiku/utils.h index 56977d3..5574f3a 100644 --- a/backends/ui/haiku/utils.h +++ b/backends/ui/haiku/utils.h @@ -30,3 +30,5 @@ inline BBitmap *get_empty_icon() { } return empty_icon; } + +#define CLASS(name) class Haiku##name \ No newline at end of file