Draw box on screen

Draw box on screen

Postby Jeff Barnes » Thu Apr 05, 2007 6:25 pm

Hi Everybody,

This might be a bit tricky to explain but I'll give it a try:

I need to allow the user to draw a box on the screen via a click/drag and fill that area with some fill color.

I also need to limit the area on the window where the user can do this.
(I only want the user to be able to do this in 2 locations)

I also need to know the top, left, bottom, right co-ordinates of where the user put the box.

I have no idea where to even start with this one ... I hope someone can help with this.


Thanks in advance,

Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Jeff Barnes » Sat Apr 07, 2007 2:05 am

Ok ... lets start over ...

How can I allow the user to draw a box on the screen with a click and drag?


If I can figure out this first step I know how I can fill the box with a color.

Then all I will need is the know the co-ordinates of the box and I think I can get the rest.



Thanks,
Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sat Apr 07, 2007 4:43 pm

Jeff,

There is a working sample at fwh\visual\source\design.prg

Please review the methods LButtonDown(), LButtonUp(), MouseMove() and DrawBox()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Apr 07, 2007 6:17 pm

Thanks Antonio, but I don't have a "visual" folder in my FWH directory.

Could you please e-mail me the design.prg file


jeff @ can-soft . net


Thanks,

Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sat Apr 07, 2007 6:26 pm

Jeff,

Already sent by email
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sat Apr 07, 2007 8:29 pm

Antonio,

Sorry to be a pain but it looks like I also need the Visual.ch file.
Could you please send that to my email as well.

Thanks,
Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sat Apr 07, 2007 9:38 pm

Jeff,

Already sent :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 08, 2007 12:14 am

I'm having trouble figuring this out.

Do you have a sample that shows how to call the function that allow you to draw the box?


Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sun Apr 08, 2007 11:44 am

Jeff,

Here you have a working sample:
Code: Select all  Expand view
#include "FiveWin.ch"

static oWnd, lBoxDraw := .f., nBoxTop, nBoxLeft, nBoxBottom, nBoxRight

function Main()

   DEFINE WINDOW oWnd TITLE "Test"
   
   oWnd:bLClicked = { | nRow, nCol | MouseDown( nRow, nCol ) }
   oWnd:bLButtonUp = { | nRow, nCol | MouseUp( nRow, nCol ) }
   oWnd:bMMoved = { | nRow, nCol | MouseMove( nRow, nCol ) }
   
   ACTIVATE WINDOW oWnd

return nil

function MouseDown( nRow, nCol )

   lBoxDraw   = .t.
   nBoxTop    = nRow
   nBoxLeft   = nCol
   nBoxBottom = nRow
   nBoxRight  = nCol
   SetCapture( oWnd:hWnd )
   DrawBox()

return nil

function MouseUp( nRow, nCol )

   if lBoxDraw
      DrawBox()
      lBoxDraw = .f.
      ReleaseCapture()
   endif   

return nil

function MouseMove( nRow, nCol )

   if lBoxDraw
      DrawBox()
      nBoxBottom = nRow
      nBoxRight  = nCol
      DrawBox()
   endif

return nil

function DrawBox()

   RectDotted( oWnd:hWnd, nBoxTop,;
                     nBoxLeft, nBoxBottom, nBoxRight )

return nil

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 08, 2007 2:23 pm

Thank you very much Antonio.

This is exactly what I needed.

With your help I was able to draw the 2 boxes with user limits and the fill colors just like I had visioned in less than 10 minutes.



Thanks again,

Jeff
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Antonio Linares » Sun Apr 08, 2007 2:29 pm

Jeff,

Would you mind to share your sample to see how it works ? Thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Jeff Barnes » Sun Apr 08, 2007 4:00 pm

Antonio,

Here is the sample you gave me with my small changes.

Basically, in my application, I have 2 waveforms on the screen where I need to give the user the option to "exclude" some data if need be.

The 2 "filled" areas in the code below would represent where my waveforms are.

You can look at an actual screen shot (with the waveforms) here:
http://img337.imageshack.us/my.php?image=boxvb4.jpg

Again, Thank you very much for all your help Antonio. I would never have figured out this one with out the help.

Jeff


Code: Select all  Expand view
#include "FiveWin.ch"

static oWnd, lBoxDraw := .f., nBoxTop, nBoxLeft, nBoxBottom, nBoxRight, oBrush

function Main()
   DEFINE BRUSH oBrush STYLE DIAGCROSS COLOR RGB(218,165,32)

   DEFINE WINDOW oWnd TITLE "Box Test with Fill"
      oWnd:bLClicked  = { | nRow, nCol | MouseDown( nRow, nCol ) }
      oWnd:bLButtonUp = { | nRow, nCol | MouseUp( nRow, nCol ) }
      oWnd:bMMoved    = { | nRow, nCol | MouseMove( nRow, nCol ) }
   ACTIVATE WINDOW oWnd MAXIMIZED
return nil

function MouseDown( nRow, nCol )
   lBoxDraw   = .t.
   nBoxTop    = nRow
   nBoxLeft   = nCol
   nBoxBottom = nRow
   nBoxRight  = nCol
   SetCapture( oWnd:hWnd )
   DrawBox()
return nil

function MouseUp( nRow, nCol )
   Local aRect1, aRect2, hPen
   oWnd:GetDc()
   hPen := CreatePen( 0, 1, RGB(54,54,54))

   if lBoxDraw
      DrawBox()
      lBoxDraw = .f.
      ReleaseCapture()

      aRect1 := { 26,nBoxLeft,125,nBoxRight}
      aRect2 := {185,nBoxLeft,395,nBoxRight}
      FillRect(oWnd:hDc,aRect1,oBrush:hBrush)
      FillRect(oWnd:hDc,aRect2,oBrush:hBrush)
   endif   
return nil

function MouseMove( nRow, nCol )
   if lBoxDraw
      DrawBox()
      nBoxBottom = nRow
      nBoxRight  = nCol
      DrawBox()
   endif
return nil

function DrawBox()
   RectDotted(oWnd:hWnd, 26,nBoxLeft,125,nBoxRight)
   RectDotted(oWnd:hWnd,185,nBoxLeft,395,nBoxRight)
return nil
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Enrico Maria Giordano » Sun Apr 08, 2007 4:40 pm

Wonderful samples!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Antonio Linares » Sun Apr 08, 2007 5:17 pm

Jeff,

Please change your function MouseUp() this way:
Code: Select all  Expand view
function MouseUp( nRow, nCol )
   Local aRect1, aRect2

   if lBoxDraw
      oWnd:GetDC()
      DrawBox()
      lBoxDraw = .f.
      ReleaseCapture()
      aRect1 := { 26,nBoxLeft,125,nBoxRight}
      aRect2 := {185,nBoxLeft,395,nBoxRight}
      FillRect(oWnd:hDc,aRect1,oBrush:hBrush)
      FillRect(oWnd:hDc,aRect2,oBrush:hBrush)
      oWnd:ReleaseDC()
   endif   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42078
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

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