Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How to blur a Ctrl
|
Re: How to blur a Ctrl [message #48774 is a reply to message #48773] |
Wed, 13 September 2017 19:13 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Wed, 13 September 2017 18:35Hello 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?
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 #48815 is a reply to message #48774] |
Mon, 25 September 2017 20:00 |
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
|
|
|
|
Goto Forum:
Current Time: Fri Apr 19 13:32:35 CEST 2024
Total time taken to generate the page: 0.02120 seconds
|