Jump to content

Problems Trying to get GUI working


mdgunn
 Share

Recommended Posts

Having problems with my first try at getting the Leadwerks GUI code running for some menus.

 

I got the exact code from this blog post....

 

http://www.leadwerks.com/werkspace/blog/1/entry-1714-leadwerks-gui/

 

and tried to run it but I get nothing. Am I missing something, did something change?

 

I'm on the beta branch and I see no errors but I also don't see a button.

 

I realise this is not final release but it looks like others are using it with success so any ideas what I'm doing wrong.

 

Here is the main.lua I created from the blog post code...

 

 

--Initialize Steamworks (optional)
Steamworks:Initialize()
--Set the application title
title="$PROJECT_TITLE"
--Create a window
local windowstyle = window.Titlebar + window.Resizable-- + window.Hidden
if System:GetProperty("fullscreen")=="1" then windowstyle=windowstyle+window.FullScreen end
window=Window:Create(title,0,0,System:GetProperty("screenwidth","1024"),System:GetProperty("screenheight","768"),windowstyle)
--window:HideMouse()
--Create the graphics context
context=Context:Create(window)
if context==nil then return end
--Create a GUI
local gui = GUI:Create(context)
--Create a new widget
local button = Widget:Create(20,20,300,50,gui:GetBase())
--Set the widget's script to make it a button
button:SetScript("Scripts/GUI/Button.lua")
--Set the button text
button:SetText("Button")
--Create a world
world=World:Create()
world:SetLightQuality((System:GetProperty("lightquality","1")))
--Load a map
local mapfile = System:GetProperty("map","Maps/start.map")
if Map:Load(mapfile)==false then return end
--window:Show()
while window:KeyDown(Key.Escape)==false do

    --Process events
    while EventQueue:Peek() do
		    local event = EventQueue:Wait()
		    if event.id == Event.WidgetAction then
				    if event.source == button then
						    System:Print("The button was pressed!")
				    end
		    end
    end

    --If window has been closed, end the program
    if window:Closed() then break end

    --Handle map change
    if changemapname~=nil then

		    --Clear all entities
		    world:Clear()

		    --Load the next map
		    Time:Pause()
		    if Map:Load("Maps/"..changemapname..".map")==false then return end
		    Time:Resume()

		    changemapname = nil
    end	

    --Update the app timing
    Time:Update()

    --Update the world
    world:Update()

    --Render the world
    world:Render()

    --Render statistics
    context:SetBlendMode(Blend.Alpha)
    if DEBUG then
		    context:SetColor(1,0,0,1)
		    context:DrawText("Debug Mode",2,2)
		    context:SetColor(1,1,1,1)
		    context:DrawStats(2,22)
		    context:SetBlendMode(Blend.Solid)
    else
		    --Toggle statistics on and off
		    if (window:KeyHit(Key.F11)) then showstats = not showstats end
		    if showstats then
				    context:SetColor(1,1,1,1)
				    context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)
		    end
    end

    --Refresh the screen
    context:Sync(true)

end

Link to comment
Share on other sites

I never got it to work decently without modifying button.lua. Haven't used it for a long time but here's an old modified button.lua script.

 

Script.pushed=false
Script.hovered=false

function Script:Draw(x,y,width,height)
   --System:Print("Paint Button")
   local gui = self.widget:GetGUI()
   local pos = self.widget:GetPosition(true)
   local sz = self.widget:GetSize(true)
   local scale = gui:GetScale()

   gui:SetColor(1,1,1,1)

   if self.pushed then
       gui:SetColor(0.2,0.2,0.2)
   else
       if self.hovered then
           gui:SetColor(0.3,0.3,0.3)
       else
           gui:SetColor(0.25,0.25,0.25)
           gui:SetColor(0.15,0.15,0.15,1.0,1)
       end
   end

--    gui:SetGradientMode(true)
--    gui:DrawRect(pos.x,pos.y,sz.width,sz.height,0,scale*3)
   gui:DrawRect(pos.x,pos.y,sz.width,sz.height,0,0)
--    gui:SetGradientMode(false)

   if self.pushed then
       gui:SetColor(0.0,0.0,0.0)
   else
       gui:SetColor(0.75,0.75,0.75)
   end
   --gui:DrawLine(pos.x,pos.y,pos.x+sz.width,pos.y)
   --gui:DrawLine(pos.x,pos.y,pos.x,pos.y+sz.height)

   if self.pushed then
       gui:SetColor(0.75,0.75,0.75)
   else
       gui:SetColor(0.0,0.0,0.0)       
   end
   --gui:DrawLine(pos.x+1,pos.y+sz.height-1,pos.x+sz.width-1,pos.y+sz.height-1)
   --gui:DrawLine(pos.x+sz.width-1,pos.y+1,pos.x+sz.width-1,pos.y+sz.height)

   if self.hovered then
       gui:SetColor(51/255/4,151/255/4,1/4)
   else
       gui:SetColor(0,0,0)
   end
--    gui:DrawRect(pos.x,pos.y,sz.width,sz.height,1,scale*3)
   gui:DrawRect(pos.x,pos.y,sz.width,sz.height,1,0)

   local text = self.widget:GetText()
   if text~="" then
       gui:SetColor(0.0,0.0,0.0)
       if self.pushed then
           --gui:DrawText(text,pos.x+scale+scale,pos.y+scale+scale,sz.width,sz.height,Text.Center+Text.VCenter)   
       else
           gui:DrawText(text,pos.x+scale,pos.y+scale,sz.width,sz.height,Text.Center+Text.VCenter)   
       end
       gui:SetColor(0.75,0.75,0.75)
       if self.pushed then
           gui:DrawText(text,pos.x+scale,pos.y+scale,sz.width,sz.height,Text.Center+Text.VCenter)   
       else
           gui:DrawText(text,pos.x,pos.y,sz.width,sz.height,Text.Center+Text.VCenter)   
       end
   end
end

function Script:MouseEnter(x,y)
   self.hovered = true
   self.widget:Redraw()
end

function Script:MouseLeave(x,y)
   self.hovered = false
   self.widget:Redraw()
end

function Script:MouseMove(x,y)
   --System:Print("MouseMove")
end

function Script:MouseDown(button,x,y)
   --System:Print("MouseDown")
   self.pushed=true
   self.widget:Redraw()
end

function Script:MouseUp(button,x,y)
   --System:Print("MouseUp")
   local gui = self.widget:GetGUI()
   self.pushed=false
   if self.hovered then
       EventQueue:Emit(Event.WidgetAction,self.widget)
   end
   self.widget:Redraw()
end

function Script:KeyDown(button,x,y)
   --System:Print("KeyDown")
end

function Script:KeyUp(button,x,y)
   --System:Print("KeyUp")   
end

post-12583-0-90158400-1483979846_thumb.jpg

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

Link to comment
Share on other sites

Thanks for that. I tried your script and i DO get a button though there are very many differences with current code. I don't have any background image of the map though, just back background. If I comment out the GUI stuff the view of the loaded map returns.

 

I also retried things at home (was on my standard work desktop earlier) and the code that didn't work (at work) works a bit better at ome. I now see text and a tiny dot or square (presumably the button outline).

 

Thanks for helping me get a bit further. I might poke around a bit more and also re-consider going back to FlowGUI for now.

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.

 Share

×
×
  • Create New...