Page 1 of 1

auto refresh imageGadget in scrollAreaGadget

Posted: Fri Jan 09, 2004 1:41 pm
by Dare2
I have a resized image in an imageGadget in a scrollAreaGadget, and draw on the image.

These changes do no show unless the scrollbars are scrolled, or unless I draw onto copy of the image, resize to new magnification and paste that onto the gadget with each change.

Is there must be a better/faster way?

Also, the resizing appears to be fairly smart and dithers the image, or something. Any way of getting a blocky resize?

eg - #PB_NO_DITHERING_AROUND_PLEASE :)

BTW, I am trying to do this using PB core and avoiding OS/api calls. Hopefully to have bitmap editor that will go whereever PB can go.

Re: auto refresh imageGadget in scrollAreaGadget

Posted: Fri Jan 09, 2004 2:17 pm
by Danilo
Dare2 wrote:These changes do no show unless the scrollbars are scrolled, or
unless I draw onto copy of the image, resize to new magnification
and paste that onto the gadget with each change.
Add a SetGadgetState(#img, ImageID) or SetGadgetState(#img, UseImage(1))
after drawing something, e.g. setting a point.

This will refresh the the ImageGadget.
Dare2 wrote:BTW, I am trying to do this using PB core and avoiding OS/api
calls. Hopefully to have bitmap editor that will go whereever PB
can go.
Maybe you can show some source how you do that?

BTW: In a coding forum its *always* a good idea to show some
test code that shows what you are trying to do, so we can
understand it better... :wink:


For example, how do you get the exact mouse position and
mouse click events on an ImageGadget in the ScrollAreaGadget
without using API, so it works at least on Windows and Linux?

The PB windows help says ScrollAreaGadget isnt available on Linux.

For what you want to do, i suggest you to go with fullscreen or
windowed screen. If all 2D drawing commands work on linux
and the mouse library too, it could work on both platforms without
a source change.

Atm i dont know how you convert mouse coordinates to ImageGadget
coordinates without any API, same for mouse clicks.

After you got the mouse click somehow, how do you convert
that to the right imagegadget coordinates when the scrollarea
is scrolled to bottom, without API?
Lets say the scrollarea is 1000x1000, but only 200x200 is visible,
how do you know at which position the scrollarea gadget is,
again without API?

Posted: Fri Jan 09, 2004 4:30 pm
by Dare2
Heya, Danilo. How you doing? :)

Will post whole bangshoot of code (or link to a zip) if you want, but here is a little klurge which I was playing with to see if I could find a solution:

Code: Select all

#_wMain=0
#_Pic=111
#_Canvas=112
#_imgGad=151
#_scroll=211

hWnd=OpenWindow(#_wMain, 10,10, 620,460, #PB_Window_SystemMenu, "SpriteEditor")

If hWnd
  CreateGadgetList(hWnd)
  fil.s="C:\masm32\00HLL\PureBasic\me\imgUtils\Source\standSE.bmp"
  LoadImage(#_Pic,fil)
  CopyImage(#_Pic,#_Canvas)
  hImg=UseImage(#_Pic)
  iWide=ImageWidth()
  iHigh=ImageHeight()
  multex=10
  ResizeImage(#_Canvas,iWide*multex,iHigh*multex)
  hImg=UseImage(#_Canvas)

  ScrollAreaGadget(#_scroll,0,0,400,300, iWide*multex,iHigh*multex, 3,#PB_ScrollArea_Single)
  ImageGadget(#_imgGad,0,0,iWide*multex,iHigh*multex, hImg)
  CloseGadgetList()

  StartDrawing(ImageOutput())
  For i=1 To iHigh
    LineXY(0,i*multex-multex,iWide*multex-1,i*multex-multex,RGB(192,192,192))
  Next
  For i=1 To iWide
    LineXY(i*multex,1,i*multex,iHigh*multex,RGB(192,192,192))
  Next
  StopDrawing()
  hImg=UseImage(#_Canvas)

;redraw to get it showing - comment out next 3 lines and the lineXY above not seen.
  OpenGadgetList(#_scroll)
  ImageGadget(#_imgGad,0,0,iWide*multex,iHigh*multex, hImg)
  CloseGadgetList()

  Repeat
    EventID.l = WaitWindowEvent()
    Select EventID
      Case #PB_EventCloseWindow
        Quit = 1
    EndSelect
  Until Quit = 1
EndIf

End
BTW, the portability thing is not an issue, just wanted to see if I could make it work. :)

You ask some tough questions :? :D

So far I have only managed to make a working editor (clunky, but working) without the scrollArea, and by forcing image to be under 100x100 pixels. Okay for tiles and sprites, but bigger would be better.

At the moment I can't track things (mouse/keyboard) without using windows references, eg, #WM_KEYDOWN, #WM_LBUTTONDOWN.

I am using the keyboard to scroll around the "canvas" area, and paint, but my mouseclicks (with or without scrollArea) are way out and I haven't conquered the metrics yet.

So the offset within a scrollAreaGadget that won't talk back is going to be interesting. :P Glad you pointed that out., because I hadn't got that far yet, I got stuck on the refresh thing. It would have been the next hole I fell in.

LOL - I have a long way to go and a lot to learn (and holes to fall into) it seems.

Thanks for the response.

PS: Haven't attacked the MIDI thing yet. 8O I am beginning to think it may be a bit ambitious for me at this point. I will just write the game and use jazz or something to write the music.

The offer for your brain still stands.

A big thankyou!

Posted: Sun Feb 22, 2004 10:30 am
by MIZ
My word! I was all set to write a big, long, HELP!!!
But it seems my prayers are already answered!

That setgadgetstate really did the trick for me - but for another problem you might find curious, or at least, windows 2000 users may?

I have a ButtonImageGadget in a ScrollAreaGadget.
The image for the button is far greater than the scroll area gadget.
Basically, I'm using it as a little window into a larger bitmap.

Scrolling up and down displays the rest of the button image - np problems there. But I draw a few things on the image, and re-draw the window (including the scroll area gadget) - and something weird happens. It all looks fine, until you try and scroll the area up and down (or left and right, I guess) - the area doesn't show the rest of the image. Its as if the iame got clipped!

After a lot of messing around, I discovered re-drawing the window and the gadgets can solve it - but the scroll position of the button gets reset - so, thats not acceptable.

Here, take a look at the code, prior to the simple change you suggest...
http://www.wolvesofantonica.co.uk/downl ... itegen.zip


Phew! So I can sleep at night again, knowing all is well, in PureBasic land.