Can I draw a line on a PanelGadget?

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

I have a 3 panel PanelGadget setup with other gadgets on it.

I need to be able to draw some lines. But every attempt puts
the lines on the window itself rather than on the panel.

Any ideas?

Thanks,
Terry
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 freak.

What Lines do you want to draw?

To draw horizontal lines i do something like this:

Code: Select all

Frame3DGadget(1, 10, 10, 300, 2, "", 2)
Can also be done vertically by setting width to 2 and increasing height.

If you want to preform real Drawing actions, you should draw to an Image using 'StartDrawing(ImageOutput())' after 'CreateImage()' and then display that image as an ImageGadget.

You have to use Gadgets here becourse with a PanelGadget drawing with WindowOutput() doesn't work.

Hope this helps a bit...

Timo

--------------------------------
Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs and the universe trying to produce bigger and better idiots.

...So far, the universe is winning.
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 TerryHough.
Originally posted by freak
If you want to preform real Drawing actions, you should draw to an Image using 'StartDrawing(ImageOutput())' after 'CreateImage()' and then display that image as an ImageGadget.

You have to use Gadgets here becourse with a PanelGadget drawing with WindowOutput() doesn't work.
Thanks, I believe this is the approach I will need to take.

Unfortunately, so far I have only been able to get the image
drawn to WindowOutput(). When I draw to an image and then
try to display on the PanelGadget it doesn't work. I am sure
it is just my poor code or I have totally misread something.

Terry
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 freak.

> Unfortunately, so far I have only been able to get the image
> drawn to WindowOutput(). When I draw to an image and then
> try to display on the PanelGadget it doesn't work. I am sure
> it is just my poor code or I have totally misread something.

To make it easyer for you to solve the problem, i've coded a short
example, and commented it as best as i could.

Maybe you'll then see, where the problem is...

Code: Select all

#Image = 1              ; just to make more clear, which values mean the same thing...
#PanelGadget = 1       
#ImageGadget = 2
  
  
If OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu, "CreateImage / Imagegadget Example") = 0  ; open window
  MessageRequester("","Window Error!",0)           ; some error
  End
EndIf 
  
If CreateImage(#Image, 300, 300) = 0               ; create image to draw on
  MessageRequester("","Image Error!",0)            ; some error
  End
EndIf
  
back.l = GetSysColor_(#COLOR_BTNFACE)              ; gets the background color for Windows (to draw the image background)
  
UseImage(#Image)                                   ; this one is only needed, if you did stuff with other Images after
                                                   ; the CreateImage() command.
StartDrawing(ImageOutput())                        ; Start Drawing on the Image

  FrontColor(Red(back), Green(back), Blue(back))   ; Set the Background Color
  Box(0, 0, 300, 300)                              ; draw background
  
  FrontColor(0, 0, 0)                              ; just some drawing action
  DrawingMode(1 | 4)
  Circle(150, 150, 100)
  Box(100, 100, 100, 100)
  Line(50, 50, 200, 200)
  
  Locate(10, 10)
  DrawText("Hello World!")
  
StopDrawing()                                       ; drawing ends here. (the drawing stuff must be done before the 
                                                    ; ImageGadget() command
                                                    
CreateGadgetList(WindowID())                        ; create GadgetList
PanelGadget(#PanelGadget, 20, 20, 600, 440)         ; Panelgadget
  AddGadgetItem(#PanelGadget, -1, "Panel 1")        ; First Panel
  
    UseImage(#Image)                                ; again, only needed if you used some other Images before
    ImageGadget(#ImageGadget, 50, 50, 300, 300, ImageID()) ; create the Imagegadget using the current Image
   
  AddGadgetItem(#PanelGadget, -1, "Panel 2")        ; some other Panels
  AddGadgetItem(#PanelGadget, -1, "Panel 3")
ClosePanelGadget()                                  ; close PanelGadget
  
SetGadgetState(#PanelGadget, 0)                     ; otherwise the drawings are not visible at the beginning
                                                    ; Thanks to Franco for the hint
  
Repeat                                             ; Main loop, only waits for close of Window
  Event.l = WaitWindowEvent()
Until Event = #PB_EventCloseWindow
  
End
---------
Hope this helps a bit...

Timo
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 Franco.

@Freak
added:

Code: Select all

SetGadgetState(#PanelGadget, 0)                     ; otherwise the drawings are not visible at the beginning
before the main loop, because the drawings & text aren't visible on my machine (w2k-Sp3)
Otherwise it's only visible after activating another Item and switch back to the first Item...

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
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 freak.

I dodn't know that, here (Win98se) everythin worked fine.
Maybe this is Terry's problem, too?
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 TerryHough.

@freak

Thanks for the code sample. That got me going in the
proper direction. I was close, but misunderstood the
UseImage command.

Hope I will be able to repay the kind folks who help
beginners like me on this forum someday.:)

Terry
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 TerryHough.
Originally posted by freak

I dodn't know that, here (Win98se) everythin worked fine.
Maybe this is Terry's problem, too?
No, I am on Win98SE and your example worked great for me.

My problem seems to be located between my ears today!

Terry
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 TerryHough.

Thanks Freak and Franco, that got me rolling.

One other question on this subject...

Is it possible to create an area within a PanelGadget that can be
vertically scrolled? My "forms" are too large (long actually) to
fit in the largest panels I can create, so I need to draw on a scrollable area, drop string gadgets on it, etc. and then be able
vertically scroll up and down through the area. (Hope that explains
it).

The Panel concept is perfect for the application for selecting the
various "forms" if I can create the above ability.

Thanks again for your help.

Terry
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 freak.

> Is it possible to create an area within a PanelGadget that can be
> vertically scrolled?

Sorry, I don't know how to do that.
Anyone else have some idea?
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 freak.

> Is it possible to create an area within a PanelGadget that can be
> vertically scrolled?

Well, nothing's impossible :), i posted a solution to
the Tips&Tricks Section.

You'll find it, here:
viewtopic.php?t=2012

You'll need to do some trick to use it in a PanelGadget, but that
is also explained there.

Timo
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 TerryHough.

:)
Well, nothing's impossible :), i posted a solution to
the Tips&Tricks Section.

You'll find it, here:
viewtopic.php?t=2012

You'll need to do some trick to use it in a PanelGadget, but that
is also explained there.
Wow! really nice work.:) I will have to study this carefully.

I must admit that I haven't learned the "trick" to make it work
in a PanelGadget. It looks like it is going to, but never shows
the scrollbars at all. The other gadgets appear, but not the
scrollbars.:cry: I'm lost.

Terry
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 freak.

Update!!

Sorry, there were some bugs in the code, that caused your problem.
Please, get the fixed code again:

viewtopic.php?t=2012

There's also a second example showing the Panelgadget stuff.
(please read also my instructions on top of the new code, since
the PanelGadget trick has changed now a bit.)

Timo
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 TerryHough.

@freak

Thanks Timo! The bug fix took care of one of my problems and
the PanelGadget example confirmed I was using it correctly.

Still had a problem that took me a while to track down. I was
using the variables Height and Width as globals in my code.
That caused problems for your procedures and so the scroll bars
just didn't appear. Simple fix, I didn't really need the
variables to be global so I just removed the definition, and
everything worked perfectly.

One note: The ScrollGadget has to be 20 pixels less in width than
the FrameGadget and 40 pixels less in heigth for me to see
both scroll bars. This was easily accomplished using the GadgetWidth()
and GadgetHeight() commands

Code: Select all

; code snippet allowing the entire panel to scroll
AddGadgetItem(1,100, "Panel Info")
    gWidth = GadgetWidth(1)
    gHeight = GadgetHeight(1)
    hFrame.l = Frame3DGadget(9,0,0,gWidth,gHeight,"",1); Create a scrollable area
    hScr.l = OpenScrollGadget(0, 0, gWidth-20, gHeight-40, 800, 800,#ScrollBar_ 
; end code snippet
Thanks again for your marvelous idea and code examples.

Terry
Post Reply