Draw a scaled bitmap with wxhaskell

The imageviewer example shows how to display an image in a ScrolledWindow.

What if I want to display the image in an accessible space, scaling the bitmap as necessary?

My google-fu failed me on this.

edit: I thought I had something with scrolledWindowSetScale, but it doesn't seem to help here.

+5
source share
1 answer

Some people pointed me to functions in wxCore, so I could find a solution that works.

The function that executes the drawing in the original example:

onPaint vbitmap dc viewArea
  = do mbBitmap <- get vbitmap value
       case mbBitmap of
         Nothing -> return () 
         Just bm -> drawBitmap dc bm pointZero False []

dcSetUserScale wxCore, :

(sw - scrolledWindow)

onPaint sw img dc viewArea = do
  mimg <- get img value
  case mimg of
    Nothing -> return ()
    Just bm -> do
      bsize <- get bm size
      vsize <- get sw size
      let scale = calcScale bsize vsize
      dcSetUserScale dc scale scale
      drawBitmap dc bm pointZero False []

calcScale :: Size -> Size -> Double
calcScale (Size bw bh) (Size vw vh) = min scalew scaleh
  where scalew = fromIntegral vw / fromIntegral bw
        scaleh = fromIntegral vh / fromIntegral bh
+2

All Articles