www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dgui - Button continually repainting

reply "Mike James" <foo bar.com> writes:
Hi.

I've created a graphic button as per this example on the dgui 
website:

import dgui.all;

class MyForm: Form
{
	this()
	{
		text = "An Exception was thrown...";
		size = Size(130, 100);

		// Or use `Bitmap.fromFile`:
		auto img = new Bitmap(90, 15, SystemColors.yellow);
		auto pen = SystemPens.blackPen;

		with(new Button())
		{
			bounds = Rect(10, 10, 100, 25);
			parent = this;
			paint.attach((s, e)
			{
				e.canvas.drawImage(img, 5, 5);
				e.canvas.drawLine(pen, 5, 10, 95, 10);
				e.canvas.drawLine(pen, 10, 5, 10, 20);
			});
		}
	}
}

int main()
{
	return Application.run(new MyForm());
}

and added a writeln("paint") in the paint.attach to show when the 
button is repainting. When the form with the button is visible 
the button is being continually repainted. Is this a 'feature' of 
dgui or is there a flag to set to only re-paint when the button 
is invalidated?

Regards, -=mike=-.
Sep 09 2014
parent reply "andre" <andre s-e-a-p.de> writes:
Hi,

Just checked, on WM_PAINT all event listeners (event paint) are 
called.

Overwriting onPaint seems to work better (issue 18 in dgui 
bitbucket site). Please file this issue also on the dgui bibucket 
home page.

Kind regards
Andre


On Tuesday, 9 September 2014 at 10:50:11 UTC, Mike James wrote:
 Hi.

 I've created a graphic button as per this example on the dgui 
 website:

 import dgui.all;

 class MyForm: Form
 {
 	this()
 	{
 		text = "An Exception was thrown...";
 		size = Size(130, 100);

 		// Or use `Bitmap.fromFile`:
 		auto img = new Bitmap(90, 15, SystemColors.yellow);
 		auto pen = SystemPens.blackPen;

 		with(new Button())
 		{
 			bounds = Rect(10, 10, 100, 25);
 			parent = this;
 			paint.attach((s, e)
 			{
 				e.canvas.drawImage(img, 5, 5);
 				e.canvas.drawLine(pen, 5, 10, 95, 10);
 				e.canvas.drawLine(pen, 10, 5, 10, 20);
 			});
 		}
 	}
 }

 int main()
 {
 	return Application.run(new MyForm());
 }

 and added a writeln("paint") in the paint.attach to show when 
 the button is repainting. When the form with the button is 
 visible the button is being continually repainted. Is this a 
 'feature' of dgui or is there a flag to set to only re-paint 
 when the button is invalidated?

 Regards, -=mike=-.
Sep 09 2014
parent reply "Mike James" <foo bar.com> writes:
//
Please file this issue also on the dgui
 bibucket home page.

 Kind regards
 Andre
// Done. Regards, -=mike=-
Sep 10 2014
parent reply "andre" <andre s-e-a-p.de> writes:
Hi,
Just noticed there is an event drawItem whichs is called on 
WM_DRAWITEM. Class core.controls.ownerdrawcontrol.d is very 
interesting.
This event seems more suitable.

Kind regards
André


On Wednesday, 10 September 2014 at 07:19:53 UTC, Mike James wrote:
 //
 Please file this issue also on the dgui
 bibucket home page.

 Kind regards
 Andre
// Done. Regards, -=mike=-
Sep 10 2014
parent "Mike James" <foo bar.com> writes:
Hi Andre,

I've found a solution to the repainting problem. If you tick the 
"Disable visual themes" in the compatibility tab of the program 
properties (associated with the program icon) the button is only 
repainted when the mouse cursor enters and exits the button area.

Regards, -=mike=-

On Wednesday, 10 September 2014 at 19:46:06 UTC, andre wrote:
 Hi,
 Just noticed there is an event drawItem whichs is called on 
 WM_DRAWITEM. Class core.controls.ownerdrawcontrol.d is very 
 interesting.
 This event seems more suitable.

 Kind regards
 André


 On Wednesday, 10 September 2014 at 07:19:53 UTC, Mike James 
 wrote:
 //
 Please file this issue also on the dgui
 bibucket home page.

 Kind regards
 Andre
// Done. Regards, -=mike=-
Sep 15 2014