DRAW A TEXT ON A BITMAP

Re: DRAW A TEXT ON A BITMAP

Postby Eoeo » Tue Jul 17, 2012 4:45 pm

But when I paint a bitmap not call tbitmap control ?
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: DRAW A TEXT ON A BITMAP

Postby Eoeo » Tue Jul 17, 2012 6:20 pm

I make a simply test

Code: Select all  Expand view  RUN
#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



 


Image


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

Image
Last edited by Eoeo on Tue Jul 17, 2012 6:48 pm, edited 1 time in total.
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: DRAW A TEXT ON A BITMAP

Postby Antonio Linares » Tue Jul 17, 2012 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DRAW A TEXT ON A BITMAP

Postby Eoeo » Thu Jul 19, 2012 7:43 am

I'm not very able to create a Object instead of a control and I am stop here :

Code: Select all  Expand view  RUN

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
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: DRAW A TEXT ON A BITMAP

Postby Antonio Linares » Thu Jul 19, 2012 10:53 am

Silvio,

Basically you do:

Code: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DRAW A TEXT ON A BITMAP

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: DRAW A TEXT ON A BITMAP

Postby Eoeo » Thu Jul 19, 2012 3:12 pm

Antonio,
I made this class ... perhaps.. but why not show the bitmap ?


Code: Select all  Expand view  RUN


#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






 
User avatar
Eoeo
 
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: DRAW A TEXT ON A BITMAP

Postby ukoenig » Mon Jul 23, 2012 1: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.

Image

Image

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 ukoenig » Wed Jul 25, 2012 9:56 am

I added a Gridpainter.
Now it is possible ( DesignMode ), to define a Value for Rows and Cols
and any Horizontal- / Vertical Splitting.

Image

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.

Image

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.

Image

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 :lol:
Last edited by ukoenig on Mon Jul 01, 2013 4:10 pm, edited 1 time in total.
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 » 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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby ukoenig » Mon Jul 01, 2013 3: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.

Image

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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: DRAW A TEXT ON A BITMAP

Postby cnavarro » Mon Jul 01, 2013 6: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

Image

I want to put text to images

Quiero poner texto a las imagenes

Image

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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby cnavarro » Mon Jul 01, 2013 6: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: Select all  Expand view  RUN

   :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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: DRAW A TEXT ON A BITMAP

Postby ukoenig » 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 :

Image

I still have to add a defined text-color

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 ukoenig » Tue Jul 02, 2013 3:08 pm

Tested transparent PNG and textcolor-change

Image

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

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 44 guests