Call me thick ...

Discussions related to graphics (2D and 3D), animation and games programming
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Call me thick ...

Post by KenDown »

I have been struggling a bit with the fact that with native BBC graphics the origin (0,0) is a bottom left (which does seem slightly counter-intuitive when the text origin is at top-left, but never mind). However if you use Windows, the graphics origin is at top-left! Anything done with GDIP has to cope with converting between the two, not much of a problem if you are working with the full screen (or full window), but a tad more tricky if you are not.

In my Display software I struggled to produce thumbnails and had all sorts of horrible bodges to convert between the two for different sizes of thumbnail when what was needed was a general purpose routine that would work without modification whatever the size of the thumbnail and wherever it was on the page. I had a Eureka moment yesterday: calculate the difference between the top of the thumbnail and the top of the screen or window and apply that to the calculations! If the "thumbnail" is full screen, that difference will be zero, of course.

Call me thick if you like - and perhaps most of you have been doing this for years - but for anyone who hasn't, here's my solution:

Code: Select all

      DEFPROCdrawpage(leftx%,bottomy%,width%,height%):LOCALi%,j%,col%
      scale=width%/1280:REM The scale at which the slide is drawn
      texty%=bottomy%+height%-20*scale:REM The starting position for text
      topx%=leftx%:topy%=bottomy%+height%:REM Coordinates for the top-left corner
      topdif%=@vdu%!212-topy%:REM Difference between the top of the slide and the top of the window
      by%=(@vdu%!212-topdif%-height%):REM Bottom of the page for IBM coordinates
Obviously the above isn't the complete drawpage routine and vdu%!212, to save you looking it up, is the height of the window in pixels. Below I give one routine using GDIP, just as an illustration.

Code: Select all

      REM Draws a thick line with a style (add values for start and end):
      REM    Line end square 1; round &12; diamond &13; arrow &14
      REM    Line start square &100; round &1200; diamond &1300; arrow &1400
      DEFFNline(lcol%,linestyle%,thick%,slx%,sly%,X%,Y%)
      LOCALn%,m%,tmp%,pen%,r%,g%,b%
      slx%=topx%+slx%*scale
      sly%=by%+sly%*scale
      X%=topx%+X%*scale
      Y%=by%+Y%*scale
      SYS"GetPaletteEntries",@hpal%,lcol%,1,^rgb%
      r%=rgb%AND&FF:g%=(rgb%>>8)AND&FF:b%=(rgb%>>16)AND&FF:rgb%=b%+(g%<<8)+(r%<<16)
      tmp%=FN_gdipsetdc(@memhdc%)
      pen%=FN_gdipcreatepen(&FF000000+rgb%,linestyle%,thick%*scale)
      PROC_gdipline(pen%,slx%,sly%,X%,Y%)
      PROC_gdipdeletepen(pen%)
      =0
I hope someone finds it useful.