Jump to content

Trying to Understand Show/Hide Paint


S3R0

Recommended Posts

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 )

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 year later...
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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