Jump to content

Trying to Understand Show/Hide Paint


Recommended Posts

Posted

Hello,

I was wondering if someone could explain a little more in-depth as to how showing/hiding paint works, as far as getting intractable buttons working. I've been trying to follow this tutorial/snippit (bottom of page):

 

http://osbot.org/forum/topic/59574-interactable-paint-not-working-on-osbot-2/

 

I'm just not sure where to create the buttons, where to place them, etc. Is there an easier way to implement showing and hiding paint with intractable buttons? (as if it's already kinda easy as it is unsure.png )

Posted

You need a rectangle, a boolean and a  mouse listener.

 

Rectangle:

 

MouseListener: 

 

  1. Create a rectangle
  2. Create a boolean
  3. Add a new MouseListener to the client
  4. When the mouse is clicked, grab the MouseEvent's point and check if the rectangle contains it, if so -> invert the boolean

 

 

  • Like 2
Posted (edited)

Our mouse class

public class Mouse implements MouseListener {
    //create a boolean
    public boolean hidePaint;

    @Override
    public void mouseClicked(MouseEvent e) {
        //create our point variable
        Point p = e.getPoint();
        //create our rectangle
        Rectangle rec = new Rectangle(x,y,width,height);
        //check if the rectangle contains point and change booleans state
        if(rec.contains(p))
            hidePaint = !hidePaint;
    }

    @Override
    public void mouseEntered(MouseEvent e) {         
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }
    @Override
    public void mouseReleased(MouseEvent e) {
    }
}

Main class

public class Main extends Script{
    //pas our mouse object
    Mouse mouse = new Mouse();
    
    public void onStart(){
        //add our mouse object as a mouse listener
        getBot().addMouseListener(mouse);
    }

    public void onPaint(Graphics2D g){
        //check if our boolean is false
        if(!mouse.hidePaint){
            //draw our stuff
        }
    }

    public int onLoop(){
        return 0;
    }
}

Hope this helps :)

Edited by Vilius
  • Like 2
  • 1 year later...
Posted
On 3/16/2016 at 4:51 AM, Vilius said:

Our mouse class


public class Mouse implements MouseListener {
    //create a boolean
    public boolean hidePaint;

    @Override
    public void mouseClicked(MouseEvent e) {
        //create our point variable
        Point p = e.getPoint();
        //create our rectangle
        Rectangle rec = new Rectangle(x,y,width,height);
        //check if the rectangle contains point and change booleans state
        if(rec.contains(p))
            hidePaint = !hidePaint;
    }

    @Override
    public void mouseEntered(MouseEvent e) {         
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }
    @Override
    public void mouseReleased(MouseEvent e) {
    }
}

Main class


public class Main extends Script{
    //pas our mouse object
    Mouse mouse = new Mouse();
    
    public void onStart(){
        //add our mouse object as a mouse listener
        getBot().addMouseListener(mouse);
    }

    public void onPaint(Graphics2D g){
        //check if our boolean is false
        if(!mouse.hidePaint){
            //draw our stuff
        }
    }

    public int onLoop(){
        return 0;
    }
}

Hope this helps :)

Thank you, this is exactly what I was looking for.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...