FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DRAW A TEXT ON A BITMAP
Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Tue Jul 17, 2012 04:45 PM

But when I paint a bitmap not call tbitmap control ?

Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Tue Jul 17, 2012 06:20 PM
I make a simply test

Code (fw): Select all Collapse
 #include "fivewin.ch"
 #define MERGEPAINT 12255782    // 0xBB0226
 #define SRCAND      8913094


static oWnd, hBmp1, hBmp2
Function test()
   hBmp1 = LoadBitmap( GetResources(), "AZZURRO" )
   hBmp2 = LoadBitmap( GetResources(), "ROSSO" )







   DEFINE WINDOW oWnd
   ACTIVATE WINDOW oWnd ;
         ON PAINT ( SayBitmaps() )
       DeleteObject( hBmp1 )
       DeleteObject( hBmp2 )

return nil




  function SayBitmaps()
    local hDC := oWnd:GetDC()
    lOCAL nRow:=20
    Local nCol:=24


   TOTY := 20
   TOTX := 20

     aBmps := ARRAY( TOTY, TOTX )
     aData := ARRAY( TOTY, TOTX )
       n=1

     For nY := 1 to TOTY
        For nX := 1 To TOTX

           aData[nY,nX] := "X"

           DrawBitmap( hDC, hBmp1, nrow, ncol, 0, 0, SRCAND )

           // write the number
                 SetBkMode( hDC, 1 )
                SetTextColor( hDC, CLR_RED )
                TextOut( hDC, nrow, ncol,str(n)  )


                n:=n+1

        ncol:=ncol+48
     Next nX

   nRow += 24
  nCol := 48
Next nY


   oWnd:ReleaseDC()
return nil





Now How I can make to click on each umbrellas ?


I need only to click on each umbrellas and open a dialog



I also write the numbers with

// write the numbers
SetBkMode( hDC, 1 )
SetTextColor( hDC, CLR_RED )
TextOut( hDC, nrow, ncol,str(nX) )

but perhaps there is an error

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Tue Jul 17, 2012 06:47 PM

I told you to use a Umbrella object for each umbrella, anyhow...

Simply divide Mouse nRow and nCol by 24 and 24 (as you used to paint the umbrellas rows and columns) and you know on which umbrella clicked the mouse :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Thu Jul 19, 2012 07:43 AM
I'm not very able to create a Object instead of a control and I am stop here :

Code (fw): Select all Collapse
CLASS Umbrella
DATA nTop, nLeft, nWidth, nHeight
DATA nStatus
DATA cBitmap
DATA oWnd
DATA   hBitmap, hPalette
METHOD IsOver( nRow, nCol ) // to detect a mouse click

METHOD New ( cBitmap, oWnd,nTop, nLeft,nWidth, nHeight) CONSTRUCTOR
METHOD Paint( )
METHOD LoadImage(cBmpFile )

ENDCLASS


 METHOD New( cBitmap, oWnd,nTop, nLeft,nWidth, nHeight)  CLASS Umbrella

      DEFAULT cBitmap := ""

       ::nTop     := nTop
       ::nLeft    := nLeft
       ::nWidth   := nWidth
       ::nHeight  := nHeight
       ::oWnd     := oWnd

     ::LoadImage(cBmpFile )


Return self



METHOD     LoadImage(cBmpFile )  CLASS Umbrella
   local lChanged := .f.
   local hBmpOld  := ::hBitmap
   local hPalOld  := ::hPalette
   local aBmpPal


         if ! Empty( cBmpFile )

       aBmpPal = PalBmpRead( ::GetDC(), AllTrim( cBmpFile ) )
       ::hBitmap = aBmpPal[ 1 ]
       ::hPalette = aBmpPal[ 2 ]
       ::ReleaseDC()
         endif

       if lChanged

         ::cBmpFile = cBmpFile

         if ! Empty( hBmpOld )
         PalBmpFree( hBmpOld, hPalOld )
      endif

      PalBmpNew( ::hWnd, ::hBitmap, ::hPalette )

   endif

  return lChanged

METHOD paint()


    if Empty( ::hBitmap ) .and. ! Empty( ::cBmpFile )
      ::LoadImage( ::cBmpFile )
   endif


     return nil


METHOD IsOver( nRow, nCol )  CLASS Umbrella
 return nil
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Thu Jul 19, 2012 10:53 AM
Silvio,

Basically you do:

Code (fw): Select all Collapse
function Click( nRow, nCol )

   local nMyRow := Int( nRow / 20 )
   local nMyCol := Int( nCol / 20 )
   
   MsgInfo( nMyRow * 20 + nMyCol )
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Thu Jul 19, 2012 11:26 AM

If you keep an array of Umbrella objects then you do:

nAt = AScan( aUmbrellas, { | oUmbrella | oUmbrella:IsOver( nRow, nCol ) } )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 222
Joined: Mon Jun 04, 2012 12:00 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Thu Jul 19, 2012 03:12 PM
Antonio,
I made this class ... perhaps.. but why not show the bitmap ?


Code (fw): Select all Collapse
 

#include "fivewin.ch"
#include "constant.ch"




Function Main()
   Local ownd
   Local umbrella

   DEFINE WINDOW oWnd

    umbrella:=Umbrella():New(10,10,oWnd,"azzurro.bmp",,.t.)



    ACTIVATE WINDOW oWnd



  RETURN NIL












CLASS Umbrella

   DATA nTop, nLeft, nWidth, nHeight

   DATA nStatus

   DATA cBmpFile, cResName, lBorder

   DATA hBmp, hBmpPal

   DATA oParent

   DATA nPen, nStylePen, nClrPen


   DATA hDCMem

   DATA hOldBmp


CLASSDATA hOld

METHOD New (nTop, nLeft, oParent,;
                  cBmpFile, cResName, lBorder )  CONSTRUCTOR

METHOD Paint( hDC, nTop, nLeft )
//METHOD IsOver( nRow, nCol ) // to detect a mouse click

METHOD EndPaint()

METHOD BeginPaint( hDC )

  METHOD Click( nRow, nCol )

METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
ENDCLASS


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

 METHOD New (nTop, nLeft, oParent,;
                  cBmpFile, cResName, lBorder ) CLASS Umbrella



DEFAULT lBorder := .t.

  ::oParent     := oParent

  ::nTop        := nTop
  ::nLeft       := nLeft
  // ::nHeight     := nBottom
  // ::nWidth     := nRight

  ::cBmpFile    := cBmpFile
  ::cResName    := cResName
  ::lBorder     := lBorder


 if File( ::cBmpFile )

     ::hBmp    := ReadBitmap (0, cBmpFile )
     ::hBmpPal := PalBmpRead( ::oParent:GetDC(), AllTrim( cBmpFile ) )
     ::oParent:ReleaseDC()

     if ! Empty( ::hOld )
        PalBmpFree( ::hOld )
     endif

     ::hOld := ::hBmpPal

     PalBmpNew( ::oParent:hWnd, ::hBmpPal )

     ::nHeight := nBmpHeight( ::hBmp )
     ::nWidth  := nBmpWidth( ::hBmp )

     ::nHeight  := ::nTop  + ::nHeight
     ::nWidth  := ::nLeft + ::nWidth



  endif
    ::Display()
   * ::Paint( ::oParent:GetDC() )

Return Self

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

METHOD Paint (hDC) CLASS Umbrella

Local hPen, hOldPen

DEFAULT hDC := ::oParent:hDC

  hPen      := CreatePen    (::nStylePen, ::nPen, ::nClrPen)
  hOldPen   := SelectObject (hDC, hPen)

  DrawBitmap (hDC, ::hBmp, ::nTop, ::nLeft, ::nWidth, ::nHeight)
  * PALBMPDraw( hDC, ::nTop, ::nLeft, ::hBmpPal, ::nWidth, ::nHeight)

  If ::lBorder

     Moveto (hDC, ::nLeft, ::nTop)

     LineTo( hDC, ::nWidth, ::nTop    )
     LineTo( hDC, ::nWidth, ::nHeight )
     LineTo( hDC, ::nLeft , ::nHeight )
     LineTo( hDC, ::nLeft , ::nTop    )


  endif


  SelectObject( hDC, hOldPen )
  DeleteObject( hPen )

Return nil




METHOD BeginPaint( hDC )
::hDCMem  := CompatDC( hDC )
::hOldBmp := SelectObject( ::hDCMem, ::hBmp )

Return nil



METHOD EndPaint()


SelectObject( ::hDCMem, ::hOldBmp )
DeleteDC( ::hDCMem )

::hDCMem  := nil


Return nil




METHOD Click( nRow, nCol )

   local nMyRow := Int( nRow / 20 )
   local nMyCol := Int( nCol / 20 )
   
   MsgInfo( nMyRow * 20 + nMyCol )
   
return nil
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Mon Jul 23, 2012 01:57 PM
I tested a Solution with xBrowse :
Using 2000 BMP's without any problem.
It is possible to define 5 horizontal and 5 vertical splittings ( empty Cells ).
I created 95 Cols with 25 Rows
From Tselex, I can change the Status of a Umbrella ( focused Cell ).
It is possible to Zoom IN / OUT
I still have to add the Umbrella-No to the Yellow Cell-parts and the Row-No. on the 1. Col.
Left Mouseclick selects a Cell with a possible Status-change and shows the Row- / Col-Number.
Each Cell belongs to a DBF-record, to save the Umbrella-status.





Best Regards
Uwe :-)
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.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Wed Jul 25, 2012 09:56 AM
I added a Gridpainter.
Now it is possible ( DesignMode ), to define a Value for Rows and Cols
and any Horizontal- / Vertical Splitting.



Exclude any defined Area
A normal Cellstatus belongs to Value 1 - 4. A unused Cell will have the Value 0
In Editmode, it is not possible to change a defined 0-Status.



Changing to < Edit-Mode >, the Settings are saved to the PROJECT.DBF

The Button < New > expects, that Mode is switched to Edit before. That makes it impossible,
to overwrite a existing Project by mystake.



A early Test. There is still the missing Object-counter.
With the JUMP-buttons, I want to move to a defined Cell.

Download :
To change the Cell-status : Left Mouseclick on the Cell and select from < Status 1- 4 >
http://www.pflegeplus.com/fw_downloads/imgxbrw1.zip

Best Regards
Uwe :-)
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.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Fri Jun 28, 2013 10:37 AM

Good morning
I have a xBrowse with images
Can you tell me how I can put a text over an image in a cell of a xBrowse?
Excuse my English (google translate)
Thanks in advance
regards

Buenos dias
Tengo un XBrowse con imagenes
Puede indicarme como puedo poner un texto sobre una imagen dentro de una celda de un XBrowse?
Disculpe mi ingles (google translate)
Gracias anticipadas
Saludos

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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Mon Jul 01, 2013 03:59 PM
How do You want to display the text ?
Working on a sample, I have to know :
Solution 1 : a centered transparent text
Solution 2 : a text centered, on bottom or top
and with a extra background-color.



Best regards
Uwe :-)
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.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Mon Jul 01, 2013 06:00 PM
Uwe, thanks in advance
Attached image of my application and then as I would like it to appear
regards

Uwe, gracias de antemano
Adjunto imagen de mi aplicacion y despues como me gustaria que apareciese
Saludos

This is my screen

Esta es mi pantalla



I want to put text to images

Quiero poner texto a las imagenes



Thanks for your time

Gracias por tu tiempo
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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Mon Jul 01, 2013 06:19 PM
ukoenig wrote:How do You want to display the text ?
Working on a sample, I have to know :
Solution 1 : a centered transparent text
Solution 2 : a text centered, on bottom or top
and with a extra background-color.

Best regards
Uwe :-)



This is the code I use to put pictures

Este es el codigo que utilizo para poner las imagenes

Code (fw): Select all Collapse
   :aCols[1]:aBitmaps       := aBitmaps1
   :aCols[1]:bStrData       := {|| Nil }
   //:aCols[1]:lBmpStretch    := .T.                     // Rellenar toda la celda con el BitMap
   :aCols[1]:bBmpData       := { | oB | oXBrw:nArrayAt }
   //:aCols[1]:cHeader      := "Nombre de Grupo"
   :aCols[1]:nDataStrAlign  := 1
   :aCols[1]:lAllowSizing   := .F.
   :aCols[1]:nEditType      := 0


Regards

Saludos
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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Tue Jul 02, 2013 10:37 AM
To display the Images with text, is a complete different solution.
As a test, I used my MEMORY-game to display the image-names for each cell
with a font-combination :



I still have to add a defined text-color

Best Regards
Uwe :-)
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.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: DRAW A TEXT ON A BITMAP
Posted: Tue Jul 02, 2013 03:08 PM
Tested transparent PNG and textcolor-change



How can I get the number of a Column, during the xBrowse-build ?

I still need the reached Col or straight the Cell-number !!!

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: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
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.