Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 12-12-2018, 10:02 PM   #1
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default proper use of flags with gfx_drawstr to center text? (FIXED)

If I want to center text on the screen, I'm trying:
Code:
gfx_x=gfx_w/2;
gfx_y=gfx_h/2;
gfx_drawstr("hello world", 1|4|256, 0, 0);
...but I'm clearly misinterpreting the docs. Any help? Thanks!
clepsydrae is offline   Reply With Quote
Old 12-13-2018, 04:43 AM   #2
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

I cannot get it to work either
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 12-13-2018, 08:00 AM   #3
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 99
Default

I dont know if its intended behavior but it works if I add gfx_x/gfx_y to "right" and "bottom".

PHP Code:
@gfx
gfx_set
(1,1,1);

p1.x=0;
p1.y=0;
p2.x=gfx_w/2;
p2.y=gfx_h;

gfx_x=p1.x;
gfx_y=p1.y;
gfx_drawstr("hello world"1|4p2.x+gfx_xp2.y+gfx_y); 
EDIT: use flags|256 for no clipping at smaller sizes

Last edited by wwwmaze; 12-13-2018 at 08:17 AM.
wwwmaze is offline   Reply With Quote
Old 12-13-2018, 01:12 PM   #4
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Ah, thanks, this seems to do the trick:

Code:
gfx_x=gfx_y=0;
gfx_drawstr("hello world", 1|4, gfx_w, gfx_h);
...so it seems like there are some bugs in there? E.g. it treats gfx_x an gfx_y as the top-left point and right/bottom as the bottom-right point of where it actually decides to center and draw. It also seems to ignore an |256 if you put it in there.

But I know better than to shout 'bug' so readily when it comes to JSFX so I will await word from others. :-)
clepsydrae is offline   Reply With Quote
Old 12-13-2018, 05:11 PM   #5
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 99
Default

Quote:
Originally Posted by clepsydrae View Post
It also seems to ignore an |256 if you put it in there.
Hmm it works here. Downsize the window to see how clipping takes effect if bit 256 isnt set. The only (imo) unexpected thing is that we need to add gfx_x/y to right/bottom.
wwwmaze is offline   Reply With Quote
Old 12-13-2018, 06:15 PM   #6
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Ah, ok. So the confusion for me was the docs that say:

Code:
Draws a string at gfx_x, gfx_y
...
In REAPER 5.30+, flags,right,bottom can be specified to control alignment:

    flags&1: center horizontally
I assumed "center horizontally" meant "center around gfx_x".

That is, when flags,right,bottom are specified, it's no longer the case that it "draws a string at gfx_x, gfx_y", but instead draws centered within the rectangle described by x,y right,bottom.

And yeah I guess the gfx_x/y addition being required is a bug? -- not required, not a bug

Last edited by clepsydrae; 12-14-2018 at 02:32 PM.
clepsydrae is offline   Reply With Quote
Old 12-14-2018, 01:03 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Quote:
Originally Posted by clepsydrae View Post
And yeah I guess the gfx_x/y addition being required is a bug?
I think this is intended. gfx_x/gfx_y/right/bottom sets the absolute position of the bounding rectangle. I'd expect it to be named width/height if it was relative to gfx_x/y.
cfillion is offline   Reply With Quote
Old 12-14-2018, 02:32 PM   #8
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

I'm not as dumb as this thread makes me look, I swear. :-)

Thanks -- it's working as you describe. I was just confused about the expected usage / documentation.
clepsydrae is offline   Reply With Quote
Old 12-14-2018, 06:57 PM   #9
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 99
Default

Quote:
Originally Posted by cfillion View Post
I think this is intended. gfx_x/gfx_y/right/bottom sets the absolute position of the bounding rectangle. I'd expect it to be named width/height if it was relative to gfx_x/y.
Its still a bit unintuitive imo.
Imagine I'd like to center at the right half of the screen. By intuition I would set gfx_x to gfx_w/2 and "Right" to gfx_w. But to make it work I need to set "Right" to 1.5*gfx_w (gfx_w + gfx_x)
PHP Code:
@gfx
gfx_set
(1,1,1);

gfx_x=gfx_w/2;
gfx_y=0;
gfx_drawstr("hello world"1|4gfx_w*1.5gfx_h); 
wwwmaze is offline   Reply With Quote
Old 12-14-2018, 07:10 PM   #10
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Aha!

I think this code will demonstrate that something is amiss, or at least that we're seriously misunderstanding the use of the function:

Code:
slider1:0<-1000,1000,1>x
slider2:0<-1000,1000,1>y
slider3:500<-1000,1000,1>right
slider4:500<-1000,1000,1>bottom

@gfx

gfx_set(1,1,1);
gfx_x=slider1;
gfx_y=slider2;
gfx_drawstr("hello world", 1|4, slider3, slider4);
gfx_x=slider1;
gfx_y=slider2;
gfx_set(0,1,0);
gfx_lineto(slider3,slider2);
gfx_lineto(slider3,slider4);
gfx_lineto(slider1,slider4);
gfx_lineto(slider1,slider2);
The clipping seems to work perfectly, but the placement is off.
clepsydrae is offline   Reply With Quote
Old 12-14-2018, 07:37 PM   #11
wwwmaze
Human being with feelings
 
Join Date: Oct 2009
Posts: 99
Default

Quote:
Originally Posted by clepsydrae View Post
Aha!

I think this code will demonstrate that something is amiss, or at least that we're seriously misunderstanding the use of the function:

Code:
slider1:0<-1000,1000,1>x
slider2:0<-1000,1000,1>y
slider3:500<-1000,1000,1>right
slider4:500<-1000,1000,1>bottom

@gfx

gfx_set(1,1,1);
gfx_x=slider1;
gfx_y=slider2;
gfx_drawstr("hello world", 1|4, slider3, slider4);
gfx_x=slider1;
gfx_y=slider2;
gfx_set(0,1,0);
gfx_lineto(slider3,slider2);
gfx_lineto(slider3,slider4);
gfx_lineto(slider1,slider4);
gfx_lineto(slider1,slider2);
The clipping seems to work perfectly, but the placement is off.
Thanks. Yes, add gfx_x/y
PHP Code:
gfx_drawstr("hello world"1|4slider3+gfx_xslider4+gfx_y); 
and everything works as expected.
EDIT: nope, now it seems clipping doesn't work correctly.

Last edited by wwwmaze; 12-14-2018 at 07:43 PM.
wwwmaze is offline   Reply With Quote
Old 12-14-2018, 07:42 PM   #12
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Quote:
Originally Posted by wwwmaze View Post
Thanks. Yes, add gfx_x/y and everything works as expected.
Actually the clipping doesn't work right against right/bottom when you do that, but the centering does. Seems we can't have both, as it stands. Hopefully it can be fixed, whether it's changed or we get a new function or option or whatever.
clepsydrae is offline   Reply With Quote
Old 12-14-2018, 08:13 PM   #13
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

Oops those flags only work right when using a font other than the builtin bitmapped font, perhaps? Adding gfx_setfont(1,"Arial"); seems to fix. Anyway, fixing!

Last edited by Justin; 12-14-2018 at 08:23 PM.
Justin is offline   Reply With Quote
Old 12-14-2018, 11:12 PM   #14
clepsydrae
Human being with feelings
 
clepsydrae's Avatar
 
Join Date: Nov 2011
Posts: 3,409
Default

Super, thanks for looking in to it!
clepsydrae is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.