Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed enhancements #22

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Dematos
Pierre Adam (https://github.com/PierreAdam)
eXpl0it3r (https://github.com/eXpl0it3r)
Zax37 (https://github.com/Zax37)
Steven Christy (https://github.com/StevenChristy)
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Changelog for SFGUI, http://sfgui.sfml-dev.de/

0.4.0-dev

Enhancements:
- HandleEvent now returns true/false to indicate whether or not an event is
handled. This allows the gui to trap events and prevent them from being
processed further by the application.
- Disabling a container now disables all child controls allowing them to
render as disabled.

0.3.0

Fixes:
Expand Down
7 changes: 5 additions & 2 deletions examples/CustomWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,27 @@ class MyCustomWidget : public sfg::Widget {
}

// This handler handles mouse button events
void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override {
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override {
bool bHandled = false;
if( !IsMouseInWidget() ) {
if( GetState() == State::ACTIVE ) {
SetState( State::NORMAL );
}

return;
return bHandled;
}

if( button == sf::Mouse::Left ) {
if( press ) {
bHandled = true;
SetLabel( sf::String( "Mouse Left Press: " + std::to_string( x ) + "," + std::to_string( y ) ) );
SetState( State::ACTIVE );
}
else if( GetState() == State::ACTIVE ) {
SetState( State::PRELIGHT );
}
}
return bHandled;
}

sf::String m_label;
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SFGUI_API Button : public Bin {
private:
void HandleMouseEnter( int x, int y ) override;
void HandleMouseLeave( int x, int y ) override;
void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void AllocateChild();

sf::String m_label;
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/ComboBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class SFGUI_API ComboBox : public Bin {
void HandleMouseEnter( int x, int y ) override;
void HandleMouseLeave( int x, int y ) override;
void HandleMouseMoveEvent( int x, int y ) override;
void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleStateChange( State old_state ) override;
void HandleUpdate( float seconds ) override;
void ChangeStartEntry();
Expand Down
10 changes: 9 additions & 1 deletion include/SFGUI/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class SFGUI_API Container : public Widget {

void Refresh() override;

void HandleEvent( const sf::Event& event ) override;
/** Handle event.
* @param event SFML event.
* @return true if event is handled.
*/
bool HandleEvent( const sf::Event& event ) override;

/** Used to inform parent that a child has been invalidated
* @param child Widget that was invalidated.
Expand Down Expand Up @@ -84,6 +88,10 @@ class SFGUI_API Container : public Widget {
/** Handle viewport change.
*/
void HandleViewportUpdate() override;

/** Handle state change.
*/
void HandleStateChange(State old_state) override;

private:
WidgetsList m_children;
Expand Down
3 changes: 2 additions & 1 deletion include/SFGUI/Desktop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class SFGUI_API Desktop {

/** Handle event.
* @param event SFML event.
* @return true if event is handled.
*/
void HandleEvent( const sf::Event& event );
bool HandleEvent( const sf::Event& event );

/** Add widget.
* The added widget will be the new top widget.
Expand Down
6 changes: 3 additions & 3 deletions include/SFGUI/Entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ class SFGUI_API Entry : public Widget {
std::unique_ptr<RenderQueue> InvalidateImpl() const override;
sf::Vector2f CalculateRequisition() override;

void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleUpdate( float seconds ) override;
void HandleTextEvent( sf::Uint32 character ) override;
void HandleKeyEvent( sf::Keyboard::Key key, bool press ) override;
bool HandleTextEvent( sf::Uint32 character ) override;
bool HandleKeyEvent( sf::Keyboard::Key key, bool press ) override;
void HandleSizeChange() override;
void HandleFocusChange( Widget::Ptr focused_widget ) override;

Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class SFGUI_API Notebook : public Container {
typedef std::deque<ChildLabelPair> ChildrenList;

void HandleMouseMoveEvent( int x, int y ) override;
void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleAdd( Widget::Ptr child ) override;
void HandleRemove( Widget::Ptr child ) override;
void HandleSizeChange() override;
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SFGUI_API Scale : public Range {
*/
Scale( Orientation orientation = Orientation::HORIZONTAL );

void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleMouseMoveEvent( int x, int y ) override;

std::unique_ptr<sf::Vector2f> m_drag_offset;
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Scrollbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SFGUI_API Scrollbar : public Range {
*/
Scrollbar( Orientation orientation = Orientation::HORIZONTAL );

void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleMouseMoveEvent( int x, int y ) override;
void HandleUpdate( float seconds ) override;

Expand Down
6 changes: 3 additions & 3 deletions include/SFGUI/SpinButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ class SFGUI_API SpinButton : public Entry {
void UpdateTextFromAdjustment();
void UpdateAdjustmentFromText();

void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleUpdate( float seconds ) override;
void HandleTextEvent( sf::Uint32 character ) override;
void HandleKeyEvent( sf::Keyboard::Key key, bool press ) override;
bool HandleTextEvent( sf::Uint32 character ) override;
bool HandleKeyEvent( sf::Keyboard::Key key, bool press ) override;
void HandleSizeChange() override;
void HandleFocusChange( Widget::Ptr focused_widget ) override;

Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Viewport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SFGUI_API Viewport : public Bin {
* Handle an SFML event and fire proper signals.
* @return true when event has been processed (eaten).
*/
void HandleEvent( const sf::Event& event ) override;
bool HandleEvent( const sf::Event& event ) override;

const std::string& GetName() const override;

Expand Down
24 changes: 19 additions & 5 deletions include/SFGUI/Widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this<Widg
ACTIVE, /*!< Active, e.g. when a button is pressed. */
PRELIGHT, /*!< Prelight, e.g. when the mouse moves over a widget. */
SELECTED, /*!< Selected, e.g. when a list item in a list is selected. */
INSENSITIVE /*!< Insensitive, disabled widget. */
INSENSITIVE, /*!< Insensitive, disabled widget. */
PARENT_INSENSITIVE /* Disabled child widget. */
};

/** Destructor.
Expand All @@ -58,6 +59,16 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this<Widg
* @param show true to show, false to hide.
*/
void Show( bool show = true );

/** Check to see if the widget is enabled.
* @return true when enabled.
*/
bool IsEnabled() const;

/** Enable or disable control.
* @param true to enable or false to disable.
*/
void Enable( bool enable = true );

/** Get name of widget.
* The name of a widget is a descriptive name of the widget itself. E.g.
Expand Down Expand Up @@ -173,8 +184,9 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this<Widg
* Handle an SFML event and fire proper signals. Normally reimplemented by
* containers only.
* @param event SFML event.
* @return true if event is handled.
*/
virtual void HandleEvent( const sf::Event& event );
virtual bool HandleEvent( const sf::Event& event );

/** Get absolute position on screen.
* @return Absolute position.
Expand Down Expand Up @@ -349,14 +361,16 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this<Widg
* @param press true if button was pressed, false if released.
* @param x Mouse X position.
* @param y Mouse Y position.
* @return true if Handled.
*/
virtual void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y );
virtual bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y );

/** Handle key event.
* @param key Key.
* @param press true if button was pressed, false if released.
* @return true if Handled.
*/
virtual void HandleKeyEvent( sf::Keyboard::Key key, bool press );
virtual bool HandleKeyEvent( sf::Keyboard::Key key, bool press );

/** Handle widget (relative) position changes.
*/
Expand All @@ -381,7 +395,7 @@ class SFGUI_API Widget : public Object, public std::enable_shared_from_this<Widg
/** Handle text event.
* @param character Character.
*/
virtual void HandleTextEvent( sf::Uint32 character );
virtual bool HandleTextEvent( sf::Uint32 character );

/** Handle mouse enter.
* @param x Mouse X position.
Expand Down
2 changes: 1 addition & 1 deletion include/SFGUI/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SFGUI_API Window : public Bin {

private:
void HandleSizeChange() override;
void HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
bool HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) override;
void HandleMouseMoveEvent( int x, int y ) override;
bool HandleAdd( Widget::Ptr child ) override;

Expand Down
10 changes: 6 additions & 4 deletions src/SFGUI/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ void Button::HandleMouseLeave( int /*x*/, int /*y*/ ) {
}
}

void Button::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int /*x*/, int /*y*/ ) {
bool Button::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int /*x*/, int /*y*/ ) {
if( !IsMouseInWidget() ) {
if( GetState() == State::ACTIVE ) {
SetState( State::NORMAL );
SetState( State::NORMAL );
}

return;
return false;
}

if( button == sf::Mouse::Left ) {
Expand All @@ -72,6 +72,8 @@ void Button::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int /
SetState( State::PRELIGHT );
}
}

return true;
}

sf::Vector2f Button::CalculateRequisition() {
Expand Down
15 changes: 9 additions & 6 deletions src/SFGUI/ComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ void ComboBox::HandleMouseMoveEvent( int x, int y ) {
}
}

void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) {
bool ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) {
bool bHandled = false;
if( ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) {
return;
return bHandled;
}

if( GetState() == State::ACTIVE ) {
Expand All @@ -288,7 +289,7 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int

ReleaseModal();
m_scrollbar->SetActiveWidget();
m_scrollbar->HandleEvent( event );
bHandled = m_scrollbar->HandleEvent( event );
SetActiveWidget();
GrabModal();

Expand All @@ -297,12 +298,12 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int
scrollbar_allocation.top += GetAllocation().top;

if( scrollbar_allocation.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) {
return;
return bHandled;
}
}

if( !press || ( button != sf::Mouse::Left ) ) {
return;
return bHandled;
}

auto emit_select = false;
Expand All @@ -327,7 +328,7 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int
GetSignals().Emit( OnSelect );
}

return;
return bHandled;
}

if( press && ( button == sf::Mouse::Left ) && IsMouseInWidget() ) {
Expand All @@ -337,7 +338,9 @@ void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int

Invalidate();
GetSignals().Emit( OnOpen );
bHandled = true;
}
return bHandled;
}

sf::Vector2f ComboBox::CalculateRequisition() {
Expand Down
Loading