Question regarding an Indicator based on wxStaticBitmap

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Fenhasan
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Aug 02, 2020 10:57 am

Question regarding an Indicator based on wxStaticBitmap

Post by Fenhasan » Fri Oct 23, 2020 1:12 pm

Hi:

I'm trying to make a custom LED, so I drew a green LED, both on and off, and saved it as two transparent background PNG files, GreenLedOn.png and GreenLedOff.png. I then added both images as 30x30 pixels static bitmaps, GreenLedOn and GreenLedOff. Later, i defined a method to "switch" the LED on and off:

Code: Select all

void LedStatus(bool x)
{
	if(x)
	{
		GreenLedOn->Show();
		GreenLedOff->Hide();
	}
	else
	{
		GreenLedOn->Hide();
		GreenLedOff->Show();
	}
}
This off course assumes both images are in the same position, so to make sure i added another method:

Code: Select all

void LedPosition(int x, int y)
{
	GreenLedOn->SetPosition(wxPoint(x,y));
	GreenLedOff->SetPosition(wxPoint(x,y));
}
As it is, it works fine, but the obvious problem is that if i wanted to add another LED, i'd have to duplicate everything, both the items and the functions, so it's not very scalable.

My question is, how can i encapsulate this, like a class, for example, so i can declare a new LED, each one with the same methods, instead of having to duplicate everything if i need a new LED? I'm fairly new to GUI and C++ (main experience in C for microcontrollers), so i have no idea on how to do this.

Thanks in advance for your help.

Best regards,
Fenhasan

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2668
Joined: Sun Jan 03, 2010 5:45 pm

Re: Question regarding an Indicator based on wxStaticBitmap

Post by PB » Fri Oct 23, 2020 2:30 pm

Perhaps you could use the wxLEDCtrl code as an inspiration:
viewtopic.php?f=21&t=46137#p192934

Obviously, you are going to have two member wxBitmaps for On and Off. Just be aware that for a real-world application, you probably need those bitmaps at several resolutions, to make them look good at high DPI.

Just keep in mind that it is an example code, not production ready one.

Fenhasan
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Aug 02, 2020 10:57 am

Re: Question regarding an Indicator based on wxStaticBitmap

Post by Fenhasan » Fri Oct 23, 2020 2:59 pm

Thanks, I'll check it out

Post Reply