[WX WIDGETS LUA] Semi-transparent shape

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Nolram_07
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Mar 17, 2017 5:56 pm

[WX WIDGETS LUA] Semi-transparent shape

Post by Nolram_07 »

i'm trying to get this:


Image

the semi-transparent rectangle, but not working
i'm working whit Windows Xp. Some way to do it

Thanks
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax »

You can't do this in one step. For shading the background you need one wxFrame without decorations, which is just black with 50% (or similar) transparency.
-> wxTopLevelWindow::SetTransparent

On top of that you can place a "shaped" frame. Check the "shaped" sample on how to do this.
-> wxNonOwnedWindow::SetShape
Use the source, Luke!
Nolram_07
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Mar 17, 2017 5:56 pm

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by Nolram_07 »

I have this:

Code: Select all

function OnKeyDown(event)
	if event:GetKeyCode() == 65 then
		dialog_messageA()
	end
	if event:GetKeyCode() == 67 then
        	dialog:Destroy()
	end
end
fuction dialog_messageA()
	local dialog = wx.wxDialog(panel, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxSize(500, 150),wx.wxNO_BORDER)
	function On_key(event)
        	if event:GetKeyCode() == 67 then
	 	       dialog:Destroy()
	        end 
    	end
    	
	function OnPaint(event)
		event:Skip()
		local dc = wx.wxPaintDC(dialog)
		dc:SetPen(wx.wxWHITE_PEN)
	        dc:DrawRectangle(1,1, 498, 15)
        	dc:SetPen(wx.wxPen(wx.wxColour(240,240,240),0,0))
	        dc:SetBrush(wx.wxBrush(wx.wxColour(240,240,240), 0))
	        dc:DrawLine(1,38, 498, 38)
        	dc:DrawRectangle(1,106, 498, 43)
	        dc:SetTextForeground(wx.wxColour(100,100,100))
	        dc:DrawText("CONFIGURACION", 30, 13)
        	dc:delete()
        end
        dialog:Connect(wx.wxEVT_PAINT, OnPaint)
        dialog:Connect(wx.wxEVT_KEY_DOWN, On_key)
end
funtion main()
	frame = wx.wxFrame( wx.NULL,   wx.wxID_ANY,  "Mi Ventana",  wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxNO_BORDER)
	panel = wx.wxPanel(frame, wx.wxID_ANY)
	panel:Connect(wx.wxEVT_KEY_DOWN, OnKeyDown) 
end
When I press the A key I need the transparent background to appear whit the dialog box
the shape of a dialog is not important
thanks
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax »

Like i said, for a "clean" solution you need two different frames: One that blends the background and another one on top.

However, there is a way to cheat: You can grab the screen content (using wxScreenDC), put it into a bitmap, blend it programatically towards black and use that as the background for your custom drawing.
Use the source, Luke!
Nolram_07
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Mar 17, 2017 5:56 pm

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by Nolram_07 »

Uknow to call method SetTransparent() on a wxFrame
this is the error on Windows XP, but in windows 7 works fine
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax »

Nolram_07 wrote:Uknow to call method SetTransparent() on a wxFrame
this is the error on Windows XP, but in windows 7 works fine
I know that wxLua is based on wxWidets 2.8.x, but SetTransparent() is available in wx 2.8.x and should also work under XP. I have no idea what to do about this.
Use the source, Luke!
Nolram_07
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Mar 17, 2017 5:56 pm

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by Nolram_07 »

doublemax wrote:I know that wxLua is based on wxWidets 2.8.x, but SetTransparent() is available in wx 2.8.x and should also work under XP. I have no idea what to do about this.
SetTransparent() is available on wxLua-2.8.12.x, but that version not working in Windows XP = "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem"
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax »

Sorry, i can't help with that. Seems to be a wxLua problem.

Maybe you can try the other approach which is probably easier to implement anyway?
Use the source, Luke!
Nolram_07
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Mar 17, 2017 5:56 pm

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by Nolram_07 »

Yes, i will try whit the bitmap
really
thanks a lot. Doublemax, really appreciate the answers.
Post Reply