mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibCards: Add a CardGame base class
For now, the only feature of this is that it sets the background colour from the `Games::Cards::BackgroundColor` config value. Later, other card game configuration and shared behaviour can go here, to save duplicating it in each game.
This commit is contained in:
parent
a01c4c50d1
commit
c5b7ad6004
Notes:
sideshowbarker
2024-07-17 08:04:36 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/c5b7ad6004 Pull-request: https://github.com/SerenityOS/serenity/pull/14956 Reviewed-by: https://github.com/krkk
@ -1,7 +1,8 @@
|
||||
set(SOURCES
|
||||
Card.cpp
|
||||
CardGame.cpp
|
||||
CardStack.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibCards cards)
|
||||
target_link_libraries(LibCards LibC LibCore)
|
||||
target_link_libraries(LibCards LibC LibCore LibConfig LibGUI)
|
||||
|
39
Userland/Libraries/LibCards/CardGame.cpp
Normal file
39
Userland/Libraries/LibCards/CardGame.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "CardGame.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace Cards {
|
||||
|
||||
CardGame::CardGame()
|
||||
{
|
||||
auto background_color = Gfx::Color::from_string(Config::read_string("Games"sv, "Cards"sv, "BackgroundColor"sv));
|
||||
set_background_color(background_color.value_or(Color::from_rgb(0x008000)));
|
||||
}
|
||||
|
||||
void CardGame::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
|
||||
{
|
||||
if (domain == "Games" && group == "Cards" && key == "BackgroundColor") {
|
||||
if (auto maybe_color = Gfx::Color::from_string(value); maybe_color.has_value()) {
|
||||
set_background_color(maybe_color.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::Color CardGame::background_color() const
|
||||
{
|
||||
return palette().color(background_role());
|
||||
}
|
||||
|
||||
void CardGame::set_background_color(Gfx::Color const& color)
|
||||
{
|
||||
auto new_palette = palette();
|
||||
new_palette.set_color(Gfx::ColorRole::Background, color);
|
||||
set_palette(new_palette);
|
||||
}
|
||||
}
|
30
Userland/Libraries/LibCards/CardGame.h
Normal file
30
Userland/Libraries/LibCards/CardGame.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
|
||||
namespace Cards {
|
||||
|
||||
class CardGame
|
||||
: public GUI::Frame
|
||||
, public Config::Listener {
|
||||
public:
|
||||
virtual ~CardGame() = default;
|
||||
|
||||
Gfx::Color background_color() const;
|
||||
void set_background_color(Gfx::Color const&);
|
||||
|
||||
protected:
|
||||
CardGame();
|
||||
|
||||
private:
|
||||
virtual void config_string_did_change(String const& domain, String const& group, String const& key, String const& value) override;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user