Compare commits
5 Commits
spacecruft
...
watchable-
Author | SHA1 | Date |
---|---|---|
Hleb Valoshka | bf1844a2f5 | |
Hleb Valoshka | 4a2bd133e0 | |
Hleb Valoshka | 98833e96bd | |
Hleb Valoshka | f692cc411f | |
Hleb Valoshka | 54bec3aa17 |
|
@ -66,6 +66,7 @@ std::ofstream hdrlog;
|
|||
#include <celutil/utf8.h>
|
||||
#include <celutil/util.h>
|
||||
#include <celutil/timer.h>
|
||||
#include <celutil/watchable.h>
|
||||
#include <GL/glew.h>
|
||||
#ifdef VIDEO_SYNC
|
||||
#ifdef _WIN32
|
||||
|
@ -7780,33 +7781,10 @@ bool Renderer::settingsHaveChanged() const
|
|||
void Renderer::markSettingsChanged()
|
||||
{
|
||||
settingsChanged = true;
|
||||
notifyWatchers();
|
||||
notifyWatchers(/*TODO: RenderFlagsChanged*/2);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::addWatcher(RendererWatcher* watcher)
|
||||
{
|
||||
assert(watcher != nullptr);
|
||||
watchers.push_back(watcher);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::removeWatcher(RendererWatcher* watcher)
|
||||
{
|
||||
auto iter = find(watchers.begin(), watchers.end(), watcher);
|
||||
if (iter != watchers.end())
|
||||
watchers.erase(iter);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::notifyWatchers() const
|
||||
{
|
||||
for (const auto watcher : watchers)
|
||||
{
|
||||
watcher->notifyRenderSettingsChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::updateBodyVisibilityMask()
|
||||
{
|
||||
int flags = 0;
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
#include <celengine/starcolors.h>
|
||||
#include <celengine/rendcontext.h>
|
||||
#include <celtxf/texturefont.h>
|
||||
#include <celutil/watchable.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
|
||||
class RendererWatcher;
|
||||
class Renderer;
|
||||
class FrameTree;
|
||||
class ReferenceMark;
|
||||
class CurvePlot;
|
||||
|
@ -84,7 +85,7 @@ struct SecondaryIlluminator
|
|||
|
||||
class PointStarVertexBuffer;
|
||||
|
||||
class Renderer
|
||||
class Renderer : public Watchable<Renderer>
|
||||
{
|
||||
public:
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
|
@ -345,10 +346,6 @@ class Renderer
|
|||
bool settingsHaveChanged() const;
|
||||
void markSettingsChanged();
|
||||
|
||||
void addWatcher(RendererWatcher*);
|
||||
void removeWatcher(RendererWatcher*);
|
||||
void notifyWatchers() const;
|
||||
|
||||
public:
|
||||
// Internal types
|
||||
// TODO: Figure out how to make these private. Even with a friend
|
||||
|
@ -752,8 +749,6 @@ class Renderer
|
|||
MarkerRepresentation openClusterRep;
|
||||
MarkerRepresentation globularRep;
|
||||
|
||||
std::list<RendererWatcher*> watchers;
|
||||
|
||||
public:
|
||||
// Colors for all lines and labels
|
||||
static Color StarLabelColor;
|
||||
|
@ -799,15 +794,4 @@ class Renderer
|
|||
static Color SelectionCursorColor;
|
||||
};
|
||||
|
||||
|
||||
class RendererWatcher
|
||||
{
|
||||
public:
|
||||
RendererWatcher() {};
|
||||
virtual ~RendererWatcher() {};
|
||||
|
||||
virtual void notifyRenderSettingsChanged(const Renderer*) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // _CELENGINE_RENDER_H_
|
||||
|
|
|
@ -4670,6 +4670,7 @@ CelestiaConfig* CelestiaCore::getConfig() const
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
void CelestiaCore::addWatcher(CelestiaWatcher* watcher)
|
||||
{
|
||||
assert(watcher != nullptr);
|
||||
|
@ -4691,6 +4692,7 @@ void CelestiaCore::notifyWatchers(int property)
|
|||
watcher->notifyChange(this, property);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void CelestiaCore::goToUrl(const string& urlStr)
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
#define _CELESTIACORE_H_
|
||||
|
||||
#include <celutil/timer.h>
|
||||
#include <celutil/watcher.h>
|
||||
// #include <celutil/watchable.h>
|
||||
#include <celutil/watchable.h>
|
||||
#include <celengine/solarsys.h>
|
||||
#include <celengine/overlay.h>
|
||||
#include <celengine/command.h>
|
||||
|
@ -31,13 +30,10 @@
|
|||
#endif
|
||||
class Url;
|
||||
|
||||
// class CelestiaWatcher;
|
||||
class CelestiaCore;
|
||||
|
||||
// class astro::Date;
|
||||
|
||||
typedef Watcher<CelestiaCore> CelestiaWatcher;
|
||||
|
||||
class ProgressNotifier
|
||||
{
|
||||
public:
|
||||
|
@ -81,7 +77,7 @@ class View
|
|||
};
|
||||
|
||||
|
||||
class CelestiaCore // : public Watchable<CelestiaCore>
|
||||
class CelestiaCore : public Watchable<CelestiaCore>
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
|
@ -318,9 +314,6 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
|
||||
void setContextMenuCallback(ContextMenuFunc);
|
||||
|
||||
void addWatcher(CelestiaWatcher*);
|
||||
void removeWatcher(CelestiaWatcher*);
|
||||
|
||||
void setFaintest(float);
|
||||
void setFaintestAutoMag();
|
||||
|
||||
|
@ -348,7 +341,7 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
|
||||
CelestiaConfig* getConfig() const;
|
||||
|
||||
void notifyWatchers(int);
|
||||
// void notifyWatchers(int);
|
||||
|
||||
class Alerter
|
||||
{
|
||||
|
@ -485,7 +478,6 @@ class CelestiaCore // : public Watchable<CelestiaCore>
|
|||
Texture* logoTexture{ nullptr };
|
||||
|
||||
Alerter* alerter{ nullptr };
|
||||
std::vector<CelestiaWatcher*> watchers;
|
||||
CursorHandler* cursorHandler{ nullptr };
|
||||
CursorShape defaultCursorShape{ CelestiaCore::CrossCursor };
|
||||
|
||||
|
|
|
@ -141,21 +141,23 @@ static void createMainMenu(GtkWidget* window, AppData* app)
|
|||
/* Our own watcher. Celestiacore will call notifyChange() to tell us
|
||||
* we need to recheck the check menu items and option buttons. */
|
||||
|
||||
class GtkWatcher : public CelestiaWatcher
|
||||
class GtkWatcher : public Watcher<CelestiaCore>
|
||||
{
|
||||
public:
|
||||
GtkWatcher(CelestiaCore*, AppData*);
|
||||
virtual void notifyChange(CelestiaCore*, int);
|
||||
private:
|
||||
AppData* app;
|
||||
public:
|
||||
GtkWatcher(CelestiaCore*, AppData*);
|
||||
void notifyChange(const CelestiaCore*, int) override;
|
||||
|
||||
private:
|
||||
AppData* app;
|
||||
};
|
||||
|
||||
GtkWatcher::GtkWatcher(CelestiaCore* _appCore, AppData* _app) :
|
||||
CelestiaWatcher(*_appCore), app(_app)
|
||||
Watcher<CelestiaCore>(*_appCore),
|
||||
app(_app)
|
||||
{
|
||||
}
|
||||
|
||||
void GtkWatcher::notifyChange(CelestiaCore*, int property)
|
||||
void GtkWatcher::notifyChange(const CelestiaCore*, int property)
|
||||
{
|
||||
if (property & CelestiaCore::LabelFlagsChanged)
|
||||
resyncLabelActions(app);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
CelestiaActions::CelestiaActions(QObject* parent,
|
||||
CelestiaCore* _appCore) :
|
||||
Watcher<Renderer>(*this),
|
||||
QObject(parent),
|
||||
appCore(_appCore)
|
||||
{
|
||||
|
@ -310,7 +311,7 @@ void CelestiaActions::syncWithAppCore()
|
|||
}
|
||||
|
||||
|
||||
void CelestiaActions::notifyRenderSettingsChanged(const Renderer* renderer)
|
||||
void CelestiaActions::notifyChange(const Renderer* renderer, int property)
|
||||
{
|
||||
syncWithRenderer(renderer);
|
||||
}
|
||||
|
|
|
@ -21,15 +21,15 @@ class QAction;
|
|||
class CelestiaCore;
|
||||
|
||||
|
||||
class CelestiaActions : public QObject, public RendererWatcher
|
||||
class CelestiaActions : public QObject, public Watcher<Renderer>
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CelestiaActions(QObject *parent, CelestiaCore* appCore);
|
||||
~CelestiaActions();
|
||||
|
||||
virtual void notifyRenderSettingsChanged(const Renderer* renderer);
|
||||
void notifyChange(const Renderer* renderer, int) override;
|
||||
|
||||
private slots:
|
||||
void slotToggleRenderFlag();
|
||||
|
|
|
@ -160,7 +160,7 @@ static BOOL APIENTRY LocationsProc(HWND hDlg,
|
|||
LocationsDialog::LocationsDialog(HINSTANCE appInstance,
|
||||
HWND _parent,
|
||||
CelestiaCore* _appCore) :
|
||||
CelestiaWatcher(*_appCore),
|
||||
Watcher<CelestiaCore>(*_appCore),
|
||||
appCore(_appCore),
|
||||
parent(_parent)
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <commctrl.h>
|
||||
#include "celestia/celestiacore.h"
|
||||
|
||||
class LocationsDialog : public CelestiaWatcher
|
||||
class LocationsDialog : public Watcher<CelestiaCore>
|
||||
{
|
||||
public:
|
||||
LocationsDialog(HINSTANCE, HWND, CelestiaCore*);
|
||||
|
@ -24,7 +24,7 @@ class LocationsDialog : public CelestiaWatcher
|
|||
void SetControls(HWND);
|
||||
void RestoreSettings(HWND);
|
||||
|
||||
virtual void notifyChange(CelestiaCore*, int);
|
||||
void notifyChange(CelestiaCore*, int) override;
|
||||
|
||||
public:
|
||||
CelestiaCore* appCore;
|
||||
|
|
|
@ -291,7 +291,7 @@ static BOOL APIENTRY ViewOptionsProc(HWND hDlg,
|
|||
ViewOptionsDialog::ViewOptionsDialog(HINSTANCE appInstance,
|
||||
HWND _parent,
|
||||
CelestiaCore* _appCore) :
|
||||
CelestiaWatcher(*_appCore),
|
||||
Watcher<CelestiaCore>(*_appCore),
|
||||
appCore(_appCore),
|
||||
parent(_parent)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "celestia/celestiacore.h"
|
||||
|
||||
class ViewOptionsDialog : public CelestiaWatcher
|
||||
class ViewOptionsDialog : public Watcher<CelestiaCore>
|
||||
{
|
||||
public:
|
||||
ViewOptionsDialog(HINSTANCE, HWND, CelestiaCore*);
|
||||
|
@ -22,7 +22,7 @@ class ViewOptionsDialog : public CelestiaWatcher
|
|||
void SetControls(HWND);
|
||||
void RestoreSettings(HWND);
|
||||
|
||||
virtual void notifyChange(CelestiaCore*, int);
|
||||
void notifyChange(CelestiaCore*, int) override;
|
||||
|
||||
public:
|
||||
CelestiaCore* appCore;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "watcher.h"
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
//namespace celutil
|
||||
//{
|
||||
template<typename T> class Watchable
|
||||
{
|
||||
public:
|
||||
inline void addWatcher(Watcher<T>* watcher);
|
||||
inline void removeWatcher(Watcher<T>* watcher);
|
||||
void notifyWatchers(int) const;
|
||||
private:
|
||||
std::vector<Watcher<T>*> watchers;
|
||||
};
|
||||
|
||||
template<typename T> void Watchable<T>::addWatcher(Watcher<T>* watcher)
|
||||
{
|
||||
assert(watcher != nullptr);
|
||||
watchers.push_back(watcher);
|
||||
}
|
||||
|
||||
template<typename T> void Watchable<T>::removeWatcher(Watcher<T>* watcher)
|
||||
{
|
||||
std::remove_if(watchers.begin(), watchers.end(),
|
||||
[&watcher](Watcher<T>* w) { return w == watcher; });
|
||||
}
|
||||
|
||||
template<typename T> void Watchable<T>::notifyWatchers(int property) const
|
||||
{
|
||||
for (const auto watcher : watchers)
|
||||
watcher->notifyChange(reinterpret_cast<const T*>(this), property);
|
||||
}
|
||||
//};
|
|
@ -26,7 +26,7 @@ template<class T> class Watcher
|
|||
watched.removeWatcher(this);
|
||||
}
|
||||
|
||||
virtual void notifyChange(T*, int) = 0;
|
||||
virtual void notifyChange(const T*, int) = 0;
|
||||
};
|
||||
|
||||
#endif // _CELUTIL_WATCHER_H_
|
||||
|
|
Loading…
Reference in New Issue