@@ -21,6 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
2222#include " flickable.hpp"
2323
24+ #include < utki/time.hpp>
25+
2426using namespace ruis ::touch;
2527
2628ruis::event_status flickable::on_mouse_button (const mouse_button_event& event)
@@ -45,6 +47,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
4547 case state::idle:
4648 utki::assert (event.action == button_action::press, SL);
4749
50+ this ->last_touch_move_timestamp_ms = utki::get_ticks_ms ();
51+
4852 this ->cur_state = state::within_scroll_threshold;
4953 this ->prev_touch_point = event.pos ;
5054 this ->cur_pointer_id = event.pointer_id ;
@@ -66,6 +70,8 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
6670 utki::assert (event.action == button_action::release, SL);
6771 this ->cur_state = state::idle;
6872
73+ // TODO: start updating
74+
6975 // std::cout << "idle\n";
7076
7177 return event_status::consumed;
@@ -81,11 +87,22 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
8187 }
8288 }
8389
90+ uint32_t cur_ticks_ms = utki::get_ticks_ms ();
91+ uint32_t dt_ms = cur_ticks_ms - this ->last_touch_move_timestamp_ms ;
92+ this ->last_touch_move_timestamp_ms = cur_ticks_ms;
93+
94+ vec2 delta = event.pos - this ->prev_touch_point ;
95+
96+ this ->touch_velocity_px_per_ms = delta / ruis::real (dt_ms);
97+
98+ std::cout << " dt_ms = " << dt_ms << std::endl;
99+ std::cout << " touch velocity = " << this ->touch_velocity_px_per_ms << std::endl;
100+
84101 switch (this ->cur_state ) {
85102 default :
86- utki::assert (false , SL);
87103 [[fallthrough]];
88104 case state::idle:
105+ utki::assert (false , SL);
89106 return this ->flickable_on_mouse_move (event);
90107 case state::within_scroll_threshold:
91108 {
@@ -96,7 +113,6 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
96113
97114 return event_status::consumed;
98115 }
99- vec2 delta = event.pos - this ->prev_touch_point ;
100116 vec2 abs_delta = abs (delta);
101117
102118 // std::cout << "mouse move: within scroll threshold, delta: " << delta << ", abs_delta: " << abs_delta << "\n";
@@ -136,12 +152,15 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
136152 return this ->flickable_on_mouse_move (event);
137153 case state::scrolling:
138154 {
139- auto delta = event.pos - this ->prev_touch_point ;
140-
141155 // std::cout << "mouse move: scrolling, delta: " << delta << "\n";
142156 this ->flickable_scroll_by (-delta);
143157 this ->prev_touch_point = event.pos ;
144158 return event_status::consumed;
145159 }
146160 }
147161}
162+
163+ void flickable::update (uint32_t dt_ms)
164+ {
165+ // TODO:
166+ }
0 commit comments