CLASS TAlbum
DATA aPhotos
DATA aLabel
DATA aRecno
DATA oWnd
DATA nWndWidth INIT oApp():oGrid:nWidth+40 // 800
DATA nWndHeight INIT oApp():oGrid:nHeight // 800
DATA nImgWidth INIT 180
DATA nGutter INIT 20
DATA nImgCols PROTECTED
DATA nOffset INIT 0 PROTECTED
DATA nHeight
DATA lExit INIT .F.
ACCESS oVScroll INLINE ::oWnd:oVScroll
METHOD New( aPhotos, aLabel, aRecno ) CONSTRUCTOR
METHOD Activate()
PROTECTED:
METHOD CreateWindow()
METHOD CreateControls()
METHOD SetVScroll()
METHOD GoUp()
METHOD GoDown()
METHOD ThumbPos( nPos )
METHOD MouseWheel()
METHOD VSetPos() INLINE ::oWnd:oVScroll:SetPos( -::nOffSet )
METHOD GoTop()
METHOD GoBottom()
METHOD KeyDown( nKey )
METHOD ScrollWnd( nPixels )
METHOD Resize( nType, nWidth, nHeight )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( aPhotos, aLabel, aRecno ) CLASS TAlbum
::aPhotos := aPhotos
::aLabel := aLabel
::aRecno := aRecno
return Self
//----------------------------------------------------------------------------//
METHOD Activate() CLASS TAlbum
local hWndMain
::CreateWindow()
::CreateControls()
::SetVScroll()
::oWnd:bResized := { |t,w,h| ::Resize( t, w, h ) }
::lExit := .F.
ACTIVATE WINDOW ::oWnd ;
ON INIT ::oWnd:Center( oApp():oWndMain ) ;
VALID (::lExit := .t.)
StopUntil( { || ::lExit } )
return Self
//----------------------------------------------------------------------------//
METHOD CreateWindow() CLASS TAlbum
local oMain, x, y
if ( oMain := WndMain() ) != nil .and. oMain:IsKindOf( "TMDIFRAME" )
DEFINE WINDOW ::oWnd MDICHILD OF oMain VSCROLL
else
x := Int( ( ScreenWidth() - ::nWndWidth ) / 2 )
y := Int( ( ScreenHeight() - ::nWndHeight ) / 2 )
DEFINE WINDOW ::oWnd FROM y,x TO ::nWndHeight + y, ::nWndWidth + x PIXEL VSCROLL ;
TITLE 'Galería de portadas de libros' ; // OF oApp():oWndMain ;
COLOR CLR_BLACK, CLR_WHITE NOMINIMIZE NOZOOM // 0xe8e8e8
//DEFINE DIALOG ::oWnd FROM y,x TO ::nWndHeight + y, ::nWndWidth + x PIXEL ; // VSCROLL ;
// COLOR CLR_BLACK, CLR_WHITE // NOMINIMIZE NOZOOM
endif
::lExit := .t.
return Self
//----------------------------------------------------------------------------//
METHOD CreateControls() CLASS TAlbum
local nImgWidth := ::nImgWidth
local nImgHeight := Int( nImgWidth * 4 / 3 )
local nGutter := ::nGutter
local nRows, nCols, nRow, nCol, x, y, nImage, xMax
Local nImages := Len( ::aPhotos )
local oImage
local oSay
local nRecno
nCols := Int( ( ::oWnd:nWidth - nGutter ) / ( nImgWidth + nGutter ) )
nRows := Ceiling( nImages / nCols )
xMax := nCols * ( nImgWidth * nGutter )
y := nGutter
nImage := 1
do while nImage <= nImages
x := nGutter
nCol := 1
do while nCol <= nCols .and. nImage <= nImages
@ y, x XIMAGE oImage SIZE nImgWidth, nImgHeight OF ::oWnd NOBORDER
oImage:SetSource( If( HB_ISARRAY( ::aPhotos[ nImage ] ), ::aPhotos[ nImage, 1 ], ::aPhotos[ nImage ] ) )
oImage:nUserControl := 0
oImage:lBmpTransparent := .F.
nRecno := ::aRecno[nImage]
// para devolver el recno tienes que hacer detached local
oImage:bLDblClick := { || (MsgInfo(nRecno), LiForm( oApp():oGrid, "edt", , nRecno )) }
@ y+nImgHeight+(nGutter/2), x SAY oSay PROMPT ::aRecno[nImage] FONT oApp():oFont ;
SIZE nImgWidth, 2*nGutter CENTER PIXEL OF ::oWnd
#if FW_VersionNo >= 21010
oImage:Shadow()
#else
oImage:bPainted := PaintBlock( oImage )
#endif
nImage++
nCol++
x += ( nImgWidth + 2*nGutter )
enddo
y += ( nImgHeight + nGutter )
enddo
::nImgCols := nCols
::nHeight := y
return Self
//----------------------------------------------------------------------------//
METHOD Resize( nType, nWidth, nHeight ) CLASS TAlbum
local nImgHeight := Int( ::nImgWidth * 4 / 3 )
local nRows, nCols, nRow, nCol, x, y, nImage, nImages := Len( ::aPhotos )
if nWidth == nil
return nil
endif
nCols := Int( ( ::oWnd:nWidth - ::nGutter ) / ( ::nImgWidth + ::nGutter ) )
if nCols == ::nImgCols
return nil
endif
nRows := Ceiling( nImages / nCols )
y := ::nGutter
nImage := 1
do while nImage <= nImages
x := ::nGutter
nCol := 1
do while nCol <= nCols .and. nImage <= nImages
WITH OBJECT ::oWnd:aControls[ nImage ]
:nTop := y
:nLeft := x
END
nImage++
x += ( ::nImgWidth + ::nGutter )
nCol++
enddo
y += ( nImgHeight + ::nGutter )
enddo
::nImgCols := nCols
::nHeight := y
::oVScroll:SetRange( 0, ::nHeight - ::oWnd:nHeight )
::nOffSet := 0
::VSetPos()
return nil
//----------------------------------------------------------------------------//
METHOD SetVScroll() CLASS TAlbum
local oSelf := Self
WITH OBJECT ::oWnd:oVScroll
:SetRange( 0, ::nHeight - ::oWnd:nHeight )
:bGoUp := { || oSelf:GoUp() }
:bGoDown := { || oSelf:GoDown() }
:bPos := { |nPos| oSelf:ThumbPos( nPos ) }
:bGoTop := { || oSelf:GoTop() }
:bGoDown := { || oSelf:GoDown() }
END
::oWnd:bMouseWheel := ;
{ |k,nDelta| oSelf:MouseWheel( k, nDelta ) }
::oWnd:bKeyDown := { |k| oSelf:KeyDown( k ) }
return Self
//----------------------------------------------------------------------------//
METHOD ScrollWnd( nPixels ) CLASS TAlbum
ScrollWindow( ::oWnd:hWnd, 0, nPixels, 0, GetClientRect( ::oWnd:hWnd ) )
return Self
//----------------------------------------------------------------------------//
METHOD GoUp() CLASS TAlbum
local nPixels := Min( 20, ::oVScroll:nMin - ::nOffset )
::ScrollWnd( nPixels )
::nOffSet += nPixels
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD GoDown() CLASS TAlbum
local nPixels := Min( 20, ::oVScroll:nMax + ::nOffSet )
::ScrollWnd( -nPixels )
::nOffSet -= nPixels
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD ThumbPos( nPos ) CLASS TAlbum
AEval( ::oWnd:aControls, { |o| o:nTop -= ( nPos + ::nOffSet ) } )
::nOffSet := -nPos
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD MouseWheel( k, nDelta ) CLASS TAlbum
if nDelta > 0
::GoUp()
else
::GoDown()
endif
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD GoTop() CLASS TAlbum
AEval( ::oWnd:aControls, { |o| o:nTop -= ::nOffSet } )
::nOffSet := 0
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD GoBottom() CLASS TAlbum
AEval( ::oWnd:aControls, { |o| o:nTop -= ( ::oVScroll:nMax + ::nOffSet ) } )
::nOffSet := -::oVScroll:nMax
::VSetPos()
return Self
//----------------------------------------------------------------------------//
METHOD KeyDown( nKey ) CLASS TAlbum
SWITCH nKey
case VK_UP
if GetKeyState( VK_CONTROL )
::GoTop()
else
::GoUp()
endif
return 0
EXIT
case VK_DOWN
if GetKeyState( VK_CONTROL )
::GoBottom()
else
::GoDown()
endif
return 0
EXIT
case VK_HOME
::GoTop()
return 0
EXIT
case VK_END
::GoBottom()
return 0
EXIT
END
return nil
//----------------------------------------------------------------------------//
#if FW_VersionNo < 21010
//----------------------------------------------------------------------------//
static function PaintBlock( oImage )
return { || DrawShadow( oImage ) }
//----------------------------------------------------------------------------//
static function DrawShadow( oImage )
local aRect := { oImage:nTop, oImage:nLeft, oImage:nTop + oImage:nHeight, oImage:nLeft + oImage:nWidth }
local hDC := oImage:oWnd:GetDC()
local n, nColor, hPen, nIncClr, nSize := 10
n := Int( ( 0xf0 - 0x48 ) / ( nSize - 1 ) )
nIncClr := n + 256 * n + 256 * 256 * n
nColor := 0x484848
for n := 0 to nSize - 1
hPen := CreatePen( PS_SOLID, 1, nColor )
MoveTo( hDC, aRect[ 4 ] + n, aRect[ 1 ] + n )
LineTo( hDC, aRect[ 4 ] + n, aRect[ 3 ] + n, hPen )
MoveTo( hDC, aRect[ 2 ] + n, aRect[ 3 ] + n )
LineTo( hDC, aRect[ 4 ] + n + 1, aRect[ 3 ] + n, hPen )
DeleteObject( hPen )
nColor += nIncClr
next
oImage:oWnd:ReleaseDC()
return nil
#endif
//----------------------------------------------------------------------------//
function bLiRecno(aRecno, nImage)
? nImage
? aRecno[nImage]
return aRecno[nImage]
ON INIT ::oWnd:Center( oApp():oWndMain )
oAlbum = Self
ON INIT oAlbum:oWnd:Center( oApp():oWndMain )
José Luis Sánchez wrote:Thanks Enrico.
I need that TAlbum class inherits from TControl because I need to put it in a dialog. It's very difficult for me to control the application flow with 2 windows, so I need to create a dialog and inside it the talbum class.
I have seen the code from Antonio, and also noticed about the TScrollPanel class existing in FWH. I'll try to build the TAlbum class from TScrollPanel so I'd have scroll features it it.
Regards,
José Luis
#include "fivewin.ch"
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function Main()
local oDlg, oFont, oBold, oPanel
local aPhotos
aPhotos := DirectoryRecurse( "c:\fivetech\fwh1905\bitmaps\*.*" )
ASort( aPhotos, nil, nil, { |x,y| x[ 2 ] > y[ 2 ] } )
ASize( aPhotos, 200 )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD
DEFINE DIALOG oDlg SIZE 1600,800 PIXEL TRUEPIXEL FONT oFont ;
TITLE "FWH TScrollPanel"
//
oPanel := TScrollPanel():New( 20, 20, 700, 1580, oDlg, .t. )
oPanel:SetFont( oDlg:oFont )
//
@ 740, 020 BUTTON "Aceptar" SIZE 100,40 PIXEL OF oDlg ACTION ( MsgInfo('bye'), oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED ON INIT ( PlaceControls( oPanel, aPhotos ) )
RELEASE FONT oFont, oBold
return nil
function PlaceControls( oPanel, aPhotos )
local nImgWidth := 180
local nImgHeight := Int( nImgWidth * 4 / 3 )
local nGutter := 20
local nRows, nCols, nRow, nCol, x, y, nImage, xMax, nImages := Len( aPhotos )
local oImage
nCols := Int( ( oPanel:nWidth - nGutter ) / ( nImgWidth + nGutter ) )
nRows := Ceiling( nImages / nCols )
xMax := nCols * ( nImgWidth * nGutter )
y := nGutter
nImage := 1
do while nImage <= nImages
x := nGutter
nCol := 1
do while nCol <= nCols .and. nImage <= nImages
@ y, x XIMAGE oImage SIZE nImgWidth, nImgHeight OF oPanel NOBORDER
oImage:SetSource( If( HB_ISARRAY( aPhotos[ nImage ] ), aPhotos[ nImage, 1 ], aPhotos[ nImage ] ) )
oImage:nUserControl := 0
//#if FW_VersionNo >= 21010
// oImage:Shadow()
//#else
// oImage:bPainted := PaintBlock( oImage )
//#endif
nImage++
nCol++
x += ( nImgWidth + nGutter )
enddo
y += ( nImgHeight + nGutter )
enddo
//::nImgCols := nCols
// ::nHeight := y
oPanel:SetRange() // call this after defining all controls
return nil
nageswaragunupudi wrote:José Luis Sánchez wrote:Thanks Enrico.
I need that TAlbum class inherits from TControl because I need to put it in a dialog. It's very difficult for me to control the application flow with 2 windows, so I need to create a dialog and inside it the talbum class.
I have seen the code from Antonio, and also noticed about the TScrollPanel class existing in FWH. I'll try to build the TAlbum class from TScrollPanel so I'd have scroll features it it.
Regards,
José Luis
Please wait a little while.
Very soon we are posting full TAlbum class derived from TPanel
José Luis Sánchez wrote:Hola José,
eso es la clase c5vmenu de Paco García. La tienes completa en los fuentes de Cuaderno de Bitácora que tengo publicados en Github: https://github.com/JoseluisSanchez/bitacora. Ahí están los fuentes y cómo uso yo la clase.
Saludos,
// _____________________________________________________________________________//
Function LiGaleria()
LOCAL cAlias := "LI"
LOCAL nRecno := ( cAlias )->( RecNo() )
LOCAL nOrder := ( cAlias )->( ordNumber() )
local aImages := {}
local aLabels := {}
local aRecno := {}
local oDlgAlbum, oAlbum
LI->(DbGoTop())
WHILE ! LI->(EOF())
IF ! Empty(Rtrim(LI->LiImagen))
AAdd(aImages, Rtrim(LI->LiImagen))
AAdd(aLabels, Rtrim(LI->LiTitulo))
AAdd(aRecno, LI->(Recno()))
ENDIF
LI->(DbSkip())
ENDDO
LI->(DbGoTo(nRecno))
DEFINE DIALOG oDlgAlbum SIZE oApp():oGrid:nWidth, oApp():oGrid:nHeight PIXEL TRUEPIXEL ;
TITLE "Galería de portadas de libros"
oDlgAlbum:SetFont(oApp():oFont)
//
oAlbum := TScrollPanel():New( 20, 20, oApp():oGrid:nHeight-50, oApp():oGrid:nWidth-20, oDlgAlbum, .f. )
oAlbum:SetColor(CLR_WHITE, CLR_WHITE)
oAlbum:SetFont( oDlgAlbum:oFont )
@ oApp():oGrid:nHeight-40, oApp():oGrid:nWidth-96 BUTTON "Aceptar" ;
SIZE 76, 24 PIXEL OF oDlgAlbum ACTION oDlgAlbum:End()
ACTIVATE DIALOG oDlgAlbum ;
ON INIT ( LiAlbum( oAlbum, aImages, aRecno, oDlgAlbum ), oDlgAlbum:Center( oApp():oWndMain ) )
RETURN NIL
function LiAlbum( oPanel, aPhotos, aRecno, oDlgAlbum )
local nImgPerRow := 8
local nImgWidth // := 180
local nImgHeight // := Int( nImgWidth * 4 / 3 )
local nHGutter := 10
local nVGutter := 20
local nCols := nImgPerRow
local nRows, nRow, nCol, x, y, nImage, xMax, nImages := Len( aPhotos )
local oImage, oSay
// el ancho del scrollbar es 16
nImgWidth := INT((oPanel:nWidth-16-(nImgPerRow+1)*nHGutter)/nImgPerRow)
nImgHeight:= Int( nImgWidth * 4 / 3 )
nRows := Ceiling( nImages / nCols )
xMax := nCols * ( nImgWidth * nHGutter )
y := nVGutter
nImage := 1
do while nImage <= nImages
x := nHGutter
nCol := 1
do while nCol <= nCols .and. nImage <= nImages
// llamo a una funcion para conseguir detached locals
LiAlbumImage(y, x, nImgWidth, nImgHeight, oPanel, aPhotos, aRecno, nImage, nVGutter, oDlgAlbum)
nImage++
nCol++
x += ( nImgWidth + nHGutter )
enddo
y += ( nImgHeight + 2*nVGutter )
enddo
//::nImgCols := nCols
// ::nHeight := y
oPanel:SetRange() // call this after defining all controls
return nil
Function LiAlbumImage(y, x, nImgWidth, nImgHeight, oPanel, aPhotos, aRecno, nImage, nVGutter, oDlgAlbum)
local oImage, oSay, nLiRecno
nLiRecno := aRecno[nImage]
@ y, x XIMAGE oImage SIZE nImgWidth, nImgHeight OF oPanel NOBORDER
oImage:SetSource( If( HB_ISARRAY( aPhotos[ nImage ] ), aPhotos[ nImage, 1 ], aPhotos[ nImage ] ) )
oImage:nUserControl := 0
oImage:lBmpTransparent := .f.
oImage:bLDblClick := { || ( LiForm( oApp():oGrid, "edt", , nLiRecno, oDlgAlbum )) }
@ y+nImgHeight+(nVGutter/2), x SAY oSay PROMPT nLiRecno FONT oApp():oFont ;
COLOR CLR_BLACK, CLR_WHITE ;
SIZE nImgWidth, 2*nVGutter CENTER PIXEL OF oPanel
return NIL
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 52 guests