use handler for context menu callback

pull/383/head
Li Linfeng 2019-08-25 14:13:29 +08:00
parent 2aa162f0bb
commit c986cdebf9
2 changed files with 23 additions and 14 deletions

View File

@ -687,8 +687,8 @@ void CelestiaCore::mouseButtonUp(float x, float y, int button)
Selection sel = sim->pickObject(pickRay, renderer->getRenderFlags(), pickTolerance);
if (!sel.empty())
{
if (contextMenuCallback != nullptr)
contextMenuCallback(x, y, sel);
if (contextMenuHandler != nullptr)
contextMenuHandler->requestContextMenu(x, y, sel);
}
}
else if (button == MiddleButton)
@ -2721,12 +2721,6 @@ void CelestiaCore::setActiveFrameVisible(bool visible)
}
void CelestiaCore::setContextMenuCallback(ContextMenuFunc callback)
{
contextMenuCallback = callback;
}
Renderer* CelestiaCore::getRenderer() const
{
return renderer;
@ -4490,6 +4484,16 @@ CelestiaCore::CursorHandler* CelestiaCore::getCursorHandler() const
return cursorHandler;
}
void CelestiaCore::setContextMenuHandler(ContextMenuHandler* handler)
{
contextMenuHandler = handler;
}
CelestiaCore::ContextMenuHandler* CelestiaCore::getContextMenuHandler() const
{
return contextMenuHandler;
}
int CelestiaCore::getTimeZoneBias() const
{
return timeZoneBias;

View File

@ -197,8 +197,6 @@ class CelestiaCore // : public Watchable<CelestiaCore>
ShowFrame = 0x010,
};
typedef void (*ContextMenuFunc)(float, float, Selection);
private:
class OverlayImage
{
@ -317,8 +315,6 @@ class CelestiaCore // : public Watchable<CelestiaCore>
int getOverlayElements() const;
void setOverlayElements(int);
void setContextMenuCallback(ContextMenuFunc);
void addWatcher(CelestiaWatcher*);
void removeWatcher(CelestiaWatcher*);
@ -372,6 +368,16 @@ class CelestiaCore // : public Watchable<CelestiaCore>
void setCursorHandler(CursorHandler*);
CursorHandler* getCursorHandler() const;
class ContextMenuHandler
{
public:
virtual ~ContextMenuHandler() = default;
virtual void requestContextMenu(float, float, Selection) = 0;
};
void setContextMenuHandler(ContextMenuHandler*);
ContextMenuHandler* getContextMenuHandler() const;
void toggleReferenceMark(const std::string& refMark, Selection sel = Selection());
bool referenceMarkEnabled(const std::string& refMark, Selection sel = Selection()) const;
@ -485,14 +491,13 @@ class CelestiaCore // : public Watchable<CelestiaCore>
MovieCapture* movieCapture{ nullptr };
bool recording{ false };
ContextMenuFunc contextMenuCallback{ nullptr };
Texture* logoTexture{ nullptr };
Alerter* alerter{ nullptr };
std::vector<CelestiaWatcher*> watchers;
CursorHandler* cursorHandler{ nullptr };
CursorShape defaultCursorShape{ CelestiaCore::CrossCursor };
ContextMenuHandler* contextMenuHandler{ nullptr };
std::vector<Url*> history;
std::vector<Url*>::size_type historyCurrent{ 0 };