From 5cea229ecbd0c5810bd1fb1107cb703758332a29 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 28 Mar 2013 12:13:49 -0700 Subject: [PATCH] GTWVG + Wvt_DrawImage( ,,,,,, lDoNotScale ) --- ChangeLog.txt | 16 +++- contrib/gtwvg/gtwvg.h | 8 +- contrib/gtwvg/tests/demowvg.prg | 6 +- contrib/gtwvg/wvgcore.c | 159 ++++++++++++-------------------- contrib/gtwvg/wvgwin.c | 8 +- 5 files changed, 90 insertions(+), 107 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 182236ed80..abc588d922 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -/* +/* * $Id$ */ @@ -10,6 +10,20 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-03-28 12:12 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/gtwvg/gtwvg.h + * contrib/gtwvg/wvgcore.c + * contrib/gtwvg/wvgwin.c + + Implemented: Wvt_DrawPicture( ,,,,,, lDoNotScale ) 7th Arg + Wvt_DrawImage( ,,,,,, lDoNotScale ) 7th Arg + Wvg_DrawImage( ,,,,, lDoNotScale ) 6th Arg + If is TRUE, then image will be displayed + in its original proportion but centered in the supplied + coordinates. This resolves many messages posted recently. + + * contrib/gtwvg/tests/demowvg.prg + % Changed to demonstrate the use of argument as above. + 2013-03-28 17:59 UTC+0100 Viktor Szakats (harbour syenar.net) * README.md + added two .po links diff --git a/contrib/gtwvg/gtwvg.h b/contrib/gtwvg/gtwvg.h index 0cd33810a2..12befb834e 100644 --- a/contrib/gtwvg/gtwvg.h +++ b/contrib/gtwvg/gtwvg.h @@ -1,3 +1,7 @@ +/* + * $Id: gtwvg.h 18909 2013-03-11 11:14:16Z vszakats $ + */ + /* * Harbour Project source code: * Header File for Video subsystem for Windows using GUI windows instead of Console @@ -575,10 +579,10 @@ extern HB_EXPORT POINT hb_wvt_gtGetXYFromColRow( int col, int row ); #if ! defined( HB_OS_WIN_CE ) extern HB_EXPORT IPicture * hb_wvt_gtLoadPicture( LPCTSTR image ); extern HB_EXPORT IPicture * hb_wvt_gtLoadPictureFromResource( LPCTSTR resource, LPCTSTR section ); -extern HB_EXPORT HB_BOOL hb_wvt_gtRenderPicture( int x1, int y1, int wd, int ht, IPicture * iPicture ); +extern HB_EXPORT HB_BOOL hb_wvt_gtRenderPicture( int x1, int y1, int wd, int ht, IPicture * iPicture, BOOL bDoNotScale ); extern HB_EXPORT HB_BOOL hb_wvt_gtDestroyPicture( IPicture * iPicture ); #endif -extern HB_EXPORT HB_BOOL hb_wvt_DrawImage( HDC hdc, int x1, int y1, int wd, int ht, LPCTSTR image ); +extern HB_EXPORT HB_BOOL hb_wvt_DrawImage( HDC hdc, int x1, int y1, int wd, int ht, LPCTSTR image, BOOL bDoNotScale ); extern HB_EXPORT void hb_wvt_GetStringAttrib( int top, int left, int bottom, int right, HB_BYTE * sBuffer, HB_BYTE * sAttrib ); extern HB_EXPORT void hb_wvt_PutStringAttrib( int top, int left, int bottom, int right, HB_BYTE * sBuffer, HB_BYTE * sAttrib ); diff --git a/contrib/gtwvg/tests/demowvg.prg b/contrib/gtwvg/tests/demowvg.prg index 3e0e21dfac..9817f6f86f 100644 --- a/contrib/gtwvg/tests/demowvg.prg +++ b/contrib/gtwvg/tests/demowvg.prg @@ -1,3 +1,7 @@ +/* + * $Id: demowvg.prg 18886 2013-03-02 01:24:02Z vszakats $ + */ + // GTWVT Console GUI Interface // // Pritpal Bedi @@ -127,7 +131,7 @@ PROCEDURE Main() AAdd( aBlocks, {|| Wvt_DrawBoxRecessed( 7, 61, 13, 70 ) } ) AAdd( aBlocks, {|| Wvt_DrawBoxGroup( 15, 59, 18, 72 ) } ) AAdd( aBlocks, {|| Wvt_DrawBoxGroup( 5, 6, 19, 44 ) } ) - AAdd( aBlocks, {|| Wvt_DrawImage( 8, 62, 12, 69, IMAGE_VOUCH ) } ) + AAdd( aBlocks, {|| Wvt_DrawImage( 8, 62, 12, 69, IMAGE_VOUCH, , .t. ) } ) AAdd( aBlocks, {|| Wvt_DrawBoxRecessed( 7, 48, 13, 55 ) } ) AAdd( aBlocks, {|| Wvt_DrawLine( MaxRow() - 2, 0, MaxRow() - 2, MaxCol(), WVT_LINE_HORZ, WVT_LINE_RECESSED, WVT_LINE_BOTTOM ) } ) AAdd( aBlocks, {|| Wvt_DrawLine( MaxRow() - 1, 41, MaxRow(), 41, WVT_LINE_VERT, WVT_LINE_RECESSED, WVT_LINE_CENTER ) } ) diff --git a/contrib/gtwvg/wvgcore.c b/contrib/gtwvg/wvgcore.c index acc461050e..32d2720eee 100644 --- a/contrib/gtwvg/wvgcore.c +++ b/contrib/gtwvg/wvgcore.c @@ -1,3 +1,7 @@ +/* + * $Id: wvgcore.c 18716 2012-12-03 13:52:22Z vszakats $ + */ + /* * Harbour Project source code: * @@ -198,84 +202,56 @@ IPicture * hb_wvt_gtLoadPicture( LPCTSTR image ) return ( IPicture * ) iPicture; } -HB_BOOL hb_wvt_gtRenderPicture( int x1, int y1, int wd, int ht, IPicture * iPicture ) +HB_BOOL hb_wvt_gtRenderPicture( int x, int y, int wd, int ht, IPicture * iPicture, BOOL bDoNotScale ) { PHB_GTWVT _s = hb_wvt_gtGetWVT(); LONG lWidth, lHeight; - int x, y, xe, ye; - int c = x1; - int r = y1; - int dc = wd; - int dr = ht; - int tor = 0; - int toc = 0; + int xe, ye, iWd = 0, iHt = 0; HRGN hrgn1; - POINT lpp; + POINT lpp = { 0, 0 }; HB_BOOL bResult = HB_FALSE; + HDC hdc = _s->hdc; if( iPicture ) { HB_VTBL( iPicture )->get_Width( HB_THIS_( iPicture ) & lWidth ); HB_VTBL( iPicture )->get_Height( HB_THIS_( iPicture ) & lHeight ); - if( dc == 0 ) - dc = ( int ) ( ( float ) dr * lWidth / lHeight ); - if( dr == 0 ) - dr = ( int ) ( ( float ) dc * lHeight / lWidth ); - if( tor == 0 ) - tor = dr; - if( toc == 0 ) - toc = dc; - - x = c; - y = r; - xe = c + toc - 1; - ye = r + tor - 1; - - GetViewportOrgEx( _s->hdc, &lpp ); - - hrgn1 = CreateRectRgn( c + lpp.x, r + lpp.y, xe + lpp.x, ye + lpp.y ); - SelectClipRgn( _s->hdc, hrgn1 ); - - while( x < xe ) + if( bDoNotScale ) { - while( y < ye ) - { - HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) _s->hdc, x, y, dc, dr, 0, lHeight, lWidth, -lHeight, NULL ); - y += dr; - } - y = r; - x += dc; + iHt = ( int ) ( ( float ) wd * lHeight / lWidth ); + iWd = ( int ) ( ( float ) iHt * lWidth / lHeight ); + x += abs( ( iWd - wd ) / 2 ); + y += abs( ( iHt - ht ) / 2 ); + wd = iWd; + ht = iHt; } + xe = x + wd - 1; + ye = y + ht - 1; - SelectClipRgn( _s->hdc, NULL ); + GetViewportOrgEx( hdc, &lpp ); + + hrgn1 = CreateRectRgn( lpp.x + x, lpp.y + y, lpp.x + xe, lpp.y + ye ); + SelectClipRgn( hdc, hrgn1 ); + + HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) hdc, x, y, wd, ht, 0, lHeight, lWidth, -lHeight, NULL ); + + SelectClipRgn( hdc, NULL ); DeleteObject( hrgn1 ); if( _s->bGui ) { - x = c; - y = r; - xe = c + toc - 1; - ye = r + tor - 1; + hdc = _s->hGuiDC; - GetViewportOrgEx( _s->hGuiDC, &lpp ); + GetViewportOrgEx( hdc, &lpp ); - hrgn1 = CreateRectRgn( c + lpp.x, r + lpp.y, xe + lpp.x, ye + lpp.y ); - SelectClipRgn( _s->hGuiDC, hrgn1 ); + hrgn1 = CreateRectRgn( lpp.x + x, lpp.y + y, lpp.x + xe, lpp.y + ye ); + SelectClipRgn( hdc, hrgn1 ); - while( x < xe ) - { - while( y < ye ) - { - HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) _s->hGuiDC, x, y, dc, dr, 0, lHeight, lWidth, -lHeight, NULL ); - y += dr; - } - y = r; - x += dc; - } + HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) hdc, x, y, wd, ht, 0, lHeight, lWidth, -lHeight, NULL ); - SelectClipRgn( _s->hGuiDC, NULL ); + SelectClipRgn( hdc, NULL ); DeleteObject( hrgn1 ); } @@ -525,7 +501,7 @@ BOOL CALLBACK hb_wvt_gtDlgProcModal( HWND hDlg, UINT message, WPARAM wParam, LPA return lReturn; } -HB_BOOL hb_wvt_DrawImage( HDC hdc, int x1, int y1, int wd, int ht, LPCTSTR lpImage ) +HB_BOOL hb_wvt_DrawImage( HDC hdc, int x, int y, int wd, int ht, LPCTSTR lpImage, BOOL bDoNotScale ) { #if ! defined( HB_OS_WIN_CE ) HGLOBAL hGlobal; @@ -533,19 +509,12 @@ HB_BOOL hb_wvt_DrawImage( HDC hdc, int x1, int y1, int wd, int ht, LPCTSTR lpIma DWORD nFileSize; DWORD nReadByte; LONG lWidth, lHeight; - int x, y, xe, ye; - int c = x1; - int r = y1; - int dc = wd; - int dr = ht; - int tor = 0; - int toc = 0; + int xe, ye, iWd = 0, iHt = 0; HRGN hrgn1; POINT lpp = { 0, 0 }; HB_BOOL bResult = HB_FALSE; - hFile = CreateFile( lpImage, GENERIC_READ, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL ); + hFile = CreateFile( lpImage, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile != INVALID_HANDLE_VALUE ) { @@ -571,36 +540,24 @@ HB_BOOL hb_wvt_DrawImage( HDC hdc, int x1, int y1, int wd, int ht, LPCTSTR lpIma HB_VTBL( iPicture )->get_Width( HB_THIS_( iPicture ) & lWidth ); HB_VTBL( iPicture )->get_Height( HB_THIS_( iPicture ) & lHeight ); - if( dc == 0 ) - dc = ( int ) ( ( float ) dr * lWidth / lHeight ); - if( dr == 0 ) - dr = ( int ) ( ( float ) dc * lHeight / lWidth ); - if( tor == 0 ) - tor = dr; - if( toc == 0 ) - toc = dc; - - x = c; - y = r; - xe = c + toc - 1; - ye = r + tor - 1; + if( bDoNotScale ) + { + iHt = ( int ) ( ( float ) wd * lHeight / lWidth ); + iWd = ( int ) ( ( float ) iHt * lWidth / lHeight ); + x += abs( ( iWd - wd ) / 2 ); + y += abs( ( iHt - ht ) / 2 ); + wd = iWd; + ht = iHt; + } + xe = x + wd - 1; + ye = y + ht - 1; GetViewportOrgEx( hdc, &lpp ); - hrgn1 = CreateRectRgn( c + lpp.x, r + lpp.y, xe + lpp.x, ye + lpp.y ); + hrgn1 = CreateRectRgn( lpp.x + x, lpp.y + y, lpp.x + xe, lpp.y + ye ); SelectClipRgn( hdc, hrgn1 ); - while( x < xe ) - { - while( y < ye ) - { - HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) hdc, x, y, dc, dr, 0, - lHeight, lWidth, -lHeight, NULL ); - y += dr; - } - y = r; - x += dc; - } + HB_VTBL( iPicture )->Render( HB_THIS_( iPicture ) hdc, x, y, wd, ht, 0, lHeight, lWidth, -lHeight, NULL ); SelectClipRgn( hdc, NULL ); DeleteObject( hrgn1 ); @@ -1046,7 +1003,7 @@ HB_FUNC( WVT_DRAWBOXGROUPRAISED ) } /* - * Wvt_DrawImage( nTop, nLeft, nBottom, nRight, cImage/nPictureSlot, aPxlOff ) + * Wvt_DrawImage( nTop, nLeft, nBottom, nRight, cImage/nPictureSlot, aPxlOff, lDoNotScale ) */ HB_FUNC( WVT_DRAWIMAGE ) { @@ -1065,16 +1022,16 @@ HB_FUNC( WVT_DRAWIMAGE ) iRight = xy.x - 1 + hb_parvni( 6, 4 ); if( HB_ISNUM( 5 ) ) - hb_wvt_gtRenderPicture( iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, _s->pGUI->iPicture[ hb_parni( 5 ) - 1 ] ); + hb_wvt_gtRenderPicture( iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, _s->pGUI->iPicture[ hb_parni( 5 ) - 1 ], hb_parl( 7 ) ); else { void * hImage; - hb_wvt_DrawImage( _s->hdc, iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, HB_PARSTR( 5, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hdc, iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, HB_PARSTR( 5, &hImage, NULL ), hb_parl( 7 ) ); hb_strfree( hImage ); #if defined( __SETGUI__ ) if( _s->bGui ) { - hb_wvt_DrawImage( _s->hGuiDC, iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, HB_PARSTR( 5, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hGuiDC, iLeft, iTop, ( iRight - iLeft ) + 1, ( iBottom - iTop ) + 1, HB_PARSTR( 5, &hImage, NULL ), hb_parl( 7 ) ); hb_strfree( hImage ); } #endif @@ -1768,16 +1725,16 @@ HB_FUNC( WVT_DRAWBUTTON ) if( HB_ISNUM( 6 ) ) { IPicture * iPicture = _s->pGUI->iPicture[ hb_parni( 6 ) - 1 ]; - hb_wvt_gtRenderPicture( iLeft + 4, iTop + 4, iImageWidth, iImageHeight, iPicture ); + hb_wvt_gtRenderPicture( iLeft + 4, iTop + 4, iImageWidth, iImageHeight, iPicture, FALSE ); } else { void * hImage; - hb_wvt_DrawImage( _s->hdc, iLeft + 4, iTop + 4, iImageWidth, iImageHeight, HB_PARSTR( 6, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hdc, iLeft + 4, iTop + 4, iImageWidth, iImageHeight, HB_PARSTR( 6, &hImage, NULL ), FALSE ); hb_strfree( hImage ); if( _s->bGui ) { - hb_wvt_DrawImage( _s->hGuiDC, iLeft + 4, iTop + 4, iImageWidth, iImageHeight, HB_PARSTR( 6, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hGuiDC, iLeft + 4, iTop + 4, iImageWidth, iImageHeight, HB_PARSTR( 6, &hImage, NULL ), FALSE ); hb_strfree( hImage ); } } @@ -1856,7 +1813,7 @@ HB_FUNC( WVT_DRAWSTATUSBAR ) } /* - * Wvt_DrawPicture( nTop, nLeft, nBottom, nRight, nSlot, aPxlOff ) -> lOk + * Wvt_DrawPicture( nTop, nLeft, nBottom, nRight, nSlot, aPxlOff, lDoNotScale ) -> lOk * nSlot <= 20 aAdj == { 0,0,-2,-2 } To Adjust the pixels for { Top,Left,Bottom,Right } */ HB_FUNC( WVT_DRAWPICTURE ) @@ -1880,7 +1837,7 @@ HB_FUNC( WVT_DRAWPICTURE ) iBottom = xy.y - 1 + hb_parvni( 6, 3 ); iRight = xy.x - 1 + hb_parvni( 6, 4 ); - hb_retl( hb_wvt_gtRenderPicture( iLeft, iTop, iRight - iLeft + 1, iBottom - iTop + 1, _s->pGUI->iPicture[ iSlot ] ) ); + hb_retl( hb_wvt_gtRenderPicture( iLeft, iTop, iRight - iLeft + 1, iBottom - iTop + 1, _s->pGUI->iPicture[ iSlot ], hb_parl( 7 ) ) ); } } #endif @@ -2671,12 +2628,12 @@ HB_FUNC( WVT_DRAWPROGRESSBAR ) if( bImage ) { void * hImage; - hb_wvt_DrawImage( _s->hdc, rc.left, rc.top, rc.right - rc.left + 1, rc.bottom - rc.top + 1, HB_PARSTR( 9, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hdc, rc.left, rc.top, rc.right - rc.left + 1, rc.bottom - rc.top + 1, HB_PARSTR( 9, &hImage, NULL ), FALSE ); hb_strfree( hImage ); #if defined( __SETGUI__ ) if( _s->bGui ) { - hb_wvt_DrawImage( _s->hGuiDC, rc.left, rc.top, rc.right - rc.left + 1, rc.bottom - rc.top + 1, HB_PARSTR( 9, &hImage, NULL ) ); + hb_wvt_DrawImage( _s->hGuiDC, rc.left, rc.top, rc.right - rc.left + 1, rc.bottom - rc.top + 1, HB_PARSTR( 9, &hImage, NULL ), FALSE ); hb_strfree( hImage ); } #endif diff --git a/contrib/gtwvg/wvgwin.c b/contrib/gtwvg/wvgwin.c index ab9b4aa333..0f40b26940 100644 --- a/contrib/gtwvg/wvgwin.c +++ b/contrib/gtwvg/wvgwin.c @@ -1,3 +1,7 @@ +/* + * $Id: wvgwin.c 18716 2012-12-03 13:52:22Z vszakats $ + */ + /* * Harbour Project source code: * Video subsystem for Windows using GUI windows instead of Console @@ -364,14 +368,14 @@ HB_FUNC( WVG_GETCLIENTRECT ) } /* - * Win_DrawImage( hdc, nLeft, nTop, nWidth, nHeight, cImage ) in Pixels + * Win_DrawImage( hdc, nLeft, nTop, nWidth, nHeight, cImage, lDoNotScale ) in Pixels */ HB_FUNC( WVG_DRAWIMAGE ) { void * hImage; hb_retl( hb_wvt_DrawImage( ( HDC ) ( HB_PTRDIFF ) hb_parnint( 1 ), hb_parni( 2 ), hb_parni( 3 ), - hb_parni( 4 ), hb_parni( 5 ), HB_PARSTR( 6, &hImage, NULL ) ) ); + hb_parni( 4 ), hb_parni( 5 ), HB_PARSTR( 6, &hImage, NULL ), hb_parl( 7 ) ) ); hb_strfree( hImage ); }