From 048bdbfb36d80fd9503e3c1405d55383b4d83b45 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 23 Jan 2011 20:33:22 -0300 Subject: [PATCH] Convert "timers" collection to std::vector (to avoid using a raw array of pointers). --- TODO.txt | 1 - src/gui/jmanager.cpp | 45 ++++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/TODO.txt b/TODO.txt index 171cc6040..ef6988e5d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,6 @@ 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. + Mini-look for sliders in palette editor (add ISliderBackground to draw RGB/HSV sliders with a customized background). diff --git a/src/gui/jmanager.cpp b/src/gui/jmanager.cpp index 64faa2efc..72f9d69fb 100644 --- a/src/gui/jmanager.cpp +++ b/src/gui/jmanager.cpp @@ -12,7 +12,7 @@ #ifdef REPORT_EVENTS #include #endif - +#include #include #include "base/memory.h" @@ -70,8 +70,7 @@ static int want_close_stage; /* variable to handle the external static JWidget default_manager = NULL; -static Timer **timers; /* registered timers */ -static int n_timers; /* number of timers */ +static std::vector timers; // Registered timers static JList new_windows; /* windows that we should show */ static JList proc_windows_list; /* current window's list in process */ @@ -163,10 +162,6 @@ JWidget jmanager_new() old_readed_key[c] = 0; key_repeated[c] = 0; } - - /* timers */ - timers = NULL; - n_timers = 0; } widget = new Widget(JI_MANAGER); @@ -201,14 +196,10 @@ void jmanager_free(JWidget widget) /* destroy this widget */ jwidget_free(widget); - /* destroy timers */ - if (timers != NULL) { - for (c=0; c 0) { + // Generate messages for timers + if (!timers.empty()) { int t = ji_clock; int count; - for (c=0; clast_time >= 0) { count = 0; 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); - for (c=0; c= 0 && timer_id < n_timers); + ASSERT(timer_id >= 0 && timer_id < (int)timers.size()); ASSERT(timers[timer_id] != NULL); delete timers[timer_id]; @@ -617,7 +608,7 @@ void jmanager_remove_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); 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) { - ASSERT(timer_id >= 0 && timer_id < n_timers); + ASSERT(timer_id >= 0 && timer_id < (int)timers.size()); ASSERT(timers[timer_id] != NULL); 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) { - ASSERT(timer_id >= 0 && timer_id < n_timers); + ASSERT(timer_id >= 0 && timer_id < (int)timers.size()); ASSERT(timers[timer_id] != NULL); 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) { - ASSERT(timer_id >= 0 && timer_id < n_timers); + ASSERT(timer_id >= 0 && timer_id < (int)timers.size()); ASSERT(timers[timer_id] != NULL); return (timers[timer_id]->last_time >= 0);