mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Move clock/tick from "she" to "base" library and switch to uint64_t type
This commit is contained in:
parent
3cd7d273d9
commit
0605166cc6
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
@ -70,7 +70,7 @@ void PlayState::onEnterState(Editor* editor)
|
|||||||
|
|
||||||
m_toScroll = false;
|
m_toScroll = false;
|
||||||
m_nextFrameTime = getNextFrameTime();
|
m_nextFrameTime = getNextFrameTime();
|
||||||
m_curFrameTick = ui::clock();
|
m_curFrameTick = base::current_tick();
|
||||||
m_pingPongForward = true;
|
m_pingPongForward = true;
|
||||||
|
|
||||||
// Maybe we came from ScrollingState and the timer is already
|
// Maybe we came from ScrollingState and the timer is already
|
||||||
@ -146,7 +146,7 @@ void PlayState::onPlaybackTick()
|
|||||||
if (m_nextFrameTime < 0)
|
if (m_nextFrameTime < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_nextFrameTime -= (ui::clock() - m_curFrameTick);
|
m_nextFrameTime -= (base::current_tick() - m_curFrameTick);
|
||||||
|
|
||||||
doc::Sprite* sprite = m_editor->sprite();
|
doc::Sprite* sprite = m_editor->sprite();
|
||||||
doc::FrameTag* tag = get_animation_tag(sprite, m_refFrame);
|
doc::FrameTag* tag = get_animation_tag(sprite, m_refFrame);
|
||||||
@ -188,7 +188,7 @@ void PlayState::onPlaybackTick()
|
|||||||
m_editor->invalidate();
|
m_editor->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_curFrameTick = ui::clock();
|
m_curFrameTick = base::current_tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before executing any command, we stop the animation
|
// Before executing any command, we stop the animation
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/ui/editor/state_with_wheel_behavior.h"
|
#include "app/ui/editor/state_with_wheel_behavior.h"
|
||||||
#include "base/connection.h"
|
#include "base/connection.h"
|
||||||
|
#include "base/time.h"
|
||||||
#include "doc/frame.h"
|
#include "doc/frame.h"
|
||||||
#include "ui/timer.h"
|
#include "ui/timer.h"
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ namespace app {
|
|||||||
// Number of milliseconds to go to the next frame if m_playTimer
|
// Number of milliseconds to go to the next frame if m_playTimer
|
||||||
// is activated.
|
// is activated.
|
||||||
double m_nextFrameTime;
|
double m_nextFrameTime;
|
||||||
int m_curFrameTick;
|
base::tick_t m_curFrameTick;
|
||||||
|
|
||||||
bool m_pingPongForward;
|
bool m_pingPongForward;
|
||||||
doc::frame_t m_refFrame;
|
doc::frame_t m_refFrame;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "app/thumbnail_generator.h"
|
#include "app/thumbnail_generator.h"
|
||||||
#include "app/ui/skin/skin_theme.h"
|
#include "app/ui/skin/skin_theme.h"
|
||||||
#include "base/string.h"
|
#include "base/string.h"
|
||||||
|
#include "base/time.h"
|
||||||
#include "she/font.h"
|
#include "she/font.h"
|
||||||
#include "she/surface.h"
|
#include "she/surface.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
@ -245,7 +246,7 @@ bool FileList::onProcessMessage(Message* msg)
|
|||||||
std::tolower(unicodeChar) <= 'z') ||
|
std::tolower(unicodeChar) <= 'z') ||
|
||||||
(unicodeChar >= '0' &&
|
(unicodeChar >= '0' &&
|
||||||
unicodeChar <= '9')) {
|
unicodeChar <= '9')) {
|
||||||
if (ui::clock() - m_isearchClock > ISEARCH_KEYPRESS_INTERVAL_MSECS)
|
if ((base::current_tick() - m_isearchClock) > ISEARCH_KEYPRESS_INTERVAL_MSECS)
|
||||||
m_isearch.clear();
|
m_isearch.clear();
|
||||||
|
|
||||||
m_isearch.push_back(unicodeChar);
|
m_isearch.push_back(unicodeChar);
|
||||||
@ -261,7 +262,7 @@ bool FileList::onProcessMessage(Message* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_isearchClock = ui::clock();
|
m_isearchClock = base::current_tick();
|
||||||
// Go to selectIndex...
|
// Go to selectIndex...
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/file_system.h"
|
#include "app/file_system.h"
|
||||||
#include "base/signal.h"
|
#include "base/signal.h"
|
||||||
|
#include "base/time.h"
|
||||||
#include "ui/timer.h"
|
#include "ui/timer.h"
|
||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ namespace app {
|
|||||||
|
|
||||||
// Incremental-search
|
// Incremental-search
|
||||||
std::string m_isearch;
|
std::string m_isearch;
|
||||||
int m_isearchClock;
|
base::tick_t m_isearchClock;
|
||||||
|
|
||||||
// Timer to start generating the thumbnail after an item is
|
// Timer to start generating the thumbnail after an item is
|
||||||
// selected.
|
// selected.
|
||||||
|
@ -263,7 +263,7 @@ void StatusBar::updateFromEditor(Editor* editor)
|
|||||||
|
|
||||||
bool StatusBar::setStatusText(int msecs, const char *format, ...)
|
bool StatusBar::setStatusText(int msecs, const char *format, ...)
|
||||||
{
|
{
|
||||||
if ((ui::clock() > m_timeout) || (msecs > 0)) {
|
if ((base::current_tick() > m_timeout) || (msecs > 0)) {
|
||||||
char buf[256]; // TODO warning buffer overflow
|
char buf[256]; // TODO warning buffer overflow
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ bool StatusBar::setStatusText(int msecs, const char *format, ...)
|
|||||||
vsprintf(buf, format, ap);
|
vsprintf(buf, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
m_timeout = ui::clock() + msecs;
|
m_timeout = base::current_tick() + msecs;
|
||||||
m_state = SHOW_TEXT;
|
m_state = SHOW_TEXT;
|
||||||
|
|
||||||
setText(buf);
|
setText(buf);
|
||||||
@ -315,7 +315,7 @@ void StatusBar::showTip(int msecs, const char *format, ...)
|
|||||||
m_tipwindow->startTimer();
|
m_tipwindow->startTimer();
|
||||||
|
|
||||||
// Set the text in status-bar (with inmediate timeout)
|
// Set the text in status-bar (with inmediate timeout)
|
||||||
m_timeout = ui::clock();
|
m_timeout = base::current_tick();
|
||||||
setText(buf);
|
setText(buf);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This program is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/color.h"
|
#include "app/color.h"
|
||||||
#include "base/observers.h"
|
#include "base/observers.h"
|
||||||
|
#include "base/time.h"
|
||||||
#include "doc/context_observer.h"
|
#include "doc/context_observer.h"
|
||||||
#include "doc/document_observer.h"
|
#include "doc/document_observer.h"
|
||||||
#include "doc/documents_observer.h"
|
#include "doc/documents_observer.h"
|
||||||
@ -86,7 +87,7 @@ namespace app {
|
|||||||
|
|
||||||
enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL };
|
enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL };
|
||||||
|
|
||||||
int m_timeout;
|
base::tick_t m_timeout;
|
||||||
State m_state;
|
State m_state;
|
||||||
|
|
||||||
// Showing a tool
|
// Showing a tool
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Base Library
|
// Aseprite Base Library
|
||||||
// Copyright (c) 2001-2013, 2015 David Capello
|
// Copyright (c) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -14,6 +14,11 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
#include <mach/mach_time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
@ -37,4 +42,22 @@ Time current_time()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tick_t current_tick()
|
||||||
|
{
|
||||||
|
#if _WIN32
|
||||||
|
// TODO use GetTickCount64 (available from Vista)
|
||||||
|
return GetTickCount();
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
static mach_timebase_info_data_t timebase = { 0, 0 };
|
||||||
|
if (timebase.denom == 0)
|
||||||
|
(void)mach_timebase_info(&timebase);
|
||||||
|
return tick_t(double(mach_absolute_time()) * double(timebase.numer) / double(timebase.denom) / 1.0e6);
|
||||||
|
#else
|
||||||
|
// TODO use clock_gettime(CLOCK_MONOTONIC, &now); if it's possible
|
||||||
|
struct timeval now;
|
||||||
|
gettimeofday(&now, nullptr);
|
||||||
|
return now.tv_sec*1000 + now.tv_usec/1000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Base Library
|
// Aseprite Base Library
|
||||||
// Copyright (c) 2001-2013, 2015 David Capello
|
// Copyright (c) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -8,10 +8,15 @@
|
|||||||
#define BASE_TIME_H_INCLUDED
|
#define BASE_TIME_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/ints.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
|
// ~1000 per second
|
||||||
|
typedef uint64_t tick_t;
|
||||||
|
|
||||||
class Time {
|
class Time {
|
||||||
public:
|
public:
|
||||||
int year, month, day;
|
int year, month, day;
|
||||||
@ -47,6 +52,7 @@ namespace base {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Time current_time();
|
Time current_time();
|
||||||
|
tick_t current_tick();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "she/alleg4/clock.h"
|
|
||||||
#include "she/alleg4/display_events.h"
|
#include "she/alleg4/display_events.h"
|
||||||
|
|
||||||
#ifdef USE_KEY_POLLER
|
#ifdef USE_KEY_POLLER
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
// SHE library
|
|
||||||
// Copyright (C) 2012-2014 David Capello
|
|
||||||
//
|
|
||||||
// This file is released under the terms of the MIT license.
|
|
||||||
// Read LICENSE.txt for more information.
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <allegro.h>
|
|
||||||
|
|
||||||
static volatile int clock_var = 0; // Global timer.
|
|
||||||
|
|
||||||
static void clock_inc()
|
|
||||||
{
|
|
||||||
++clock_var;
|
|
||||||
}
|
|
||||||
|
|
||||||
END_OF_STATIC_FUNCTION(clock_inc);
|
|
||||||
|
|
||||||
namespace she {
|
|
||||||
|
|
||||||
void clock_init()
|
|
||||||
{
|
|
||||||
// Install timer related stuff
|
|
||||||
LOCK_VARIABLE(clock_var);
|
|
||||||
LOCK_FUNCTION(clock_inc);
|
|
||||||
|
|
||||||
install_int_ex(clock_inc, BPS_TO_TIMER(1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
void clock_exit()
|
|
||||||
{
|
|
||||||
remove_int(clock_inc);
|
|
||||||
}
|
|
||||||
|
|
||||||
int clock_value()
|
|
||||||
{
|
|
||||||
return clock_var;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace she
|
|
@ -1,18 +0,0 @@
|
|||||||
// SHE library
|
|
||||||
// Copyright (C) 2012-2014 David Capello
|
|
||||||
//
|
|
||||||
// This file is released under the terms of the MIT license.
|
|
||||||
// Read LICENSE.txt for more information.
|
|
||||||
|
|
||||||
#ifndef SHE_ALLEG4_CLOCK_H_INCLUDED
|
|
||||||
#define SHE_ALLEG4_CLOCK_H_INCLUDED
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace she {
|
|
||||||
|
|
||||||
void clock_init();
|
|
||||||
void clock_exit();
|
|
||||||
|
|
||||||
} // namespace she
|
|
||||||
|
|
||||||
#endif
|
|
@ -8,8 +8,8 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "base/time.h"
|
||||||
#include "she/alleg4/alleg_display.h"
|
#include "she/alleg4/alleg_display.h"
|
||||||
#include "she/clock.h"
|
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/event.h"
|
#include "she/event.h"
|
||||||
#include "she/event_queue.h"
|
#include "she/event_queue.h"
|
||||||
@ -49,7 +49,7 @@ bool mouse_left = false;
|
|||||||
|
|
||||||
DlbClk double_click_level;
|
DlbClk double_click_level;
|
||||||
Event::MouseButton double_click_button = Event::NoneButton;
|
Event::MouseButton double_click_button = Event::NoneButton;
|
||||||
int double_click_ticks;
|
base::tick_t double_click_ticks;
|
||||||
|
|
||||||
#if !defined(__APPLE__) && !defined(_WIN32)
|
#if !defined(__APPLE__) && !defined(_WIN32)
|
||||||
// Mouse enter/leave
|
// Mouse enter/leave
|
||||||
@ -121,11 +121,11 @@ void generate_mouse_event_for_button(Event::MouseButton button, int old_b, int n
|
|||||||
ev.setButton(button);
|
ev.setButton(button);
|
||||||
|
|
||||||
// Double Click
|
// Double Click
|
||||||
int current_ticks = clock_value();
|
base::tick_t current_ticks = base::current_tick();
|
||||||
if (ev.type() == Event::MouseDown) {
|
if (ev.type() == Event::MouseDown) {
|
||||||
if (double_click_level != DOUBLE_CLICK_NONE) {
|
if (double_click_level != DOUBLE_CLICK_NONE) {
|
||||||
// Time out, back to NONE
|
// Time out, back to NONE
|
||||||
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
|
if ((current_ticks - double_click_ticks) > DOUBLE_CLICK_TIMEOUT_MSECS) {
|
||||||
double_click_level = DOUBLE_CLICK_NONE;
|
double_click_level = DOUBLE_CLICK_NONE;
|
||||||
}
|
}
|
||||||
else if (double_click_button == button) {
|
else if (double_click_button == button) {
|
||||||
@ -152,7 +152,7 @@ void generate_mouse_event_for_button(Event::MouseButton button, int old_b, int n
|
|||||||
else if (ev.type() == Event::MouseUp) {
|
else if (ev.type() == Event::MouseUp) {
|
||||||
if (double_click_level != DOUBLE_CLICK_NONE) {
|
if (double_click_level != DOUBLE_CLICK_NONE) {
|
||||||
// Time out, back to NONE
|
// Time out, back to NONE
|
||||||
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
|
if ((current_ticks - double_click_ticks) > DOUBLE_CLICK_TIMEOUT_MSECS) {
|
||||||
double_click_level = DOUBLE_CLICK_NONE;
|
double_click_level = DOUBLE_CLICK_NONE;
|
||||||
}
|
}
|
||||||
else if (double_click_level == DOUBLE_CLICK_DOWN) {
|
else if (double_click_level == DOUBLE_CLICK_DOWN) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2012-2015 David Capello
|
// Copyright (C) 2012-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -55,7 +55,6 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "she/alleg4/clock.h"
|
|
||||||
#include "she/alleg4/display_events.h"
|
#include "she/alleg4/display_events.h"
|
||||||
#ifdef USE_KEY_POLLER
|
#ifdef USE_KEY_POLLER
|
||||||
#include "she/alleg4/key_poller.h"
|
#include "she/alleg4/key_poller.h"
|
||||||
@ -123,7 +122,6 @@ public:
|
|||||||
register_bitmap_file_type("png", load_png, save_png);
|
register_bitmap_file_type("png", load_png, save_png);
|
||||||
|
|
||||||
// Init event sources
|
// Init event sources
|
||||||
clock_init();
|
|
||||||
display_events_init();
|
display_events_init();
|
||||||
#ifdef USE_KEY_POLLER
|
#ifdef USE_KEY_POLLER
|
||||||
key_poller_init();
|
key_poller_init();
|
||||||
@ -136,7 +134,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~Alleg4System() {
|
~Alleg4System() {
|
||||||
clock_exit();
|
|
||||||
remove_timer();
|
remove_timer();
|
||||||
allegro_exit();
|
allegro_exit();
|
||||||
|
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
// SHE library
|
|
||||||
// Copyright (C) 2012-2014 David Capello
|
|
||||||
//
|
|
||||||
// This file is released under the terms of the MIT license.
|
|
||||||
// Read LICENSE.txt for more information.
|
|
||||||
|
|
||||||
#ifndef SHE_CLOCK_H_INCLUDED
|
|
||||||
#define SHE_CLOCK_H_INCLUDED
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace she {
|
|
||||||
|
|
||||||
int clock_value();
|
|
||||||
|
|
||||||
} // namespace she
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2012-2015 David Capello
|
// Copyright (C) 2012-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -20,7 +20,6 @@
|
|||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
#include "she/osx/app.h"
|
#include "she/osx/app.h"
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#include <mach/mach_time.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
@ -47,20 +46,6 @@ void clear_keyboard_buffer()
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
int clock_value()
|
|
||||||
{
|
|
||||||
#if _WIN32
|
|
||||||
return (int)GetTickCount();
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
static mach_timebase_info_data_t timebase = { 0, 0 };
|
|
||||||
if (timebase.denom == 0)
|
|
||||||
(void)mach_timebase_info(&timebase);
|
|
||||||
return int(float(mach_absolute_time()) * float(timebase.numer) / float(timebase.denom) / 1.0e6f);
|
|
||||||
#else
|
|
||||||
return 0; // TODO
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace she
|
} // namespace she
|
||||||
|
|
||||||
extern int app_main(int argc, char* argv[]);
|
extern int app_main(int argc, char* argv[]);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
|
|
||||||
#include "base/scoped_value.h"
|
#include "base/scoped_value.h"
|
||||||
|
#include "base/time.h"
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/event.h"
|
#include "she/event.h"
|
||||||
#include "she/event_queue.h"
|
#include "she/event_queue.h"
|
||||||
@ -1189,13 +1190,13 @@ void Manager::onSizeHint(SizeHintEvent& ev)
|
|||||||
void Manager::pumpQueue()
|
void Manager::pumpQueue()
|
||||||
{
|
{
|
||||||
#ifdef LIMIT_DISPATCH_TIME
|
#ifdef LIMIT_DISPATCH_TIME
|
||||||
int t = ui::clock();
|
base::tick_t t = base::current_tick();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Messages::iterator it = msg_queue.begin();
|
Messages::iterator it = msg_queue.begin();
|
||||||
while (it != msg_queue.end()) {
|
while (it != msg_queue.end()) {
|
||||||
#ifdef LIMIT_DISPATCH_TIME
|
#ifdef LIMIT_DISPATCH_TIME
|
||||||
if (ui::clock()-t > 250)
|
if (base::current_tick()-t > 250)
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite UI Library
|
// Aseprite UI Library
|
||||||
// Copyright (C) 2001-2013, 2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -11,7 +11,6 @@
|
|||||||
#include "ui/system.h"
|
#include "ui/system.h"
|
||||||
|
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
#include "she/clock.h"
|
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/surface.h"
|
#include "she/surface.h"
|
||||||
#include "she/system.h"
|
#include "she/system.h"
|
||||||
@ -150,11 +149,6 @@ UISystem::~UISystem()
|
|||||||
update_mouse_overlay(NULL);
|
update_mouse_overlay(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int clock()
|
|
||||||
{
|
|
||||||
return she::clock_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _internal_set_mouse_display(she::Display* display)
|
void _internal_set_mouse_display(she::Display* display)
|
||||||
{
|
{
|
||||||
CursorType cursor = get_mouse_cursor();
|
CursorType cursor = get_mouse_cursor();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite UI Library
|
// Aseprite UI Library
|
||||||
// Copyright (C) 2001-2013, 2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -28,10 +28,6 @@ namespace ui {
|
|||||||
int display_w();
|
int display_w();
|
||||||
int display_h();
|
int display_h();
|
||||||
|
|
||||||
// Timer related
|
|
||||||
|
|
||||||
int clock();
|
|
||||||
|
|
||||||
// Mouse related
|
// Mouse related
|
||||||
|
|
||||||
// Updates the position of the mouse cursor overlay depending on the
|
// Updates the position of the mouse cursor overlay depending on the
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite UI Library
|
// Aseprite UI Library
|
||||||
// Copyright (C) 2001-2013 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
#include "ui/timer.h"
|
#include "ui/timer.h"
|
||||||
|
|
||||||
|
#include "base/time.h"
|
||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
#include "ui/message.h"
|
#include "ui/message.h"
|
||||||
#include "ui/system.h"
|
|
||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -27,9 +27,10 @@ static Timers timers; // Registered timers
|
|||||||
Timer::Timer(int interval, Widget* owner)
|
Timer::Timer(int interval, Widget* owner)
|
||||||
: m_owner(owner ? owner: Manager::getDefault())
|
: m_owner(owner ? owner: Manager::getDefault())
|
||||||
, m_interval(interval)
|
, m_interval(interval)
|
||||||
, m_lastTime(-1)
|
, m_running(false)
|
||||||
|
, m_lastTick(0)
|
||||||
{
|
{
|
||||||
ASSERT(m_owner != NULL);
|
ASSERT(m_owner != nullptr);
|
||||||
|
|
||||||
timers.push_back(this);
|
timers.push_back(this);
|
||||||
}
|
}
|
||||||
@ -44,19 +45,15 @@ Timer::~Timer()
|
|||||||
Manager::getDefault()->removeMessagesForTimer(this);
|
Manager::getDefault()->removeMessagesForTimer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Timer::isRunning() const
|
|
||||||
{
|
|
||||||
return (m_lastTime >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::start()
|
void Timer::start()
|
||||||
{
|
{
|
||||||
m_lastTime = ui::clock();
|
m_lastTick = base::current_tick();
|
||||||
|
m_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::stop()
|
void Timer::stop()
|
||||||
{
|
{
|
||||||
m_lastTime = -1;
|
m_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::tick()
|
void Timer::tick()
|
||||||
@ -79,26 +76,16 @@ void Timer::pollTimers()
|
|||||||
{
|
{
|
||||||
// Generate messages for timers
|
// Generate messages for timers
|
||||||
if (!timers.empty()) {
|
if (!timers.empty()) {
|
||||||
int t = ui::clock();
|
base::tick_t t = base::current_tick();
|
||||||
int count;
|
|
||||||
|
|
||||||
for (Timers::iterator it=timers.begin(), end=timers.end(); it != end; ++it) {
|
for (Timers::iterator it=timers.begin(), end=timers.end(); it != end; ++it) {
|
||||||
Timer* timer = *it;
|
Timer* timer = *it;
|
||||||
if (timer && timer->m_lastTime >= 0) {
|
if (timer && timer->isRunning()) {
|
||||||
count = 0;
|
int64_t count = ((t - timer->m_lastTick) / timer->m_interval);
|
||||||
while (t - timer->m_lastTime > timer->m_interval) {
|
|
||||||
timer->m_lastTime += timer->m_interval;
|
|
||||||
++count;
|
|
||||||
|
|
||||||
/* we spend too much time here */
|
|
||||||
if (ui::clock() - t > timer->m_interval) {
|
|
||||||
timer->m_lastTime = ui::clock();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
ASSERT(timer->m_owner != NULL);
|
timer->m_lastTick += count * timer->m_interval;
|
||||||
|
|
||||||
|
ASSERT(timer->m_owner != nullptr);
|
||||||
|
|
||||||
Message* msg = new TimerMessage(count, timer);
|
Message* msg = new TimerMessage(count, timer);
|
||||||
msg->addRecipient(timer->m_owner);
|
msg->addRecipient(timer->m_owner);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite UI Library
|
// Aseprite UI Library
|
||||||
// Copyright (C) 2001-2013, 2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -10,21 +10,23 @@
|
|||||||
|
|
||||||
#include "base/disable_copying.h"
|
#include "base/disable_copying.h"
|
||||||
#include "base/signal.h"
|
#include "base/signal.h"
|
||||||
|
#include "base/time.h"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class Widget;
|
class Widget;
|
||||||
|
|
||||||
class Timer
|
class Timer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Timer(int interval, Widget* owner = NULL);
|
Timer(int interval, Widget* owner = NULL);
|
||||||
virtual ~Timer();
|
virtual ~Timer();
|
||||||
|
|
||||||
int getInterval() const;
|
int interval() const { return m_interval; }
|
||||||
void setInterval(int interval);
|
void setInterval(int interval);
|
||||||
|
|
||||||
bool isRunning() const;
|
bool isRunning() const {
|
||||||
|
return m_running;
|
||||||
|
}
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
@ -42,7 +44,8 @@ namespace ui {
|
|||||||
public:
|
public:
|
||||||
Widget* m_owner;
|
Widget* m_owner;
|
||||||
int m_interval;
|
int m_interval;
|
||||||
int m_lastTime;
|
bool m_running;
|
||||||
|
base::tick_t m_lastTick;
|
||||||
|
|
||||||
DISABLE_COPYING(Timer);
|
DISABLE_COPYING(Timer);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user