84 lines
3.4 KiB
C++
84 lines
3.4 KiB
C++
#include "Time_Axis_p.h"
|
|
#include "../base/Memory.h"
|
|
namespace renderive {
|
|
RENDERIVE_DEFINE_RENDERABLE_BINDING(Time_Axis, Time_Axis_Private, Time_Axis_Render_State, Time_Axis_Input_Data, "time_axis")
|
|
int Time_Axis::visible_time_point_count() {
|
|
return d()->edit_state_value(&Time_Axis_Render_State::visible_time_point_count);
|
|
}
|
|
void Time_Axis::set_visible_time_point_count(int value) {
|
|
value = std::max(1, value);
|
|
d()->set_state_value(&Time_Axis_Render_State::visible_time_point_count, value);
|
|
}
|
|
int Time_Axis::tick_label_spacing_px() {
|
|
return d()->edit_state_value(&Time_Axis_Render_State::tick_label_spacing_px);
|
|
}
|
|
void Time_Axis::set_tick_label_spacing_px(int value) {
|
|
d()->set_state_value(&Time_Axis_Render_State::tick_label_spacing_px, std::max(1, value));
|
|
}
|
|
RENDERIVE_DEFINE_STATE_PROP(Time_Axis, Time_Axis_Render_State, std::string, time_format)
|
|
RENDERIVE_DEFINE_STATE_PROP(Time_Axis, Time_Axis_Render_State, Font, font)
|
|
std::shared_ptr<Timeline_Stream> Time_Axis::timeline_stream() {
|
|
return d()->edit_state_value(&Time_Axis_Render_State::timeline_stream);
|
|
}
|
|
void Time_Axis::set_timeline_stream(std::shared_ptr<Timeline_Stream> value) {
|
|
d()->set_state_value(&Time_Axis_Render_State::timeline_stream, std::move(value));
|
|
}
|
|
bool Time_Axis::newest_at_axis_start() {
|
|
return d()->edit_state_value(&Time_Axis_Render_State::newest_at_axis_start);
|
|
}
|
|
void Time_Axis::set_newest_at_axis_start(bool value) {
|
|
d()->set_state_value(&Time_Axis_Render_State::newest_at_axis_start, value);
|
|
}
|
|
int Time_Axis::append_time(Time_Of_Day time) {
|
|
if (!ok())
|
|
return -1;
|
|
auto stream = timeline_stream();
|
|
if (!stream)
|
|
return -1;
|
|
int tick = stream->append_time(time);
|
|
mark_render_dirty();
|
|
return tick;
|
|
}
|
|
Time_Of_Day Time_Axis::tick_to_time(int tick) {
|
|
std::shared_ptr<Timeline_Stream> stream;
|
|
int point_count = 1;
|
|
int interval_hint = 1;
|
|
bool newest_at_start = false;
|
|
{
|
|
Render_State_Lease<Time_Axis_Private, Time_Axis_Render_State> state(d());
|
|
if (state) {
|
|
stream = state->timeline_stream;
|
|
point_count = state->visible_time_point_count;
|
|
interval_hint = state->label_tick_interval_hint();
|
|
newest_at_start = state->newest_at_axis_start;
|
|
}
|
|
}
|
|
if (stream)
|
|
return stream->capture(point_count, interval_hint, newest_at_start).time_by_tick(tick);
|
|
return {};
|
|
}
|
|
Time_Axis::Builder::Builder(std::shared_ptr<Renderable> parent, Orientation orientation) {
|
|
ASSERT(parent && parent->attached_to_plot(), "Time_Axis build error! parent invalid");
|
|
this->parent = parent;
|
|
this->orientation = orientation;
|
|
}
|
|
std::shared_ptr<Time_Axis> Time_Axis::Builder::build() {
|
|
auto ret = renderive::make_shared<Time_Axis>();
|
|
set(ret.get());
|
|
Time_Axis_Private* pd = ret->d();
|
|
Render_Edit_Lease<Time_Axis_Private, Time_Axis_Render_State> edit(pd);
|
|
Time_Axis_Render_State* sc = edit.operator->();
|
|
PROP_R(int, visible_time_point_count)
|
|
PROP_R(int, tick_label_spacing_px)
|
|
PROP_R(std::string, time_format)
|
|
PROP_R(Font, font)
|
|
PROP_R(std::shared_ptr<Timeline_Stream>, timeline_stream)
|
|
PROP_R(bool, newest_at_axis_start)
|
|
sc->visible_time_point_count = std::max(1, sc->visible_time_point_count);
|
|
sc->tick_label_spacing_px = std::max(1, sc->tick_label_spacing_px);
|
|
if (!sc->timeline_stream)
|
|
sc->timeline_stream = renderive::make_shared<Timeline_Stream>();
|
|
return ret;
|
|
}
|
|
} // namespace renderive
|