Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

I need some classes

boalen (fat line, ellipse), password (Textbox, that I have, but I need to replace every letter with •••••), many lines textparagraph with highlight by special words, integer (line, ellipse), THANK YOU ALL!

Comments

  • dave1707dave1707 Mod
    edited November 2015 Posts: 8,459

    @TokOut Are you looking for a Password TextBox like this.

    EDIT: Replaced original code with a class version.

    function setup()
        rectMode(CENTER)
        showKeyboard()
        pw=passwordBox(300,500,150,50)
    end
    
    function draw()
        pw:draw()    
    end
    
    function keyboard(k)
        pw:keyboard(k)
    end
    
    passwordBox=class()
    
    function passwordBox:init(x,y,w,h)
        self.x=x
        self.y=y
        self.w=w
        self.h=h
        self.rtn=false
        self.str=""
        self.per="*********************"
    end
    
    function passwordBox:draw()
        background(127, 224, 224, 255)  
        noStroke()
        fill(0)
        rect(self.x+10,self.y+90,self.w,self.h)    
        fill(255, 90, 0, 255)
        stroke(255)
        strokeWidth(5)    
        rect(self.x,self.y+100,self.w,self.h)    
        self.str=keyboardBuffer()
        if self.rtn then
            self.rtn=false
            hideKeyboard()
            showKeyboard()
        end        
        fill(255)
        if self.str=="" then
            text("Password",self.x,self.y+100) 
        else
            text(string.sub(self.per,1,string.len(self.str)),self.x,self.y+100) 
        end    
    end
    
    function passwordBox:keyboard(k)
        if k==RETURN then
            self.rtn=true
            print(self.str)
        end     
    end
    
  • What about boalen and many-lines-text-paragraph?

  • Posts: 2,020

    You can use textWrapWidth to automatically start a new line at a given width (soft wrap). If you want to add a manual new line (hard wrap) you can use the new line character \n eg myString = "this string has a\nnew line in the middle"

    Or, you can use the [[ ]] literal string brackets eg:

    myString = [[this string has a
    new line in the middle]]
    
  • Posts: 2,020

    What is boalen (fat line, ellipse)? Boolean?

  • parameter.boalen()

  • Posts: 2,020

    parameter.boolean()

  • In the screen

  • dave1707dave1707 Mod
    Posts: 8,459

    @TokOut Here's a simple Boolean button.

    function setup()
        rectMode(CENTER)
        b=boolBtn(200,400,80,40)
    end
    
    function draw()
        background(40, 40, 50)
        b:draw()
    end
    
    function touched(t)
        b:touched(t)
    end
    
    boolBtn=class()
    
    function boolBtn:init(x,y,w,h)
        self.x=x
        self.y=y
        self.w=w
        self.h=h
        self.val="false"
    end
    
    function boolBtn:draw()
        fill(0, 231, 255, 255)
        rect(self.x,self.y,self.w,self.h)
        fill(255,0,0)
        text(self.val,self.x,self.y)
    end
    
    function boolBtn:touched(t)
        if t.state==BEGAN then
            if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
                    t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                if self.val=="true" then
                    self.val="false"
                else
                    self.val="true"
                end
                print(self.val)
            end
        end
    end
    
  • @yojimbo2000, 1. Your code don't work 2. And? I can create a new acount

  • dave1707dave1707 Mod
    edited November 2015 Posts: 8,459

    @TokOut Here's a class that allows you to key in a lot of text in a TextBox. Just key as much as you want, then press return.

    function setup()
        showKeyboard()
        tx=txtBox(300,450,150,250)
    end
    
    function draw()
        background(40, 40, 50)
        tx:draw()
    end
    
    function keyboard(k)
        tx:keyboard(k)
    end
    
    txtBox=class()
    
    function txtBox:init(x,y,w,h)
        self.x=x
        self.y=y
        self.w=w
        self.h=h
        self.str=""
        self.wrap=self.w-8
        self.strW=0
        self.strH=0
    end
    
    function txtBox:draw()
        textMode(CORNER)
        stroke(255, 41, 0, 255)
        strokeWidth(3)
        textWrapWidth(self.wrap)
        fill(178, 221, 223, 255)
        rect(self.x,self.y,self.w,self.h)
        self.str=keyboardBuffer()
        self.strW,self.strH=textSize(self.str)
        fill(0)
        text(self.str,self.x+5,self.y+self.h-self.strH)
    end
    
    function txtBox:keyboard(k)
        if k==RETURN then
            str=self.str
            self.str=""
            hideKeyboard()
            showKeyboard()
            print(str)
        end
    end
    
  • edited November 2015 Posts: 55

    Okay, this is my boalen class:

    Boalen = class()
    
    function Boalen:init(x, y, value)
        self.x = x -- Position X
        self.y = y
        self.value = value
        self.size = 22.5
        if self.value == true then
            self.elx = self.x + 50
        else
            self.elx = self.x + 2.5
        end
    end
    
    function Boalen:draw()
        strokeWidth(50)
        stroke(255, 255, 255, 255)
        line(self.x, self.y, self.x + 50, self.y)
    
        fill(225, 220, 0, 255)
        ellipseMode(RADIUS)
        strokeWidth(0)
        ellipse(self.elx, self.y, self.size)
    end
    
    function Boalen:touched(t)
        if t.state == BEGAN and self:hit(vec2(t.x, t.y)) then
        if self.value == true then
            self.value = false
        else
            self.value = true
        end
        end
    end
    
    function Boalen:hit(p)
        local r = self.x + 50
        local t = self.y + 5
        local b = self.y - 5
        local l = self.x
            if l < p.x
            and t > p.y
            and r > p.x
            and b < p.y
            then
            return true
        end
        return false
    end
    

    I made it at my own, what was I doing false? If I touch it, it doesn't work. Can you explain my error

  • IgnatzIgnatz Mod
    Posts: 5,396

    Do you have a touched function as well?

    Suppose you have 2 Boalen objects

    b1 = Boalen(1,2,3)
    b2 = Boalen(4,5,6)
    

    Then you need this to make the touches work in your class

    function touched(t)
        b1:touched(t)
        b2:touched(t)
    end 
    
  • This is the main function by me:

    displayMode(OVERLAY)
    displayMode(FULLSCREEN)
    supportedOrientations(WIDTH)
    
    function setup()
        boaly = Boalen(500, 500, false)
    end
    
    function draw()
        boaly:draw()
    end
    
    function touched(t)
        boaly:touched(t)
    end
    
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    What I do is to put print statements in my code to see what is happening

    For example, like this

    function Boalen:touched(t)
        print("touch!")
        if t.state == BEGAN and self:hit(vec2(t.x, t.y)) then
        if self.value == true then
            self.value = false
        else
            self.value = true
        end
        print("change self.value to ",self.value)
        end
    end
    
  • @Ignatz ERROR: Attempt to a concencate boalen value to 34: self.value

  • IgnatzIgnatz Mod
    Posts: 5,396

    what line of code is that?

  • I have written print("Boalen: ".. self.value)

  • IgnatzIgnatz Mod
    Posts: 5,396

    Use print("Boalen: ", self.value)

  • @Ignatz

    Boalen = class()
    
    function Boalen:init(x, y, value)
        self.x = x
        self.y = y
        self.value = value -- t/f
        self.size = 22.5
        if self.value == true then
            self.elx = self.x + 50
        else
            self.elx = self.x + 2.5
        end
    end
    
    function Boalen:draw()
        strokeWidth(50)
        stroke(255, 255, 255, 255)
        line(self.x, self.y, self.x + 50, self.y)
    
        fill(225, 220, 0, 255)
        ellipseMode(RADIUS)
        strokeWidth(0)
        ellipse(self.elx, self.y, self.size)
    end
    
    function Boalen:touched(t)
        if t.state == BEGAN and self:hit(vec2(t.x, t.y)) then
            if self.value == true then
                self.value = false
                print("Set to false")
            else
                self.value = true
                print("Set to true")
            end
        end
    end
    
    function Boalen:hit(p)
        local r = self.x + 50
        local t = self.y + 5
        local b = self.y - 5
        local l = self.x
            if l < p.x
            and t > p.y
            and r > p.x
            and b < p.y
            then
            return true
        end
        return false
    end
    

    So Ignatz. Can you make it so, if you touch the boalen it will be moved, because he don't move. I am trying to make a video later, but he don't move if he will get moved

  • IgnatzIgnatz Mod
    Posts: 5,396

    This code

     if self.value == true then
            self.elx = self.x + 50
        else
            self.elx = self.x + 2.5
        end
    

    Should be in Boalen:draw, not Boalen:init

Sign In or Register to comment.