colorbook problem

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.

The following code reads a artdrawing bmp file and you can color the picture, thanks to Kale and Paul.

But if you select a new file and already filled a color the whole screen is painted as the selected color.

I cannot find the problem, can someone help !

You can use the following file
http://www.chordplanet.com/purebasic/auto.gif
Please convert it to an bmp file

Code: Select all

Global ratio.f,himage.f,vimage.f,CurrentWidth.l,CurrentHeight.l,CurrentColor.l
Global appdir$
Global fotogeladen.b

fotogeladen=0
CurrentColor=RGB(255,255,255)
;- Gadget Constants
;
#btnFileOpen = 0
#btnBlack = 1
#btnWhite = 2
#imgPicture = 10

;- Image Globals
Global Image0
Global Image1

;- Catch Images
Image0 = CatchImage(0, ?Image0)
Image1 = CatchImage(1, ?Image1)

;- Images
DataSection
Image0:
  IncludeBinary "P:\cor\purebasic\ontwikkel\colorbook\black.bmp"
Image1:
  IncludeBinary "P:\cor\purebasic\ontwikkel\colorbook\blue.bmp"
EndDataSection


;Get app's directory.
appdir$=Space(255) 
GetCurrentDirectory_(255,appdir$) 
 If Right(appdir$,1)"\" 
  appdir$=appdir$+"\" 
 EndIf


;LoadImage(100,"barbie.bmp")
;LoadImage(2,"bg.bmp")

Procedure WindowCallback(WindowID, Message, lParam, wParam)
  If Message = #WM_PAINT And fotogeladen=1
    StartDrawing(WindowOutput())
      Line (0,40,WindowWidth(),0, RGB(0,0,0) )
;      DrawImage(UseImage(100), 0, 45)
    StopDrawing()
  EndIf
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

 
If OpenWindow(1,0,0,ImageWidth(),ImageHeight()+45,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"")
ShowWindow_(WindowID(),#SW_MAXIMIZE)
SetWindowCallback(@WindowCallback())
 If  CreateGadgetList(WindowID())
   ButtonGadget(#btnFileOpen, 5, 5, 55, 30, "File Open")
   ButtonImageGadget(#btnBlack, 75, 5, 55, 30, Image0)
   ButtonImageGadget(#btnWhite, 140, 5, 55, 30, Image1)
   ImageGadget(#imgPicture,0,MenuHeight()+45,-1,-1,Image1)

EndIf 

  Repeat
    EventId=WaitWindowEvent()
    If EventID = #PB_EventGadget
      Select EventGadgetID()
        Case #btnFileOpen
          FileName$ = OpenFileRequester("Laad tekening", appdir$, "Texte file | *.bmp", "0") 
          If FileName$  ""
           
            LoadImage(100,FileName$)
            SetGadgetState(#imgPicture, UseImage(100)) 
            ResizeGadget(#imgPicture, -1, -1, ImageWidth(), ImageHeight() ) 
            fotogeladen=1 

          EndIf
 
        Case #btnBlack
         CurrentColor=RGB(0,0,0)
         
        Case #btnWhite
         CurrentColor=RGB(0,0,255)
      EndSelect     
    EndIf
    
    
    If EventId=#WM_LBUTTONUP And fotogeladen=1
      StartDrawing(WindowOutput())
         FillArea(WindowMouseX(),WindowMouseY()-MenuHeight(),RGB(0,0,0),CurrentColor)
      StopDrawing()
      
    EndIf
    
  Until eventid=#PB_Event_CloseWindow
EndIf
End 
; ExecutableFormat=Windows
; EOF
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 cor.

When Debugger is enabled problem is there.

download complete with source:
http://www.chordplanet.com/purebasic/colorbook.zip

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 Kale.

i think maybe the 'StartDrawing(WindowOutput())' could be to blame, i personally would keep the drawn image and the window display seperate, e.g. load the image using 'LoadImage()' then display it, then use the display to get the coords for the 'FillArea()' command, draw on the image using 'StartDrawing(ImageOutput())' then display the image back onto the window. (using this method you could save your images aswell :))

i think also maybe the problems you are having might be because the click on the load image button is being detected and new colour drawn to the whole window, this again could be avoided drawing to the image itself.

--Kale

In love with PureBasic! :)
Post Reply