Datepicker / calendargadget

Share your advanced PureBasic knowledge/code with the community.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Datepicker / calendargadget

Post by jesperbrannmark »

Hi all. Yesterday I ran into some problems with the Mac calendargadget - it was giving me wrong dates etc... and the one in windows... isnt that ugly like something from the 80's... I decided to make my own, thats a ripoff of the jquery datepicker plugin (http://jqueryui.com/demos/datepicker/)
I was using sprites and openwindowedscreen, but this doesnt get me far since we can only have one of those.. so now i am using the fantastic canvasgadget thats available in 4.60beta and up.
I have not cleaned up my code.... It should work on mac/win/linux (untested). Entire package with images available at http://www.clinicbuddy.com/datepicker.zip but here it is for anyone that could find any use for it:

Code: Select all

;init
UsePNGImageDecoder()
Global smartbooker_datepicker_month=Month(Date())
Global smartbooker_datepicker_year=Year(Date())
Global smartbooker_selected_date=Date()
Enumeration
  #smartbooker_window
  #smartbooker_calendar  
  #smartbooker_image1
  #smartbooker_image2
  #smartbooker_image3
  #smartbooker_image4
EndEnumeration
;the images
CatchImage(#smartbooker_image1, ?datepicker1)
CatchImage(#smartbooker_image2, ?datepicker2)
CatchImage(#smartbooker_image3, ?datepicker3)
CatchImage(#smartbooker_image4, ?datepicker4)
;our months
Global Dim monthname.s(13)
monthname(1)="Jan":monthname(2)="Feb":monthname(3)="Mar":monthname(4)="Apr":monthname(5)="May":monthname(6)="Jun":monthname(7)="Jul":monthname(8)="Aug":monthname(9)="Sep":monthname(10)="Oct":monthname(11)="Nov":monthname(12)="Dec"

Procedure.s monthname_to_string(month,year)
  If month=<12
    ProcedureReturn monthname.s(month)+" "+Trim(Str(year))
  Else
    ProcedureReturn monthname.s(month-12)+" "+Trim(Str(year+1))
  EndIf
EndProcedure
Procedure daysofmonth(month.b)
  If month.b=>1 And month.b=<12
    Restore daysofmonth_data    
    For i=1 To month.b::Read.b x.b:Next
    ProcedureReturn x.b
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure smartbooker_draw_datepicker()
  Debug "DRAW"
  Global Dim smartbooker_datepicker_dates.b(7,7)
  StartDrawing(CanvasOutput(#smartbooker_calendar))
  Box(0,0,200,400,RGB(255,255,255))
  DrawImage(ImageID(  #smartbooker_image1),0,0)
  DrawingMode(#PB_2DDrawing_Transparent)  
  DrawText(50,15,monthname_to_string(smartbooker_datepicker_month,smartbooker_datepicker_year),RGB(0,0,0),RGB(255,255,255))
  DrawingMode(#PB_2DDrawing_Default)  
  y=0
  theyear=smartbooker_datepicker_year
  themonth=smartbooker_datepicker_month
  For days=1 To daysofmonth(themonth)
    x=DayOfWeek(Date(theyear,themonth,days,0,0,0))-1
    If x=-1
      x=6
    EndIf
    If x=0 And days<>1
      y+1
    EndIf
    smartbooker_datepicker_dates.b(x,y)=days
    If ParseDate("%yyyy-%mm-%dd",Str(theyear)+"-"+Str(themonth)+"-"+Str(days))=smartbooker_selected_date 
      DrawImage(ImageID(#smartbooker_image2),7+(x*27),60+(y*22),25,21)
    ElseIf theyear=Year(Date()) And themonth=Month(Date()) And days=Day(Date())
      DrawImage(ImageID(#smartbooker_image3),7+(x*27),60+(y*22),25,21)
    Else
      DrawImage(ImageID(#smartbooker_image4),7+(x*27),60+(y*22),25,21)
    EndIf
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(9+(x*27),62+(y*22),Trim(Str(days)),RGB(0,0,0),RGB(255,255,255))
    DrawingMode(#PB_2DDrawing_Default)
  Next
  StopDrawing()  
EndProcedure
Procedure smartbooker_handle_datepicker()  
  gadget=#smartbooker_calendar
  Xx = GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseX)
  Yy = GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseY)
  If xx>170 And xx<210 And yy>10 And yy<30
    smartbooker_datepicker_month+1
    If smartbooker_datepicker_month=13
      smartbooker_datepicker_month=1
      smartbooker_datepicker_year+1
    EndIf
    smartbooker_draw_datepicker()
  ElseIf xx>0 And xx<30 And yy>10 And yy<30
    smartbooker_datepicker_month-1
    If smartbooker_datepicker_month=0
      smartbooker_datepicker_month=12
      smartbooker_datepicker_year-1
    EndIf
    smartbooker_draw_datepicker()
  Else
    xvalue.b=-1:    yvalue.b=-1    
    For x.b=0 To 6
      If xx>7+(x*27) And xx<7+((x+1)*27)
        xvalue=x
      EndIf
    Next
    For y.b=0 To 6
      If yy>60+(y*22) And yy<60+((y+1)*22)
        yvalue=y
      EndIf
    Next
    If xvalue<>-1 And yvalue<>-1
      If smartbooker_datepicker_dates(xvalue,yvalue) ; If not then we are clicking somewhere else       
        smartbooker_selected_date=ParseDate("%yyyy-%mm-%dd",Str(smartbooker_datepicker_year)+"-"+Str(smartbooker_datepicker_month)+"-"+Str(smartbooker_datepicker_dates(xvalue,yvalue)))
        smartbooker_draw_datepicker()
        Debug "DATE:"+FormatDate("%yyyy-%mm-%dd",retdate)
      EndIf
    EndIf
  EndIf
EndProcedure  
If OpenWindow(#smartbooker_Window, 220, 0, 792, 600, "TEST DATEPICKER",  #PB_Window_TitleBar | #PB_Window_SystemMenu )
  CanvasGadget(#smartbooker_calendar,0,0,200,200)
  smartbooker_draw_datepicker()
  Repeat
    myEventId=WaitWindowEvent()
    myEventType=EventType()
    myEventGadget=EventGadget()
    If myeventid=#PB_Event_Gadget And myEventGadget=#smartbooker_calendar And EventType()=#PB_EventType_LeftButtonUp       
      smartbooker_handle_datepicker()
    ElseIf myeventid=#PB_Event_CloseWindow
      CloseWindow(#smartbooker_Window)
    EndIf
  Until Not IsWindow(#smartbooker_Window)
EndIf


DataSection
  daysofmonth_data: Data.b 31,28,31,30,31,30,31,31,30,31,30,31
  datepicker1: IncludeBinary "datepicker_01.png"
  datepicker2: IncludeBinary "datepicker_02.png"
  datepicker3: IncludeBinary "datepicker_03.png"
  datepicker4: IncludeBinary "datepicker_04.png"
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Datepicker / calendargadget

Post by WilliamL »

I agree the CalendarGadget() for the Mac is lacking. Your example is very interesting and a good use of the CanvasGadget. I put a CalendarGadget() next to yours (in your code) as a comparison.

I tried your example and found the debug date to always be 'DATE: 1970-01-01'.

Code: Select all

Debug "DATE:"+FormatDate("%yyyy-%mm-%dd",smartbooker_selected_date)
Seems to work ok.

I think using 'EnableExplicit' is always a good idea.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Datepicker / calendargadget

Post by jamirokwai »

jesperbrannmark wrote:Hi all. Yesterday I ran into some problems with the Mac calendargadget - it was giving me wrong dates etc... and the one in windows... isnt that ugly like something from the 80's... I decided to make my own, thats a ripoff of the jquery datepicker plugin (http://jqueryui.com/demos/datepicker/)
I was using sprites and openwindowedscreen, but this doesnt get me far since we can only have one of those.. so now i am using the fantastic canvasgadget thats available in 4.60beta and up.
Looks great! Thanks for sharing.
May we use this in commercial projects?
Regards,
JamiroKwai
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Datepicker / calendargadget

Post by jesperbrannmark »

Yes please do so, it is made to be used ;-)
If you decide to clean up my code, maybe you could post some new code here in the forum... (no demand from my side, but it would be a really nice gesture).

Jesper
User avatar
happer66
User
User
Posts: 33
Joined: Tue Jan 12, 2010 12:10 pm
Location: Sweden

Re: Datepicker / calendargadget

Post by happer66 »

Not so much cleaning, but added leap years.

Code: Select all

EnableExplicit ;the most important line in any code ;)
;Original author: jesperbrannmark
;http://www.purebasic.fr/english/viewtopic.php?f=12&t=46300

;init
UsePNGImageDecoder()
Global smartbooker_datepicker_month=Month(Date())
Global smartbooker_datepicker_year=Year(Date())
Global smartbooker_selected_date=Date()
;our months
Global Dim monthname.s(13)
monthname(1)="Jan":monthname(2)="Feb":monthname(3)="Mar":monthname(4)="Apr":monthname(5)="May":monthname(6)="Jun":monthname(7)="Jul":monthname(8)="Aug":monthname(9)="Sep":monthname(10)="Oct":monthname(11)="Nov":monthname(12)="Dec"
Global Dim smartbooker_datepicker_dates(7,7)

Define Event, EventType,EventGadget

Enumeration
  #smartbooker_window
  #smartbooker_calendar  
  #smartbooker_image1
  #smartbooker_image2
  #smartbooker_image3
  #smartbooker_image4
EndEnumeration

;the images
CatchImage(#smartbooker_image1, ?datepicker1)
CatchImage(#smartbooker_image2, ?datepicker2)
CatchImage(#smartbooker_image3, ?datepicker3)
CatchImage(#smartbooker_image4, ?datepicker4)

Procedure IsLeap(year)
If Not year % 400 Or Not year % 4
  ProcedureReturn #True
ElseIf Not year % 100
  ProcedureReturn #False
Else
  ProcedureReturn #False
EndIf
EndProcedure

Procedure.s monthname_to_string(month,year)  
  If month=<12
    ProcedureReturn monthname.s(month)+" "+Trim(Str(year))
  Else
    ProcedureReturn monthname.s(month-12)+" "+Trim(Str(year+1))
  EndIf
EndProcedure

Procedure daysofmonth(year, month)
  Protected i,x

  If month=>1 And month=<12
    If IsLeap(year)
      Restore daysofmonthleap_data
    Else
      Restore daysofmonth_data    
    EndIf
    
    For i=1 To month
      Read.b x
    Next
    ProcedureReturn x
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure smartbooker_draw_datepicker()
  Protected x, y, theyear, themonth, days
  Debug "DRAW"
  
  StartDrawing(CanvasOutput(#smartbooker_calendar))
  Box(0,0,200,400,#White)
  DrawImage(ImageID(#smartbooker_image1),0,0)
  DrawingMode(#PB_2DDrawing_Transparent)  
  DrawText(50,15,monthname_to_string(smartbooker_datepicker_month,smartbooker_datepicker_year),RGB(0,0,0),#White)
  DrawingMode(#PB_2DDrawing_Default)  
  
  theyear=smartbooker_datepicker_year
  themonth=smartbooker_datepicker_month
  For days=1 To daysofmonth(theyear, themonth)
    x=DayOfWeek(Date(theyear,themonth,days,0,0,0))-1
    If x=-1
      x=6
    EndIf
    If x=0 And days<>1
      y+1
    EndIf
    
    smartbooker_datepicker_dates(x,y)=days
    If ParseDate("%yyyy-%mm-%dd",Str(theyear)+"-"+Str(themonth)+"-"+Str(days))=smartbooker_selected_date 
      DrawImage(ImageID(#smartbooker_image2),7+(x*27),60+(y*22),25,21)
    ElseIf theyear=Year(Date()) And themonth=Month(Date()) And days=Day(Date())
      DrawImage(ImageID(#smartbooker_image3),7+(x*27),60+(y*22),25,21)
    Else
      DrawImage(ImageID(#smartbooker_image4),7+(x*27),60+(y*22),25,21)
    EndIf
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(9+(x*27),62+(y*22),Trim(Str(days)),RGB(0,0,0),RGB(255,255,255))
    DrawingMode(#PB_2DDrawing_Default)
  Next
  StopDrawing()  
EndProcedure

Procedure smartbooker_handle_datepicker()  
  Protected gadget, xx, yy, xvalue, yvalue, x, y
  
  gadget=#smartbooker_calendar
  xx = GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseX)
  yy = GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseY)
  If xx>170 And xx<210 And yy>10 And yy<30
    smartbooker_datepicker_month+1
    If smartbooker_datepicker_month=13
      smartbooker_datepicker_month=1
      smartbooker_datepicker_year+1
    EndIf
    smartbooker_draw_datepicker()
  ElseIf xx>0 And xx<30 And yy>10 And yy<30
    smartbooker_datepicker_month-1
    If smartbooker_datepicker_month=0
      smartbooker_datepicker_month=12
      smartbooker_datepicker_year-1
    EndIf
    smartbooker_draw_datepicker()
  Else
    xvalue = -1
    yvalue = -1    
    For x=0 To 6
      If xx>7+(x*27) And xx<7+((x+1)*27)
        xvalue=x
      EndIf
    Next
    
    For y=0 To 6
      If yy>60+(y*22) And yy<60+((y+1)*22)
        yvalue=y
      EndIf
    Next
    
    If xvalue <> -1 And yvalue <> -1
      If smartbooker_datepicker_dates(xvalue,yvalue) ; If not then we are clicking somewhere else       

        smartbooker_selected_date=ParseDate("%yyyy-%mm-%dd",Str(smartbooker_datepicker_year)+"-"+Str(smartbooker_datepicker_month)+"-"+Str(smartbooker_datepicker_dates(xvalue,yvalue)))
        smartbooker_draw_datepicker()
        Debug "DATE:"+FormatDate("%yyyy-%mm-%dd",smartbooker_selected_date)
      EndIf
    EndIf
  EndIf
EndProcedure  

If OpenWindow(#smartbooker_Window, 220, 0, 792, 600, "TEST DATEPICKER",  #PB_Window_TitleBar | #PB_Window_SystemMenu )
  CanvasGadget(#smartbooker_calendar,0,0,200,200)
  smartbooker_draw_datepicker()
  
  Repeat
    Event=WaitWindowEvent(20)
    EventType=EventType()
    EventGadget=EventGadget()
    
    If Event=#PB_Event_Gadget And EventGadget=#smartbooker_calendar And EventType=#PB_EventType_LeftButtonUp       
      smartbooker_handle_datepicker()
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf


DataSection
  daysofmonth_data: Data.b 31,28,31,30,31,30,31,31,30,31,30,31
  daysofmonthleap_data: Data.b 31,29,31,30,31,30,31,31,30,31,30,31

;Just in case the link to the original code (w/ resources) goes down:
datepicker1:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 200, 0, 0, 0, 197, 8, 6, 0, 0, 0, 17, 198, 189, 64, 0, 0, 0, 1, 115, 82, 71
  Data.b 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0, 255, 0, 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19
  Data.b 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 3, 16, 25, 50, 231, 197, 140, 238, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0
  Data.b 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129, 14, 23, 0, 0, 11, 122, 73, 68, 65, 84, 120, 218, 237, 220, 219, 79, 28, 215, 1, 199, 241
  Data.b 223, 114, 49, 248, 130, 77, 136, 193, 113, 9, 9, 108, 184, 165, 107, 229, 82, 37, 149, 90, 181, 106, 74, 109, 252, 96, 170, 218, 94, 169, 85, 171, 190, 84, 66, 34, 169, 20, 41, 234
  Data.b 131, 241, 31, 208, 7, 227, 167, 40, 82, 43, 35, 241, 80, 85, 149, 170, 68, 194, 241, 131, 83, 41, 198, 113, 46, 125, 232, 37, 86, 82, 41, 29, 25, 216, 205, 46, 6, 19, 26, 108
  Data.b 140, 13, 54, 24, 3, 59, 125, 216, 89, 188, 187, 236, 206, 204, 238, 14, 132, 203, 247, 35, 161, 120, 103, 103, 207, 153, 57, 115, 126, 115, 206, 25, 54, 248, 76, 211, 52, 5, 32, 163
  Data.b 34, 154, 0, 32, 32, 0, 1, 1, 8, 8, 176, 142, 74, 236, 222, 124, 176, 20, 147, 113, 227, 142, 162, 83, 115, 90, 92, 102, 45, 143, 173, 167, 172, 164, 72, 79, 87, 237, 212, 161
  Data.b 39, 43, 85, 86, 178, 122, 188, 240, 101, 123, 138, 117, 125, 234, 190, 174, 77, 204, 234, 219, 7, 43, 84, 251, 216, 78, 90, 18, 91, 214, 87, 119, 230, 101, 124, 53, 171, 231, 235, 246
  Data.b 233, 224, 190, 157, 206, 35, 200, 131, 165, 152, 174, 77, 204, 234, 149, 150, 106, 149, 22, 251, 104, 65, 108, 105, 223, 170, 220, 169, 234, 138, 114, 125, 52, 116, 83, 85, 187, 203, 82, 70
  Data.b 146, 140, 35, 200, 103, 215, 167, 181, 127, 207, 142, 148, 145, 227, 63, 99, 51, 250, 211, 213, 91, 26, 158, 90, 210, 82, 140, 70, 197, 230, 181, 163, 72, 106, 124, 188, 68, 175, 125, 175
  Data.b 70, 45, 79, 236, 89, 217, 62, 62, 61, 175, 153, 7, 75, 58, 84, 187, 207, 62, 32, 231, 63, 27, 215, 207, 94, 56, 184, 242, 250, 173, 143, 111, 232, 227, 232, 156, 252, 251, 138, 244
  Data.b 196, 110, 201, 52, 37, 95, 218, 192, 146, 40, 37, 177, 221, 233, 215, 143, 62, 95, 234, 62, 233, 159, 75, 126, 63, 185, 174, 244, 247, 211, 203, 73, 47, 63, 189, 28, 187, 207, 56, 113
  Data.b 250, 92, 122, 249, 118, 251, 187, 61, 134, 124, 206, 51, 159, 243, 73, 46, 39, 219, 117, 176, 187, 78, 153, 246, 75, 47, 207, 169, 236, 66, 100, 235, 143, 217, 206, 225, 235, 251, 166, 190
  Data.b 188, 107, 42, 120, 104, 159, 126, 245, 210, 129, 149, 247, 254, 246, 197, 215, 250, 233, 243, 7, 237, 167, 88, 11, 73, 67, 196, 231, 99, 51, 250, 56, 58, 167, 151, 14, 20, 169, 180, 232
  Data.b 81, 69, 217, 78, 204, 237, 9, 167, 239, 103, 247, 58, 83, 153, 110, 143, 35, 83, 57, 249, 94, 20, 167, 207, 165, 151, 111, 183, 127, 174, 237, 148, 203, 121, 230, 115, 62, 217, 202, 113
  Data.b 251, 218, 205, 118, 167, 178, 10, 145, 75, 91, 155, 166, 84, 179, 203, 167, 199, 202, 125, 234, 255, 98, 70, 47, 214, 238, 210, 179, 7, 43, 36, 73, 247, 22, 150, 82, 246, 117, 124, 204
  Data.b 251, 151, 171, 83, 122, 102, 95, 60, 28, 192, 86, 82, 90, 36, 61, 83, 233, 83, 239, 63, 111, 102, 221, 199, 177, 219, 15, 77, 45, 170, 122, 87, 150, 100, 102, 248, 175, 153, 244, 90
  Data.b 105, 219, 211, 63, 151, 233, 51, 110, 223, 147, 205, 126, 178, 249, 140, 221, 77, 203, 204, 114, 188, 178, 217, 238, 180, 159, 221, 121, 101, 107, 15, 55, 237, 100, 183, 191, 233, 240, 111, 211
  Data.b 102, 31, 55, 237, 224, 246, 92, 237, 142, 195, 77, 127, 114, 234, 7, 166, 139, 246, 116, 82, 179, 75, 10, 79, 45, 101, 125, 191, 196, 169, 128, 135, 177, 252, 79, 74, 46, 46, 166, 155
  Data.b 178, 228, 162, 113, 157, 58, 76, 174, 33, 113, 115, 206, 202, 241, 130, 155, 46, 235, 50, 115, 104, 199, 66, 202, 41, 244, 179, 110, 207, 213, 204, 225, 58, 154, 5, 180, 105, 190, 33, 121
  Data.b 104, 243, 208, 137, 137, 19, 32, 2, 2, 16, 16, 192, 107, 37, 94, 22, 182, 127, 215, 14, 213, 86, 150, 171, 185, 166, 34, 101, 251, 240, 228, 172, 198, 239, 60, 208, 173, 185, 135, 180
  Data.b 56, 54, 85, 127, 243, 44, 32, 245, 85, 59, 245, 242, 83, 85, 25, 223, 107, 174, 169, 80, 115, 77, 133, 62, 29, 189, 173, 145, 219, 243, 92, 89, 108, 154, 254, 230, 42, 32, 78, 191
  Data.b 208, 169, 217, 83, 150, 245, 96, 147, 189, 252, 84, 149, 238, 47, 220, 210, 228, 189, 5, 174, 48, 242, 182, 158, 253, 205, 213, 26, 196, 238, 57, 186, 41, 169, 182, 178, 60, 227, 231, 222
  Data.b 249, 124, 124, 213, 182, 218, 202, 242, 156, 159, 211, 43, 195, 190, 153, 182, 111, 148, 159, 111, 202, 70, 58, 15, 167, 223, 185, 216, 189, 239, 84, 198, 147, 25, 250, 219, 219, 25, 250, 154
  Data.b 83, 127, 243, 116, 145, 110, 87, 104, 83, 245, 158, 140, 7, 108, 58, 236, 235, 246, 57, 189, 233, 208, 112, 27, 205, 86, 9, 166, 215, 199, 98, 230, 120, 35, 78, 97, 125, 217, 202, 148
  Data.b 212, 152, 161, 191, 101, 11, 137, 93, 127, 115, 211, 110, 174, 166, 88, 11, 57, 126, 125, 247, 207, 159, 142, 217, 190, 191, 20, 139, 185, 76, 175, 79, 69, 69, 238, 190, 110, 239, 182, 204
  Data.b 124, 249, 210, 254, 149, 233, 168, 30, 125, 97, 46, 105, 31, 254, 111, 129, 117, 245, 246, 231, 227, 250, 197, 139, 181, 235, 251, 20, 235, 254, 194, 82, 78, 133, 58, 237, 63, 51, 191, 196
  Data.b 149, 68, 30, 183, 40, 83, 85, 187, 119, 172, 107, 173, 158, 44, 210, 211, 189, 246, 131, 6, 253, 241, 239, 81, 207, 202, 3, 220, 242, 114, 244, 200, 105, 13, 98, 231, 218, 255, 102, 87
  Data.b 109, 251, 237, 15, 27, 92, 239, 11, 228, 34, 114, 235, 190, 235, 112, 100, 219, 119, 93, 3, 242, 101, 150, 131, 200, 20, 146, 47, 11, 60, 96, 108, 111, 177, 152, 169, 209, 233, 57, 215
  Data.b 35, 199, 232, 244, 156, 98, 49, 211, 246, 103, 205, 3, 50, 58, 61, 175, 79, 194, 183, 28, 247, 251, 36, 124, 75, 163, 211, 252, 162, 16, 133, 153, 152, 89, 208, 213, 209, 105, 199, 253
  Data.b 174, 142, 78, 107, 98, 166, 176, 223, 185, 185, 91, 131, 184, 120, 136, 248, 197, 196, 140, 238, 62, 88, 84, 99, 245, 30, 61, 123, 32, 245, 87, 255, 215, 190, 158, 85, 248, 230, 61, 194
  Data.b 129, 2, 153, 186, 109, 125, 125, 228, 95, 215, 31, 106, 98, 230, 65, 198, 254, 54, 52, 121, 79, 225, 201, 123, 26, 187, 99, 223, 223, 74, 138, 139, 28, 199, 9, 79, 23, 233, 215, 111
  Data.b 207, 235, 250, 237, 121, 125, 48, 116, 147, 107, 137, 53, 87, 104, 127, 91, 138, 45, 59, 6, 132, 111, 243, 2, 5, 79, 177, 120, 46, 139, 13, 50, 197, 90, 111, 140, 32, 32, 28, 133
  Data.b 140, 32, 37, 174, 150, 232, 192, 102, 158, 70, 153, 249, 7, 164, 190, 178, 88, 51, 15, 151, 181, 183, 52, 143, 239, 58, 249, 50, 4, 63, 177, 205, 103, 115, 83, 72, 127, 47, 249, 181
  Data.b 93, 153, 94, 242, 37, 221, 184, 114, 41, 223, 151, 231, 103, 188, 184, 73, 102, 43, 39, 211, 49, 217, 213, 153, 203, 181, 41, 244, 88, 147, 219, 88, 121, 180, 179, 10, 219, 127, 102, 177
  Data.b 72, 77, 251, 75, 243, 159, 98, 253, 250, 59, 143, 107, 114, 161, 88, 121, 253, 113, 247, 124, 255, 60, 137, 219, 63, 219, 177, 150, 163, 175, 41, 247, 127, 74, 37, 215, 243, 179, 171, 203
  Data.b 171, 99, 118, 58, 166, 124, 191, 118, 107, 122, 220, 190, 249, 126, 15, 221, 44, 188, 47, 46, 155, 210, 228, 66, 177, 126, 243, 242, 254, 252, 71, 144, 239, 55, 62, 166, 182, 177, 123, 186
  Data.b 18, 153, 83, 117, 89, 158, 35, 9, 176, 193, 204, 44, 22, 233, 230, 66, 177, 58, 90, 42, 244, 66, 221, 222, 252, 3, 34, 73, 111, 252, 184, 78, 109, 141, 51, 250, 195, 63, 110, 234
  Data.b 218, 221, 37, 197, 76, 190, 195, 141, 205, 189, 230, 168, 171, 44, 209, 239, 127, 84, 173, 231, 108, 194, 225, 58, 32, 146, 244, 92, 221, 94, 245, 58, 20, 6, 108, 53, 60, 230, 5, 8
  Data.b 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 128, 252, 3, 50, 210, 167, 19, 77, 77, 106, 110, 106, 82, 243, 233, 43, 43, 155, 175, 156
  Data.b 182, 182, 53, 29, 87, 223, 136, 87, 135, 54, 162, 190, 227, 137, 114, 211, 126, 142, 247, 41, 234, 105, 29, 167, 117, 101, 213, 57, 38, 159, 203, 21, 157, 94, 147, 122, 179, 156, 155, 117
  Data.b 12, 39, 188, 106, 204, 43, 167, 87, 213, 147, 116, 249, 188, 149, 86, 215, 154, 212, 179, 30, 117, 20, 50, 130, 4, 2, 1, 105, 48, 98, 117, 150, 17, 69, 6, 173, 109, 158, 170, 87
  Data.b 231, 133, 144, 134, 67, 33, 13, 247, 6, 37, 73, 39, 123, 173, 215, 23, 58, 213, 224, 81, 29, 254, 86, 73, 26, 84, 36, 209, 23, 35, 97, 25, 129, 160, 78, 6, 12, 189, 119, 217
  Data.b 218, 56, 18, 209, 144, 36, 181, 250, 61, 171, 119, 237, 207, 109, 181, 149, 58, 66, 33, 157, 105, 91, 131, 10, 70, 250, 116, 162, 171, 95, 129, 238, 1, 13, 135, 6, 116, 42, 32, 157
  Data.b 239, 74, 186, 249, 108, 150, 58, 10, 158, 98, 117, 116, 232, 164, 17, 182, 2, 18, 81, 216, 8, 234, 88, 135, 205, 104, 227, 233, 200, 146, 122, 23, 73, 220, 101, 227, 163, 88, 238, 13
  Data.b 213, 214, 30, 148, 100, 40, 28, 137, 191, 142, 70, 6, 165, 214, 118, 181, 183, 74, 70, 98, 99, 36, 44, 67, 210, 201, 246, 182, 245, 57, 183, 132, 139, 111, 172, 220, 37, 79, 172, 73
  Data.b 37, 137, 145, 241, 120, 134, 81, 211, 171, 155, 192, 25, 37, 178, 24, 237, 59, 158, 114, 231, 47, 252, 156, 210, 234, 240, 168, 79, 120, 176, 6, 241, 171, 49, 96, 221, 117, 71, 34, 26
  Data.b 10, 52, 202, 159, 222, 240, 71, 122, 100, 4, 123, 53, 28, 10, 233, 253, 110, 233, 236, 145, 53, 236, 72, 133, 240, 55, 42, 32, 105, 40, 126, 50, 250, 224, 162, 161, 147, 237, 109, 241
  Data.b 224, 88, 163, 100, 52, 50, 40, 41, 160, 70, 191, 21, 142, 35, 61, 82, 247, 128, 134, 67, 33, 157, 11, 26, 58, 123, 100, 109, 238, 96, 134, 58, 244, 190, 117, 151, 52, 122, 206, 173
  Data.b 217, 93, 82, 70, 171, 94, 15, 133, 52, 28, 186, 160, 206, 250, 66, 250, 171, 95, 45, 146, 140, 158, 35, 171, 59, 255, 72, 159, 126, 215, 35, 157, 26, 8, 89, 237, 150, 231, 57, 217
  Data.b 213, 177, 113, 22, 233, 126, 249, 91, 173, 187, 110, 36, 44, 35, 109, 234, 17, 237, 123, 75, 231, 21, 208, 169, 87, 227, 247, 142, 134, 195, 29, 10, 40, 105, 202, 178, 145, 212, 31, 214
  Data.b 177, 64, 98, 180, 136, 40, 108, 88, 65, 240, 55, 42, 96, 141, 146, 209, 176, 33, 5, 58, 244, 147, 122, 41, 122, 249, 162, 12, 5, 116, 236, 112, 125, 210, 8, 212, 175, 75, 107, 208
  Data.b 123, 3, 29, 135, 213, 176, 50, 13, 44, 220, 249, 174, 44, 107, 184, 96, 187, 188, 153, 113, 181, 233, 204, 64, 183, 2, 86, 7, 78, 185, 123, 215, 119, 234, 221, 208, 5, 117, 70, 226
  Data.b 119, 249, 87, 251, 211, 166, 182, 94, 212, 177, 145, 158, 98, 53, 52, 6, 52, 20, 25, 81, 52, 50, 168, 64, 163, 223, 93, 234, 19, 83, 150, 141, 149, 144, 120, 7, 28, 140, 40, 58
  Data.b 18, 209, 144, 90, 229, 175, 79, 28, 243, 160, 34, 35, 241, 53, 86, 234, 250, 195, 208, 217, 35, 86, 103, 235, 234, 151, 86, 70, 160, 141, 109, 61, 214, 57, 241, 32, 132, 244, 126, 119
  Data.b 64, 82, 191, 94, 77, 76, 219, 18, 211, 210, 46, 233, 156, 53, 130, 120, 94, 199, 134, 10, 136, 191, 85, 70, 56, 162, 104, 216, 80, 139, 223, 97, 92, 182, 22, 185, 142, 65, 250, 134
  Data.b 180, 181, 7, 37, 35, 172, 15, 46, 95, 148, 177, 114, 55, 109, 83, 123, 208, 208, 123, 151, 47, 43, 108, 36, 173, 63, 226, 247, 246, 149, 169, 66, 226, 231, 221, 130, 230, 38, 91, 79
  Data.b 67, 231, 5, 235, 1, 68, 124, 166, 145, 24, 121, 79, 13, 156, 73, 26, 173, 172, 155, 145, 71, 117, 108, 168, 128, 200, 223, 168, 192, 224, 37, 93, 26, 180, 166, 36, 201, 7, 110, 77
  Data.b 169, 206, 158, 139, 15, 126, 233, 211, 18, 47, 215, 14, 137, 53, 207, 165, 254, 66, 203, 234, 215, 217, 30, 35, 37, 196, 13, 141, 1, 25, 23, 47, 106, 72, 143, 206, 49, 125, 186, 24
  Data.b 95, 120, 110, 208, 245, 213, 58, 75, 44, 194, 19, 143, 93, 83, 214, 110, 214, 200, 27, 239, 200, 137, 235, 149, 251, 20, 203, 182, 14, 47, 251, 68, 193, 1, 169, 63, 172, 99, 234, 215
  Data.b 121, 197, 231, 230, 171, 134, 192, 129, 110, 5, 250, 187, 212, 220, 212, 164, 163, 61, 210, 169, 129, 2, 23, 128, 25, 134, 217, 215, 131, 137, 121, 232, 37, 169, 160, 33, 59, 190, 14, 145
  Data.b 148, 50, 26, 54, 248, 91, 37, 195, 144, 17, 72, 58, 199, 250, 78, 189, 219, 27, 180, 234, 109, 210, 209, 30, 67, 39, 123, 61, 62, 183, 77, 60, 106, 156, 11, 62, 90, 235, 28, 237
  Data.b 49, 20, 232, 126, 83, 157, 245, 82, 67, 231, 155, 214, 35, 217, 38, 53, 55, 117, 73, 193, 252, 238, 252, 118, 117, 120, 218, 39, 44, 62, 51, 195, 223, 21, 253, 235, 191, 199, 244, 243
  Data.b 151, 106, 185, 226, 216, 118, 222, 185, 58, 174, 95, 126, 183, 206, 131, 17, 4, 216, 6, 28, 255, 170, 73, 113, 145, 183, 25, 90, 142, 241, 119, 181, 176, 133, 2, 226, 53, 175, 3, 7
  Data.b 172, 229, 141, 155, 222, 10, 216, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128
  Data.b 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0
  Data.b 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8
  Data.b 64, 64, 0, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16
  Data.b 16, 128, 128, 0, 4, 4, 32, 32, 0, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 182, 176, 146, 108, 111, 248, 104, 27, 108, 35, 62, 70
  Data.b 16, 128, 41, 22, 64, 64, 0, 2, 2, 108, 228, 69, 186, 124, 44, 211, 177, 157, 86, 233, 62, 70, 16, 128, 41, 22, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32
  Data.b 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64
  Data.b 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 172, 93
  Data.b 64, 202, 74, 30, 109, 142, 153, 166, 98, 166, 73, 75, 97, 91, 72, 238, 251, 89, 3, 242, 76, 205, 30, 221, 152, 158, 167, 181, 176, 173, 220, 152, 158, 151, 191, 122, 119, 202, 182, 146
  Data.b 76, 59, 182, 28, 168, 208, 71, 67, 147, 58, 176, 183, 92, 165, 197, 190, 149, 145, 4, 216, 170, 22, 151, 77, 93, 155, 152, 213, 43, 45, 213, 206, 35, 72, 121, 105, 145, 90, 158, 168
  Data.b 208, 135, 131, 147, 140, 36, 216, 242, 198, 239, 204, 235, 195, 193, 73, 61, 123, 176, 98, 213, 20, 203, 103, 154, 217, 135, 134, 133, 229, 152, 254, 59, 118, 87, 209, 169, 251, 90, 92, 102
  Data.b 4, 193, 214, 92, 115, 60, 93, 181, 75, 135, 234, 246, 169, 172, 120, 245, 120, 97, 27, 16, 96, 187, 227, 49, 47, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 192
  Data.b 166, 246, 127, 74, 109, 171, 128, 80, 107, 91, 233, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
datepicker2:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0
  Data.b 0, 0, 27, 0, 0, 0, 21, 8, 6, 0, 0, 0, 183, 222, 149, 37, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0
  Data.b 255, 0, 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 12
  Data.b 12, 51, 54, 194, 156, 206, 157, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80
  Data.b 87, 129, 14, 23, 0, 0, 0, 171, 73, 68, 65, 84, 72, 199, 237, 149, 65, 14, 2, 49, 8, 69, 127, 11, 214, 185, 136, 183, 114, 237, 89, 189, 195, 156, 100, 106, 11, 46, 76, 55
  Data.b 133, 133, 9, 58, 49, 102, 88, 146, 150, 7, 191, 20, 210, 237, 126, 85, 236, 100, 12, 0, 237, 242, 125, 30, 175, 233, 5, 139, 90, 43, 205, 6, 175, 54, 116, 198, 142, 118, 192, 14
  Data.b 216, 239, 192, 24, 0, 186, 110, 161, 32, 162, 246, 159, 117, 237, 19, 104, 249, 119, 25, 79, 181, 4, 51, 182, 57, 147, 51, 174, 24, 0, 114, 145, 16, 76, 89, 156, 4, 196, 120, 24
  Data.b 0, 68, 98, 106, 54, 199, 151, 166, 152, 121, 84, 22, 29, 253, 73, 201, 202, 56, 119, 236, 224, 60, 40, 182, 207, 182, 82, 141, 239, 44, 139, 129, 127, 164, 50, 117, 26, 132, 205, 153
  Data.b 177, 169, 131, 48, 239, 205, 155, 35, 43, 3, 0, 173, 20, 130, 17, 222, 187, 255, 4, 91, 226, 41, 194, 52, 168, 174, 172, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
datepicker3:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0
  Data.b 27, 0, 0, 0, 21, 8, 6, 0, 0, 0, 183, 222, 149, 37, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0, 255, 0
  Data.b 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 3, 16, 30
  Data.b 28, 116, 82, 23, 230, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129
  Data.b 14, 23, 0, 0, 0, 57, 73, 68, 65, 84, 72, 199, 99, 252, 117, 69, 239, 63, 3, 157, 0, 11, 3, 3, 3, 3, 163, 68, 20, 205, 45, 250, 255, 98, 25, 3, 19, 3, 29, 193
  Data.b 168, 101, 163, 150, 141, 90, 54, 106, 217, 168, 101, 163, 150, 141, 90, 70, 34, 96, 164, 103, 27, 4, 0, 48, 50, 9, 33, 177, 88, 200, 172, 0, 0, 0, 0, 73, 69, 78, 68, 174
  Data.b 66, 96, 130
datepicker4:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 27, 0, 0, 0, 21, 8, 4, 0, 0, 0, 29, 215, 93, 174, 0, 0, 0, 1
  Data.b 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 2, 98, 75, 71, 68, 0, 255, 135, 143, 204, 191, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1
  Data.b 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 12, 12, 50, 12, 29, 139, 38, 110, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67
  Data.b 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129, 14, 23, 0, 0, 0, 70, 73, 68, 65, 84, 56, 203, 99, 188, 241, 159, 129, 12, 192, 194, 192, 192
  Data.b 73, 178, 166, 239, 12, 44, 132, 21, 49, 194, 89, 8, 135, 49, 49, 144, 5, 70, 181, 81, 75, 27, 11, 3, 195, 207, 225, 26, 111, 44, 132, 117, 98, 250, 237, 31, 5, 182, 49, 18
  Data.b 109, 27, 61, 180, 33, 252, 241, 143, 14, 169, 4, 27, 0, 0, 150, 151, 10, 8, 68, 242, 110, 109, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
EndDataSection  
Image If your code isn't clean atleast make sure it's pure!
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Datepicker / calendargadget

Post by Kwai chang caine »

Thanks jesperbrannmark for sharing 8)
ImageThe happiness is a road...
Not a destination
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Re: Datepicker / calendargadget

Post by liam »

hello guys, thanks for posting this very helpful trick but i keep encountering an error everytime i try to run both of your codes. it says "CanvasOutput() is not a function, array, macro or linked list."
did i miss something?
PureBasic 4.51(x86) on WinXP SP3
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Datepicker / calendargadget

Post by WilliamL »

You must use pb version 4.60. The gadget didn't exist before that.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Re: Datepicker / calendargadget

Post by liam »

i see. im still trying to learn PB so im only using the demo. i guess i'll just wait for the demo 4.6x to be available (right now its still 4.51).
but thanks for the explanation
PureBasic 4.51(x86) on WinXP SP3
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Datepicker / calendargadget

Post by jesperbrannmark »

Hi liam.
Been there, done that (still doing that) (learning PB)

Try this example, i changed it to imagegadget
Every imagegadget also as a image (picture) - while the canvasgadget has it "all-in-one".
What I did was first create this image (createimage) and then put it on screen (imagegadet). Then i changed the eventtype from #pb_eventtype_leftbuttonup to #pb_eventtype_leftclick - this because the imagegadget has different eventtypes.
If i needed to have the buttonup specific, i could probably use #WM_LBUTTONUP on Windows - but then it wouldn't work on Macos or Linux.
Also I changed the thing that detected where we click, since there is no such thing in "imagegadget" - i did this with the help of knowing where in the window we clicked (windowmousex()) and the top x of the gadget (gadgetx()) and similar with y axis.
I also did something I hope someone will have a comment about. When we have updated the image thats used for the imagegadet (painted the picture) - this is not updated automatic so we need to update it somehow - i did this by putting the gadget there in the window once again. this is probably poor practice and i hope someone can comment on a better way.

Good luck with PB!

Code: Select all

EnableExplicit ;the most important line in any code ;)
;Original author: jesperbrannmark
;http://www.purebasic.fr/english/viewtopic.php?f=12&t=46300

;init
UsePNGImageDecoder()
Global smartbooker_datepicker_month=Month(Date())
Global smartbooker_datepicker_year=Year(Date())
Global smartbooker_selected_date=Date()
;our months
Global Dim monthname.s(13)
monthname(1)="Jan":monthname(2)="Feb":monthname(3)="Mar":monthname(4)="Apr":monthname(5)="May":monthname(6)="Jun":monthname(7)="Jul":monthname(8)="Aug":monthname(9)="Sep":monthname(10)="Oct":monthname(11)="Nov":monthname(12)="Dec"
Global Dim smartbooker_datepicker_dates(7,7)

Define Event, EventType,EventGadget

Enumeration
  #smartbooker_window
  #smartbooker_calendar_gadget ;new
  #smartbooker_calendar_image ;new
  #smartbooker_image1
  #smartbooker_image2
  #smartbooker_image3
  #smartbooker_image4
EndEnumeration
#White=$ffffff ;new
;the images
CatchImage(#smartbooker_image1, ?datepicker1)
CatchImage(#smartbooker_image2, ?datepicker2)
CatchImage(#smartbooker_image3, ?datepicker3)
CatchImage(#smartbooker_image4, ?datepicker4)

Procedure IsLeap(year)
If Not year % 400 Or Not year % 4
  ProcedureReturn #True
ElseIf Not year % 100
  ProcedureReturn #False
Else
  ProcedureReturn #False
EndIf
EndProcedure

Procedure.s monthname_to_string(month,year)  
  If month=<12
    ProcedureReturn monthname.s(month)+" "+Trim(Str(year))
  Else
    ProcedureReturn monthname.s(month-12)+" "+Trim(Str(year+1))
  EndIf
EndProcedure

Procedure daysofmonth(year, month)
  Protected i,x

  If month=>1 And month=<12
    If IsLeap(year)
      Restore daysofmonthleap_data
    Else
      Restore daysofmonth_data    
    EndIf
    
    For i=1 To month
      Read.b x
    Next
    ProcedureReturn x
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure smartbooker_draw_datepicker()
  Protected x, y, theyear, themonth, days
  Debug "DRAW"
  
  StartDrawing(ImageOutput(#smartbooker_calendar_image)) ;CanvasOutput(#smartbooker_calendar))
  Box(0,0,200,400,#White)
  DrawImage(ImageID(#smartbooker_image1),0,0)
  DrawingMode(#PB_2DDrawing_Transparent)  
  DrawText(50,15,monthname_to_string(smartbooker_datepicker_month,smartbooker_datepicker_year),RGB(0,0,0),#White)
  DrawingMode(#PB_2DDrawing_Default)  
  
  theyear=smartbooker_datepicker_year
  themonth=smartbooker_datepicker_month
  For days=1 To daysofmonth(theyear, themonth)
    x=DayOfWeek(Date(theyear,themonth,days,0,0,0))-1
    If x=-1
      x=6
    EndIf
    If x=0 And days<>1
      y+1
    EndIf
    
    smartbooker_datepicker_dates(x,y)=days
    If ParseDate("%yyyy-%mm-%dd",Str(theyear)+"-"+Str(themonth)+"-"+Str(days))=smartbooker_selected_date 
      DrawImage(ImageID(#smartbooker_image2),7+(x*27),60+(y*22),25,21)
    ElseIf theyear=Year(Date()) And themonth=Month(Date()) And days=Day(Date())
      DrawImage(ImageID(#smartbooker_image3),7+(x*27),60+(y*22),25,21)
    Else
      DrawImage(ImageID(#smartbooker_image4),7+(x*27),60+(y*22),25,21)
    EndIf
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(9+(x*27),62+(y*22),Trim(Str(days)),RGB(0,0,0),RGB(255,255,255))
    DrawingMode(#PB_2DDrawing_Default)
  Next
  StopDrawing()  
    ImageGadget(#smartbooker_calendar_gadget,0,0,200,200,ImageID(#smartbooker_calendar_image)) ;was canvasgadget(#smartbooker_calendar

EndProcedure

Procedure smartbooker_handle_datepicker()  
  Protected gadget, xx, yy, xvalue, yvalue, x, y
  
  gadget=#smartbooker_calendar_gadget ;changed
  xx = WindowMouseX(#smartbooker_window)-GadgetX(#smartbooker_calendar_gadget) ;was GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseX)
  yy = WindowMouseY(#smartbooker_window)-GadgetY(#smartbooker_calendar_gadget) ;was GetGadgetAttribute(#smartbooker_calendar, #PB_Canvas_MouseY)
  If xx>170 And xx<210 And yy>10 And yy<30
    smartbooker_datepicker_month+1
    If smartbooker_datepicker_month=13
      smartbooker_datepicker_month=1
      smartbooker_datepicker_year+1
    EndIf
    smartbooker_draw_datepicker()
  ElseIf xx>0 And xx<30 And yy>10 And yy<30
    smartbooker_datepicker_month-1
    If smartbooker_datepicker_month=0
      smartbooker_datepicker_month=12
      smartbooker_datepicker_year-1
    EndIf
    smartbooker_draw_datepicker()
  Else
    xvalue = -1
    yvalue = -1    
    For x=0 To 6
      If xx>7+(x*27) And xx<7+((x+1)*27)
        xvalue=x
      EndIf
    Next
    
    For y=0 To 6
      If yy>60+(y*22) And yy<60+((y+1)*22)
        yvalue=y
      EndIf
    Next
    
    If xvalue <> -1 And yvalue <> -1
      If smartbooker_datepicker_dates(xvalue,yvalue) ; If not then we are clicking somewhere else       

        smartbooker_selected_date=ParseDate("%yyyy-%mm-%dd",Str(smartbooker_datepicker_year)+"-"+Str(smartbooker_datepicker_month)+"-"+Str(smartbooker_datepicker_dates(xvalue,yvalue)))
        smartbooker_draw_datepicker()
        Debug "DATE:"+FormatDate("%yyyy-%mm-%dd",smartbooker_selected_date)
      EndIf
    EndIf
  EndIf
EndProcedure  

If OpenWindow(#smartbooker_Window, 220, 0, 792, 600, "TEST DATEPICKER",  #PB_Window_TitleBar | #PB_Window_SystemMenu )
  CreateImage(#smartbooker_calendar_image,200,200) ;new
  ImageGadget(#smartbooker_calendar_gadget,0,0,200,200,ImageID(#smartbooker_calendar_image)) ;was canvasgadget(#smartbooker_calendar
  smartbooker_draw_datepicker()
  
  Repeat
    Event=WaitWindowEvent(20)
    EventType=EventType()
    EventGadget=EventGadget()
    
    If Event=#PB_Event_Gadget And EventGadget=#smartbooker_calendar_gadget And EventType=#PB_EventType_LeftClick ;was leftButtonUp 
      smartbooker_handle_datepicker()
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf


DataSection
  daysofmonth_data: Data.b 31,28,31,30,31,30,31,31,30,31,30,31
  daysofmonthleap_data: Data.b 31,29,31,30,31,30,31,31,30,31,30,31

;Just in case the link to the original code (w/ resources) goes down:
datepicker1:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 200, 0, 0, 0, 197, 8, 6, 0, 0, 0, 17, 198, 189, 64, 0, 0, 0, 1, 115, 82, 71
  Data.b 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0, 255, 0, 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19
  Data.b 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 3, 16, 25, 50, 231, 197, 140, 238, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0
  Data.b 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129, 14, 23, 0, 0, 11, 122, 73, 68, 65, 84, 120, 218, 237, 220, 219, 79, 28, 215, 1, 199, 241
  Data.b 223, 114, 49, 248, 130, 77, 136, 193, 113, 9, 9, 108, 184, 165, 107, 229, 82, 37, 149, 90, 181, 106, 74, 109, 252, 96, 170, 218, 94, 169, 85, 171, 190, 84, 66, 34, 169, 20, 41, 234
  Data.b 131, 241, 31, 208, 7, 227, 167, 40, 82, 43, 35, 241, 80, 85, 149, 170, 68, 194, 241, 131, 83, 41, 198, 113, 46, 125, 232, 37, 86, 82, 41, 29, 25, 216, 205, 46, 6, 19, 26, 108
  Data.b 140, 13, 54, 24, 3, 59, 125, 216, 89, 188, 187, 236, 206, 204, 238, 14, 132, 203, 247, 35, 161, 120, 103, 103, 207, 153, 57, 115, 126, 115, 206, 25, 54, 248, 76, 211, 52, 5, 32, 163
  Data.b 34, 154, 0, 32, 32, 0, 1, 1, 8, 8, 176, 142, 74, 236, 222, 124, 176, 20, 147, 113, 227, 142, 162, 83, 115, 90, 92, 102, 45, 143, 173, 167, 172, 164, 72, 79, 87, 237, 212, 161
  Data.b 39, 43, 85, 86, 178, 122, 188, 240, 101, 123, 138, 117, 125, 234, 190, 174, 77, 204, 234, 219, 7, 43, 84, 251, 216, 78, 90, 18, 91, 214, 87, 119, 230, 101, 124, 53, 171, 231, 235, 246
  Data.b 233, 224, 190, 157, 206, 35, 200, 131, 165, 152, 174, 77, 204, 234, 149, 150, 106, 149, 22, 251, 104, 65, 108, 105, 223, 170, 220, 169, 234, 138, 114, 125, 52, 116, 83, 85, 187, 203, 82, 70
  Data.b 146, 140, 35, 200, 103, 215, 167, 181, 127, 207, 142, 148, 145, 227, 63, 99, 51, 250, 211, 213, 91, 26, 158, 90, 210, 82, 140, 70, 197, 230, 181, 163, 72, 106, 124, 188, 68, 175, 125, 175
  Data.b 70, 45, 79, 236, 89, 217, 62, 62, 61, 175, 153, 7, 75, 58, 84, 187, 207, 62, 32, 231, 63, 27, 215, 207, 94, 56, 184, 242, 250, 173, 143, 111, 232, 227, 232, 156, 252, 251, 138, 244
  Data.b 196, 110, 201, 52, 37, 95, 218, 192, 146, 40, 37, 177, 221, 233, 215, 143, 62, 95, 234, 62, 233, 159, 75, 126, 63, 185, 174, 244, 247, 211, 203, 73, 47, 63, 189, 28, 187, 207, 56, 113
  Data.b 250, 92, 122, 249, 118, 251, 187, 61, 134, 124, 206, 51, 159, 243, 73, 46, 39, 219, 117, 176, 187, 78, 153, 246, 75, 47, 207, 169, 236, 66, 100, 235, 143, 217, 206, 225, 235, 251, 166, 190
  Data.b 188, 107, 42, 120, 104, 159, 126, 245, 210, 129, 149, 247, 254, 246, 197, 215, 250, 233, 243, 7, 237, 167, 88, 11, 73, 67, 196, 231, 99, 51, 250, 56, 58, 167, 151, 14, 20, 169, 180, 232
  Data.b 81, 69, 217, 78, 204, 237, 9, 167, 239, 103, 247, 58, 83, 153, 110, 143, 35, 83, 57, 249, 94, 20, 167, 207, 165, 151, 111, 183, 127, 174, 237, 148, 203, 121, 230, 115, 62, 217, 202, 113
  Data.b 251, 218, 205, 118, 167, 178, 10, 145, 75, 91, 155, 166, 84, 179, 203, 167, 199, 202, 125, 234, 255, 98, 70, 47, 214, 238, 210, 179, 7, 43, 36, 73, 247, 22, 150, 82, 246, 117, 124, 204
  Data.b 251, 151, 171, 83, 122, 102, 95, 60, 28, 192, 86, 82, 90, 36, 61, 83, 233, 83, 239, 63, 111, 102, 221, 199, 177, 219, 15, 77, 45, 170, 122, 87, 150, 100, 102, 248, 175, 153, 244, 90
  Data.b 105, 219, 211, 63, 151, 233, 51, 110, 223, 147, 205, 126, 178, 249, 140, 221, 77, 203, 204, 114, 188, 178, 217, 238, 180, 159, 221, 121, 101, 107, 15, 55, 237, 100, 183, 191, 233, 240, 111, 211
  Data.b 102, 31, 55, 237, 224, 246, 92, 237, 142, 195, 77, 127, 114, 234, 7, 166, 139, 246, 116, 82, 179, 75, 10, 79, 45, 101, 125, 191, 196, 169, 128, 135, 177, 252, 79, 74, 46, 46, 166, 155
  Data.b 178, 228, 162, 113, 157, 58, 76, 174, 33, 113, 115, 206, 202, 241, 130, 155, 46, 235, 50, 115, 104, 199, 66, 202, 41, 244, 179, 110, 207, 213, 204, 225, 58, 154, 5, 180, 105, 190, 33, 121
  Data.b 104, 243, 208, 137, 137, 19, 32, 2, 2, 16, 16, 192, 107, 37, 94, 22, 182, 127, 215, 14, 213, 86, 150, 171, 185, 166, 34, 101, 251, 240, 228, 172, 198, 239, 60, 208, 173, 185, 135, 180
  Data.b 56, 54, 85, 127, 243, 44, 32, 245, 85, 59, 245, 242, 83, 85, 25, 223, 107, 174, 169, 80, 115, 77, 133, 62, 29, 189, 173, 145, 219, 243, 92, 89, 108, 154, 254, 230, 42, 32, 78, 191
  Data.b 208, 169, 217, 83, 150, 245, 96, 147, 189, 252, 84, 149, 238, 47, 220, 210, 228, 189, 5, 174, 48, 242, 182, 158, 253, 205, 213, 26, 196, 238, 57, 186, 41, 169, 182, 178, 60, 227, 231, 222
  Data.b 249, 124, 124, 213, 182, 218, 202, 242, 156, 159, 211, 43, 195, 190, 153, 182, 111, 148, 159, 111, 202, 70, 58, 15, 167, 223, 185, 216, 189, 239, 84, 198, 147, 25, 250, 219, 219, 25, 250, 154
  Data.b 83, 127, 243, 116, 145, 110, 87, 104, 83, 245, 158, 140, 7, 108, 58, 236, 235, 246, 57, 189, 233, 208, 112, 27, 205, 86, 9, 166, 215, 199, 98, 230, 120, 35, 78, 97, 125, 217, 202, 148
  Data.b 212, 152, 161, 191, 101, 11, 137, 93, 127, 115, 211, 110, 174, 166, 88, 11, 57, 126, 125, 247, 207, 159, 142, 217, 190, 191, 20, 139, 185, 76, 175, 79, 69, 69, 238, 190, 110, 239, 182, 204
  Data.b 124, 249, 210, 254, 149, 233, 168, 30, 125, 97, 46, 105, 31, 254, 111, 129, 117, 245, 246, 231, 227, 250, 197, 139, 181, 235, 251, 20, 235, 254, 194, 82, 78, 133, 58, 237, 63, 51, 191, 196
  Data.b 149, 68, 30, 183, 40, 83, 85, 187, 119, 172, 107, 173, 158, 44, 210, 211, 189, 246, 131, 6, 253, 241, 239, 81, 207, 202, 3, 220, 242, 114, 244, 200, 105, 13, 98, 231, 218, 255, 102, 87
  Data.b 109, 251, 237, 15, 27, 92, 239, 11, 228, 34, 114, 235, 190, 235, 112, 100, 219, 119, 93, 3, 242, 101, 150, 131, 200, 20, 146, 47, 11, 60, 96, 108, 111, 177, 152, 169, 209, 233, 57, 215
  Data.b 35, 199, 232, 244, 156, 98, 49, 211, 246, 103, 205, 3, 50, 58, 61, 175, 79, 194, 183, 28, 247, 251, 36, 124, 75, 163, 211, 252, 162, 16, 133, 153, 152, 89, 208, 213, 209, 105, 199, 253
  Data.b 174, 142, 78, 107, 98, 166, 176, 223, 185, 185, 91, 131, 184, 120, 136, 248, 197, 196, 140, 238, 62, 88, 84, 99, 245, 30, 61, 123, 32, 245, 87, 255, 215, 190, 158, 85, 248, 230, 61, 194
  Data.b 129, 2, 153, 186, 109, 125, 125, 228, 95, 215, 31, 106, 98, 230, 65, 198, 254, 54, 52, 121, 79, 225, 201, 123, 26, 187, 99, 223, 223, 74, 138, 139, 28, 199, 9, 79, 23, 233, 215, 111
  Data.b 207, 235, 250, 237, 121, 125, 48, 116, 147, 107, 137, 53, 87, 104, 127, 91, 138, 45, 59, 6, 132, 111, 243, 2, 5, 79, 177, 120, 46, 139, 13, 50, 197, 90, 111, 140, 32, 32, 28, 133
  Data.b 140, 32, 37, 174, 150, 232, 192, 102, 158, 70, 153, 249, 7, 164, 190, 178, 88, 51, 15, 151, 181, 183, 52, 143, 239, 58, 249, 50, 4, 63, 177, 205, 103, 115, 83, 72, 127, 47, 249, 181
  Data.b 93, 153, 94, 242, 37, 221, 184, 114, 41, 223, 151, 231, 103, 188, 184, 73, 102, 43, 39, 211, 49, 217, 213, 153, 203, 181, 41, 244, 88, 147, 219, 88, 121, 180, 179, 10, 219, 127, 102, 177
  Data.b 72, 77, 251, 75, 243, 159, 98, 253, 250, 59, 143, 107, 114, 161, 88, 121, 253, 113, 247, 124, 255, 60, 137, 219, 63, 219, 177, 150, 163, 175, 41, 247, 127, 74, 37, 215, 243, 179, 171, 203
  Data.b 171, 99, 118, 58, 166, 124, 191, 118, 107, 122, 220, 190, 249, 126, 15, 221, 44, 188, 47, 46, 155, 210, 228, 66, 177, 126, 243, 242, 254, 252, 71, 144, 239, 55, 62, 166, 182, 177, 123, 186
  Data.b 18, 153, 83, 117, 89, 158, 35, 9, 176, 193, 204, 44, 22, 233, 230, 66, 177, 58, 90, 42, 244, 66, 221, 222, 252, 3, 34, 73, 111, 252, 184, 78, 109, 141, 51, 250, 195, 63, 110, 234
  Data.b 218, 221, 37, 197, 76, 190, 195, 141, 205, 189, 230, 168, 171, 44, 209, 239, 127, 84, 173, 231, 108, 194, 225, 58, 32, 146, 244, 92, 221, 94, 245, 58, 20, 6, 108, 53, 60, 230, 5, 8
  Data.b 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 128, 252, 3, 50, 210, 167, 19, 77, 77, 106, 110, 106, 82, 243, 233, 43, 43, 155, 175, 156
  Data.b 182, 182, 53, 29, 87, 223, 136, 87, 135, 54, 162, 190, 227, 137, 114, 211, 126, 142, 247, 41, 234, 105, 29, 167, 117, 101, 213, 57, 38, 159, 203, 21, 157, 94, 147, 122, 179, 156, 155, 117
  Data.b 12, 39, 188, 106, 204, 43, 167, 87, 213, 147, 116, 249, 188, 149, 86, 215, 154, 212, 179, 30, 117, 20, 50, 130, 4, 2, 1, 105, 48, 98, 117, 150, 17, 69, 6, 173, 109, 158, 170, 87
  Data.b 231, 133, 144, 134, 67, 33, 13, 247, 6, 37, 73, 39, 123, 173, 215, 23, 58, 213, 224, 81, 29, 254, 86, 73, 26, 84, 36, 209, 23, 35, 97, 25, 129, 160, 78, 6, 12, 189, 119, 217
  Data.b 218, 56, 18, 209, 144, 36, 181, 250, 61, 171, 119, 237, 207, 109, 181, 149, 58, 66, 33, 157, 105, 91, 131, 10, 70, 250, 116, 162, 171, 95, 129, 238, 1, 13, 135, 6, 116, 42, 32, 157
  Data.b 239, 74, 186, 249, 108, 150, 58, 10, 158, 98, 117, 116, 232, 164, 17, 182, 2, 18, 81, 216, 8, 234, 88, 135, 205, 104, 227, 233, 200, 146, 122, 23, 73, 220, 101, 227, 163, 88, 238, 13
  Data.b 213, 214, 30, 148, 100, 40, 28, 137, 191, 142, 70, 6, 165, 214, 118, 181, 183, 74, 70, 98, 99, 36, 44, 67, 210, 201, 246, 182, 245, 57, 183, 132, 139, 111, 172, 220, 37, 79, 172, 73
  Data.b 37, 137, 145, 241, 120, 134, 81, 211, 171, 155, 192, 25, 37, 178, 24, 237, 59, 158, 114, 231, 47, 252, 156, 210, 234, 240, 168, 79, 120, 176, 6, 241, 171, 49, 96, 221, 117, 71, 34, 26
  Data.b 10, 52, 202, 159, 222, 240, 71, 122, 100, 4, 123, 53, 28, 10, 233, 253, 110, 233, 236, 145, 53, 236, 72, 133, 240, 55, 42, 32, 105, 40, 126, 50, 250, 224, 162, 161, 147, 237, 109, 241
  Data.b 224, 88, 163, 100, 52, 50, 40, 41, 160, 70, 191, 21, 142, 35, 61, 82, 247, 128, 134, 67, 33, 157, 11, 26, 58, 123, 100, 109, 238, 96, 134, 58, 244, 190, 117, 151, 52, 122, 206, 173
  Data.b 217, 93, 82, 70, 171, 94, 15, 133, 52, 28, 186, 160, 206, 250, 66, 250, 171, 95, 45, 146, 140, 158, 35, 171, 59, 255, 72, 159, 126, 215, 35, 157, 26, 8, 89, 237, 150, 231, 57, 217
  Data.b 213, 177, 113, 22, 233, 126, 249, 91, 173, 187, 110, 36, 44, 35, 109, 234, 17, 237, 123, 75, 231, 21, 208, 169, 87, 227, 247, 142, 134, 195, 29, 10, 40, 105, 202, 178, 145, 212, 31, 214
  Data.b 177, 64, 98, 180, 136, 40, 108, 88, 65, 240, 55, 42, 96, 141, 146, 209, 176, 33, 5, 58, 244, 147, 122, 41, 122, 249, 162, 12, 5, 116, 236, 112, 125, 210, 8, 212, 175, 75, 107, 208
  Data.b 123, 3, 29, 135, 213, 176, 50, 13, 44, 220, 249, 174, 44, 107, 184, 96, 187, 188, 153, 113, 181, 233, 204, 64, 183, 2, 86, 7, 78, 185, 123, 215, 119, 234, 221, 208, 5, 117, 70, 226
  Data.b 119, 249, 87, 251, 211, 166, 182, 94, 212, 177, 145, 158, 98, 53, 52, 6, 52, 20, 25, 81, 52, 50, 168, 64, 163, 223, 93, 234, 19, 83, 150, 141, 149, 144, 120, 7, 28, 140, 40, 58
  Data.b 18, 209, 144, 90, 229, 175, 79, 28, 243, 160, 34, 35, 241, 53, 86, 234, 250, 195, 208, 217, 35, 86, 103, 235, 234, 151, 86, 70, 160, 141, 109, 61, 214, 57, 241, 32, 132, 244, 126, 119
  Data.b 64, 82, 191, 94, 77, 76, 219, 18, 211, 210, 46, 233, 156, 53, 130, 120, 94, 199, 134, 10, 136, 191, 85, 70, 56, 162, 104, 216, 80, 139, 223, 97, 92, 182, 22, 185, 142, 65, 250, 134
  Data.b 180, 181, 7, 37, 35, 172, 15, 46, 95, 148, 177, 114, 55, 109, 83, 123, 208, 208, 123, 151, 47, 43, 108, 36, 173, 63, 226, 247, 246, 149, 169, 66, 226, 231, 221, 130, 230, 38, 91, 79
  Data.b 67, 231, 5, 235, 1, 68, 124, 166, 145, 24, 121, 79, 13, 156, 73, 26, 173, 172, 155, 145, 71, 117, 108, 168, 128, 200, 223, 168, 192, 224, 37, 93, 26, 180, 166, 36, 201, 7, 110, 77
  Data.b 169, 206, 158, 139, 15, 126, 233, 211, 18, 47, 215, 14, 137, 53, 207, 165, 254, 66, 203, 234, 215, 217, 30, 35, 37, 196, 13, 141, 1, 25, 23, 47, 106, 72, 143, 206, 49, 125, 186, 24
  Data.b 95, 120, 110, 208, 245, 213, 58, 75, 44, 194, 19, 143, 93, 83, 214, 110, 214, 200, 27, 239, 200, 137, 235, 149, 251, 20, 203, 182, 14, 47, 251, 68, 193, 1, 169, 63, 172, 99, 234, 215
  Data.b 121, 197, 231, 230, 171, 134, 192, 129, 110, 5, 250, 187, 212, 220, 212, 164, 163, 61, 210, 169, 129, 2, 23, 128, 25, 134, 217, 215, 131, 137, 121, 232, 37, 169, 160, 33, 59, 190, 14, 145
  Data.b 148, 50, 26, 54, 248, 91, 37, 195, 144, 17, 72, 58, 199, 250, 78, 189, 219, 27, 180, 234, 109, 210, 209, 30, 67, 39, 123, 61, 62, 183, 77, 60, 106, 156, 11, 62, 90, 235, 28, 237
  Data.b 49, 20, 232, 126, 83, 157, 245, 82, 67, 231, 155, 214, 35, 217, 38, 53, 55, 117, 73, 193, 252, 238, 252, 118, 117, 120, 218, 39, 44, 62, 51, 195, 223, 21, 253, 235, 191, 199, 244, 243
  Data.b 151, 106, 185, 226, 216, 118, 222, 185, 58, 174, 95, 126, 183, 206, 131, 17, 4, 216, 6, 28, 255, 170, 73, 113, 145, 183, 25, 90, 142, 241, 119, 181, 176, 133, 2, 226, 53, 175, 3, 7
  Data.b 172, 229, 141, 155, 222, 10, 216, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128
  Data.b 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0
  Data.b 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8
  Data.b 64, 64, 0, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16
  Data.b 16, 128, 128, 0, 4, 4, 32, 32, 0, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 182, 176, 146, 108, 111, 248, 104, 27, 108, 35, 62, 70
  Data.b 16, 128, 41, 22, 64, 64, 0, 2, 2, 108, 228, 69, 186, 124, 44, 211, 177, 157, 86, 233, 62, 70, 16, 128, 41, 22, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32
  Data.b 0, 1, 1, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 8, 8, 64
  Data.b 64, 0, 2, 2, 16, 16, 128, 128, 0, 32, 32, 0, 1, 1, 8, 8, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 0, 1, 1, 64, 64, 0, 2, 2, 172, 93
  Data.b 64, 202, 74, 30, 109, 142, 153, 166, 98, 166, 73, 75, 97, 91, 72, 238, 251, 89, 3, 242, 76, 205, 30, 221, 152, 158, 167, 181, 176, 173, 220, 152, 158, 151, 191, 122, 119, 202, 182, 146
  Data.b 76, 59, 182, 28, 168, 208, 71, 67, 147, 58, 176, 183, 92, 165, 197, 190, 149, 145, 4, 216, 170, 22, 151, 77, 93, 155, 152, 213, 43, 45, 213, 206, 35, 72, 121, 105, 145, 90, 158, 168
  Data.b 208, 135, 131, 147, 140, 36, 216, 242, 198, 239, 204, 235, 195, 193, 73, 61, 123, 176, 98, 213, 20, 203, 103, 154, 217, 135, 134, 133, 229, 152, 254, 59, 118, 87, 209, 169, 251, 90, 92, 102
  Data.b 4, 193, 214, 92, 115, 60, 93, 181, 75, 135, 234, 246, 169, 172, 120, 245, 120, 97, 27, 16, 96, 187, 227, 49, 47, 64, 64, 0, 2, 2, 16, 16, 128, 128, 0, 4, 4, 32, 32, 192
  Data.b 166, 246, 127, 74, 109, 171, 128, 80, 107, 91, 233, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
datepicker2:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0
  Data.b 0, 0, 27, 0, 0, 0, 21, 8, 6, 0, 0, 0, 183, 222, 149, 37, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0
  Data.b 255, 0, 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 12
  Data.b 12, 51, 54, 194, 156, 206, 157, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80
  Data.b 87, 129, 14, 23, 0, 0, 0, 171, 73, 68, 65, 84, 72, 199, 237, 149, 65, 14, 2, 49, 8, 69, 127, 11, 214, 185, 136, 183, 114, 237, 89, 189, 195, 156, 100, 106, 11, 46, 76, 55
  Data.b 133, 133, 9, 58, 49, 102, 88, 146, 150, 7, 191, 20, 210, 237, 126, 85, 236, 100, 12, 0, 237, 242, 125, 30, 175, 233, 5, 139, 90, 43, 205, 6, 175, 54, 116, 198, 142, 118, 192, 14
  Data.b 216, 239, 192, 24, 0, 186, 110, 161, 32, 162, 246, 159, 117, 237, 19, 104, 249, 119, 25, 79, 181, 4, 51, 182, 57, 147, 51, 174, 24, 0, 114, 145, 16, 76, 89, 156, 4, 196, 120, 24
  Data.b 0, 68, 98, 106, 54, 199, 151, 166, 152, 121, 84, 22, 29, 253, 73, 201, 202, 56, 119, 236, 224, 60, 40, 182, 207, 182, 82, 141, 239, 44, 139, 129, 127, 164, 50, 117, 26, 132, 205, 153
  Data.b 177, 169, 131, 48, 239, 205, 155, 35, 43, 3, 0, 173, 20, 130, 17, 222, 187, 255, 4, 91, 226, 41, 194, 52, 168, 174, 172, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
datepicker3:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0
  Data.b 27, 0, 0, 0, 21, 8, 6, 0, 0, 0, 183, 222, 149, 37, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 6, 98, 75, 71, 68, 0, 255, 0, 255, 0
  Data.b 255, 160, 189, 167, 147, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 3, 16, 30
  Data.b 28, 116, 82, 23, 230, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129
  Data.b 14, 23, 0, 0, 0, 57, 73, 68, 65, 84, 72, 199, 99, 252, 117, 69, 239, 63, 3, 157, 0, 11, 3, 3, 3, 3, 163, 68, 20, 205, 45, 250, 255, 98, 25, 3, 19, 3, 29, 193
  Data.b 168, 101, 163, 150, 141, 90, 54, 106, 217, 168, 101, 163, 150, 141, 90, 70, 34, 96, 164, 103, 27, 4, 0, 48, 50, 9, 33, 177, 88, 200, 172, 0, 0, 0, 0, 73, 69, 78, 68, 174
  Data.b 66, 96, 130
datepicker4:
  Data.b 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 27, 0, 0, 0, 21, 8, 4, 0, 0, 0, 29, 215, 93, 174, 0, 0, 0, 1
  Data.b 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 2, 98, 75, 71, 68, 0, 255, 135, 143, 204, 191, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1
  Data.b 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 218, 12, 12, 12, 50, 12, 29, 139, 38, 110, 0, 0, 0, 25, 116, 69, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 67
  Data.b 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 87, 129, 14, 23, 0, 0, 0, 70, 73, 68, 65, 84, 56, 203, 99, 188, 241, 159, 129, 12, 192, 194, 192, 192
  Data.b 73, 178, 166, 239, 12, 44, 132, 21, 49, 194, 89, 8, 135, 49, 49, 144, 5, 70, 181, 81, 75, 27, 11, 3, 195, 207, 225, 26, 111, 44, 132, 117, 98, 250, 237, 31, 5, 182, 49, 18
  Data.b 109, 27, 61, 180, 33, 252, 241, 143, 14, 169, 4, 27, 0, 0, 150, 151, 10, 8, 68, 242, 110, 109, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
EndDataSection 
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Re: Datepicker / calendargadget

Post by liam »

i can run it now, thanks jesperbrannmark!
i'll add it to my snippets collection to play with and practice.
PureBasic 4.51(x86) on WinXP SP3
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Datepicker / calendargadget

Post by WilliamL »

jasper,

I hope I understand what you were saying correctly.

How about replacing in Procedure smartbooker_draw_datepicker():

Code: Select all

ImageGadget(#smartbooker_calendar_gadget,0,0,200,200,ImageID(#smartbooker_calendar_image))
with

Code: Select all

SetGadgetState(#smartbooker_calendar_gadget,ImageID(#smartbooker_calendar_image))
It's a little shorter, doesn't have to transfer the dimensions, and it seems to work.

Nice job of transferring the code to ImageGadget and also bring along the pictures!
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Datepicker / calendargadget

Post by jesperbrannmark »

Hehe. yep. i had it on the tip of my tongue but had a blackout for a second there so i did the imagegadget() instead... ugly hack.

Thanks
WilliamL
Addict
Addict
Posts: 1224
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Datepicker / calendargadget

Post by WilliamL »

jasper,

I'm trying to figure out how you loaded the picture from the data section. Do you need to use UsePNGImageDecoder()? How did you create the data from the original image? So 'CatchImage(#smartbooker_image1, ?datepicker1)' knows it is in the data section?

I've got something to learn here...
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: Datepicker / calendargadget

Post by jesperbrannmark »

I inlines binary files. It was happer66 that did the data section... I don't know how that was done.
Post Reply