image and canvas

Just starting out? Need help? Post your questions and find answers here.
coffee
User
User
Posts: 77
Joined: Fri Oct 06, 2017 10:43 am

image and canvas

Post by coffee »

hi,

i can't get the following code to work. can anybody see the problem?

Code: Select all

  Structure DrawingValues
    windownum.i
    canvasnum.i
    scroolernum.i
    ;;;;; set imagesizes
    imageSizev.i
    imageSizeh.i
    colorimagebackground.i
    ;;; id of a possible parentwindow that is to be used, -1 if not
    parentwindow.i
    ;;; windows title string to be used
    title.s
    winsizev.i
    winsizeh.i
  EndStructure

Procedure DrawSimpleGraph(*graf.DrawingValues)
  Protected x.d=0,i.i
  Protected myimage = CreateImage(#PB_Any, *graf\imageSizev, *graf\imageSizeh, 32, *graf\colorimagebackground)
  If StartVectorDrawing(ImageVectorOutput(myimage, #PB_Unit_Pixel))
    
    MovePathCursor(40, 20)
    For i = 1 To 4
      AddPathLine(80, 0, #PB_Path_Relative)
      AddPathLine(0, 40, #PB_Path_Relative)
    Next i
    
    StopVectorDrawing()
    SetGadgetAttribute(*graf\canvasnum, #PB_Canvas_Image, ImageID(myimage))
    FreeImage(myimage)

  EndIf
EndProcedure

Procedure OpenGraphWindow(*graf.DrawingValues)   
  Protected.i window,parent,canvas,Event,CrossCur
  Protected y.d,x.d,res1.i,res2.i,Rubber.RECT
  CrossCur  = LoadCursor_(0, #IDC_CROSS)
  If *graf\parentwindow <> -1
    window = OpenWindow(#PB_Any,0,0,*graf\winsizev,*graf\winsizeh,*graf\title,#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget,*graf\parentwindow)
  Else
    window = OpenWindow(#PB_Any,0,0,*graf\winsizev,*graf\winsizeh,*graf\title,#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget)
  EndIf
  parent = ScrollAreaGadget(#PB_Any,0,0,imageSizev,imageSizeh,imageSizev,imageSizeh,1,#PB_ScrollArea_BorderLess)
  canvas = CanvasGadget(#PB_Any,0,0,*graf\winsizev,*graf\winsizeh)
  CloseGadgetList()
  *graf\windownum = window
  *graf\canvasnum = canvas
  *graf\scroolernum = parent
  
  DrawSimpleGraph(*graf)
  SmartWindowRefresh(window, #True) 
  ResizeWindow(window, #PB_Ignore, #PB_Ignore, *graf\winsizev+1,*graf\winsizeh+1)
  Repeat
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case canvas 
            Select EventType()
              Case #PB_EventType_MouseEnter
                SetGadgetAttribute(canvas, #PB_Canvas_CustomCursor, CrossCur)
              Case #PB_EventType_MouseMove
                 x = GetGadgetAttribute(canvas, #PB_Canvas_MouseX)
                 y = GetGadgetAttribute(canvas, #PB_Canvas_MouseY)
                 ; find_org_coord(x, y)
              Case #PB_EventType_LeftButtonDown
                ;
            EndSelect
      EndSelect
   EndSelect
  Until Event = #PB_Event_CloseWindow 
EndProcedure   
  
plot.DrawingValues
plot\title = "test"
plot\imageSizev = 1200
plot\imageSizeh = 1200
plot\colorimagebackground = $FFFFFFFF
plot\winsizev = 800
plot\winsizeh = 600

OpenGraphWindow(@plot)  
thanks for any help
coffee
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: image and canvas

Post by Demivec »

This

Code: Select all

parent = ScrollAreaGadget(#PB_Any,0,0,imageSizev,imageSizeh,imageSizev,imageSizeh,1,#PB_ScrollArea_BorderLess)
should be

Code: Select all

parent = ScrollAreaGadget(#PB_Any,0,0,*graf\imageSizev,*graf\imageSizeh,*graf\imageSizev,*graf\imageSizeh,1,#PB_ScrollArea_BorderLess)
coffee
User
User
Posts: 77
Joined: Fri Oct 06, 2017 10:43 am

Re: image and canvas

Post by coffee »

thanks a million, but the

Code: Select all

    MovePathCursor(40, 20)
    For i = 1 To 4
      AddPathLine(80, 0, #PB_Path_Relative)
      AddPathLine(0, 40, #PB_Path_Relative)
    Next i
does not appear.

1st part solved.

coffee
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: image and canvas

Post by #NULL »

add this before StopVectorDrawing(), see documentation of AddPathLine() for an example (from which your code may come from in the first place)

Code: Select all

      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10, #PB_Path_RoundCorner)
coffee
User
User
Posts: 77
Joined: Fri Oct 06, 2017 10:43 am

Re: image and canvas

Post by coffee »

yes thanks. that thruth, i try to use the stuff like the vector stuff from long ago, but ...

example
set color, line or pixel ...
set color ....

older people have problems there.
well i try to snag some stuff from a guy who put some bgi lib up - but it isn't easy, some copied help instructions.

i hope you'll forgive.


coffee
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: image and canvas

Post by #NULL »

wasn't meant to be sternly, only hopefully helpful. :)
i'm pretty sure i did the same mistake once. good luck with your project.
coffee
User
User
Posts: 77
Joined: Fri Oct 06, 2017 10:43 am

Re: image and canvas

Post by coffee »

i havn't taken it that way, just wanted to explain.
thank you for your help! and hopfully i get it to work.
coffee
Post Reply