Use custom image view widget in Haiku frontend
Some checks failed
Build / get-source-code (push) Blocked by required conditions
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / build-gentoo (push) Failing after 1m16s
Build / download-system-deps (push) Has been cancelled
Some checks failed
Build / get-source-code (push) Blocked by required conditions
Build / build-deb (push) Blocked by required conditions
Build / build-appimage (push) Blocked by required conditions
Build / build-android (push) Blocked by required conditions
Build / build-windows (push) Blocked by required conditions
Build / build-gentoo (push) Failing after 1m16s
Build / download-system-deps (push) Has been cancelled
This commit is contained in:
parent
b0bfa7945f
commit
83ecc38fce
6 changed files with 111 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
set(BACKEND_HAIKU_SRC_BASE main.cpp main_window.cpp prefs.cpp slider.cpp slider.h main.h main_window.h aboutwindow.h aboutwindow.cpp prefs.h)
|
set(BACKEND_HAIKU_SRC_BASE main.cpp main_window.cpp prefs.cpp slider.cpp slider.h main.h main_window.h aboutwindow.h aboutwindow.cpp prefs.h image_view.cpp image_view.h)
|
||||||
set(BACKEND_HAIKU_SRC )
|
set(BACKEND_HAIKU_SRC )
|
||||||
foreach(SRC IN ITEMS ${BACKEND_HAIKU_SRC_BASE})
|
foreach(SRC IN ITEMS ${BACKEND_HAIKU_SRC_BASE})
|
||||||
set(BACKEND_HAIKU_SRC ${BACKEND_HAIKU_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
|
set(BACKEND_HAIKU_SRC ${BACKEND_HAIKU_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
|
||||||
|
|
80
backends/ui/haiku/image_view.cpp
Normal file
80
backends/ui/haiku/image_view.cpp
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
#include "image_view.h"
|
||||||
|
|
||||||
|
|
||||||
|
LImageView::LImageView(const char *name, BBitmap *bitmap, BAlignment align) : BView(name)
|
||||||
|
{
|
||||||
|
SetBitmap(bitmap);
|
||||||
|
SetAlignment(align);
|
||||||
|
}
|
||||||
|
void LImageView::SetBitmap(BBitmap *bitmap) {
|
||||||
|
this->bitmap = bitmap;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
void LImageView::SetAlignment(BAlignment align) {
|
||||||
|
this->align = align;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
BBitmap *LImageView::Bitmap() {
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
BAlignment LImageView::Alignment() {
|
||||||
|
return align;
|
||||||
|
}
|
||||||
|
void LImageView::Draw(BRect updateRect) {
|
||||||
|
if (bitmap == NULL) return; // Handle null image.
|
||||||
|
int x = 0, y = 0;
|
||||||
|
int mw, mh;
|
||||||
|
int bw, bh;
|
||||||
|
bw = bitmap->Bounds().Width();
|
||||||
|
bh = bitmap->Bounds().Height();
|
||||||
|
mw = Bounds().Width();
|
||||||
|
mh = Bounds().Height();
|
||||||
|
switch (align.Horizontal()) {
|
||||||
|
case B_ALIGN_LEFT: {
|
||||||
|
x = 0;
|
||||||
|
} break;
|
||||||
|
case B_ALIGN_HORIZONTAL_CENTER: {
|
||||||
|
x = (mw - bw) / 2;
|
||||||
|
} break;
|
||||||
|
case B_ALIGN_RIGHT: {
|
||||||
|
x = mw - bw;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
switch (align.Vertical()) {
|
||||||
|
case B_ALIGN_TOP: {
|
||||||
|
y = 0;
|
||||||
|
} break;
|
||||||
|
case B_ALIGN_VERTICAL_CENTER: {
|
||||||
|
y = (mh - bh) / 2;
|
||||||
|
} break;
|
||||||
|
case B_ALIGN_BOTTOM: {
|
||||||
|
y = mh - bh;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
BRect bitmap_rect(0, 0, bw, bh);
|
||||||
|
BRect draw_rect(x, y, bw + x, bh + y);
|
||||||
|
int left = updateRect.left;
|
||||||
|
int right = updateRect.right;
|
||||||
|
int top = updateRect.top;
|
||||||
|
int bottom = updateRect.bottom;
|
||||||
|
int x2 = x + bw;
|
||||||
|
int y2 = y + bh;
|
||||||
|
if (x > right || x2 < left || y > bottom || y2 < top) return;
|
||||||
|
if (x < left) {
|
||||||
|
bitmap_rect.left = left - x;
|
||||||
|
draw_rect.left = left;
|
||||||
|
}
|
||||||
|
if (x2 > right) {
|
||||||
|
bitmap_rect.right = right - x;
|
||||||
|
draw_rect.right = right;
|
||||||
|
}
|
||||||
|
if (y < top) {
|
||||||
|
bitmap_rect.top = top - y;
|
||||||
|
draw_rect.top = top;
|
||||||
|
}
|
||||||
|
if (y2 > bottom) {
|
||||||
|
bitmap_rect.bottom = bottom - y;
|
||||||
|
draw_rect.bottom = bottom;
|
||||||
|
}
|
||||||
|
DrawBitmap(bitmap, bitmap_rect, draw_rect);
|
||||||
|
}
|
17
backends/ui/haiku/image_view.h
Normal file
17
backends/ui/haiku/image_view.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
#include <View.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <Alignment.h>
|
||||||
|
#include <Rect.h>
|
||||||
|
|
||||||
|
class LImageView : public BView {
|
||||||
|
BBitmap *bitmap;
|
||||||
|
BAlignment align;
|
||||||
|
public:
|
||||||
|
void SetBitmap(BBitmap *bitmap);
|
||||||
|
BBitmap *Bitmap();
|
||||||
|
void SetAlignment(BAlignment align);
|
||||||
|
BAlignment Alignment();
|
||||||
|
void Draw(BRect updateRect) override;
|
||||||
|
LImageView(const char *name, BBitmap *bitmap, BAlignment align);
|
||||||
|
};
|
|
@ -97,7 +97,7 @@ HaikuLooperWindow::HaikuLooperWindow(Playback *playback) : BWindow(BRect(100, 10
|
||||||
menu_bar->AddItem(file_menu);
|
menu_bar->AddItem(file_menu);
|
||||||
menu_bar->AddItem(help_menu);
|
menu_bar->AddItem(help_menu);
|
||||||
layout->AddView(menu_bar);
|
layout->AddView(menu_bar);
|
||||||
spacer = new BView("spacer", B_SUPPORTS_LAYOUT|B_FRAME_EVENTS);
|
spacer = new LImageView("spacer", NULL, BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM));
|
||||||
spacer->SetExplicitPreferredSize(BSize(0, 0));
|
spacer->SetExplicitPreferredSize(BSize(0, 0));
|
||||||
spacer->SetExplicitMinSize(BSize(0, 0));
|
spacer->SetExplicitMinSize(BSize(0, 0));
|
||||||
layout->AddView(spacer);
|
layout->AddView(spacer);
|
||||||
|
@ -184,9 +184,9 @@ void HaikuLooperWindow::UpdateCat(BBitmap *cat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BRect dst(sw - w, sh - h, w, h);
|
BRect dst(sw - w, sh - h, w, h);
|
||||||
spacer->SetViewOverlay(cat, src, dst, NULL, B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM);
|
spacer->SetBitmap(cat);
|
||||||
} else {
|
} else {
|
||||||
spacer->ClearViewOverlay();
|
spacer->SetBitmap(NULL);
|
||||||
}
|
}
|
||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "aboutwindow.h"
|
#include "aboutwindow.h"
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
|
#include "image_view.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <util.hpp>
|
#include <util.hpp>
|
||||||
#define CMD_UPDATE_LABEL_SETTING 0x1000
|
#define CMD_UPDATE_LABEL_SETTING 0x1000
|
||||||
|
@ -59,7 +60,7 @@ class HaikuLooperWindow : public BWindow {
|
||||||
BButton *restart_btn;
|
BButton *restart_btn;
|
||||||
BButton *stop_btn;
|
BButton *stop_btn;
|
||||||
BButton *pause_resume_btn;
|
BButton *pause_resume_btn;
|
||||||
BView *spacer;
|
LImageView *spacer;
|
||||||
void UpdateCat(BBitmap *cat);
|
void UpdateCat(BBitmap *cat);
|
||||||
bool volume_clicked = false;
|
bool volume_clicked = false;
|
||||||
bool speed_clicked = false;
|
bool speed_clicked = false;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "main_window.h"
|
#include "main_window.h"
|
||||||
#include <cats.hpp>
|
#include <cats.hpp>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
#include "image_view.h"
|
||||||
using namespace Looper::Options;
|
using namespace Looper::Options;
|
||||||
#define CMD_UPDATE_LABEL_SETTING 0x1000
|
#define CMD_UPDATE_LABEL_SETTING 0x1000
|
||||||
#define CMD_FRONTEND 0x1001
|
#define CMD_FRONTEND 0x1001
|
||||||
|
@ -101,7 +102,8 @@ HaikuPrefsWindow::HaikuPrefsWindow(BLooper *next_handler) : BWindow(BRect(100, 1
|
||||||
BMessage *msg = new BMessage(CMD_SET_SETTING);
|
BMessage *msg = new BMessage(CMD_SET_SETTING);
|
||||||
msg->AddString("pref_path", "ui.cat");
|
msg->AddString("pref_path", "ui.cat");
|
||||||
msg->AddString("pref_value", kv.first.c_str());
|
msg->AddString("pref_value", kv.first.c_str());
|
||||||
BRadioButton *cat_radio = new BRadioButton(fmt::format("prefs:cat:{}", kv.first).c_str(), msg);
|
BGroupView *cat_row = new BGroupView(B_HORIZONTAL);
|
||||||
|
BRadioButton *cat_radio = new BRadioButton(kv.first.c_str(), msg);
|
||||||
cat_btns[kv.first] = cat_radio;
|
cat_btns[kv.first] = cat_radio;
|
||||||
BBitmap *cat_bmp = kv.second;
|
BBitmap *cat_bmp = kv.second;
|
||||||
BRect src = cat_bmp->Bounds();
|
BRect src = cat_bmp->Bounds();
|
||||||
|
@ -119,14 +121,14 @@ HaikuPrefsWindow::HaikuPrefsWindow(BLooper *next_handler) : BWindow(BRect(100, 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BRect dst(rw - w, (rh - h) / 2, rw, rh);
|
BRect dst(rw - w, (rh - h) / 2, rw, rh);
|
||||||
LockLooper();
|
LImageView *img_view = new LImageView("prefs:cat:preview", cat_bmp, BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM));
|
||||||
cat_radio->SetViewOverlay(cat_bmp, src, dst, NULL, B_FOLLOW_RIGHT|B_FOLLOW_TOP_BOTTOM);
|
cat_row->AddChild(cat_radio);
|
||||||
UnlockLooper();
|
cat_row->AddChild(img_view);
|
||||||
cat_layout->AddView(cat_radio);
|
cat_layout->AddView(cat_row);
|
||||||
}
|
}
|
||||||
root_layout->AddView(box, 3.0);
|
root_layout->AddView(box, 3.0);
|
||||||
cat_box->AddChild(cat_group);
|
cat_box->AddChild(cat_group);
|
||||||
root_layout->AddView(cat_enable);
|
root_layout->AddView(cat_enable, 1.0);
|
||||||
root_layout->AddView(cat_box, 3.0);
|
root_layout->AddView(cat_box, 3.0);
|
||||||
BGroupView *btn_view = new BGroupView(B_HORIZONTAL);
|
BGroupView *btn_view = new BGroupView(B_HORIZONTAL);
|
||||||
BGroupLayout *btn_box = btn_view->GroupLayout();
|
BGroupLayout *btn_box = btn_view->GroupLayout();
|
||||||
|
|
Loading…
Reference in a new issue