|
|
|
12-12-2018, 10:02 PM
|
#1
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
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!
|
|
|
12-13-2018, 04:43 AM
|
#2
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
|
I cannot get it to work either
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
12-13-2018, 08:00 AM
|
#3
|
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
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|4, p2.x+gfx_x, p2.y+gfx_y);
EDIT: use flags|256 for no clipping at smaller sizes
Last edited by wwwmaze; 12-13-2018 at 08:17 AM.
|
|
|
12-13-2018, 01:12 PM
|
#4
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
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. :-)
|
|
|
12-13-2018, 05:11 PM
|
#5
|
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
Originally Posted by clepsydrae
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.
|
|
|
12-13-2018, 06:15 PM
|
#6
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
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.
|
|
|
12-14-2018, 01:03 PM
|
#7
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
Quote:
Originally Posted by clepsydrae
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.
|
|
|
12-14-2018, 02:32 PM
|
#8
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
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.
|
|
|
12-14-2018, 06:57 PM
|
#9
|
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
Originally Posted by cfillion
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|4, gfx_w*1.5, gfx_h);
|
|
|
12-14-2018, 07:10 PM
|
#10
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
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.
|
|
|
12-14-2018, 07:37 PM
|
#11
|
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
Originally Posted by clepsydrae
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|4, slider3+gfx_x, slider4+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.
|
|
|
12-14-2018, 07:42 PM
|
#12
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
Quote:
Originally Posted by wwwmaze
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.
|
|
|
12-14-2018, 08:13 PM
|
#13
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
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.
|
|
|
12-14-2018, 11:12 PM
|
#14
|
Human being with feelings
Join Date: Nov 2011
Posts: 3,409
|
Super, thanks for looking in to it!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 05:01 AM.
|