Skip to content

Commit

Permalink
Fix the high cpu usage when switching to the event editor on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlevasseur committed Apr 24, 2015
1 parent 752d2a4 commit 5c8c580
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Core/GDCore/IDE/Dialogs/LayoutEditorCanvas/LayoutEditorCanvas.cpp
Expand Up @@ -118,7 +118,8 @@ LayoutEditorCanvas::LayoutEditorCanvas(wxWindow* parent, gd::Project & project_,
smallButtonSize(gd::GUIContentScaleFactor::Get() > 1 ? 12 : 5),
firstRefresh(true),
isSelecting(false),
editing(true)
editing(true),
enableIdleEvents(true)
{
//(*Initialize(LayoutEditorCanvas)
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS, _T("wxID_ANY"));
Expand Down Expand Up @@ -313,11 +314,14 @@ LayoutEditorCanvas::~LayoutEditorCanvas()

void LayoutEditorCanvas::OnIdle(wxIdleEvent & event)
{
// Send a paint message when the control is idle, to ensure maximum framerate
Refresh();
#if defined(__WXGTK__)
event.RequestMore(); //On GTK, we need to specify that we want continuous idle events.
#endif
if(enableIdleEvents)
{
// Send a paint message when the control is idle, to ensure maximum framerate
Refresh();
#if defined(__WXGTK__)
event.RequestMore(); //On GTK, we need to specify that we want continuous idle events.
#endif
}
}

void LayoutEditorCanvas::OnPaint(wxPaintEvent&)
Expand Down
Expand Up @@ -247,6 +247,12 @@ class GD_CORE_API LayoutEditorCanvas: public wxPanel, public sf::RenderWindow
*/
void GoToEditingState();

/**
* \brief Enable or disable idle events. Disabling them avoid the scene to be constantly rendered.
* \note Used by the scene editor when the user switch to the event editor.
*/
void EnableIdleEvents(bool enable = true) {enableIdleEvents = enable;};

virtual sf::Vector2f GetInitialInstanceSize(gd::InitialInstance & instance) const;
virtual sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance & instance) const;

Expand Down Expand Up @@ -500,6 +506,8 @@ class GD_CORE_API LayoutEditorCanvas: public wxPanel, public sf::RenderWindow
bool editing; ///< True if the layout is being edited, false if a preview is running.
std::shared_ptr<gd::LayoutEditorPreviewer> currentPreviewer; ///< The previewer being used to preview the layout.

bool enableIdleEvents;

wxMenu contextMenu;
wxMenu noObjectContextMenu;
wxMenu zoomMenu;
Expand Down
2 changes: 2 additions & 0 deletions IDE/EditorScene.cpp
Expand Up @@ -185,12 +185,14 @@ void EditorScene::ForceRefreshRibbonAndConnect()
if ( notebook->GetPageText(notebook->GetSelection()) == _("Scene") )
{
layoutEditorCanvas->RecreateRibbonToolbar();
layoutEditorCanvas->EnableIdleEvents();
mainFrameWrapper.GetRibbon()->SetActivePage(2);
layoutEditorCanvas->ConnectEvents();
}
else if ( notebook->GetPageText(notebook->GetSelection()) == _("Events") )
{
mainFrameWrapper.GetRibbon()->SetActivePage(3);
layoutEditorCanvas->EnableIdleEvents(false);
eventsEditor->ConnectEvents();
}
}
Expand Down

0 comments on commit 5c8c580

Please sign in to comment.