11 #ifndef SCROLLSYNCHRONIZER_H
12 #define SCROLLSYNCHRONIZER_H
24 #define NO_SCROLL_SYNC (-1)
38 operator unsigned()
const {
return t; }
56 if (spec1.
isNull())
return spec2.
isNull() ?
true :
false;
57 if (spec2.
isNull())
return false;
59 return *spec1 == *spec2;
62 return !(spec1 == spec2);
103 void update_SpeciesSet() {
104 if (last_Refresh.
newer_than(last_SetChange)) {
106 if (last_Refresh.
newer_than(last_DisplayTrack)) {
108 last_DisplayTrack = last_Refresh;
109 #if defined(DUMP_SYNC)
110 fprintf(stderr,
"DEBUG: MasterCanvas tracking species (idx=%i, last_DisplayTrack=%u, species count=%zu)\n",
get_index(),
unsigned(last_DisplayTrack), current_species->size());
113 if (species != current_species) {
114 species = current_species;
115 last_SetChange = last_DisplayTrack;
116 #if defined(DUMP_SYNC)
117 fprintf(stderr,
" MasterCanvas::SpeciesSet changed/updated (last_SetChange=%u)\n",
unsigned(last_SetChange));
120 #if defined(DUMP_SYNC)
122 fputs(
" MasterCanvas::SpeciesSet did not change\n", stderr);
132 last_DisplayTrack(7),
141 return last_SetChange;
153 bool need_PositionTrack;
154 bool need_ScrollZoom;
160 void track_display_positions();
161 void calc_scroll_zoom();
164 bool update_only_if_master_changed =
false;
166 if (!need_SetUpdate) {
167 if (!last_master) need_SetUpdate =
true;
168 else if (last_master != &master) need_SetUpdate =
true;
169 else update_only_if_master_changed =
true;
172 if (need_SetUpdate || update_only_if_master_changed) {
176 if (update_only_if_master_changed && !need_SetUpdate) {
177 need_SetUpdate = master_stamp.
newer_than(last_master_change);
179 if (need_SetUpdate) {
180 last_master = &master;
181 last_master_change = master_stamp;
183 if (master_spec != species) {
184 species = master_spec;
185 need_PositionTrack =
true;
187 #if defined(DUMP_SYNC)
188 fprintf(stderr,
"DEBUG: updating SlaveCanvas::SpeciesSet (idx=%i, species count=%zu)\n",
get_index(), species->size());
191 need_SetUpdate =
false;
196 void update_tracked_positions() {
198 if (need_PositionTrack) {
199 #if defined(DUMP_SYNC)
200 fprintf(stderr,
"DEBUG: SlaveCanvas tracks positions (idx=%i)\n",
get_index());
202 track_display_positions();
203 need_ScrollZoom =
true;
204 need_PositionTrack =
false;
207 void update_scroll_zoom() {
209 if (need_ScrollZoom) {
210 #if defined(DUMP_SYNC)
211 fprintf(stderr,
"DEBUG: SlaveCanvas updates scroll/zoom (idx=%i)\n",
get_index());
215 need_ScrollZoom =
false;
219 void refresh_scroll_zoom();
229 need_SetUpdate =
true;
233 update_set_from_master(master);
234 update_tracked_positions();
235 update_scroll_zoom();
239 refresh_scroll_zoom();
240 need_Refresh =
false;
254 bool autosynced_with(
int canvas,
int with)
const {
258 if (autosynced[canvas]) {
259 int master = master_index[canvas];
260 if (master == with)
return true;
266 int autosync_master(
int slave)
const {
289 master_index[slave_idx] = master_idx;
290 autosynced[slave_idx] =
false;
294 if (autosynced_with(master_idx, slave_idx)) {
295 error =
"dependency loop detected";
298 autosynced[slave_idx] =
true;
307 #if defined(DUMP_SYNC_AUTO)
308 fprintf(stderr,
"DEBUG: announce_update(canvas_idx=%i)\n", canvas_idx);
323 int master_idx = master_index[slave_idx];
327 #if defined(DUMP_SYNC)
328 fputs(
"------------------------------\n", stderr);
329 fprintf(stderr,
"DEBUG: update_explicit(slave_idx=%i) from master_idx=%i\n", slave_idx, master_idx);
338 error =
"No master-window defined";
350 int master_idx = master_index[slave_idx];
352 #if defined(DUMP_SYNC)
353 fputs(
"------------------------------\n", stderr);
354 fprintf(stderr,
"DEBUG: update_implicit(slave_idx=%i) from master_idx=%i\n", slave_idx, master_idx);
367 #if defined(DUMP_SYNC_AUTO)
368 fputs(
"------------------------------\n"
369 "DEBUG: auto_update\n", stderr);
374 check_update[i] = autosynced[i];
377 bool need_check =
true;
382 if (check_update[slave_idx]) {
383 int master_idx = autosync_master(slave_idx);
385 if (check_update[master_idx]) {
390 #if defined(DUMP_SYNC_AUTO)
391 fprintf(stderr,
"DEBUG: auto_update(slave_idx=%i) from master_idx=%i\n", slave_idx, master_idx);
398 check_update[slave_idx] =
false;
409 #error ScrollSynchronizer.h included twice
410 #endif // SCROLLSYNCHRONIZER_H
bool older_than(const timestamp &other) const
bool newer_than(const timestamp &other) const
bool isNull() const
test if SmartPtr is NULp
TREE_canvas * NT_get_canvas_by_index(int idx)
TREE_canvas * get_canvas() const
void define_canvas_index(int i)
static void error(const char *msg)
static timestamp before(const timestamp &t)
static timestamp after(const timestamp &t)
void setOlderThan(const timestamp &other)
fputs(TRACE_PREFIX, stderr)
const timestamp & get_updated_SpeciesSet(SpeciesSetPtr &specset)
void setNewerThan(const timestamp &other)
bool sameObject(const SmartPtr< T, C > &other) const
void refresh_if_needed(MasterCanvas &master)