custom canvas gadget

For everything that's not in any way related to PureBasic. General chat etc...
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

custom canvas gadget

Post by mestnyi »

I used to find a custom canvas gadget on the forum before Fred added it, now I can't find it.
Can anyone help me with this?
User avatar
Demivec
Addict
Addict
Posts: 4082
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: custom canvas gadget

Post by Demivec »

mestnyi wrote: Mon Oct 25, 2021 7:40 pm I used to find a custom canvas gadget on the forum before Fred added it, now I can't find it.
Can anyone help me with this?
What did the gadget do? There wasn't a 'general' gadget of any sort but ones that were created for a specific purpose such as images, button, options, lists, etc.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: custom canvas gadget

Post by mestnyi »

Based on it, Fred made the current canvas gadget.
It worked on all three operating systems and did not have full functionality compared to the current canvas
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: custom canvas gadget

Post by mestnyi »

viewtopic.php?f=12&t=43558&p=339741&hil ... et#p339741
I found something, but that's not it.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: custom canvas gadget

Post by mestnyi »

what i found to work on mac os can someone help me?

Code: Select all

;CanvasGadget v0.82   
;Coding: Erlend 'Preacher' Rovik
;
;- added from top of head code for carbon(MacOSX) so only bare bones and probably filled with bugs...

;Canvas events:
Enumeration
  #Canvas_Paint
  #Canvas_MouseScroll
  #Canvas_MouseMove
  #Canvas_MouseLeave
  #Canvas_MouseEnter
  #Canvas_MouseButtonDown
  #Canvas_MouseButtonUp
  #Canvas_KeyUp         
  #Canvas_KeyDown    
EndEnumeration

Prototype CBFunc(*Canvas)
;Canvas CallbackProcedure Structure
Structure CanvasStruct
  Canvas.i     ; Handle
  Width.w      ;
  Height.w     ;
  Event.i      
  Callback.CBFunc           ; The callback procedure, called when anything happens....
  MouseInsideCanvas.b  ; True if mouse inside/over gadget
  MouseCursor.i        ; Set this to alter mouse cursor...
  MouseX.w
  MouseY.w
  Value.i       ; Can be Wheel / Button / Key depending on event
  ImageBuffer.i ; Create a image and put imagevalue here, it will be automaticly painted when needed...      
  Repaint.b  
EndStructure

NewList CanvasList.CanvasStruct()

;
;Here starts the real mess.... hehe...
;
CompilerSelect  #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    ;
    ;MacOSX Canvas Code
    ;  
    #kEventClassMouse = 'mous' 
    #kEventClassControl = 'cntl'
    #kEventMouseDown = 1
    #kEventMouseUp = 2
    #kEventMouseMoved = 5
    #kEventMouseDragged = 6
    #kEventControlTrackingAreaEntered = 23
    #kEventControlTrackingAreaExited = 24
    
    ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
      GetEventClass.i(inEvent.l)
      HIViewNewTrackingArea(inView.l, inShape.l, inID.q, *outRef)
    EndImport
    
    Structure EventTypeSpec
      eventClass.l
      eventKind.l
    EndStructure
    
    ProcedureDLL CanvasHandler(*nextHandler, Event, *userdata)
      *canvas.canvasstruct=*userdata
      
      Select GetEventClass(Event)
          
        Case #kEventControlDraw
          context.CGContextRef 
          
          result = GetEventParameter_( Event, #kEventParamCGContextRef, typeCGContextRef,#Null, SizeOf( context ),#Null, @context );
          
          bounds.HIRect;
          HIViewGetBounds_(*canvas\canvas, @bounds );
          
          CGContextSaveGState_( context );
          *transform.CGAffineTransform = #CGAffineTransformIdentity;
          transform = CGAffineTransformScale_(*transform, 1, -1 );
          CGContextSetTextMatrix_( context,*transform );
          
          CGContextRestoreGState_( context );
          result = noErr;
          
        Case #kEventClassMouse
          If *canvas\MouseInsideCanvas
            Select GetEventKind_(Event)
              Case #kEventMouseDown
                *canvas\event=#canvas_mousebuttondown
                ;*canvas\MouseX=
                ;*canvas\MouseY=
                ;*canvas\Value=
              Case #kEventMouseMoved, #kEventMouseDragged
                *canvas\event=#canvas_mousemove
                ;*canvas\MouseX=
                ;*canvas\MouseY=
                ;*canvas\Value=
              Case #kEventMouseUp
                *canvas\event=#canvas_mousebuttonup
                ;*canvas\MouseX=
                ;*canvas\MouseY=
                ;*canvas\Value=
            EndSelect
          EndIf
          
        Case #kEventClassControl 
          Select GetEventKind_(Event)
            Case #kEventControlTrackingAreaEntered
              *canvas\MouseInsideCanvas=#True
              *canvas\event=#canvas_mouseenter
            Case #kEventControlTrackingAreaExited
              *canvas\MouseInsideCanvas=#False
              *canvas\event=#canvas_mouseleave
          EndSelect         
      EndSelect
      
      If *nexthandler : CallNextEventHandler_(*nextHandler, Event) : EndIf
    EndProcedure
    Procedure.i CanvasGadget(parent,x,y,w,h,callback.i)
      *canvasstructpointer=AddElement(Canvaslist())
      Canvaslist()\callback=callback
      
      event_count = 8
      Dim eventtypes.EventTypeSpec(Events_Count - 1)
      eventTypes(0)\eventClass = #kEventClassHIObject
      eventtypes(0)\eventKind = #kEventHIObjectConstruct
      eventTypes(1)\eventClass = #kEventClassHIObject
      eventtypes(1)\eventKind = #kEventHIObjectDestruct
      eventTypes(2)\eventClass = #kEventClassMouse
      eventtypes(2)\eventKind = #kEventMouseDown
      eventTypes(3)\eventClass = #kEventClassMouse
      eventtypes(3)\eventKind = #kEventMouseMoved
      eventTypes(4)\eventClass = #kEventClassMouse
      eventtypes(4)\eventKind = #kEventMouseDragged
      eventTypes(5)\eventClass = #kEventClassMouse
      eventtypes(5)\eventKind = #kEventMouseUp
      eventTypes(6)\eventClass = #kEventClassControl
      eventtypes(6)\eventKind = #kEventControlTrackingAreaEntered
      eventTypes(7)\eventClass = #kEventClassControl
      eventtypes(7)\eventKind = #kEventControlTrackingAreaExited
      drawareaclass = HIObjectRegisterSubclass_( @"Com.BlackSwan.PBSC", #kHIViewClassID,0, NewEventHandlerUPP_(@canvashandler( )),ArraySize(eventtypes()),@eventtypes(),#Null, #Null );
      
      ;Create Class
      drawarea.HIViewRef 
      HIObjectCreate_(@"Com.BlackSwan.PBSC", #Null, @drawarea);
      ;Ref to content view
      contentView.HIViewRef = #Null;
      HIViewFindByID_( HIViewGetRoot_( parent ), #kHIViewWindowContentID, @contentView );
      HIViewAddSubview_( contentView, parent );
      HIViewSetVisible_( drawarea, #True );
      HIViewNewTrackingArea(drawarea, #Null, 0, #Null)
      Canvaslist()\Canvas=drawarea
      ProcedureReturn drawarea
    EndProcedure
    
CompilerEndSelect
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Re: custom canvas gadget

Post by Erlend »

@mestnyi:
I created that a long time ago, but dropped it after CanvasGadget() was added (around 2011?)
But out of curiosity what is your aim with this? What do you need it to do?

BR
Erlend
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: custom canvas gadget

Post by mestnyi »

Erlend wrote: Thu Oct 28, 2021 4:20 pm @mestnyi:
I created that a long time ago, but dropped it after CanvasGadget() was added (around 2011?)
But out of curiosity what is your aim with this? What do you need it to do?

BR
Erlend
You may or may not know, but I am writing replacements for all gadgets on canvas.
So, in my opinion, there are a lot of errors in the canvas events in the poppy wasp, so I want to fix them myself, and not wait for Fred to fix them.
Second, I want to understand how to use Apple code in purebasic.
You wrote this code, didn't you?
So you can help me, can you? :)
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Re: custom canvas gadget

Post by Erlend »

Ok, Cool I did not know about your gadgets :-)
However I have very little to help you with as this code is what I could scrape together at the time 11 years ago, and
as I said, I dropped it all when the inbuilt Canvas came out.
But I'm sure some other people here have more Mac related code to help you out.

Also post in mac section of forum if you have not allready. Just luck I saw this in Offtopic ;-)

Best of luck to you :-)

BR
Erlend
Post Reply