Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: creating a control (button) class  (Read 3208 times)

0 Members and 1 Guest are viewing this topic.

globalenemy

  • Newbie
  • *
  • Posts: 10
    • View Profile
creating a control (button) class
« on: March 21, 2016, 11:06:48 pm »
Hey,
I'm trying to ceate a control (button) class, by following this c++ example:
http://alexanderx.net/create-simple-button/

But my Update method doesn't seem to operate:
public virtual void Update(RenderTarget _target) {
   if (enabled) {
      if (hovered) {
         if (Mouse.IsButtonPressed(Mouse.Button.Left)) {
            if (!pressed) {
               RaiseMouseDown();
               pressed = true;
            }
         }
         else {
            if (pressed) {
               RaiseMouseUp();
               RaiseMouseClick();
               pressed = false;
            }
         }
      }
      Vector2i mouse = Mouse.GetPosition();
      if (mouse != prevMouse) {
         prevMouse = mouse;
         FloatRect body = new FloatRect(Position + Origin, new Vector2f(Size.X, Size.Y));
         if (body.Contains(mouse.X, mouse.Y)) {
            if (!hovered) {
               RaiseMouseEnter();
               hovered = true;
            }
            RaiseMouseMove();
         }
         else if (hovered) {
            RaiseMouseLeave();
            hovered = false;
         }
      }
   }
}

Complete Class (containing button class):
http://pastebin.com/fAMj2t3s

How do I make this work?
« Last Edit: March 22, 2016, 12:06:18 am by globalenemy »

globalenemy

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: creating a control (button) class
« Reply #1 on: March 22, 2016, 12:17:11 am »
okay, got it working.

public virtual void Update(SFML.Window.Window _window) {...

Vector2i mouse = Mouse.GetPosition(_window);

Needed to get the mouse position relative to my window.