Mercurial > fife-parpg
changeset 154:d29593182f40
- modified clicklabel to provide a mouse listener for hover events
- modified clicklabel.i to make new methods available for python
- added LabelListener to pychan wrapper, as well as two new methods to Label class to set enter / exit callbacks
NOTE:
author | chewie@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 11 Oct 2008 14:13:56 +0000 |
parents | d8e32b4adc5c |
children | 29309cd5e240 |
files | engine/core/gui/widgets/clicklabel.cpp engine/core/gui/widgets/clicklabel.h engine/core/gui/widgets/widgets.i engine/extensions/basicapplication.py engine/extensions/pychan/widgets.py |
diffstat | 5 files changed, 87 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/gui/widgets/clicklabel.cpp Sat Oct 11 14:03:01 2008 +0000 +++ b/engine/core/gui/widgets/clicklabel.cpp Sat Oct 11 14:13:56 2008 +0000 @@ -40,7 +40,7 @@ // setAlignment(Graphics::LEFT); setTextWrapping(false); setFrameSize(0); - + m_listener = NULL; addMouseListener(this); addKeyListener(this); addFocusListener(this); @@ -53,7 +53,7 @@ setTextWrapping(false); setCaption(caption); setFrameSize(0); - + m_listener = NULL; addMouseListener(this); addKeyListener(this); addFocusListener(this); @@ -141,11 +141,19 @@ void ClickLabel::mouseExited(MouseEvent& mouseEvent) { + // taken from TwoButton.cpp + if (m_listener) { + m_listener->mouseExited(*this); + } mHasMouse = false; } void ClickLabel::mouseEntered(MouseEvent& mouseEvent) { + // taken from TwoButton.cpp + if (m_listener) { + m_listener->mouseEntered(*this); + } mHasMouse = true; }
--- a/engine/core/gui/widgets/clicklabel.h Sat Oct 11 14:03:01 2008 +0000 +++ b/engine/core/gui/widgets/clicklabel.h Sat Oct 11 14:13:56 2008 +0000 @@ -38,6 +38,19 @@ } namespace gcn { + + // taken from TwoButton.cpp + // FIXME: the listener code for Twobutton and Clicklabel is + // a kind of a hack and shouldn't be necessary later. So if + // eventmanager changes some day, this should be modified, too + class ClickLabel; + class ClickLabelListener { + public: + virtual ~ClickLabelListener() {} + virtual void mouseEntered(ClickLabel& btn) = 0; + virtual void mouseExited(ClickLabel& btn) = 0; + }; + class ClickLabel : public Widget, public MouseListener, public KeyListener, public FocusListener { public: ClickLabel(); @@ -79,6 +92,11 @@ virtual void keyReleased(KeyEvent& keyEvent); + + // taken from TwoButton.cpp + void setListener(ClickLabelListener* listener) { m_listener = listener; } + ClickLabelListener* getListener() { return m_listener; } + protected: void wrapText(); @@ -86,6 +104,7 @@ bool mTextWrapping; std::string mCaption; std::string mWrappedText; + ClickLabelListener* m_listener; bool mHasMouse; bool mKeyPressed;
--- a/engine/core/gui/widgets/widgets.i Sat Oct 11 14:03:01 2008 +0000 +++ b/engine/core/gui/widgets/widgets.i Sat Oct 11 14:13:56 2008 +0000 @@ -379,6 +379,15 @@ virtual void resizeToContent(); }; + class ClickLabel; + %feature("director") ClickLabelListener; + class ClickLabelListener { + public: + virtual ~ClickLabelListener(); + virtual void mouseEntered(ClickLabel& btn) = 0; + virtual void mouseExited(ClickLabel& btn) = 0; + }; + %feature("notabstract") ClickLabel; %rename(Label) ClickLabel; class ClickLabel: public Widget { @@ -392,6 +401,9 @@ void setTextWrapping(bool); virtual void setWidth(int width); virtual void adjustSize(); + + void setListener(ClickLabelListener* listener); + ClickLabelListener* getListener(); }; %feature("notabstract") Icon2;
--- a/engine/extensions/basicapplication.py Sat Oct 11 14:03:01 2008 +0000 +++ b/engine/extensions/basicapplication.py Sat Oct 11 14:13:56 2008 +0000 @@ -29,6 +29,9 @@ keyval = evt.getKey().getValue() if keyval == fife.Key.ESCAPE: self.app.quit() + elif keyval == fife.Key.F10: + self.engine.getGuiManager().getConsole().toggleShowHide() + evt.consume() def keyReleased(self, evt): pass
--- a/engine/extensions/pychan/widgets.py Sat Oct 11 14:03:01 2008 +0000 +++ b/engine/extensions/pychan/widgets.py Sat Oct 11 14:13:56 2008 +0000 @@ -1028,11 +1028,31 @@ return self._image image = property(_getImage,_setImage) +class LabelListener(fife.ClickLabelListener): + """ the listener class for label onMouse events + + @type btn: object + @param btn: the label widget + """ + def __init__(self, lbl): + fife.ClickLabelListener.__init__(self) + self.lbl = lbl + self.entercb = None + self.exitcb = None + + def mouseEntered(self, lbl): + if self.entercb: + self.entercb(self.lbl) + + def mouseExited(self, lbl): + if self.exitcb: + self.exitcb(self.lbl) + class Label(BasicTextWidget): """ A basic label - displaying a string. - Also allows text wrapping. + Also allows text wrapping and onMouse hover callbacks. New Attributes ============== @@ -1041,6 +1061,7 @@ Currently to actually see text wrapping you have to explicitly set a max_size with the desired width of the text, as the layout engine is not capable of deriving the maximum width from a parent container. + """ ATTRIBUTES = BasicTextWidget.ATTRIBUTES + [BoolAttr('wrap_text')] @@ -1049,7 +1070,9 @@ self.real_widget = fife.Label("") self.wrap_text = wrap_text super(Label,self).__init__(**kwargs) - + self.listener = LabelListener(self) + self.real_widget.setListener(self.listener) + def resizeToContent(self): self.real_widget.setWidth( self.max_size[0] ) self.real_widget.adjustSize() @@ -1061,6 +1084,20 @@ def _getTextWrapping(self): self.real_widget.isTextWrapping() wrap_text = property(_getTextWrapping,_setTextWrapping) + def setEnterCallback(self, cb): + """ + Callback is called when mouse enters the area of Label + callback should have form of function(button) + """ + self.listener.entercb = cb + + def setExitCallback(self, cb): + """ + Callback is called when mouse enters the area of Label + callback should have form of function(button) + """ + self.listener.exitcb = cb + class ClickLabel(Label): """ Deprecated - use L{Label} instead. @@ -1165,17 +1202,17 @@ self.width = max(self._upimage.getWidth(),self._downimage.getWidth(),self._hoverimage.getWidth()) + self.margins[1]*2 def setEnterCallback(self, cb): - ''' + """ Callback is called when mouse enters the area of ImageButton callback should have form of function(button) - ''' + """ self.listener.entercb = cb def setExitCallback(self, cb): - ''' + """ Callback is called when mouse enters the area of ImageButton callback should have form of function(button) - ''' + """ self.listener.exitcb = cb