DRAW A TEXT ON A BITMAP

Re: DRAW A TEXT ON A BITMAP

Postby cnavarro » Tue Jul 02, 2013 5:44 pm

Thanks Uwe

The text that I want to see behind the image.
No one could get the hDC of the image that contains the cell? Maybe so they could paint over the image

Gracias Uwe

El texto que quiero poner aparece por detrás de la imagen.
No se podria obtener el hDC de la imagen que contiene la celda ? Quizas asi se podria pintar encima de la imagen.

Code: Select all  Expand view

:aCols[1]:bPaintText     := {|oB, hDC, cData, aRect, aClrs, lHigh| DRAWTEXT( oXBrw:aCols[ oXBrw:nColSel ], hDC, oXBrw, cData, aRect, , ) }
 


Regards
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby ukoenig » Tue Jul 02, 2013 6:53 pm

It is a bit more complicated. The images are defined with :
DrawCell( oBrw1, oCol, hDC, cData, aRect, hBrush1 ) }
It works fine, but still needed to define different textcolors of cells.
For the moment only ROW works.
I will create a sample of the final solution.

The browser :

Code: Select all  Expand view

FUNCTION SHOW_BROW()
LOCAL hBrush1 := CreateSolidBrush( nObjColor )

@ 60, 55 XBROWSE oBrw1 SIZE 730, 601 PIXEL OF oDlg1 ;
AUTOCOLS ARRAY aImg NOBORDER
oBrw1:lHeader := .F.
oBrw1:lFooter := .F.
oBrw1:lRecordSelector := .F.
oBrw1:lHScroll := .F.
oBrw1:lVScroll := .F.
oBrw1:lAllowRowSizing := .F.
oBrw1:lAllowColSwapping := .F.
oBrw1:lContrastClr := .F.

oBrw1:nMarqueeStyle := 0
oBrw1:nRowDividerStyle := 1
oBrw1:nColDividerStyle := 1

FOR nCol := 1 to nSGet[3]
    WITH OBJECT oBrw1:aCols[ nCol ]
        :nWidth := nCellSize
        :bPaintText := { | oCol, hDC, cData, aRect | DrawCell( oBrw1, oCol, hDC, cData, aRect, hBrush1 ) }
            :lAllowSizing := .F.
    END
NEXT

WITH OBJECT oBrw1
    :nRowHeight := nCellSize
    // Selected Row on Focus ( Text / Background )
    // ------------------------------------------------------------
    :bClrSelFocus = { || { , 16777215 } }  

    // Selected Row on LostFocus ( Text / Background )
    // -----------------------------------------------------------------
    :bClrSel = { || { 0, 16777215 } }  
    :bClrStd  := {|| { 0, 16777215 } }
    :bClrSelFocus = { || { 0, 16777215 } }  
        XBRW_BACK(oBrw1)
END

// DEFINE YOUR ACTION !!!
// ------------------------------
oBrw1:bLClicked := { | nRow, nCol | ( nRPos := oBrw1:KeyNo(), ;
                                nCPos := oBrw1:SelectedCol():nCreationOrder, ;
                                nRecPos1 := ( ( nRPos - 1 )* nSGet[3] ) + nCPos, ;  
                                IIF( ALLTRIM(aImg[ nRPos, nCPos ]) <> ALLTRIM(c_path1 + cImages[17]) , ;
                                          ( SOUND_PLAY(3), MsgAlert( "Selected Image !" + CRLF + "Please hide the Preview !", "Error" ) ), ;       
                                  ( nSelect++, ;
                                    aImg[ nRPos, nCPos ] :=  c_path1 + cCards[nRecPos1], ;
                                    IIF( nSelect = 1, ( nRPos1 := nRPos, nCPos1 := nCPos ), NIL ), ;
                                    IIF( nSelect = 2, ( nRPos2 := nRPos, nCPos2 := nCPos ), NIL ), ;
                                    SET_POINTS() ) ) ) }
                                                                   

oBrw1:CreateFromCode()

RETURN NIL

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

STATIC FUNCTION DrawCell ( oBrw1, oCol, hDC, cData, aRect, hBrush1 )
LOCAL oBrw := oCol:oBrw
LOCAL nTop := aRect[ 1 ]
LOCAL nLeft := aRect[ 2 ]
LOCAL nBottom := aRect[ 3 ]
LOCAL nRight := aRect[ 4 ]
LOCAL nOld, nOld1, lAlpha, nZeroClr
LOCAL hBmp, hBmpO, nBmpW, nBmpH, nBmpTop, nBmpLeft
LOCAL oBold, oItalic

DEFINE FONT oBold   NAME 'TAHOMA' SIZE 0,-18 BOLD
DEFINE FONT oItalic NAME 'TAHOMA' SIZE 0,-18 ITALIC

IF ! Empty( cData := oCol:Value() ) // note: cData is reassigned
    hBmp := FILoadImg( cData )
    nBmpH  := nCellSize
    nBmpW := nCellSize + 2
    nBmpTop := nTop - 2
    nBmpLeft := nLeft - 4

    lAlpha := HasAlpha( hBmp )

    IF lAlpha .or. ! oCol:lBmpTransparent
        hBmpO := hBmp
        hBmp := ResizeImg( hBmpO, nBmpW, nBmpH )
        DeleteObject( hBmpO )
    ENDIF
    IF lAlpha
        ABPaint( hDC, nBmpLeft, nBmpTop, hBmp, oCol:nAlphaLevel(255) )
    ELSEIF oCol:lBmpTransparent
        nZeroClr := GetZeroZeroClr( hDC, hBmp )
        TransBmp( hBmp, nBmpWidth( hBmp ), nBmpHeight( hBmp ),;
                nZeroClr, hDC, nBmpLeft, nBmpTop, nBmpW, nBmpH )
    ELSE
        DrawBitmap( hDC, hBmp, nBmpTop, nBmpLeft )
    ENDIF

    // --------------------
    // --------------------
    DRAWTEXT( oCol, hDC, oBrw1, cFileNoPath(cData), aRect, oBold, oItalic )
    // --------------------
    // --------------------

    DeleteObject( hBmp )
    DeleteObject( hBrush1)

ENDIF
RELEASE FONT oBold
RELEASE FONT oItalic

RETURN NIL

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

STATIC FUNCTION GetZeroZeroClr( hDC, hBmp )
LOCAL hDCMem, hOldBmp, nZeroZeroClr

hDCMem = CreateCompatibleDC( hDC )
hOldBmp = SelectObject( hDCMem, hBmp )
nZeroZeroClr = GetPixel( hDCMem,0,0)
SelectObject( hDCMem, hOldBmp )
DeleteDC( hDCMem )

RETURN nZerozeroClr

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

STATIC FUNCTION DRAWTEXT( oCol, hDC, oBrw1, cText, aCoord, oBold, oItalic )
local nTop  := aCoord[ 1 ], nLeft := aCoord[ 2 ]
local nBottom := aCoord[ 3 ], nRight := aCoord[ 4 ]
local nRow  := nTop
local cLine, nFontHt, nAt

nAt := AT( CRLF, cText )
IF nAt > 0
    cLine := Left( cText, nAt - 1  )
    oBold:Activate( hDC )
    nFontHt  := GetTextHeight( oCol:oBrw:hWnd, hDC )
    DRAWTEXTEX( hDC, cLine, { nRow, nLeft, nRow + nFontHt + 4, nRight }, 1 ) //oCol:nDataStyle )
    oBold:DeActivate( hDC )
    nRow += nFontHt + 4
    cLine := SubStr( cText, nAt + 2 )
ELSE
    cLine := cText
ENDIF
IF oBrw1:KeyNo() = 2 .or. oBrw1:KeyNo() = 4
    SetTextColor( hDC, 255 )
ELSE
    SetTextColor( hDC, 0 )
ENDIF

oItalic:Activate( hDC )
DRAWTEXTEX( hDC, cLine, { nRow, nLeft, nBottom, nRight }, oCol:nDataStyle )
oItalic:DeActivate( hDC )

RETURN NIL
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: DRAW A TEXT ON A BITMAP

Postby cnavarro » Wed Jul 03, 2013 7:41 am

Thank you very much Uwe
I continue testing and will comment the results.

One more question:
Would it be easier to put text on the bottom of the image? I've seen your example below there are pictures and text in another cell. Any hints on this issue?
A main panel pictures, as they are fixed, I can put up with titles IconLover pictures but no side panel, because they are created at runtime.
Attached is a picture of what I need and another of the images that I have to put the text in the foot.
Windows 8
Image
and my images
with xbrowse
Image

Image


Thanks again and greetings

Muchas gracias Uwe
Sigo haciendo pruebas y comentare los resultados.
Una pregunta mas:
¿Seria mas facil poner el texto en el pie de la imagen? He visto un ejemplo tuyo que hay imagenes y debajo en otra celda un texto. ¿Alguna pista sobre este tema?
A las imagenes del panel principal, como son fijas, les puedo poner con IconLover los titulos pero a las imagenes del panel lateral no, porque se crean en tiempo de ejecucion.
Adjunto una imagen de lo que necesito y otra de las imagenes que tengo que poner el texto en el pie.
Windows 8

y mis imagenes
con xbrowse
Gracias de nuevo y saludos
Last edited by cnavarro on Wed Jul 03, 2013 10:05 am, edited 1 time in total.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby cnavarro » Wed Jul 03, 2013 8:18 am

This example is done with yours xbrowse

Este ejemplo tuyo esta hecho con un xbrowse

viewtopic.php?f=3&t=24494&p=132531#p132531

I'm trying to understand the operation of the FUNCTION DrawCell
Estoy intentando entender el funcionamiento de la FUNCTION DrawCell

Regards
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby arthursilvestre » Tue Jul 09, 2013 1:58 pm

How can I change the text font?
User avatar
arthursilvestre
 
Posts: 32
Joined: Thu Sep 20, 2012 7:29 pm

Re: DRAW A TEXT ON A BITMAP

Postby ukoenig » Tue Jul 09, 2013 2:32 pm

Adjust TEXT-position and FONTSIZE.

Image

You can try .

oBrw1:lContrastClr := .T.

Code: Select all  Expand view

#define DT_LEFT    0x00000000
#define DT_CENTER     0x00000001
#define DT_VCENTER   0x00000004

FOR nCol := 1 to 5  // ? Your cols
    WITH OBJECT oBrw1:aCols[ nCol ]
        :nWidth := nCellSize
        :bPaintText := { | oCol, hDC, cData, aRect | ;
                  DRAWCELL( oBrw1, oCol, hDC, cData, aRect, hBrush1 ), ;
              DRAWTEXT( oCol, hDC, cFileNoPath(cData), aRect ) }
        :lAllowSizing := .F.
        SETTEXTCOLOR( hDC,  255 )
    END
NEXT

...
...
//----------------------------------------------------------------------------//

STATIC FUNCTION DRAWTEXT( oCol, hDC, cText, aCoord )
local nTop  := aCoord[ 1 ], nLeft := aCoord[ 2 ]
local nBottom := aCoord[ 3 ], nRight := aCoord[ 4 ]
local nRow  := nTop
local cLine, nFontHt, nAt
LOCAL oBold, oItalic

DEFINE FONT oBold   NAME 'TAHOMA' SIZE 0,-16 BOLD
DEFINE FONT oItalic NAME 'TAHOMA' SIZE 0,-16 ITALIC

nAt := AT( CRLF, cText )
IF nAt > 0
    cLine := Left( cText, nAt - 1  )
    oBold:Activate( hDC )
    nFontHt  := GetTextHeight( oCol:oBrw:hWnd, hDC )
    DRAWTEXTEX( hDC, cLine, { nRow, nLeft, nRow + nFontHt + 4, nRight }, 1 ) //oCol:nDataStyle )
    oBold:DeActivate( hDC )
    nRow += nFontHt + 4
    cLine := SubStr( cText, nAt + 2 )
ELSE
    cLine := cText
ENDIF

oBold:Activate( hDC )
nFontHt  := GetTextHeight( oCol:oBrw:hWnd, hDC )

// calculate the TEXTPOSITION
// ---------------------------------
DRAWTEXTEX( hDC, cLine, { nBottom - nFontHt - 5, nLeft + 5, nBottom - 1, nRight - 1 }, ;
               DT_VCENTER )
oBold:DeActivate( hDC )

RELEASE FONT oBold
RELEASE FONT oItalic

//SETTEXTCOLOR( hDC,  255 )

RETURN NIL
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 133 guests