Insert waterImage and other into Ttaskpanel class

Insert waterImage and other into Ttaskpanel class

Postby Silvio » Sat Nov 20, 2010 11:20 am

add these new datas into TTASKPANEL CLASS

DATA lBorder
DATA lRound
DATA nClrBorder
DATA cWaterImage
DATA hWaterImage
DATA nWaterTrans // 0 VISIBLE 300 TRASPARENT


change the new method

METHOD New( cTitle, oWnd, nIndex, cBmpPanel, nBodyHeight,lborder,;
nClrBorder,cWaterImage,nWatertrans
) CLASS TTaskPanel



...


DEFAULT nBodyHeight := 50
DEFAULT lBorder := .f.
DEFAULT nClrBorder := CLR_WHITE //RGB( 206, 99, 49 )


then loadbitmaps()
::lBorder := lBorder
::nClrBorder := nClrBorder
::cWaterImage := cWaterImage
::nWatertrans := nWatertrans


On Paint method


before this line local aInfo := ::DispBegin(), oItem, n
insert
local aRect := GetClientRect(::hWnd)


then before these lines
if ! Empty( ::aControls )
AEval( ::aControls, { | oControl | oControl:Refresh() } )
endif


insert


if ::lBorder
If ::lRound
RoundBox( ::hDC, aRect[ 2 ] , aRect[ 1 ] , aRect[ 4 ]-0.50 , aRect[ 3 ] , 5, 5, ::nClrBorder )

ELSE
RoundBox( ::hDC, aRect[ 2 ] , aRect[ 1 ] , aRect[ 4 ]-1 , aRect[ 3 ] , 0, 0, ::nClrBorder )
endif
endif



before ::DispEnd( aInfo )

insert

::WaterImage()


then add two new methods on ttaskpanel

METHOD WaterImage()
METHOD LoadImage( cImage )


Code: Select all  Expand view
METHOD WaterImage() CLASS TTaskPanel
   local hBmp
   if !Empty(::cWaterImage ) .and. !::lCollapsed
      hBmp := ::LoadImage( ::cWaterImage )
      if ::hWaterImage != 0
         nWidth = nBmpWidth( hBmp )
         nHeight = nBmpHeight( hBmp )
         nTop := ::nHeight - nHeight-1
         nLeft := ::nWidth - nWidth-10
         nBottom := nTop + nHeight
         nRight := nLeft + nWidth
         nAlphaLevel := 20
         DrawAlphaTransparentBitmap( ::hDC,  hBmp, {nTop,nLeft,nBottom,nRight}, ::nWaterTrans, RGB(255,0,255) )
         DeleteObject( hBmp )
      ENDIF
   ENDIF

RETURN NIL


METHOD LoadImage( cImage )  CLASS TTaskPanel    
    local hBmp := 0

 hBmp := LoadBitmap( GetResources(), cImage )
 if hBmp == 0
    hBmp := ReadBitmap( 0, cImage )
 endif

return hBmp



THAN ADD THIS FUNCTION
Code: Select all  Expand view

 //-----------------------------------------------------------------//
#pragma BEGINDUMP
#include "Windows.h"
#include "hbapi.h"

 void DrawAlphaTransparentBitmap(HDC hDC, HBITMAP hBmp, RECT rc, BYTE iAlpha, COLORREF clrTrans)
{
   typedef BOOL (CALLBACK *LPALPHABLEND)(HDC,int, int, int, int,HDC, int, int, int, int, BLENDFUNCTION);
   LPALPHABLEND lpAlphaBlend;   //static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) GetProcAddress( GetModuleHandle("msimg32.dll"), "AlphaBlend");
   int cx, cy, x, y;
   BOOL bRes;
   LPDWORD pSrcBits, pDest, pSrc;
   DWORD dwKey, dwShowColor;
   BITMAPINFO bmi = { 0 };
   HBITMAP hOldBitmap, bmpDest;
   HDC dcCompat;
   BLENDFUNCTION bf;
   HINSTANCE hLib = LoadLibrary( "msimg32.dll" );
   lpAlphaBlend = ( LPALPHABLEND ) GetProcAddress( hLib, "AlphaBlend" );


   if( lpAlphaBlend == NULL )
   {
      FreeLibrary( hLib );
      return;
   }
   cx = rc.right - rc.left;
   cy = rc.bottom - rc.top;

   bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   bRes = GetDIBits(hDC, hBmp, 0, cy, NULL, &bmi, DIB_RGB_COLORS);
   if( !bRes )
   {
      FreeLibrary( hLib );
      return;
   }
   pSrcBits = (LPDWORD) LocalAlloc(LPTR, bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight * sizeof(DWORD));
   bmi.bmiHeader.biBitCount = 32;  // Ask for ARGB codec
   bmi.bmiHeader.biCompression = BI_RGB;
   bRes = GetDIBits(hDC, hBmp, 0, cy, pSrcBits, &bmi, DIB_RGB_COLORS);
   if( !bRes || bmi.bmiHeader.biBitCount != 32 ) {
      LocalFree(pSrcBits);
      FreeLibrary( hLib );
      return;
   }
   pDest = NULL;
   bmpDest = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (LPVOID*) &pDest, NULL, 0);
   if( bmpDest == NULL ) {
      LocalFree(pSrcBits);
      FreeLibrary( hLib );
      return;
   }
   dwKey = RGB(GetBValue(clrTrans), GetGValue(clrTrans), GetRValue(clrTrans));
   pSrc = pSrcBits;
   dwShowColor = 0xFF000000;
   for( y = 0; y < abs(bmi.bmiHeader.biHeight); y++ ) {
      for( x = 0; x < bmi.bmiHeader.biWidth; x++ ) {
         if( *pSrc != dwKey ) *pDest++ = *pSrc | dwShowColor;
         else *pDest++ = 0x00000000;
         pSrc++;
      }
   }

   dcCompat = CreateCompatibleDC(hDC);
   hOldBitmap = (HBITMAP) SelectObject(dcCompat, bmpDest);
   SetStretchBltMode(hDC, COLORONCOLOR);
   bf.BlendOp = AC_SRC_OVER;
   bf.BlendFlags = 0;
   bf.AlphaFormat = AC_SRC_ALPHA;
   bf.SourceConstantAlpha = iAlpha;
   //bRes =
   lpAlphaBlend(hDC, rc.left, rc.top, cx, cy, dcCompat, 0, 0, cx, cy, bf);
   SelectObject(dcCompat, hOldBitmap);
   LocalFree(pSrcBits);
   FreeLibrary( hLib );
}


HB_FUNC( DRAWALPHATRANSPARENTBITMAP )
{
    RECT rc;
    rc.top    = hb_parni( 3, 1 );
    rc.left   = hb_parni( 3, 2 );
    rc.bottom = hb_parni( 3, 3 );
    rc.right  = hb_parni( 3, 4 );

    DrawAlphaTransparentBitmap((HDC) hb_parnl( 1 ),
                               (HBITMAP) hb_parnl( 2 ),
                               rc,
                               (BYTE) hb_parni( 4 ),
                               (COLORREF) hb_parnl( 5 ));
    hb_ret();
}



#pragma ENDDUMP








 



THEN YOU CAN ADD ALSO ANEW COMMAND INTO YOUR CH FILES

#xcommand ADD PANEL [ <oPanel> ] ;
[ <of: OF> <oExBar> ];
[ HEIGHT <nHeight> ] ;
[ <lBorder: BORDER> ] ;
[ BORDERCOLOR <nClrBorder> ];
[ WATERIMAGE <cWaterImage> ] ;
[ NTRANSPARENT <nWaterTrans> ] ;
[ <color: COLOR, COLORS> <nClrText> ,<nClrPane> ] ;
[ <lOpenClose:OPENCLOSE > ] ; //NOT RUN YET!
[ BMPBTN <cBmpUp>[, <cBmpDown>]] ;
=>;
[ <oPanel> := ] <oExBar>:AddPanel( <nHeight>,;
[<.lBorder.>],<nClrBorder>,<cWaterImage>,[ <nWaterTrans> ],;
<nClrText>, <nClrPane>,[ <.lOpenClose.> ],[ <cBmpUp> ],[ <cBmpDown> ] )
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: Insert waterImage and other into Ttaskpanel class

Postby Silvio » Sat Nov 20, 2010 11:22 am

SAMPLE

DEFINE WINDOW oWnd TITLE "FWH Class TExplorerBar"

oWnd:SetSize( 400, 500 )

oExBar = TExplorerBar():New()

ADD PANEL oPanel1 of oExBar ;
HEIGHT 150 ;
BORDER ;
BORDERCOLOR CLR_BLACK ;
WATERIMAGE ".\bitmaps\star.bmp" ;
NTRANSPARENT 100 ;
OPENCLOSE
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: Insert waterImage and other into Ttaskpanel class

Postby Silvio » Sat Nov 20, 2010 11:24 am

OTHER MODIFIES

ADD ON YOUR CH
#xcommand PANELITEM ;
[ <of: OF> <oPanel> ];
[PROMPT <cPrompt> ];
[ FONT <oFont> ] ;
[ HEIGHT <nHeigth> ] ;
[ LEFT <nLeft> ] ;
[ BITMAP <cBitmap> ] ;
[ ACTION <uAction> ] ;
=>;
<oPanel>:AddLink( <(cPrompt)>,;
<nHeigth> ,;
<nLeft> ,;
[{|Self|<uAction>}],;
[<cBitmap>],;
[ <oFont> ] )


METHOD ADDLINK MODIFIED

Code: Select all  Expand view

METHOD AddLink( cPrompt,bAction, cBitmap,nHeight,nLeft,oFontItem ) CLASS TTaskPanel

   local nTop := ::nTitleHeight + 10, n, oUrlLink

    DEFAULT nHeight := 7
    DEFAULT nLeft := 33

    if oFontItem == nil
      oFontItem :=  ::oFont
   endif

   if ! Empty( ::aControls )
      for n = 1 to Len( ::aControls )
         nTop += ::aControls[ n ]:nHeight + nHeight
      next
   endif

   oUrlLink := TUrlLink():New( nTop, nLeft, Self, .T., .F., oFontItem, "", cPrompt )

   oUrlLink:SetColor( oUrlLink:nClrText, ::nClrPane )
   oUrlLink:nClrOver = ::nClrHover
   oUrlLink:bAction = bAction

   if File( cBitmap )
      oUrlLink:hBmp = ReadBitmap( 0, cBitmap )
   else
      oUrlLink:hBmp = LoadBitmap( GetResources(), cBitmap )
   endif

   if oUrlLink:nTop + oUrlLink:nHeight > ::nHeight
      ::nHeight = oUrlLink:nTop + oUrlLink:nHeight + 10
      ::nBodyHeight = ::nHeight - ::nTitleHeight
      ::UpdateRegion()
   endif

return nil



SAMPLE :
PANELITEM OF oPanel1 PROMPT "First item" BITMAP ".\bitmaps\16x16\additem.bmp" ACTION bClick
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 79 guests