Home » Community » Newbie corner » Display transparent paper
|
Re: Display transparent paper [message #58050 is a reply to message #58049] |
Sun, 30 January 2022 00:09   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
If I want to change the background to something I specify, I just
draw.DrawRect(arect, acolor);
without this, the text will be drawn on whatever the current background is. Is this the transparent background you meant? So do nothing, you get a transparent background.
As for font.
Draw::DrawText(int x, int y, const String& text, Font font = StdFont(),...)
Just specify the font you intended there.
HTH,
Lance
|
|
|
Re: Display transparent paper [message #58051 is a reply to message #58049] |
Sun, 30 January 2022 09:34   |
Silvan
Messages: 56 Registered: December 2014 Location: Trento (IT)
|
Member |
|
|
Thak you, I specify better my question-
I want to use the alignment capacity of Display and I use this:
Display::Paint(Draww,Rectrc,AttrText(sometext).Center(),Red, White,0);
White is the paper color, but I want to write on the existing background (transparent).
I finally used something like this:
Size size = GetTextSize(sometext, font);
Draw::.DrawText((sz.cx-size.cx)/2, (sz.cy-size.cy)/2, sometext, font, Red);
I'm wandering if there exist I direct way to use Display.
Bye
Silvano
|
|
|
Re: Display transparent paper [message #58052 is a reply to message #58051] |
Sun, 30 January 2022 18:14   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Silvan:
Dig a little into Upp source code, I find something like this
void Display::PaintBackground(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const
{
if(IsType<AttrText>(q)) {
const AttrText& t = ValueTo<AttrText>(q);
if(!IsNull(t.paper))
paper = t.paper;
if(!IsNull(t.normalpaper) && !(style & (CURSOR|SELECT|READONLY)))
paper = t.normalpaper;
}
w.DrawRect(r, paper);
}
void Display::Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
{
PaintBackground(w, r, q, ink, paper, style);
Single<StdDisplayClass>().Paint0(w, r, q, ink, paper, style);
}
Do you want to try set both paper for AttrText and the Paint parameter to Null and see if you get what you want. Obviously when you set the paper color of AttrText to Null, then the paper color of passed in parameter to funciton Display::Paint will be used. I am not quite sure if set it to Null will make a do nothing DrawRect. I think its the only reasonable result, but before actually test it, I cannot really tell for sure.
HTH,
Lance
|
|
|
|
Re: Display transparent paper [message #58054 is a reply to message #58049] |
Sun, 30 January 2022 19:15   |
Silvan
Messages: 56 Registered: December 2014 Location: Trento (IT)
|
Member |
|
|
Yes it works. Thank you
Display::Paint(aDraw,aRect,AttrText(sometext).Center().SetFo nt(Arial(40)),Red,Null,0);
The answer is to set to Null the paper color.
Ps:
I have to declare the Display object, but I read somewhere that it is static.
How can I use it directly without declaraction?
Like this:
Single<StdDisplayClass>().Paint(w, r, q, ink, paper, style); // don't compile
|
|
|
|
|
|
Re: Display transparent paper [message #58058 is a reply to message #58057] |
Mon, 31 January 2022 17:47   |
Oblivion
Messages: 1204 Registered: August 2007
|
Senior Contributor |
|
|
Hello Silvan,
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyApp : TopWindow {
MyApp()
{
Sizeable().Zoomable().CenterScreen().SetRect(0, 0, 640, 480);
}
void Paint(Draw& w) override
{
Size sz = GetSize();
w.DrawRect(sz, Red());
StdCenterDisplay().Paint(w, sz, "Centered", White, Null, 0L); // <-- There are ready-made displays which you can use in-place (they are functional globals)
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
You can also create your own Display objects. See uppsrc/Draw/Display.cpp for details.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 31 January 2022 17:54] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 01:47:26 CEST 2025
Total time taken to generate the page: 0.01189 seconds
|