Fillrect in artdrawing

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

I want to fill a rect with different colors in a artdraw.bmp file like the following.

Original bmp
http://www.chordplanet.com/purebasic/auto.gif

Colored bmp
http://www.chordplanet.com/purebasic/auto1.gif



I'am going to use it for my little kids.

Is this possible with PB?

Using Windows 98 SE
Registered Purebasic
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

FillArea() might work, no?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

Code: Select all

...
#Sprite = 1
LoadSprite(#Sprite, "auto.bmp", 0) ; The sprite can be in BMP (uncompressed form) or any other format supported by the ImagePlugin library.
StartDrawing(SpriteOutput(#Sprite))
    FillArea(250, 215, RGB(0, 0, 0), RGB(230, 30, 0)) ; Draw Red on image
    FillArea(160, 230, RGB(0, 0, 0), RGB(0, 0, 255)) ; Draw Blue on image
StopDrawing()
...
FillArea(x, y, BorderColor [, Color])
Description

Fill an arbitrary area starting from x,y location until the BorderColor is encounter. This is useful to fill any kind of shapes. If the 'Color' parameter is not specified, the default color set with FrontColor() will be used. RGB() can be used to get a valid color value. The current output is set with StartDrawing().


:)

--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

And some code for beginners to try :)
(save the above image as a BMP in the same folder as this code)

Code: Select all

LoadImage(1,"auto.bmp")
 
If OpenWindow(0,0,0,ImageWidth(),ImageHeight(),#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"")
  CreateGadgetList(WindowID())
  ImageGadget(1,0,0,ImageWidth(),ImageHeight(),UseImage(1))
 
  Repeat
    eventid=WaitWindowEvent()
    If eventid=#WM_LBUTTONUP
      StartDrawing(WindowOutput())
        FillArea(WindowMouseX(),WindowMouseY(),RGB(0,0,0),RGB(0,0,255))
      StopDrawing()
    EndIf
  Until eventid=#PB_Event_CloseWindow
EndIf
End

----------
Visit the PB Resources Site at http://www.reelmediaproductions.com/pb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

Thanks Kale and Paul,

My kids will love this.

This is a start to make more lovely things

Other suggestions for making things like drag and drop are also welcome.

Using Windows 98 SE
Registered Purebasic
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ebs.

Paul,

That's a nice "coloring book"! I noticed that clicking on certain areas produces incorrect results. For example, try clicking in the triangular shape directly in front of the right front tire. Depending on exactly where you click, sometimes nothing happens, sometimes the entire background of the image gets filled.

Can you reproduce these results? Can you explain why this happens?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ebs.

I found the answer - WindowMouseY() doesn't account for the height of the window titlebar, so the Y coordinate is approximately 20 pixels too high. If you subtract 20 from WindowMouseY(), everything works fine.

Eric
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Thomas.

better subtract MenuHeight()
Post Reply