2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-10 16:28:48 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-05-28 15:40:53 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-05-05 22:21:23 -03:00
|
|
|
#include <AK/CircularQueue.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Frame.h>
|
2021-02-14 06:04:38 -03:00
|
|
|
#include <LibGfx/SystemTheme.h>
|
2019-05-05 22:21:23 -03:00
|
|
|
|
2022-03-18 19:56:04 -03:00
|
|
|
namespace SystemMonitor {
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
class GraphWidget final : public GUI::Frame {
|
2019-09-21 13:17:23 -03:00
|
|
|
C_OBJECT(GraphWidget)
|
2019-05-05 22:21:23 -03:00
|
|
|
public:
|
2022-02-10 16:28:48 -03:00
|
|
|
virtual ~GraphWidget() override = default;
|
2019-05-05 22:21:23 -03:00
|
|
|
|
2021-10-06 19:32:56 -03:00
|
|
|
void set_max(u64 max) { m_max = max; }
|
|
|
|
|
u64 max() const { return m_max; }
|
2019-05-05 22:21:23 -03:00
|
|
|
|
2021-10-06 19:32:56 -03:00
|
|
|
void add_value(Vector<u64, 1>&&);
|
2019-05-05 22:21:23 -03:00
|
|
|
|
2021-01-05 00:14:52 -03:00
|
|
|
struct ValueFormat {
|
2021-02-14 06:04:38 -03:00
|
|
|
Gfx::ColorRole graph_color_role { Gfx::ColorRole::Base };
|
2021-01-05 00:14:52 -03:00
|
|
|
Color text_shadow_color { Color::Transparent };
|
2022-05-05 16:17:43 -03:00
|
|
|
Function<String(u64)> text_formatter;
|
2021-01-05 00:14:52 -03:00
|
|
|
};
|
|
|
|
|
void set_value_format(size_t index, ValueFormat&& format)
|
|
|
|
|
{
|
|
|
|
|
if (m_value_format.size() <= index)
|
|
|
|
|
m_value_format.resize(index + 1);
|
|
|
|
|
m_value_format[index] = move(format);
|
|
|
|
|
}
|
2022-03-22 21:31:21 -03:00
|
|
|
void set_stack_values(bool stack_values);
|
|
|
|
|
bool stack_values() const { return m_stack_values; }
|
2019-05-05 22:21:23 -03:00
|
|
|
|
|
|
|
|
private:
|
2022-03-22 21:31:21 -03:00
|
|
|
explicit GraphWidget();
|
2019-09-21 13:17:23 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
2019-05-05 22:21:23 -03:00
|
|
|
|
2021-10-06 19:32:56 -03:00
|
|
|
u64 m_max { 100 };
|
2021-01-05 00:14:52 -03:00
|
|
|
Vector<ValueFormat, 1> m_value_format;
|
2021-10-06 19:32:56 -03:00
|
|
|
CircularQueue<Vector<u64, 1>, 4000> m_values;
|
2021-01-05 00:14:52 -03:00
|
|
|
bool m_stack_values { false };
|
|
|
|
|
|
|
|
|
|
Vector<Gfx::IntPoint, 1> m_calculated_points;
|
2019-05-05 22:21:23 -03:00
|
|
|
};
|
2022-03-18 19:56:04 -03:00
|
|
|
|
|
|
|
|
}
|