2021-05-17 08:58:16 +12:00
|
|
|
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
indent = tab
|
|
|
|
tab-size = 4
|
|
|
|
*/
|
|
|
|
|
2021-06-20 00:57:27 +12:00
|
|
|
#pragma once
|
2021-05-17 08:58:16 +12:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-05-29 12:32:36 +12:00
|
|
|
#include <robin_hood.h>
|
2021-07-04 11:18:48 +12:00
|
|
|
#include <deque>
|
2021-05-17 08:58:16 +12:00
|
|
|
|
2021-07-21 13:17:34 +12:00
|
|
|
using std::string, std::vector, robin_hood::unordered_flat_map, std::deque;
|
2021-07-16 09:49:16 +12:00
|
|
|
|
2021-05-27 02:23:29 +12:00
|
|
|
namespace Draw {
|
2021-05-17 08:58:16 +12:00
|
|
|
|
2021-07-24 12:13:26 +12:00
|
|
|
//* An editable text field
|
|
|
|
class TextEdit {
|
|
|
|
size_t pos = 0;
|
|
|
|
size_t upos = 0;
|
|
|
|
public:
|
|
|
|
string text;
|
|
|
|
TextEdit();
|
|
|
|
TextEdit(string text);
|
|
|
|
bool command(const string& key);
|
|
|
|
string operator()(const size_t limit=0);
|
|
|
|
};
|
|
|
|
|
2021-07-05 08:02:31 +12:00
|
|
|
//* Create a box and return as a string
|
2021-07-24 12:13:26 +12:00
|
|
|
string createBox(const int x, const int y, const int width, const int height, string line_color="", const bool fill=false, const string title="", const string title2="", const int num=0);
|
2021-05-17 08:58:16 +12:00
|
|
|
|
2021-05-29 12:32:36 +12:00
|
|
|
//* Class holding a percentage meter
|
2021-05-27 02:23:29 +12:00
|
|
|
class Meter {
|
2021-08-04 09:47:46 +12:00
|
|
|
int width;
|
|
|
|
string color_gradient;
|
|
|
|
bool invert;
|
2021-05-28 08:29:36 +12:00
|
|
|
vector<string> cache;
|
|
|
|
public:
|
2021-08-04 09:47:46 +12:00
|
|
|
Meter();
|
2021-07-24 12:13:26 +12:00
|
|
|
Meter(const int width, const string& color_gradient, const bool invert = false);
|
2021-05-28 08:29:36 +12:00
|
|
|
|
2021-05-29 12:32:36 +12:00
|
|
|
//* Return a string representation of the meter with given value
|
2021-06-20 00:57:27 +12:00
|
|
|
string operator()(int value);
|
2021-05-27 02:23:29 +12:00
|
|
|
};
|
|
|
|
|
2021-07-21 13:17:34 +12:00
|
|
|
//* Class holding a percentage graph
|
2021-05-30 12:15:09 +12:00
|
|
|
class Graph {
|
2021-07-24 12:13:26 +12:00
|
|
|
int width, height;
|
|
|
|
string color_gradient;
|
|
|
|
string out, symbol = "default";
|
|
|
|
bool invert, no_zero;
|
|
|
|
long long offset;
|
|
|
|
long long last = 0, max_value = 0;
|
|
|
|
bool current = true, tty_mode = false;
|
2021-05-30 12:15:09 +12:00
|
|
|
unordered_flat_map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};
|
|
|
|
|
2021-05-31 03:01:57 +12:00
|
|
|
//* Create two representations of the graph to switch between to represent two values for each braille character
|
2021-07-04 11:18:48 +12:00
|
|
|
void _create(const deque<long long>& data, int data_offset);
|
2021-05-30 12:15:09 +12:00
|
|
|
|
|
|
|
public:
|
2021-07-24 12:13:26 +12:00
|
|
|
Graph();
|
|
|
|
Graph( int width,
|
|
|
|
int height,
|
|
|
|
const string& color_gradient,
|
|
|
|
const deque<long long>& data,
|
|
|
|
const string& symbol="default",
|
|
|
|
bool invert=false,
|
|
|
|
bool no_zero=false,
|
|
|
|
long long max_value=0,
|
|
|
|
long long offset=0);
|
2021-05-30 12:15:09 +12:00
|
|
|
|
2021-06-02 08:36:36 +12:00
|
|
|
//* Add last value from back of <data> and return string representation of graph
|
2021-07-24 12:13:26 +12:00
|
|
|
string& operator()(const deque<long long>& data, const bool data_same=false);
|
2021-05-30 12:15:09 +12:00
|
|
|
|
|
|
|
//* Return string representation of graph
|
2021-06-20 00:57:27 +12:00
|
|
|
string& operator()();
|
2021-05-30 12:15:09 +12:00
|
|
|
};
|
|
|
|
|
2021-07-04 11:18:48 +12:00
|
|
|
//* Calculate sizes of boxes, draw outlines and save to enabled boxes namespaces
|
|
|
|
void calcSizes();
|
|
|
|
|
2021-07-24 12:13:26 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Proc {
|
|
|
|
extern Draw::TextEdit filter;
|
2021-06-20 00:57:27 +12:00
|
|
|
}
|