[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 » Tue Apr 25, 2017 11:20 pm

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: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax » Wed Apr 26, 2017 5:32 am

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 » Wed Apr 26, 2017 7:38 am

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: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax » Wed Apr 26, 2017 9:26 am

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 » Thu Apr 27, 2017 6:15 am

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: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax » Thu Apr 27, 2017 9:55 am

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 » Thu Apr 27, 2017 10:06 pm

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: 13990
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [WX WIDGETS LUA] Semi-transparent shape

Post by doublemax » Thu Apr 27, 2017 10:36 pm

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 » Thu Apr 27, 2017 10:45 pm

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

Post Reply