mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Add new Console Icons to GUI
This commit is contained in:
parent
673a2de9c1
commit
7dd26f974f
13 changed files with 222 additions and 110 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
struct DiscoveryHost
|
||||
{
|
||||
bool ps5;
|
||||
ChiakiDiscoveryHostState state;
|
||||
uint16_t host_request_port;
|
||||
#define STRING_MEMBER(name) QString name;
|
||||
|
|
|
@ -22,6 +22,8 @@ struct DisplayServer
|
|||
bool registered;
|
||||
|
||||
QString GetHostAddr() const { return discovered ? discovery_host.host_addr : manual_host.GetHost(); }
|
||||
bool IsPS5() const { return discovered ? discovery_host.ps5 :
|
||||
(registered ? chiaki_target_is_ps5(registered_host.GetTarget()) : false); }
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
|
|
|
@ -6,13 +6,18 @@
|
|||
#include <chiaki/discovery.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
class ServerIconWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool ps5 = false;
|
||||
ChiakiDiscoveryHostState state = CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN;
|
||||
QSvgRenderer svg_renderer;
|
||||
|
||||
void LoadSvg();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
@ -20,7 +25,7 @@ class ServerIconWidget : public QWidget
|
|||
public:
|
||||
explicit ServerIconWidget(QWidget *parent = nullptr);
|
||||
|
||||
void SetState(ChiakiDiscoveryHostState state) { this->state = state; update(); }
|
||||
void SetState(bool ps5, ChiakiDiscoveryHostState state);
|
||||
};
|
||||
|
||||
#endif // CHIAKI_SERVERICONWIDGET_H
|
||||
|
|
43
gui/res/console-ps4.svg
Normal file
43
gui/res/console-ps4.svg
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="512"
|
||||
height="86"
|
||||
viewBox="0 0 135.46666 22.754167"
|
||||
version="1.1"
|
||||
id="svg965">
|
||||
<defs
|
||||
id="defs959" />
|
||||
<metadata
|
||||
id="metadata962">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1"
|
||||
transform="translate(0,-274.24582)">
|
||||
<path
|
||||
id="light_standby"
|
||||
d="m 7.9302857,283.67047 -2.3238588,3.90561 c 40.8387811,5.10156 81.4752601,4.92996 121.9292031,0 l 2.32387,-3.90561 c -41.598755,-4.20777 -82.184535,-3.9555 -121.9292143,0 z"
|
||||
style="fill:#ffae2f;fill-opacity:1;stroke:none;stroke-width:16.7939;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
id="light_on"
|
||||
d="m 7.9302857,283.67047 -2.3238588,3.90561 c 40.8387811,5.10156 81.4752601,4.92996 121.9292031,0 l 2.32387,-3.90561 c -41.598755,-4.20777 -82.184535,-3.9555 -121.9292143,0 z"
|
||||
style="fill:#00a7ff;fill-opacity:1;stroke:none;stroke-width:16.7939;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:16.7939;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 13.537456,274.24582 -5.6071703,9.42465 H 129.85949 l 5.60718,-9.42465 z M 5.6064269,287.57608 -3.729265e-7,296.99999 H 121.9292 l 5.60644,-9.42391 z"
|
||||
id="console" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
42
gui/res/console-ps5.svg
Normal file
42
gui/res/console-ps5.svg
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="512"
|
||||
height="136"
|
||||
viewBox="0 0 135.46666 35.983334"
|
||||
version="1.1"
|
||||
id="svg965">
|
||||
<defs
|
||||
id="defs959" />
|
||||
<metadata
|
||||
id="metadata962">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
id="layer1">
|
||||
<path
|
||||
style="display:inline;fill:#ffae2f;fill-opacity:1;stroke:none;stroke-width:0.264483;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 1.90851,11.7633 V 8.78962 L 127.635,1.80686 V 29.5406 L 1.90851,22.9017 v -3.1579 l 6.69123,-3.6455 z"
|
||||
id="light_standby" />
|
||||
<path
|
||||
style="display:inline;fill:#00a7ff;fill-opacity:1;stroke:none;stroke-width:0.264483;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 1.90851,11.7633 V 8.78962 L 127.635,1.80686 V 29.5406 L 1.90851,22.9017 v -3.1579 l 6.69123,-3.6455 z"
|
||||
id="light_on" />
|
||||
<path
|
||||
id="console"
|
||||
style="display:inline;fill:#000000;stroke:none;stroke-width:0.264483;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 135.059,0.00361735 C 105.38,2.67905 69.7613,6.71862 7.63725,2.23759 2.36805,1.85752 -2.0101,10.5297 0.965315,10.4913 65.3799,9.66192 117.287,1.77461 124.96,2.9347 c 1.336,0.20209 1.574,0.63399 2.277,3.27111 0.014,0.05608 0.023,0.07751 0.037,0.12971 C 127.222,6.33518 127.18,6.33367 127.127,6.33346 111.134,6.26936 42.5958,12.2796 1.90841,11.7636 V 19.744 C 42.7269,19.2263 111.141,25.2757 127.21,25.1721 c -0.021,0.0757 -0.034,0.1108 -0.056,0.1953 -0.703,2.6371 -0.941,3.069 -2.278,3.2711 C 117.203,29.7986 65.8099,22.0167 1.39526,21.1873 0.890231,21.1808 0.0271625,21.6584 0.0697631,22.3945 0.299552,26.3647 0.436565,35.8186 1.11931,35.8195 c 9.35179,0.0128 30.51999,0.601 40.77269,-0.5323 18.7057,-2.0678 32.929,-4.7279 44.5021,-5.3898 21.5319,-1.2316 33.9069,0.0527 48.5829,1.6722 0.933,0.103 0.031,-1.2457 -0.448,-1.2407 -1.987,0.0225 -4.222,-2.7307 -6.798,-4.992 -0.019,-0.0164 -0.028,-0.0822 -0.032,-0.1741 1.321,-0.0216 2.268,-0.0875 2.695,-0.2171 V 16.0465 15.4616 6.56238 c -0.424,-0.12876 -1.327,-0.19659 -2.607,-0.21859 0.006,-0.05334 0.013,-0.09568 0.027,-0.10749 2.576,-2.26123 4.811,-5.01452 6.797,-4.99193 0.479,0.005 1.384,-1.3250825 0.448,-1.24075265 z" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
|
@ -5,5 +5,7 @@
|
|||
<file>discover-24px.svg</file>
|
||||
<file>discover-off-24px.svg</file>
|
||||
<file>chiaki.svg</file>
|
||||
<file>console-ps4.svg</file>
|
||||
<file>console-ps5.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -129,6 +129,7 @@ static void DiscoveryServiceHostsCallback(ChiakiDiscoveryHost *hosts, size_t hos
|
|||
{
|
||||
ChiakiDiscoveryHost *h = hosts + i;
|
||||
DiscoveryHost o = {};
|
||||
o.ps5 = chiaki_discovery_host_is_ps5(h);
|
||||
o.state = h->state;
|
||||
o.host_request_port = o.host_request_port;
|
||||
#define CONVERT_STRING(name) if(h->name) { o.name = QString::fromLocal8Bit(h->name); }
|
||||
|
|
|
@ -7,73 +7,87 @@
|
|||
|
||||
ServerIconWidget::ServerIconWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
LoadSvg();
|
||||
}
|
||||
|
||||
void ServerIconWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
static const float icon_aspect = 100.0f / 17.0f;
|
||||
static const float coolness = 0.585913713f;
|
||||
|
||||
if(width() == 0 || height() == 0)
|
||||
QRectF view_box = svg_renderer.viewBoxF();
|
||||
if(view_box.width() < 0.00001f || view_box.height() < 0.00001f)
|
||||
return;
|
||||
float icon_aspect = view_box.width() / view_box.height();
|
||||
float widget_aspect = (float)width() / (float)height();
|
||||
QRectF icon_rect;
|
||||
if(widget_aspect > icon_aspect)
|
||||
{
|
||||
icon_rect.setHeight(height());
|
||||
icon_rect.setWidth((float)height() * icon_aspect);
|
||||
icon_rect.moveTop(0.0f);
|
||||
icon_rect.moveLeft(((float)width() - icon_rect.width()) * 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
icon_rect.setWidth(width());
|
||||
icon_rect.setHeight((float)width() / icon_aspect);
|
||||
icon_rect.moveLeft(0.0f);
|
||||
icon_rect.moveTop(((float)height() - icon_rect.height()) * 0.5f);
|
||||
}
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QRectF icon_rect;
|
||||
float widget_aspect = (float)width() / (float)height();
|
||||
if(widget_aspect > icon_aspect)
|
||||
{
|
||||
icon_rect.setHeight(height());
|
||||
icon_rect.setWidth((float)height() * icon_aspect);
|
||||
icon_rect.moveTop(0.0f);
|
||||
icon_rect.moveLeft(((float)width() - icon_rect.width()) * 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
icon_rect.setWidth(width());
|
||||
icon_rect.setHeight((float)width() / icon_aspect);
|
||||
icon_rect.moveLeft(0.0f);
|
||||
icon_rect.moveTop(((float)height() - icon_rect.height()) * 0.5f);
|
||||
}
|
||||
|
||||
|
||||
auto XForY = [&icon_rect](float y, bool right)
|
||||
{
|
||||
float r = (icon_rect.height() - y) * coolness;
|
||||
if(right)
|
||||
r += icon_rect.width() - icon_rect.height() * coolness;
|
||||
return r;
|
||||
auto render_element = [&view_box, &icon_rect, this](QPainter &painter, const QString &id) {
|
||||
QRectF src = svg_renderer.transformForElement(id).mapRect(svg_renderer.boundsOnElement(id));
|
||||
QRectF dst = src.translated(-view_box.left(), -view_box.top());
|
||||
dst = QRectF(
|
||||
icon_rect.width() * dst.left() / view_box.width(),
|
||||
icon_rect.height() * dst.top() / view_box.height(),
|
||||
icon_rect.width() * dst.width() / view_box.width(),
|
||||
icon_rect.height() * dst.height() / view_box.height());
|
||||
dst = dst.translated(icon_rect.left(), icon_rect.top());
|
||||
svg_renderer.render(&painter, id, dst);
|
||||
};
|
||||
|
||||
auto SectionPath = [&XForY, &icon_rect](float y0, float y1)
|
||||
{
|
||||
QPainterPath path;
|
||||
path.moveTo(XForY(y0, false), y0);
|
||||
path.lineTo(XForY(y1, false), y1);
|
||||
path.lineTo(XForY(y1, true), y1);
|
||||
path.lineTo(XForY(y0, true), y0);
|
||||
path.translate(icon_rect.topLeft());
|
||||
return path;
|
||||
};
|
||||
|
||||
auto color = palette().color(QPalette::Text);
|
||||
|
||||
QColor bar_color;
|
||||
switch(state)
|
||||
{
|
||||
case CHIAKI_DISCOVERY_HOST_STATE_STANDBY:
|
||||
bar_color = QColor(255, 174, 47);
|
||||
break;
|
||||
case CHIAKI_DISCOVERY_HOST_STATE_READY:
|
||||
bar_color = QColor(0, 167, 255);
|
||||
render_element(painter, "light_on");
|
||||
break;
|
||||
case CHIAKI_DISCOVERY_HOST_STATE_STANDBY:
|
||||
render_element(painter, "light_standby");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(bar_color.isValid())
|
||||
painter.fillPath(SectionPath(icon_rect.height() * 0.41f - 1.0f, icon_rect.height() * 0.59f + 1.0f), bar_color);
|
||||
painter.fillPath(SectionPath(0, icon_rect.height() * 0.41f), color);
|
||||
painter.fillPath(SectionPath(icon_rect.height() * 0.59f, icon_rect.height()), color);
|
||||
}
|
||||
auto color = palette().color(QPalette::Text);
|
||||
|
||||
QImage temp_image((int)(devicePixelRatioF() * width()),
|
||||
(int)(devicePixelRatioF() * height()),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
{
|
||||
temp_image.fill(QColor(0, 0, 0, 0));
|
||||
QPainter temp_painter(&temp_image);
|
||||
render_element(temp_painter, "console");
|
||||
temp_painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
||||
temp_painter.fillRect(icon_rect, color);
|
||||
}
|
||||
painter.drawImage(QRectF(0.0f, 0.0f, width(), height()), temp_image);
|
||||
}
|
||||
|
||||
void ServerIconWidget::LoadSvg()
|
||||
{
|
||||
QString path = ps5 ? ":/icons/console-ps5.svg" : ":/icons/console-ps4.svg";
|
||||
svg_renderer.load(path);
|
||||
update();
|
||||
}
|
||||
|
||||
void ServerIconWidget::SetState(bool ps5, ChiakiDiscoveryHostState state)
|
||||
{
|
||||
bool reload = this->ps5 != ps5;
|
||||
this->ps5 = ps5;
|
||||
this->state = state;
|
||||
if(reload)
|
||||
LoadSvg();
|
||||
update();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ void ServerItemWidget::Update(const DisplayServer &display_server)
|
|||
delete_action->setEnabled(!display_server.discovered);
|
||||
wake_action->setEnabled(display_server.registered);
|
||||
|
||||
icon_widget->SetState(display_server.discovered ? display_server.discovery_host.state : CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN);
|
||||
icon_widget->SetState(display_server.IsPS5(),
|
||||
display_server.discovered ? display_server.discovery_host.state : CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN);
|
||||
|
||||
QString top_text = "";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue