mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-16 22:18:30 +00:00
Convert "timers" collection to std::vector (to avoid using a raw array of pointers).
This commit is contained in:
parent
f018ab64df
commit
048bdbfb36
1
TODO.txt
1
TODO.txt
@ -1,7 +1,6 @@
|
|||||||
For next release
|
For next release
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
+ "timers" collection in jmanager.cpp must be a std::vector<>.
|
|
||||||
+ After creating or opening a sprite, it should be shown centered in the editor.
|
+ After creating or opening a sprite, it should be shown centered in the editor.
|
||||||
+ Mini-look for sliders in palette editor (add ISliderBackground to draw RGB/HSV sliders
|
+ Mini-look for sliders in palette editor (add ISliderBackground to draw RGB/HSV sliders
|
||||||
with a customized background).
|
with a customized background).
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#ifdef REPORT_EVENTS
|
#ifdef REPORT_EVENTS
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <vector>
|
||||||
#include <allegro.h>
|
#include <allegro.h>
|
||||||
|
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
@ -70,8 +70,7 @@ static int want_close_stage; /* variable to handle the external
|
|||||||
|
|
||||||
static JWidget default_manager = NULL;
|
static JWidget default_manager = NULL;
|
||||||
|
|
||||||
static Timer **timers; /* registered timers */
|
static std::vector<Timer*> timers; // Registered timers
|
||||||
static int n_timers; /* number of timers */
|
|
||||||
|
|
||||||
static JList new_windows; /* windows that we should show */
|
static JList new_windows; /* windows that we should show */
|
||||||
static JList proc_windows_list; /* current window's list in process */
|
static JList proc_windows_list; /* current window's list in process */
|
||||||
@ -163,10 +162,6 @@ JWidget jmanager_new()
|
|||||||
old_readed_key[c] = 0;
|
old_readed_key[c] = 0;
|
||||||
key_repeated[c] = 0;
|
key_repeated[c] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* timers */
|
|
||||||
timers = NULL;
|
|
||||||
n_timers = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widget = new Widget(JI_MANAGER);
|
widget = new Widget(JI_MANAGER);
|
||||||
@ -201,14 +196,10 @@ void jmanager_free(JWidget widget)
|
|||||||
/* destroy this widget */
|
/* destroy this widget */
|
||||||
jwidget_free(widget);
|
jwidget_free(widget);
|
||||||
|
|
||||||
/* destroy timers */
|
// Destroy timers
|
||||||
if (timers != NULL) {
|
for (c=0; c<(int)timers.size(); ++c)
|
||||||
for (c=0; c<n_timers; ++c)
|
delete timers[c];
|
||||||
if (timers[c] != NULL)
|
timers.clear();
|
||||||
delete timers[c];
|
|
||||||
base_free(timers);
|
|
||||||
n_timers = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* destroy filters */
|
/* destroy filters */
|
||||||
for (c=0; c<NFILTERS; ++c) {
|
for (c=0; c<NFILTERS; ++c) {
|
||||||
@ -502,12 +493,12 @@ bool jmanager_generate_messages(JWidget manager)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* timers */
|
// Generate messages for timers
|
||||||
if (n_timers > 0) {
|
if (!timers.empty()) {
|
||||||
int t = ji_clock;
|
int t = ji_clock;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
for (c=0; c<n_timers; ++c) {
|
for (c=0; c<(int)timers.size(); ++c) {
|
||||||
if (timers[c] && timers[c]->last_time >= 0) {
|
if (timers[c] && timers[c]->last_time >= 0) {
|
||||||
count = 0;
|
count = 0;
|
||||||
while (t - timers[c]->last_time > timers[c]->interval) {
|
while (t - timers[c]->last_time > timers[c]->interval) {
|
||||||
@ -569,8 +560,8 @@ int jmanager_add_timer(JWidget widget, int interval)
|
|||||||
|
|
||||||
ASSERT_VALID_WIDGET(widget);
|
ASSERT_VALID_WIDGET(widget);
|
||||||
|
|
||||||
for (c=0; c<n_timers; ++c) {
|
for (c=0; c<(int)timers.size(); ++c) {
|
||||||
/* there are an empty slot */
|
// There are an empty slot
|
||||||
if (timers[c] == NULL) {
|
if (timers[c] == NULL) {
|
||||||
new_id = c;
|
new_id = c;
|
||||||
break;
|
break;
|
||||||
@ -578,8 +569,8 @@ int jmanager_add_timer(JWidget widget, int interval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (new_id < 0) {
|
if (new_id < 0) {
|
||||||
new_id = n_timers++;
|
new_id = timers.size();
|
||||||
timers = (Timer**)base_realloc(timers, sizeof(Timer*) * n_timers);
|
timers.push_back(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer* timer = new Timer;
|
Timer* timer = new Timer;
|
||||||
@ -596,7 +587,7 @@ void jmanager_remove_timer(int timer_id)
|
|||||||
JMessage message;
|
JMessage message;
|
||||||
JLink link, next;
|
JLink link, next;
|
||||||
|
|
||||||
ASSERT(timer_id >= 0 && timer_id < n_timers);
|
ASSERT(timer_id >= 0 && timer_id < (int)timers.size());
|
||||||
ASSERT(timers[timer_id] != NULL);
|
ASSERT(timers[timer_id] != NULL);
|
||||||
|
|
||||||
delete timers[timer_id];
|
delete timers[timer_id];
|
||||||
@ -617,7 +608,7 @@ void jmanager_remove_timer(int timer_id)
|
|||||||
|
|
||||||
void jmanager_start_timer(int timer_id)
|
void jmanager_start_timer(int timer_id)
|
||||||
{
|
{
|
||||||
ASSERT(timer_id >= 0 && timer_id < n_timers);
|
ASSERT(timer_id >= 0 && timer_id < (int)timers.size());
|
||||||
ASSERT(timers[timer_id] != NULL);
|
ASSERT(timers[timer_id] != NULL);
|
||||||
|
|
||||||
timers[timer_id]->last_time = ji_clock;
|
timers[timer_id]->last_time = ji_clock;
|
||||||
@ -625,7 +616,7 @@ void jmanager_start_timer(int timer_id)
|
|||||||
|
|
||||||
void jmanager_stop_timer(int timer_id)
|
void jmanager_stop_timer(int timer_id)
|
||||||
{
|
{
|
||||||
ASSERT(timer_id >= 0 && timer_id < n_timers);
|
ASSERT(timer_id >= 0 && timer_id < (int)timers.size());
|
||||||
ASSERT(timers[timer_id] != NULL);
|
ASSERT(timers[timer_id] != NULL);
|
||||||
|
|
||||||
timers[timer_id]->last_time = -1;
|
timers[timer_id]->last_time = -1;
|
||||||
@ -633,7 +624,7 @@ void jmanager_stop_timer(int timer_id)
|
|||||||
|
|
||||||
void jmanager_set_timer_interval(int timer_id, int interval)
|
void jmanager_set_timer_interval(int timer_id, int interval)
|
||||||
{
|
{
|
||||||
ASSERT(timer_id >= 0 && timer_id < n_timers);
|
ASSERT(timer_id >= 0 && timer_id < (int)timers.size());
|
||||||
ASSERT(timers[timer_id] != NULL);
|
ASSERT(timers[timer_id] != NULL);
|
||||||
|
|
||||||
timers[timer_id]->interval = interval;
|
timers[timer_id]->interval = interval;
|
||||||
@ -641,7 +632,7 @@ void jmanager_set_timer_interval(int timer_id, int interval)
|
|||||||
|
|
||||||
bool jmanager_timer_is_running(int timer_id)
|
bool jmanager_timer_is_running(int timer_id)
|
||||||
{
|
{
|
||||||
ASSERT(timer_id >= 0 && timer_id < n_timers);
|
ASSERT(timer_id >= 0 && timer_id < (int)timers.size());
|
||||||
ASSERT(timers[timer_id] != NULL);
|
ASSERT(timers[timer_id] != NULL);
|
||||||
|
|
||||||
return (timers[timer_id]->last_time >= 0);
|
return (timers[timer_id]->last_time >= 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user