Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How to blur a Ctrl
How to blur a Ctrl [message #48773] Wed, 13 September 2017 18:35 Go to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

I wanted to blur an area of a Ctrl, so that user can distinguish but cannot realize the details under the blurred area.

Do you know if it is possible?

index.php?t=getfile&id=5398&private=0

A possible way would be to "mask" the Ctrl by painting small squares in void Paint(), but maybe it would be possible a more professional blurring effect.
  • Attachment: Captura.JPG
    (Size: 30.48KB, Downloaded 470 times)


Best regards
Iñaki
Re: How to blur a Ctrl [message #48774 is a reply to message #48773] Wed, 13 September 2017 19:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 13 September 2017 18:35
Hello all

I wanted to blur an area of a Ctrl, so that user can distinguish but cannot realize the details under the blurred area.

Do you know if it is possible?

index.php?t=getfile&id=5398&private=0

A possible way would be to "mask" the Ctrl by painting small squares in void Paint(), but maybe it would be possible a more professional blurring effect.


Relatively easy way is to go through Image...

This is far from good, but to give the idea:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp : TopWindow {
	virtual void Paint(Draw& w) {
		ImageDraw iw(GetSize());
		iw.DrawRect(GetSize(), White());
		iw.DrawText(10, 10, "Hello World!", Arial(20));
		Image m = iw;
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		w.DrawImage(0, 0, m);
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}
Re: How to blur a Ctrl [message #48808 is a reply to message #48774] Sun, 24 September 2017 08:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you Mirek

However this solution only blurs itself, but it does not blur but hides the Ctrl under it.


Best regards
Iñaki
Re: How to blur a Ctrl [message #48809 is a reply to message #48808] Sun, 24 September 2017 09:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sun, 24 September 2017 08:51
Thank you Mirek

However this solution only blurs itself, but it does not blur but hides the Ctrl under it.


I see. Now that one would be tricky, depending on circustances.

If "blurred" widgets are not active, I would try to implement that by drawing the whole thing into Image and then use that Image as background.

Another option would be to use something in host OS.

Mirek
Re: How to blur a Ctrl [message #48810 is a reply to message #48809] Sun, 24 September 2017 09:45 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Something like

https://msdn.microsoft.com/en-us/library/windows/desktop/aa9 69524(v=vs.85).aspx
Re: How to blur a Ctrl [message #48811 is a reply to message #48810] Sun, 24 September 2017 16:27 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you Mirek

I have tried it with DwmEnableBlurBehindWindow(). However I can only blur all TopWindow and not simply a region.
As this feature is not too important for me, I will maintain this:
	void Paint(Draw& w) {
		Size sz = GetSize();
	
		for (double x = 0; x < sz.cx; x += (visible + hidden)) 
			for (double y = 0; y < sz.cy; y += (visible + hidden)) 
				w.DrawRect(int(x), int(y), int(hidden), int(hidden), SColorFace);
	}
	void Layout() {
		Font f = parent->GetFont();
		int q = f.GetHeight();
		visible = 0.1*q;
		hidden = 0.3*q;
	}


Best regards
Iñaki
Re: How to blur a Ctrl [message #48815 is a reply to message #48774] Mon, 25 September 2017 20:00 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi,

Maybe somthing like this could do the trick:

template <class T>
class BlurringDecorator : public T {
	
	private:
	bool doBlur;

	void blurImage(Image& m) {
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
		m = Sharpen(m, -200);
	}


	public:
	
	BlurringDecorator() : doBlur(true) {}
	virtual ~BlurringDecorator() {}
	void setBlur(bool blur = true)  { doBlur = blur; }
	
	virtual void Paint(Draw& w) {
		
		if (doBlur) {
			ImageDraw dw(T::GetSize());
			T::Paint(dw);
			Image im = dw;
			blurImage(im);
			w.DrawImage(0, 0, im);
		}
		else {
			T::Paint(w);
		}
	}
	
};


In layout
BlurringDecorator<CtrlToBlur>  myCtrl;



EDIT: just tried, works fine (but only blurrs the current Ctrl ... not what is under it !!!)


[Updated on: Mon, 25 September 2017 20:26]

Report message to a moderator

Re: How to blur a Ctrl [message #48819 is a reply to message #48815] Thu, 28 September 2017 08:12 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Excellent! That's it!

Thank you.


Best regards
Iñaki
Previous Topic: [Closed] Get size and position of widget
Next Topic: Size of TopWindow is different then the size I set for it
Goto Forum:
  


Current Time: Fri Mar 29 02:09:01 CET 2024

Total time taken to generate the page: 0.02225 seconds