Pickdate

User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Here you have the PRG (with some more changes) and the EXE:

http://www.mediafire.com/?t0mymexcjje
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

A little obvious typo:

Code: Select all

   METHOD  PreviousYear() INLINE ::nYear--, ::Refresh()
   METHOD  NextYear() INLINE ::nYear++, ::Refresh() 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Some gradients to make it nicer :-)

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Antonio,

thank you very much.
Now I will try to get the functionality I had (MOVEMOUSE) into the new class design.
Regards,
Otto
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Otto,

What do you need mousemove for ?

If you want to change a dates range, maybe we could use right click, or similar.

The easier you make it for the final user, the better.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Antonio, here is what I want to do.

Regards,
Otto

http://www.atzwanger.com/sniptv/calender/calender.html
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

I think Otto want the user can select from a date to another with the mouse , the movement must colorize the box where there are the numbers of the days

When the user not press the click the mouse the procedure must return how many day he selected from date a to date b

Right, Otto ?
Best Regards, Saludos

Falconi Silvio
User avatar
Andrés González
Posts: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

Antonio and Otto would you mind the possibility to include and aPrompt and aBmp in the tPickData class.

Image
Last edited by Andrés González on Wed Jul 30, 2008 7:03 pm, edited 6 times in total.
Saludos

Andrés González desde Mallorca
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Post by Silvio »

Dear Andres,
before the mousemose movement is max important
then we can think to insert bitmaps or ctext
Best Regards, Saludos

Falconi Silvio
User avatar
Andrés González
Posts: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

Thanks Sylvio, just an idea.
Saludos

Andrés González desde Mallorca
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Hello Antonio,

I tried to insert mousemove in the control class design.
I works but performance is bad. The class I had performs much better.
Is this normal that a control is slower or did I made a mistake by inserting the mouse move method.
Would you be so kind to check the code. Thanks in advance.
Otto






Code: Select all

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oPickDate

   DEFINE WINDOW oWnd TITLE "Calendar"

   oPickDate := TPickDate():New( 10, 10,,, oWnd )

   oWnd:oClient = oPickDate

   ACTIVATE WINDOW oWnd MAXIMIZED

return nil

//----------------------------------------------------------------------------//

CLASS TPickDate FROM TControl

   DATA    dStart, dEnd,lMove
   DATA    ClickRow,  hBru
   DATA    ClickCol
   DATA    nYear, syTemp

   CLASSDATA lRegistered AS LOGICAL

   METHOD  New( nTop, nLeft, nWidth, nHeight, oWnd, nYear, nClrFore, nClrBack )
   METHOD  Paint()
   METHOD  Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
   METHOD  LButtonDown( nRow, nCol, nFlags )
   METHOD  LButtonUp( nRow, nCol, nFlags )

   METHOD  PreviousYear() INLINE ::nYear--, ::Refresh()
   METHOD  NextYear() INLINE ::nYear++, ::Refresh()
   METHOD  EraseBkGnd( hDC ) INLINE 0

   METHOD  MouseMove( nRow, nCol, nKeyFlags )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nTop, nLeft, nWidth, nHeight, oWnd, nYear, nClrFore, nClrBack ) CLASS TPickDate

   DEFAULT nWidth    := 800,;
      nHeight   := 300,;
      nLeft     := 0,;
      nTop      := 0,;
      nYear     := Year( Date() ),;
      oWnd      := GetWndDefault()

   ::lMove      :=.f.

   ::nTop       = nTop
   ::nLeft      = nLeft
   ::nBottom    = nTop + nHeight - 1
   ::nRight     = nLeft + nWidth - 1
   ::nYear      = Year( Date() )
   ::oWnd       = oWnd
   ::nClrText   = nClrFore
   ::nClrPane   = nClrBack
   ::nStyle     = nOr( WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER )
   ::syTemp:=0
   ::hBru        := CreateSolidBrush( RGB(255,0,0) )


   ::ClickRow  := 0
   ::ClickCol  := 0
   ::nHeight   := 0
   ::nWidth    := 0


   DEFINE FONT ::oFont NAME "Tahoma" SIZE 0, -12

   #ifdef __XPP__
   DEFAULT ::lRegistered := .F.
   #endif

   ::Register( nOR( CS_VREDRAW, CS_HREDRAW ) )

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
   else
      oWnd:DefControl( Self )
   endif

return self

//----------------------------------------------------------------------------//

METHOD Paint() CLASS TPickDate

   //  local aInfo := ::DispBegin(), nRowStep, nColStep, n, dDate
   local hDC := ::hDC, cDay, oBrush, nDay, oFont := ::oFont

   FillRect( hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )

   DEFINE BRUSH oBrush COLOR nRGB( 183, 249, 185 ) // Sundays column green brush

   nRowStep = ::nHeight / 13

   //GradientFill( hDC, 0, 0, ::nHeight, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )

   for n = 1 to 12
      ::Line( n * nRowStep, 0, n * nRowStep, ::nWidth - 1 )
      ::Say( n * nRowStep + ( nRowStep / 2 ) - ( oFont:nHeight / 2 ), 3, cMonth( CToD( Str( n, 2 ) + "/01/" + ;
         Str( Year( Date() ), 4 ) ) ),,, oFont, .T., .T. )
   next

   dDate = CToD( "06/01/" + Str( ::nYear, 4 ) )
   nColStep = ( ::nWidth - 60 ) / 37

   //   GradientFill( hDC, 0, 0, nRowStep - 1, ::nWidth, { { 1, nRGB( 128, 217, 255 ), nRGB( 54, 147, 255 ) } } )

   ::Say( ( nRowStep / 2 ) - ( oFont:nHeight / 2 ),;
      ( ( 60 + nColStep ) / 2 ) - ( GetTextWidth( hDC, Str( ::nYear, 4 ), ::oFont:hFont ) / 2 ),;
      Str( ::nYear, 4 ),,, oFont, .T., .T. )


   for n = 1 to 36 step 7
      FillRect( hDC, { 0, 60 + ( nColStep * n ), ::nHeight - 1, 60 + ( nColStep * ( n + 1 ) ) }, oBrush:hBrush )
   next

   IF ::lMove=.t.

      FillRect(hDC, {::ClickRow,;
         ::ClickCol,;
         ::ClickRow + ( ::nHeight / 13 ),;
         ::syTemp}, ::hBru )
   ENDIF

   for n = 1 to 36
      ::Line( 0, 60 + ( nColStep * n ), ::nHeight - 1, 60 + ( nColStep * n ) )
      cDay = SubStr( CDoW( dDate ), 1, 2 )
      ::Say( nRowStep * 0.4,;
         60 + ( nColStep * n ) + ( nColStep / 2 ) - ( GetTextWidth( hDC, cDay, oFont:hFont ) / 2 ) + 1,;
         cDay, 0, If( DoW( dDate++ ) == 1, nRGB( 128, 233, 176 ),), oFont, .T., .T. )
   next

   for n = 1 to 12
      dDate = CToD( Str( n ) + "/01/" + Str( ::nYear, 4 ) )
      nDay = DoW( dDate )
      while Month( dDate ) == n
         cDay = AllTrim( Str( Day( dDate ) ) )
         ::Say( n * nRowStep + ( nRowStep * 0.4 ),;
            60 + ( nColStep * nDay++ ) + ( nColStep / 2 ) - ( GetTextWidth( hDC, cDay, oFont:hFont ) / 2 ) + 1,;
            cDay, 0, If( ! Empty( ::dStart ) .and. dDate >= ::dStart .and. dDate <= ::dEnd, nRGB( 178, 204, 235 ),;
            If( DoW( dDate ) == 1, nRGB( 128, 233, 176 ),) ), oFont, .T. )
         dDate++
      end
   next

   //  ::DispEnd( aInfo )

   oBrush:End()

return 0

//----------------------------------------------------------------------------//

METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TPickDate

   local nMonth := Int( nRow / ( ::nHeight / 13 ) )
   local nDay   := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) - ;
      DoW( CToD( Str( nMonth ) + "/01/" + Str( ::nYear, 4 ) ) ) + 1
   local dDate  := CToD( AllTrim( Str( nMonth ) ) + "/" + AllTrim( Str( nDay ) ) + "/" + Str( ::nYear, 4 ) )

   ::lMove:=.t.

   ::ClickRow   := Int( nRow / ( ::nHeight / 13 ) )    * ( ::nHeight / 13 )
   ::ClickCol   := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) * ( ( ::nWidth - 60 ) / 37 )  + 60

return nil

//-----------------------------------------------------------------//

METHOD LButtonUp( nRow, nCol, nFlags ) CLASS TPickDate
   ::lMove:=.f.
return nil

//-----------------------------------------------------------------//

METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TPickDate

   if ::lMove = .t.

      ::syTemp := Int( ( nCol - 60 ) / ( ( ::nWidth - 60 ) / 37 ) ) * ( ( ::nWidth - 60 ) / 37 )  + 60   + ( ( ::nWidth - 60 ) / 37 )
      ::Paint()

      ::refresh()

   endif

   // ::Say(  nRow+10 ,nCol,str( ::nYear, 4 ),,,::oFont, .T., .T. )


return nil
*/
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Otto,

You only have to call ::Refresh() and not ::Paint().

::Refresh() will request a paint.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Otto,

Although calls to Paint() and Refresh() will work they are going to be slow. For speed, what you want to do is redraw only the old highlight (as unhighlighted) and the new highlighted area--not the entire screen. Right now you are redrawing the entire screen twice for each mouse movement.

For ideas how a similar MouseMove() works, take a look at TWBrowse(). Note that it inherits from TControl which inherits from TWindow, so take a look at the MouseMove() methods in those classes also. I am not saying that your MouseMove method should work the same as TWBrowse's, but you can see how it processes the information and when it calls the parent class.

Note also that your MouseMove() method should return 0 not nil.

James
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Hello Antonio, hello James,

I eliminated the call for Paint method.
But with not much success. The painting of the days is very slow.
I turned off double buffering. You can see how the rows get painted.

In my wrapped class design the painting is optimal . Please see the video or try the exe.

I can’t find out the problem in the new code.

James you are right with you advice to repaint only the changes. But that is much more work.
And as the whole repainting in my initial project works so well I don’t think it is necessary.


Regards,
Otto
Post Reply