2D Drawing

Just starting out? Need help? Post your questions and find answers here.
eggpure
New User
New User
Posts: 3
Joined: Sat Oct 07, 2006 2:02 pm
Location: Tasmania

2D Drawing

Post by eggpure »

Having used VB3 for many years, it didn't take me long to get started in writing a farm mapping program. However, VB3 is quite old now, it isn't cross-platform, etc. so I looked round for an alternative and found Real Basic. I came unstuck at the first hurdle when I tried to create a menu (so easy to do in VB3), so looked further and found PureBasic. Now I have a menu- not as easy as VB3, but achievable. I've also been able to get PureBasic to load my map data files into arrays, using the original VB3 code with only a few small alterations.

But now I'm stuck on 2D drawing. Again, this is very easy in VB3, but it is far from obvious in PureBasic. I've looked at the example code (2DDrawing.pb) but can't follow it, despite the fact that I've been dabbling in coding for about 25 years- perhaps I'm getting too old. To be specific:-

There are too many zeros in the example code, e.g. "ImageID(0)"; ImageOutput(0); CreateImage(0, 300, 200); WindowID(0). This makes the code difficult to follow: I can't tell what is referring to what.

I'm well aware that writing tutorials isn't easy, and I thank those who have made the effort to try to explain things so far, but sometimes an explanation from someone else can "hit the spot".

If I tell you that I have these lines in my code (which compiles without errors)-

If CreateGadgetList(WindowID(#mapper))
map = ImageGadget(0, 60, 80, 50, 20, 0)
EndIf

Can someone tell me how to draw a line on my map?

Alan
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Maybe this should help you get started:

Code: Select all

#mapper = 0
#ImageId = 0

If OpenWindow(#mapper,0,0,300,250,"Title",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(#mapper))
  CreateImage(#ImageId,300,250)
  StartDrawing(ImageOutput(#ImageId))
    Line(0,0,300,250,#Red)
  StopDrawing()
  map = ImageGadget(#PB_Any,0,0,300,250,ImageID(#ImageId))
Else
  MessageRequester("Error!","Couldn't create window.",#MB_ICONERROR)
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Welcome to the forum btw! :D
I like logic, hence I dislike humans but love computers.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

If you use a image gadget you have to update it's image each time you change it, you can do that like this: SetGadgetState(map,ImageID(#ImageId))
I like logic, hence I dislike humans but love computers.
eggpure
New User
New User
Posts: 3
Joined: Sat Oct 07, 2006 2:02 pm
Location: Tasmania

Post by eggpure »

Thankyou Joakim,
Your example is much easier to follow, and now my project is moving again.
Post Reply