123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- #include "pch.h"
- //////////////////////////////////////////////////////////////////////////////
- //
- //
- //
- //////////////////////////////////////////////////////////////////////////////
- class StringComboFacePane : public ComboFacePane {
- private:
- TRef<StringPane> m_pstringPane;
- TRef<BorderPane> m_pborder;
- public:
- StringComboFacePane(
- const WinPoint& size,
- IEngineFont* pfont,
- const Color& color,
- bool bBackgroundColor
- ) {
- InternalSetSize(size);
- m_pstringPane =
- new StringPane(
- ZString(),
- pfont,
- size
- );
- m_pstringPane->SetTextColor(color);
- if (bBackgroundColor) {
- InsertAtBottom(
- m_pborder = new BorderPane(
- 0,
- Color(0.25, 0.25, 0.25),
- m_pstringPane
- )
- );
- } else {
- InsertAtBottom(m_pstringPane);
- }
- }
- void SetString(const ZString& str)
- {
- m_pstringPane->SetString(str);
- }
- void SetInside(bool bInside)
- {
- }
- void SetColor(const Color& color)
- {
- if (m_pborder) {
- m_pborder->SetColor(color);
- }
- }
- };
- TRef<ComboFacePane> CreateStringComboFacePane(
- const WinPoint& size,
- IEngineFont* pfont,
- const Color& color,
- bool bBackgroundColor
- ) {
- return new StringComboFacePane(size, pfont, color, bBackgroundColor);
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- //
- //
- //////////////////////////////////////////////////////////////////////////////
- class ImageComboFacePane : public ComboFacePane {
- private:
- TRef<ButtonFacePane> m_pfacePane;
- public:
- ImageComboFacePane(Image* pimage)
- {
- m_pfacePane =
- CreateButtonFacePane(
- pimage->GetSurface(),
- ButtonFaceUp | ButtonFaceInside
- );
- InsertAtBottom(m_pfacePane);
- }
- void SetString(const ZString& str)
- {
- }
- void SetColor(const Color& color)
- {
- }
- void SetInside(bool bInside)
- {
- m_pfacePane->SetInside(bInside);
- }
- void UpdateLayout()
- {
- DefaultUpdateLayout();
- }
- };
- TRef<ComboFacePane> CreateImageComboFacePane(Image* pimage)
- {
- return new ImageComboFacePane(pimage);
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- //
- //
- //////////////////////////////////////////////////////////////////////////////
- class ComboPaneImpl :
- public ComboPane,
- public IMenuCommandSink
- {
- private:
- TRef<IntegerEventSourceImpl> m_peventSource;
- TRef<EventSourceImpl> m_peventMouseEnterWhileEnabledSource;
- TRef<EventSourceImpl> m_peventMenuSelectSource;
- TRef<IMenu> m_pmenu;
- TRef<Modeler> m_pmodeler;
- TRef<IEngineFont> m_pfont;
- TRef<ComboFacePane> m_pface;
- TRef<IPopupContainer> m_ppopupContainer;
- bool m_bFirstItem;
- TVector<ZString> m_vstrItems;
- int m_idSelection;
- bool m_bEnabled;
- bool m_bInside;
- public:
- ComboPaneImpl(
- Modeler* pmodeler,
- IPopupContainer* ppopupContainer,
- IEngineFont* pfont,
- const WinPoint& size,
- ComboFacePane* pface
- ) :
- m_peventMouseEnterWhileEnabledSource(new EventSourceImpl()),
- m_peventMenuSelectSource(new EventSourceImpl()),
- m_ppopupContainer(ppopupContainer),
- m_pface(pface),
- m_bFirstItem(true),
- m_idSelection(0),
- m_bInside(false),
- m_bEnabled(true),
- m_pmodeler(pmodeler),
- m_pfont(pfont)
- {
- InsertAtBottom(
- new JustifyPane(
- JustifyPane::Left,
- size,
- pface
- )
- );
- m_peventSource = new IntegerEventSourceImpl();
- m_pmenu =
- CreateMenu(
- pmodeler,
- pfont,
- IMenuCommandSink::CreateDelegate(this)
- );
- }
- ~ComboPaneImpl()
- {
- m_pmenu->SetMenuCommandSink(NULL);
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // IEventSink
- //
- //////////////////////////////////////////////////////////////////////////////
- bool OnEvent(IEventSource* peventSource)
- {
- return true;
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // IMenuCommandSink
- //
- //////////////////////////////////////////////////////////////////////////////
- void OnMenuCommand(IMenuItem* pitem)
- {
- m_pface->SetString(pitem->GetString());
- m_pface->SetColor(pitem->GetColor());
- m_idSelection = pitem->GetID();
- m_peventMenuSelectSource->Trigger();
- m_peventSource->Trigger(pitem->GetID());
- m_ppopupContainer->ClosePopup(m_pmenu);
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // ComboPane methods
- //
- //////////////////////////////////////////////////////////////////////////////
- void ClearContents()
- {
- m_bFirstItem = true;
- m_idSelection = 0;
- m_vstrItems.SetEmpty();
- m_pmenu =
- CreateMenu(
- m_pmodeler,
- m_pfont,
- IMenuCommandSink::CreateDelegate(this)
- );
- }
-
- TRef<IMenuItem> AddItem(const ZString& str, int id)
- {
- TRef<IMenuItem> pitem = m_pmenu->AddMenuItem(id, str);
- if (m_bFirstItem) {
- m_bFirstItem = false;
- m_idSelection = id;
- m_pface->SetString(pitem->GetString());
- m_pface->SetColor(pitem->GetColor());
- }
- m_vstrItems.PushEnd(str);
- return pitem;
- }
- TRef<IMenuItem> AddItem(const ZString& str, int id, const Color& color)
- {
- bool bFirstItem = m_bFirstItem;
- TRef<IMenuItem> pitem = m_pmenu->AddMenuItem(id, str);
- if (bFirstItem) {
- m_pface->SetColor(color);
- }
- return pitem;
- }
- void SetSelection(int id)
- {
- m_idSelection = id;
- IMenuItem* pitem = m_pmenu->FindMenuItem(id);
- if (pitem) {
- m_pface->SetString(pitem->GetString());
- m_pface->SetColor(pitem->GetColor());
- m_peventSource->Trigger(id);
- } else {
- m_pface->SetString("");
- m_peventSource->Trigger(id);
- }
- }
- const ZString * GetSelectionString()
- {
- return &m_vstrItems[m_idSelection];
- }
- int GetSelection()
- {
- return m_idSelection;
- }
- IIntegerEventSource* GetEventSource()
- {
- return m_peventSource;
- }
- void SetEnabled(bool bEnabled)
- {
- if (m_bEnabled != bEnabled)
- {
- m_bEnabled = bEnabled;
- if (bEnabled && m_bInside)
- m_peventMouseEnterWhileEnabledSource->Trigger();
- }
- }
- IEventSource* GetMouseEnterWhileEnabledEventSource()
- {
- return m_peventMouseEnterWhileEnabledSource;
- }
- IEventSource* GetMenuSelectEventSource()
- {
- return m_peventMenuSelectSource;
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // Pane methods
- //
- //////////////////////////////////////////////////////////////////////////////
- void UpdateLayout()
- {
- DefaultUpdateLayout();
- }
- //////////////////////////////////////////////////////////////////////////////
- //
- // IMouseInput methods
- //
- //////////////////////////////////////////////////////////////////////////////
- void MouseEnter(IInputProvider* pprovider, const Point& point)
- {
- m_bInside = true;
- m_pface->SetInside(true);
- if (m_bEnabled)
- m_peventMouseEnterWhileEnabledSource->Trigger();
- }
- void MouseLeave(IInputProvider* pprovider)
- {
- m_bInside = false;
- m_pface->SetInside(false);
- }
- MouseResult HitTest(IInputProvider* pprovider, const Point& point, bool bCaptured)
- {
- bool bInside =
- !IsHidden()
- && point.X() >= 0
- && point.X() < (float)XSize()
- && point.Y() >= 0
- && point.Y() < (float)YSize();
- return bInside ? MouseResultHit() : MouseResult();
- }
- MouseResult Button(IInputProvider* pprovider, const Point& point, int button, bool bCaptured, bool bInside, bool bDown)
- {
- if (button == 0 && m_bEnabled) {
- if (bDown) {
- Point point =
- TransformLocalToImage(
- WinPoint(
- 0,
- m_pface->GetSize().Y()
- )
- );
- m_ppopupContainer->OpenPopup(m_pmenu, Rect(point,point), true, true);
- }
- }
- return MouseResult();
- }
- };
- TRef<ComboPane> CreateComboPane(
- Modeler* pmodeler,
- IPopupContainer* ppopupContainer,
- IEngineFont* pfont,
- const WinPoint& size,
- ComboFacePane* pface
- ) {
- return new ComboPaneImpl(pmodeler, ppopupContainer, pfont, size, pface);
- }
|