colored square blink

colored square blink

Postby Silvio.Falconi » Wed Oct 02, 2024 7:25 am

How to display a red colored square over an image at x,y coordinates ( measure on mm) and the square should blink
Can have a small sample please ?

I create this

Image

Problems
1) the square is not flashing
2) if I change record it does not delete the previous one

Any help please

the test

Code: Select all  Expand view  RUN


oBrw:bChange  := { || ShowBox(oBrw,oCoupon) }


FUNCTION ShowBox(oBrw, oImage)
    LOCAL hDC, nX, nY, nSize, hBrush
    LOCAL nImgX, nImgY



    // Coordinate del quadrato in mm (distanze specificate)
    nX := VAL(oBrw:aArrayData[oBrw:nArrayAt][2])
    nY := VAL(oBrw:aArrayData[oBrw:nArrayAt][3])
    nSize := 2 // dimensione del quadrato

    // Dimensioni e posizione dell'immagine
    nImgX := 10  // Posizione X dell'immagine
    nImgY := 0   // Posizione Y dell'immagine

    // Converti le misure da mm a pixel (96 DPI)
    nX := nX * 96 / 25.4
    nY := nY * 96 / 25.4
    nSize := nSize * 96 / 25.4
    nImgX := nImgX * 96 / 25.4
    nImgY := nImgY * 96 / 25.4

    // Calcola le coordinate finali tenendo conto della posizione dell'immagine
    nX := nImgX + nX
    nY := nImgY + nY

    hDC := oImage:GetDC()

    // Cancella il quadrato precedente disegnando uno sfondo bianco
    hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Bianco
    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Disegna il nuovo quadrato lampeggiante
    IF MOD(GetTickCount(), 1000) < 500
        hBrush := CreateSolidBrush(RGB(255, 0, 0)) // Rosso
    ELSE
        hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Trasparente (o sfondo)
    ENDIF

    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Rilascia il contesto e pulisci
    oImage:ReleaseDC(hDC)
    DeleteObject(hBrush)

    RETURN nil

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7066
Joined: Thu Oct 18, 2012 7:17 pm

Re: colored square blink

Postby Silvio.Falconi » Wed Oct 02, 2024 10:06 am

this realease the box blink right but not if I change record it does not delete the previous one

Image


oBrw:bChange := { || BuildTimer( oBrw, oCoupon, oDlg) }

Code: Select all  Expand view  RUN
FUNCTION ShowBox(oBrw, oImage)
    LOCAL hDC, nX, nY, nSize, hBrush
    LOCAL nImgX, nImgY



    // Coordinate del quadrato in mm (distanze specificate)
    nX := VAL(oBrw:aArrayData[oBrw:nArrayAt][2])
    nY := VAL(oBrw:aArrayData[oBrw:nArrayAt][3])
    nSize := 2 // dimensione del quadrato

    // Dimensioni e posizione dell'immagine
    nImgX := 10  // Posizione X dell'immagine
    nImgY := 0   // Posizione Y dell'immagine

    // Converti le misure da mm a pixel (96 DPI)
    nX := nX * 96 / 25.4
    nY := nY * 96 / 25.4
    nSize := nSize * 96 / 25.4
    nImgX := nImgX * 96 / 25.4
    nImgY := nImgY * 96 / 25.4

    // Calcola le coordinate finali tenendo conto della posizione dell'immagine
    nX := nImgX + nX
    nY := nImgY + nY

    hDC := oImage:GetDC()

    // Cancella il quadrato precedente disegnando uno sfondo bianco
    hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Bianco
    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Disegna il nuovo quadrato lampeggiante
    IF MOD(GetTickCount(), 1000) < 500
        hBrush := CreateSolidBrush(RGB(255, 0, 0)) // Rosso
    ELSE
        hBrush := CreateSolidBrush(RGB(255, 255, 255)) // Trasparente (o sfondo)
    ENDIF

    SelectObject(hDC, hBrush)
    Rectangle(hDC, nX, nY, nX + nSize, nY + nSize)

    // Rilascia il contesto e pulisci
    oImage:ReleaseDC(hDC)
    DeleteObject(hBrush)

    RETURN nil


    function BuildTimer( oBrw, oImage, oDlg)
       local nTime := 0
       local oTmr

       DEFINE TIMER oTmr OF oDlg ;
          ACTION ( nTime++, If( nTime > 14, ShowBox(oBrw, oImage) ,)) INTERVAL 5

       ACTIVATE TIMER oTmr


    return nil

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7066
Joined: Thu Oct 18, 2012 7:17 pm

Re: colored square blink

Postby Silvio.Falconi » Wed Oct 02, 2024 10:15 am

Now Run ok

I discovered that the coordinates are reversed


Image

it just flashes a little too much, how do I reduce the flashing speed?

Code: Select all  Expand view  RUN
  function BuildTimer( oBrw, oImage, oDlg)
       local nTime := 0
       local oTmr
       loca nInterval := 10

       DEFINE TIMER oTmr OF oDlg ;
          ACTION ( nTime++,oImage:refresh(), If( nTime > 14, ShowBox(oBrw, oImage) ,)) INTERVAL nInterval

       ACTIVATE TIMER oTmr


    return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7066
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 39 guests