71 lines
3.1 KiB
C++
71 lines
3.1 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::start_coord_to_end_coord() {
|
|
return d()->edit_state_value(&Time_Axis_Render_State::start_coord_to_end_coord);
|
|
}
|
|
void Time_Axis::set_start_coord_to_end_coord(bool value) {
|
|
d()->set_state_value(&Time_Axis_Render_State::start_coord_to_end_coord, 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) {
|
|
auto stream = timeline_stream();
|
|
if (stream)
|
|
return stream->capture(visible_time_point_count(), d()->state_data(State_Edit)->label_tick_interval_hint(), start_coord_to_end_coord()).time_by_tick(tick);
|
|
return d()->time_by_tick(tick);
|
|
}
|
|
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();
|
|
Time_Axis_Render_State* sc = reinterpret_cast<Time_Axis_Render_State*>(pd->state(State_Edit));
|
|
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, start_coord_to_end_coord)
|
|
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
|