Problems with scrollareagadget

Just starting out? Need help? Post your questions and find answers here.
Megaborsti
User
User
Posts: 35
Joined: Sat Aug 16, 2003 4:52 pm
Location: Germany

Problems with scrollareagadget

Post by Megaborsti »

Hi,
I tried to make a map-editor for rpg-games...
It is possible to choose tiles and the map is made similar to this:

Code: Select all

ScrollAreaGadget(0, 0,0,416,416,3840,3840,16)  
      
      Createimage(0,3840,3840)
      StartDrawing(ImageOutput())
      Box(0,0,3840,3840,RGB(0,0,0))
      StopDrawing()
      ImageGadget(1,0,0,3840,3840,ImageID())
      
CloseGadgetList()
My problem is:
If I wanted to click somewhere in the map to place a tile there, what do I have to do?
If there was only an image, I could use the position of the mouse, but the image is in the scrollareagadget.
Is there any function or another way to find out on which position of an image someone clicked with the mouse or a way to find out, how far the scrollarea has scrolled?
If not, how could I realize the editor then (only in theory) ?
(Another question:
is there any way to rezise a scrollareagadget without creating it new?)
I become better!!! :)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

I use also ScrollArea For a map editor

Sorry i don't speak english , i cant say more , but i hope this code help you.

I use Mulot\MapX and Mulot\MapY to know position of tile

Code: Select all

Procedure Souris()
   ; Position curseur de la ScrollArea
   PosScrollH.l = GetScrollPos_(GadgetID(#GADG_ScrollArea_0), #SB_HORZ) 
   PosScrollV.l = GetScrollPos_(GadgetID(#GADG_ScrollArea_0), #SB_VERT)
   
   ; Largeur et hauteur bordures de la fenêtre 
   Largeur.l = GetWindowSize(1)
   Hauteur.l = GetWindowSize(2)
   
   ; Calcule la position de la souris sur la fenêtre 
   Mulot\FenetreX = PosScrollH + WindowMouseX()-Largeur
   Mulot\FenetreY = PosScrollV + WindowMouseY()-Hauteur - MenuHeight()
   
   ; Calcule la position de la souris sur la Map 
   If Map\Init
      Mulot\MapX = Mulot\FenetreX / Tile\TailleX
      Mulot\MapY = Mulot\FenetreY / Tile\TailleY

...

 
Please correct my english
http://purebasic.developpez.com/
Megaborsti
User
User
Posts: 35
Joined: Sat Aug 16, 2003 4:52 pm
Location: Germany

Post by Megaborsti »

I hope this code would help me, but there is still a problem (not with your english):

Code: Select all

PosScrollH.l = GetScrollPos_(GadgetID(#GADG_ScrollArea_0), #SB_HORZ) 
PosScrollV.l = GetScrollPos_(GadgetID(#GADG_ScrollArea_0), #SB_VERT) 

These two lines do not work right. I use the the Scrollareagadget this way:

Code: Select all

ScrollAreaGadget(#ScrollAreaGadget, 20,30,416,416,3840,3840,16)  
      
      UseImage(4)
      StartDrawing(ImageOutput())
      Box(0,0,3840,3840,RGB(0,0,0))
      StopDrawing()
      ButtonImageGadget(#imageGadget,-3,-3,3840,3840,ImageID())
      
CloseGadgetList()

And the following code is in the event loop:

Code: Select all

If GadgetID = #imageGadget
      PosScrollH.l = GetScrollPos_(GadgetID(#ScrollAreaGadget), 3840) 
      PosScrollV.l = GetScrollPos_(GadgetID(#ScrollAreaGadget), 3840) 
      MessageRequester(Str(PosScrollH),Str(PosScrollV),0)
      
      UseWindow(0)
      Mapx = WindowMouseX()-GadgetX(#ScrollAreaGadget)-4 +PosScrollH
      MapY = WindowMouseY()-GadgetY(#ScrollAreaGadget)-22 +PosScrollV
      MessageRequester(Str(Mapx),Str(MapY),0) 

If I run the program and click in the map, the first messagerequester always shows:
posscrollh = 0 and posscrollv = 0

Did I do something wrong?
I become better!!! :)
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Code: Select all

Procedure.l GetWindowSize(type.l)
   ; Source http://forum.purebasic.fr/    
   ; type = 1 : largeur de la bordure droite, gauche ou basse d'une fenêtre 
   ; type = 2 : hauteur de la bordure de titre d'une fenêtre 
   ; type = 3 : largeur de la fenêtre 
   ; type = 4 : hauteur de la fenêtre 
   
   GetWindowRect_(WindowID(), @Taille_Fenetre.RECT) 
   Largeur_Fenetre = Taille_Fenetre\Right - Taille_Fenetre\Left 
   Hauteur_Fenetre = Taille_Fenetre\Bottom - Taille_Fenetre\top 
   Largeur_Bordure = (Largeur_Fenetre - WindowWidth()) / 2 
   Hauteur_Titre = Hauteur_Fenetre - WindowHeight() - Largeur_Bordure 
   Select type 
      Case 1 
         ProcedureReturn Largeur_Bordure 
      Case 2 
         ProcedureReturn Hauteur_Titre 
      Case 3 
         ProcedureReturn Largeur_Fenetre 
      Case 4 
         ProcedureReturn Hauteur_Fenetre 
   EndSelect 
EndProcedure

If OpenWindow(0, 0, 0, 500, 500, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "TEST") 
  
   If CreateGadgetList(WindowID()) 
      ScrollAreaGadget(0, 0, 0, 450, 450, 1000, 1000, 5, #PB_ScrollArea_BorderLess) 
      CloseGadgetList() 
   EndIf 
  
   If CreateStatusBar(0, WindowID())
      AddStatusBarField(100)
      AddStatusBarField(100)
   EndIf

   Repeat 
      ; Position curseur de la ScrollArea
      PosScrollH.l = GetScrollPos_(GadgetID(0), #SB_HORZ) 
      PosScrollV.l = GetScrollPos_(GadgetID(0), #SB_VERT)
      
      ; Largeur et hauteur bordures de la fenêtre 
      Largeur.l = GetWindowSize(1)
      Hauteur.l = GetWindowSize(2)
      
      ; Calcule la position de la souris sur la ScrollArea 
      MulotX = PosScrollH + WindowMouseX()-Largeur
      MulotY = PosScrollV + WindowMouseY()-Hauteur 
      
      StatusBarText(0,0,Str(PosScrollH)+" - " +Str(PosScrollV),#PB_StatusBar_Center)
      StatusBarText(0,1,Str(MulotX)+" - " +Str(MulotY),#PB_StatusBar_Center)
  Until WaitWindowEvent() = #PB_EventCloseWindow 
EndIf 
End
Please correct my english
http://purebasic.developpez.com/
Post Reply