Draggable handles

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

Draggable handles

Post by KenDown »

Apologies if this has been dealt with before.

I notice in many programs (such as PowerPoint) that when you click on an object - a picture or a block of text - it is surrounded by a rectangle with small squares in each corner and at the mid-points of the sides. You can drag these "handles" to alter the size and proportions of the rectangle.

Is there any simple way of providing and interpreting such a rectangle?
DDRM

Re: Draggable handles

Post by DDRM »

I don't know of an automated way, but when I want drag boxes I use xor plotting, so that it's easy to move/resize them. I often want to drag a box round something, and this approach works very well for that. What you want is a bit different, but should be doable that way?
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Draggable handles

Post by KenDown »

To do that for a simple rectangle is one thing; to do a rectangle and eight small squares (plus calculating the mid-point of the sides) would involve a degree of overheads that would make it rather slow and clunky. Plus interpreting the mouse position and which directions movement is constrained in (ie. the middle side handles are constrained to horizontal dragging). Hmmmm.

In addition, what I want is to drag and resize jpeg pictures. It happens very smoothly in PowerPoint; I doubt similar smoothness could be achieved in BB4W.
RichardRussell

Re: Draggable handles

Post by RichardRussell »

KenDown wrote: Sat 28 Nov 2020, 20:36I doubt similar smoothness could be achieved in BB4W.
So use BBCSDL instead. It has exactly the features you need:
  • GPU-accelerated 2D graphics.
  • GPU-accelerated image resizing.
  • Built-in support for vSync.
resulting in it being both extremely fast and super-smooth.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Draggable handles

Post by KenDown »

That thought had already occurred to me - but I immediately ran up against a problem (for which my ignorance is, no doubt, to blame). How do I display a .jpg picture in SDL? Please?
RichardRussell

Re: Draggable handles

Post by RichardRussell »

KenDown wrote: Fri 04 Dec 2020, 20:28How do I display a .jpg picture in SDL?
*DISPLAY (OSCLI "DISPLAY...") will display BMPs, GIFs, PNGs and JPGs (at least), but is slow.

*MDISPLAY (OSCLI "MDISPLAY...") is faster, but still not great.

For your application I was anticipating that you would use the imglib library for maximum speed (plus it supports non-integer coordinates and scaling, which you may need as you implied you wanted extreme 'smoothness').

Note that although there is a compatible IMGLIB library for BB4W, it is not hardware-accelerated so is nowhere near as fast as the BBCSDL version. Compare aliens.bbc running on both platforms for a stark demonstration of the difference.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Draggable handles

Post by KenDown »

Unfortunately the IMGLIB library is not listed in the Help for BB4W, so I was unaware of its existence. In fact, looking in the LIB directory, it does not appear to be installed along with BB4W 6.13a. I notice that there is some discussion about changes you introduced (which sound very useful) but there is no list of functions and procedures provided by the library nor any statements about what it can do.

In fact, I notice that IMGLIB does not feature in the SDL help, though it is present in the SDL LIB directory.

I know it is a lot to ask, but is there any possibility that the Help files could be updated?
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: Draggable handles

Post by KenDown »

After a good deal of head-banging I came up with the following procedures which take the picture size returned by Richard's PROC_imgSize and the angle and centre of the picture coordinates and calculates or draws a box around the picture, whatever its angle. Maths is not my strong point, but memories of high school geometry got me through. You will require two arrays: frx%(n,4) and fry%(n,4) where n can be zero.

Code: Select all

      DEFPROCcalcbox(ang,sx%,sy%,w%,h%):LOCALtan,x%,y%
      frp%=0
      frx%(frp%,0)=sx%:fry%(frp%,0)=sy%
      tan=w%/h%
      deg=DEGATNtan
      l=w%DIV2/SINRADdeg
      PROCcalc(ang+deg+180,l,X%,Y%)
      X%+=sx%:Y%+=sy%
      frx%(frp%,1)=X%:fry%(frp%,1)=Y%
      sx%=X%:sy%=Y%
      SWAPX%,x%:SWAPY%,y%
      PROCcalc(90+ang,w%,X%,Y%)
      X%+=x%:Y%+=y%
      frx%(frp%,2)=X%:fry%(frp%,2)=Y%
      SWAPX%,x%:SWAPY%,y%
      PROCcalc(ang,h%,X%,Y%)
      X%+=x%:Y%+=y%
      frx%(frp%,3)=X%:fry%(frp%,3)=Y%
      x%=sx%:y%=sy%
      PROCcalc(ang,h%,X%,Y%)
      X%+=x%:Y%+=y%
      frx%(frp%,4)=X%:fry%(frp%,4)=Y%
      ENDPROC
      :
      DEFPROCdrawbox(ang,sx%,sy%,w%,h%,frp%):LOCALtan,x%,y%
      GCOL3,6
      frx%(frp%,0)=sx%:fry%(frp%,0)=sy%
      tan=w%/h%
      deg=DEGATNtan
      l=w%DIV2/SINRADdeg
      PROCcalc(ang+deg+180,l,X%,Y%)
      X%+=sx%:Y%+=sy%:MOVEX%,Y%
      frx%(frp%,1)=X%:fry%(frp%,1)=Y%
      sx%=X%:sy%=Y%
      SWAPX%,x%:SWAPY%,y%
      PROCcalc(90+ang,w%,X%,Y%)
      X%+=x%:Y%+=y%:DRAWX%,Y%
      frx%(frp%,2)=X%:fry%(frp%,2)=Y%
      SWAPX%,x%:SWAPY%,y%
      PROCcalc(ang,h%,X%,Y%)
      X%+=x%:Y%+=y%:DRAWX%,Y%
      frx%(frp%,3)=X%:fry%(frp%,3)=Y%
      x%=sx%:y%=sy%
      PROCcalc(ang,h%,X%,Y%)
      X%+=x%:Y%+=y%:DRAWX%,Y%
      frx%(frp%,4)=X%:fry%(frp%,4)=Y%
      DRAWsx%,sy%
      CIRCLEfrx%(frp%,2),fry%(frp%,2),20
      CIRCLEfrx%(frp%,3),fry%(frp%,3),20
      ENDPROC
      :
      DEFPROCcalc(angle%,length%,RETURN X%, RETURN Y%)
      pi=RADangle%:X%=length%*SINpi:Y%=length%*COSpi
      ENDPROC