Re: Center text in Graphics mode?
- Posted by Graeme <graemeburke at CROSSWINDS.NET> Dec 31, 2000
- 542 views
At 06:15 PM 30/12/00 -0500, you wrote: > >Hi > >To display text and to have that text centered (Stupid Question) >inside xy coordinates in all graphics modes virtually the same location >on screen I setup cx,cy values like this (read-on theres a question) > >-- Insure every Graphics Mode Coordinates display accurate drawn images > >integer cx, cy, sx, sy > >if mode = 261 then cx = 192 cy = 144 sx = 384 sy = 288 >elsif mode = 260 then cx = 192 cy = 144 sx = 384 sy = 288 >elsif mode = 259 then cx = 80 cy = 60 sx = 160 sy = 120 >elsif mode = 258 then cx = 80 cy = 60 sx = 160 sy = 120 >elsif mode = 256 then cx = 0 cy = -80 sx = 0 sy = 0 >else cx = 0 cy = 0 sx = 0 sy = 0 >end if > >-- ? >justify(CENTRE) >x = floor((x1+cx)/2+(x2+cx)/2) >y = floor((y1+cy)/2+(y2+cy)/2-6) >setx(x) sety(y) >write(text) > >I get centered with x and y integers useing floor (above) >Could there be a mathematical equation that would work faster >than the one provided? > >euman at bellsouth.net Not sure if I understand the question, but this might help. **UNTESTED** include graphics.e constant tw = --width of text in pixels constant th = --height of text in pixels sequence vc, --Video Config centre,--centre of screen {x,y} pos --Position to display text at to be centred. {x,y} vc=video_config() centre={vc[VC_XPIXELS],vc[VC_YPIXELS]}/2 pos=centre-floor({tw,th}/2) ---------------------------- ---------------------------- or you could centre the text around a point that is 20% of the way accross the screen and 80% of the way down the screen (regardless of the mode) like this ***UNTESTED*** include graphics.e constant tw = --width of text in pixels constant th = --height of text in pixels constant percent = {20,80} -- position for text sequence vc, --Video Config centre,--centre of screen {x,y} pos --Position to display text at to be centred. {x,y} vc=video_config() pos=floor(centre-({tw,th}/2)) ------------------------------- ------------------------------- graeme ----------------------------------------------------