Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/uimodule'
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 6, 2017
2 parents b62e6d0 + 865a554 commit 155250f
Show file tree
Hide file tree
Showing 64 changed files with 2,091 additions and 1,305 deletions.
6 changes: 2 additions & 4 deletions include/ifiltermenu.h
Expand Up @@ -12,10 +12,7 @@ namespace ui
* A class representing a Filters submenu, with a proper
* getWidget() method for packing it into a parent container.
*
* Upon construction, the menu will be registered in the
* global MenuManager. The destructor will remove it from there,
* so the client needs to prevent this class from getting
* out of scope too soon.
* It's the caller's responsibility to delete the object.
*
* Use the GlobalUIManager() interface to acquire
* a new instance of this filter menu.
Expand All @@ -28,6 +25,7 @@ class IFilterMenu
// Constructs and returns the widget of a full filters menu
// including submenu and the items. This can be packed into an
// existing menu bar or toolitem right away.
// Caller is responsible of deleting the menu!
virtual wxMenu* getMenuWidget() = 0;
};
typedef std::shared_ptr<IFilterMenu> IFilterMenuPtr;
Expand Down
12 changes: 12 additions & 0 deletions include/ilayer.h
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <functional>
#include "imodule.h"
#include <sigc++/signal.h>

namespace scene
{
Expand Down Expand Up @@ -178,6 +179,17 @@ class ILayerSystem :
* should be de-selected.
*/
virtual void setSelected(int layerID, bool selected) = 0;

/**
* A signal for client code to get notified about layer creation,
* addition, removal.
*/
virtual sigc::signal<void> signal_layersChanged() = 0;

/**
*
*/
virtual sigc::signal<void> signal_layerVisibilityChanged() = 0;
};

} // namespace scene
Expand Down
1 change: 1 addition & 0 deletions include/imap.h
Expand Up @@ -66,6 +66,7 @@ class IMap :
MapLoaded, // emitted when the current map is done loading
MapUnloading, // emitted just before a map is unloaded from memory
MapUnloaded, // emitted after a map has been unloaded
MapSaved, // emitted right after a map has been saved
};

typedef sigc::signal<void, MapEvent> MapEventSignal;
Expand Down
57 changes: 57 additions & 0 deletions include/imediabrowser.h
@@ -0,0 +1,57 @@
#pragma once

#include "imodule.h"
#include <string>

namespace ui
{

/**
* Interface to the MediaBrowser, which is displaying the
* available materials, accessible as a page in the
* GroupDialog's notebook.
*/
class IMediaBrowser :
public RegisterableModule
{
public:
virtual ~IMediaBrowser()
{}

/**
* Returns the texture name of the currently selected item.
* Will return an empty string if a folder is selected or
* nothing is selected at all.
*/
virtual std::string getSelection() = 0;

/** Set the given path as the current selection, highlighting it
* in the tree view.
*
* @param selection
* The fullname of the item to select, or the empty string if there
* should be no selection.
*/
virtual void setSelection(const std::string& selection) = 0;

// The tab name as registred in the GroupDialog
const char* const getGroupDialogTabName() const
{
return "mediabrowser";
}
};

}

const char* const MODULE_MEDIABROWSER = "MediaBrowser";

inline ui::IMediaBrowser& GlobalMediaBrowser()
{
// Cache the reference locally
static ui::IMediaBrowser& _mediaBrowser(
*std::static_pointer_cast<ui::IMediaBrowser>(
module::GlobalModuleRegistry().getModule(MODULE_MEDIABROWSER)
)
);
return _mediaBrowser;
}
26 changes: 9 additions & 17 deletions include/iuimanager.h
Expand Up @@ -5,8 +5,8 @@

// Forward declarations
class wxWindow;
class wxObject;
class wxToolBar;
class wxMenuBar;

class IColourSchemeManager {
public:
Expand All @@ -32,22 +32,17 @@ namespace ui
};
} // namespace ui

/** greebo: Implementation documentation: see MenuManager.h.
*/
class IMenuManager
{
public:
/** Destructor
*/
virtual ~IMenuManager() {}

/** greebo: Retrieves the menuitem widget specified by the path.
*
* Example: get("main/file/open") delivers the widget for the "Open..." command.
*
* @returns: the widget, or NULL, if no the path hasn't been found.
/**
* Returns the constructed menu bar, ready for packing into a parent container.
*/
virtual wxObject* get(const std::string& path) = 0;
virtual wxMenuBar* getMenuBar(const std::string& name) = 0;

/** greebo: Shows/hides the menuitem under the given path.
*
Expand All @@ -64,11 +59,8 @@ class IMenuManager
* @caption: the display string of the menu item (incl. mnemonic)
* @icon: the icon filename (can be empty)
* @eventname: the event name (e.g. "ToggleShowSizeInfo")
*
* @returns: the menu item wxObject, which might be a wxMenuItem, or
* a wxMenu or wxMenuBar pointer.
*/
virtual wxObject* add(const std::string& insertPath,
virtual void add(const std::string& insertPath,
const std::string& name,
ui::eMenuItemType type,
const std::string& caption,
Expand All @@ -82,17 +74,17 @@ class IMenuManager
* @caption: the display string including mnemonic
* @icon: the image file name relative to "bitmaps/", can be empty.
* @eventName: the event name this item is associated with (can be empty).
*
* @returns: the menu item wxObject, which might be a wxMenuItem, or
* a wxMenu or wxMenuBar pointer.
*/
virtual wxObject* insert(const std::string& insertPath,
virtual void insert(const std::string& insertPath,
const std::string& name,
ui::eMenuItemType type,
const std::string& caption,
const std::string& icon,
const std::string& eventName) = 0;

// Returns true if the given path exists
virtual bool exists(const std::string& path) = 0;

/**
* Removes an entire path from the menus.
*/
Expand Down
1 change: 1 addition & 0 deletions include/precompiled_interfaces.h
Expand Up @@ -50,6 +50,7 @@
#include "imapresource.h"
#include "imd5anim.h"
#include "imd5model.h"
#include "imediabrowser.h"
#include "imenu.h"
#include "imodel.h"
#include "imodelcache.h"
Expand Down
3 changes: 0 additions & 3 deletions install/user.xml
Expand Up @@ -109,9 +109,6 @@
<grid>
<defaultGridPower value="3" />
</grid>
<mediaBrowser>
<preLoadMediaTree value="1" />
</mediaBrowser>
<mainFrame>
<windowLayout value="1" />
<window xPosition="0" yPosition="0" width="800" height="580" state="4" />
Expand Down
8 changes: 8 additions & 0 deletions libs/wxutil/menu/PopupMenu.cpp
Expand Up @@ -84,4 +84,12 @@ void PopupMenu::_onItemClick(wxCommandEvent& ev)
}
}

void PopupMenu::foreachMenuItem(const std::function<void(const ui::IMenuItemPtr&)>& functor)
{
for (const ui::IMenuItemPtr& item : _menuItems)
{
functor(item);
}
}

} // namespace
3 changes: 3 additions & 0 deletions libs/wxutil/menu/PopupMenu.h
Expand Up @@ -77,6 +77,9 @@ class PopupMenu :
* displayed.
*/
virtual void show(wxWindow* parent);

protected:
virtual void foreachMenuItem(const std::function<void(const ui::IMenuItemPtr&)>& functor);
};
typedef std::shared_ptr<PopupMenu> PopupMenuPtr;

Expand Down
7 changes: 5 additions & 2 deletions libs/wxutil/preview/RenderPreview.cpp
Expand Up @@ -48,7 +48,8 @@ RenderPreview::RenderPreview(wxWindow* parent, bool enableAnimation) :
_timer(this),
_previewWidth(0),
_previewHeight(0),
_filtersMenu(GlobalUIManager().createFilterMenu())
_filtersMenu(GlobalUIManager().createFilterMenu()),
_filterTool(nullptr)
{
Connect(wxEVT_TIMER, wxTimerEventHandler(RenderPreview::_onFrame), NULL, this);

Expand Down Expand Up @@ -96,6 +97,8 @@ void RenderPreview::setupToolbars(bool enableAnimation)
wxToolBarToolBase* filterTool = filterToolbar->AddTool(wxID_ANY, _("Filters"),
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "iconFilter16.png"),
_("Filters"), wxITEM_DROPDOWN);

// By setting it as dropdown menu the toolitem will take ownership and delete the menu on destruction
filterToolbar->SetDropdownMenu(filterTool->GetId(), filterSubmenu);

filterToolbar->Realize();
Expand Down Expand Up @@ -134,7 +137,7 @@ void RenderPreview::connectToolbarSignals()

RenderPreview::~RenderPreview()
{
_timer.Stop();
_timer.Stop();
}

void RenderPreview::updateActiveRenderModeButton()
Expand Down
3 changes: 3 additions & 0 deletions libs/wxutil/preview/RenderPreview.h
Expand Up @@ -16,6 +16,8 @@
#include "render/SceneRenderWalker.h"
#include "render/NopVolumeTest.h"

class wxToolBarToolBase;

namespace wxutil
{

Expand Down Expand Up @@ -117,6 +119,7 @@ class RenderPreview :

// The filters menu
ui::IFilterMenuPtr _filtersMenu;
wxToolBarToolBase* _filterTool;

protected:
const scene::GraphPtr& getScene();
Expand Down
56 changes: 26 additions & 30 deletions plugins/uimanager/FilterMenu.cpp
@@ -1,60 +1,56 @@
#include "FilterMenu.h"

#include "iuimanager.h"
#include "string/convert.h"
#include "i18n.h"
#include "ieventmanager.h"
#include <wx/menu.h>

#include "wxutil/menu/IconTextMenuItem.h"

namespace ui
{

namespace
{
// These are used for the general-purpose Filter Menu:
const char* const FILTERS_MENU_BAR = "filters";
const char* const FILTERS_MENU_FOLDER = "allfilters";
const char* const FILTERS_MENU_CAPTION = N_("_Filters");

const char* const MENU_ICON = "iconFilter16.png";
}

std::size_t FilterMenu::_counter = 0;

FilterMenu::FilterMenu()
FilterMenu::FilterMenu() :
_menu(new wxutil::PopupMenu)
{
IMenuManager& menuManager = GlobalUIManager().getMenuManager();

// Create a unique name for the menu
_path = FILTERS_MENU_BAR + string::to_string(_counter++);

// Menu not yet constructed, do it now
_menu = dynamic_cast<wxMenu*>(menuManager.add("", _path,
menuFolder, _(FILTERS_MENU_CAPTION), "", ""));
assert(_menu != NULL);

_targetPath = _path;

// Visit the filters in the FilterSystem to populate the menu
GlobalFilterSystem().forEachFilter(*this);
}

FilterMenu::~FilterMenu()
{
GlobalUIManager().getMenuManager().remove(_path);
for (auto i : _filterItems)
{
IEventPtr event = GlobalEventManager().findEvent(i.first);

if (event)
{
event->disconnectMenuItem(i.second);
}
}

_menu = nullptr;
}

// Visitor function
void FilterMenu::visit(const std::string& filterName)
{
// Get the menu manager
IMenuManager& menuManager = GlobalUIManager().getMenuManager();
wxMenuItem* item = _menu->Append(new wxutil::IconTextMenuItem(filterName, MENU_ICON));
item->SetCheckable(true);

std::string eventName = GlobalFilterSystem().getFilterEventName(filterName);

// Create the menu item
menuManager.add(_targetPath, _targetPath + "_" + filterName,
menuItem, filterName,
MENU_ICON, eventName);
IEventPtr event = GlobalEventManager().findEvent(eventName);

if (event)
{
event->connectMenuItem(item);
}

_filterItems.insert(std::make_pair(eventName, item));
}

wxMenu* FilterMenu::getMenuWidget()
Expand Down
17 changes: 6 additions & 11 deletions plugins/uimanager/FilterMenu.h
@@ -1,7 +1,9 @@
#pragma once

#include <map>
#include "ifiltermenu.h"
#include "ifilter.h"
#include "wxutil/menu/PopupMenu.h"

namespace ui
{
Expand All @@ -10,26 +12,19 @@ namespace ui
* registers the relevant menuitems on demand.
*
* Construct a FiltersMenu instance to generate a new Filter Menu which
* can be packed into a parent container widget using the GtkWidget* operator.
* can be packed into a parent container widget using the getMenuWidget().
*/
class FilterMenu :
public IFilterMenu,
public IFilterVisitor
{
private:
wxMenu* _menu;
std::map<std::string, wxMenuItem*> _filterItems;

// Static counter to create unique menu bar widgets
static std::size_t _counter;

// The path of this menu
std::string _path;

// The target path used for population
std::string _targetPath;
wxutil::PopupMenu* _menu;

public:
// Constructs the filters submenu including menu bar
// Constructs the filter items
FilterMenu();

~FilterMenu();
Expand Down

0 comments on commit 155250f

Please sign in to comment.