mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Applets/Audio: Use Array for the volume level bitmaps
This commit is contained in:
parent
cab6384966
commit
4efe6210ee
Notes:
sideshowbarker
2024-07-17 20:04:15 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/4efe6210ee7 Pull-request: https://github.com/SerenityOS/serenity/pull/12162 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 10 additions and 9 deletions
|
@ -6,6 +6,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <LibAudio/ClientConnection.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/System.h>
|
||||
|
@ -34,12 +35,12 @@ private:
|
|||
public:
|
||||
static ErrorOr<NonnullRefPtr<AudioWidget>> try_create()
|
||||
{
|
||||
Vector<VolumeBitmapPair, 5> volume_level_bitmaps = {
|
||||
{ 66, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-high.png")) },
|
||||
{ 33, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-medium.png")) },
|
||||
{ 1, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-low.png")) },
|
||||
{ 0, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-zero.png")) },
|
||||
{ 0, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-muted.png")) }
|
||||
Array<VolumeBitmapPair, 5> volume_level_bitmaps = {
|
||||
{ { 66, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-high.png")) },
|
||||
{ 33, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-medium.png")) },
|
||||
{ 1, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-low.png")) },
|
||||
{ 0, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-zero.png")) },
|
||||
{ 0, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/audio-volume-muted.png")) } }
|
||||
};
|
||||
auto audio_client = TRY(Audio::ClientConnection::try_create());
|
||||
NonnullRefPtr<AudioWidget> audio_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AudioWidget(move(audio_client), move(volume_level_bitmaps))));
|
||||
|
@ -48,7 +49,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
AudioWidget(NonnullRefPtr<Audio::ClientConnection> audio_client, Vector<VolumeBitmapPair, 5> volume_level_bitmaps)
|
||||
AudioWidget(NonnullRefPtr<Audio::ClientConnection> audio_client, Array<VolumeBitmapPair, 5> volume_level_bitmaps)
|
||||
: m_audio_client(move(audio_client))
|
||||
, m_volume_level_bitmaps(move(volume_level_bitmaps))
|
||||
, m_show_percent(Config::read_bool("AudioApplet", "Applet", "ShowPercent", false))
|
||||
|
@ -201,7 +202,7 @@ private:
|
|||
Gfx::Bitmap& choose_bitmap_from_volume()
|
||||
{
|
||||
if (m_audio_muted)
|
||||
return *m_volume_level_bitmaps.last().bitmap;
|
||||
return *m_volume_level_bitmaps.back().bitmap;
|
||||
|
||||
for (auto& pair : m_volume_level_bitmaps) {
|
||||
if (m_audio_volume >= pair.volume_threshold)
|
||||
|
@ -217,7 +218,7 @@ private:
|
|||
}
|
||||
|
||||
NonnullRefPtr<Audio::ClientConnection> m_audio_client;
|
||||
Vector<VolumeBitmapPair, 5> m_volume_level_bitmaps;
|
||||
Array<VolumeBitmapPair, 5> m_volume_level_bitmaps;
|
||||
bool m_show_percent { false };
|
||||
bool m_audio_muted { false };
|
||||
int m_audio_volume { 100 };
|
||||
|
|
Loading…
Reference in a new issue