Howdy, Stranger!

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

Help with windows

AnatolyAnatoly Mod
edited December 2015 in Questions Posts: 878

I want to make that you can decide the look of the content (text or image ....) and not creating hundred classes with Window.Alert, Window.TextParagraph or Window.Brouser. Can you only answer me how? I want to make it my self and not with your codes. Only say how to do it. Thank you very much!

Main {In SC formatting}

-- setup
win = Window(50, 50)
win.logo = readImage("Documents:Logo")
win.name = "My Window Test"
-- draw
win:draw()
-- touched (t)
win:touched(t)
--[[
Information
With win.drawing = true, you can set it visible again.
]]

Class called Window

Window = class()

function Window:init(x, y, w, h)
    if x==nil or y==nil then x=0 y=0 end
    if w==nil then w=500 end
    if h==nil then h=200 end
    self.x = x
    self.y = y
    self.w = w
    self.h = h
    self.name = "Window"
    self.logo = readImage("Platformer Art:Block Grass")
    self.drawing = true
end

function Window:draw()
    if self.drawing == true then
        self.tw, self.th = textSize(self.name)
        fill(255, 255, 255, 255)
        rect(self.x, self.y, self.w, self.h)
        -- Panel [[
        rect(self.x, self.y + self.h, self.w, 75)
        -- Logo
        sprite(self.logo, self.x + 40, self.y + self.h + 37.5, 55, 55)
        -- Name
        fill(0, 0, 0, 255)
        fontSize(30)
        font("Baskerville")
        text(self.name, self.x + self.w/2, self.y + self.h + 35)
        -- Close Button
        fill(0, 0, 255, 255)
        rect(self.x + self.w - 65, self.y + self.h + 10, 55, 55)
        fill(255, 0, 0, 255)
        font("AmericanTypewriter-Bold")
        fontSize(50)
        text("X", self.x + self.w - 36.5, self.y + self.h + 35)
        -- Panel ]]
    end
end

function Window:touched(t)
    if t.state == BEGAN and t.x> -60+self.x+self.w and t.x<-10+self.w+self.x and t.y>15+self.y+self.h and t.y<165+self.h+self.y then
        print("Closed!")
        self.drawing = false
    end
end
Tagged:

Comments

  • AnatolyAnatoly Mod
    Posts: 878

    Please help! Thx if someone WON'T ignore this message!

  • edited December 2015 Posts: 82
    Assuming every Window instance has an unique id, I would create a simple function that confines all subsequent drawing to that window's canvas:

    ~~~
    function DrawInWindow(window)
    pushMatrix()
    translate(window.x, window.y)
    clip(0, 0, window.w, window.h)
    end
    ~~~

    Then, in your draw function:

    ~~~
    function draw()
    background(0)
    DrawInWindow(windowAlert)
    -- Draw something in your window
    popMatrix()
    clip()
    -- Resets to drawing fullscreen
    end
    ~~~

    Maybe you could implement those last two lines for resetting in the `DrawInWindow()` function when called without arguments.
  • AnatolyAnatoly Mod
    Posts: 878

    Thx

  • AnatolyAnatoly Mod
    Posts: 878

    But I already created this functions (classes) and I want to fix them.

Sign In or Register to comment.