REAL Software Forums

The forum for REAL Studio and other REAL Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 02, 2010 9:32 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to Drag a Rectangle Containing Text??
PostPosted: Tue Nov 20, 2007 6:30 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
OK. Here's what I want to do, but I can't figure out how to do it.

I want to have a rectangle with text in it on the screen, and I want the user to be able to click on the rectangle with the mouse and drag the rectangle to another location, with the rectangle and text visible during the dragging.

I've tried various combinations of MouseDown, MouseDrag (and MouseMove), and MouseUp with various controls, but I haven't found anything yet that really works.

(StaticText perhaps comes closest, but (1) the control disappears while it is being moved, and I want it to stay visible, and (2) I want the rectangle to have a border, and StaticText doesn't.)

Any advice (or, even better, information on where I can find sample code that shows how to do this)?

Barry Traver


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 8:36 am 
Offline

Joined: Wed Jan 04, 2006 7:58 pm
Posts: 485
Location: Tri-State Area (NJ, NY, CT)
Barry

One approach would be to create a Picture image from the rect with the text in it, and draw that to the window during the drag event.

Should work fine, there's an example in the Examples folder look for Drag and Drop.

_________________
http://www.kaliware.com
Carbon Declare Library Contributor ;)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:00 am 
Offline
User avatar

Joined: Thu Jul 27, 2006 6:31 pm
Posts: 1645
Location: Monterey, CA
You can set the drag object's preview image via declares or plugins. Or fake it using a semi-transparent window and a timer (for tracking the mouse), and then fire the drag code at the end (when the user releases the mouse).

_________________
ImagePlay Effects Library (40+ image effects in one open source module. No plugins, no dependencies, no restrictions.)
http://imageplay.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:15 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
Jordan,


Thanks for the sugggestions.

Quote:
One approach would be to create a Picture image from the rect with the text in it, and draw that to the window during the drag event.

Actually, the DrawPics demo in the Graphics subfolder of the Examples folder is _very_ close to what I want. I even figured out how to modify it so that the ovals contain words instead of letters of the alphabet. My problem is that I do not understand graphics code at all. Yes, I can move the ovals, but I can's figure out how to find out the text that they contain. (It would have been nice if it I could distinguish between the ovals in a simple way - e.g., Pic(1).Text = "For" - but it's not that simple.)

With most code, I can figure out what most of the lines are doing, but with graphicss code I don't have the slightest idea what most of the lines are doing.

Quote:
... there's an example in the Examples folder look for Drag and Drop.

True, but if we have the same sample program in mind, it doesn't show how to drag a control, but how to drag text (e.g., a line from a ListBox) from a control to a different control, and that's not what I want to do.

I do know how to write the code so that a person can click on a control (e.g., a PushButton) and then click on the location desired for that control and the control will immediately go to that location, but that is not as "intuitive" for the user, even though it is simple to write, merely changing properties of the control, e.g. through code like this:

Code:
PushButton1.Left = PushButton1.Left - (PushButton1.Width)/2
PushButton1.Top - NewY = PushButton1.Top - (PushButton1.Height)/2

Any additional advice?

Barry Traver

P.S. The intent of the program is to give the user a quotation where the word order is scrambled and the user has to put the words in the correct order.


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 9:54 am 
Offline

Joined: Wed Jan 04, 2006 7:58 pm
Posts: 485
Location: Tri-State Area (NJ, NY, CT)
Did you want to drag a control (ie. pushbutton) or text that is part of an editfield?

Not sure which. For a control, you can simply capture the mousedown event and then in the MouseMove event have the control's coordinate (top, left) track with the MouseMove's (X and Y). This will move the control until the MouseUp event is detected. Of course in the MouseUp you'd position the moved control exactly where you'd like it to appear.

If you want to move text as part of an editfield (Roughly the steps are):

0. Starting with a MouseDown event.
1. You'd first have to determine which word the mouse is currently on using editfield.selStart
2. Highlight the word
3. create a Picture image, draw the highlighted text to the picture's graphic property.
4. draw this to the screen while Mouse is still down. While the Mouse is still down, update the window, refreshing only the part of the window that is being affected by the dragged picture.
5. In the MouseUp event, you'd insert/place the new text, and remove the highlighted text from the original location.

Sounds more complicated than it really is.

_________________
http://www.kaliware.com
Carbon Declare Library Contributor ;)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 4:33 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3261
Location: England
barrytraver wrote:
]I've tried various combinations of MouseDown, MouseDrag (and MouseMove), and MouseUp with various controls, but I haven't found anything yet that really works.

(StaticText perhaps comes closest, but (1) the control disappears while it is being moved, and I want it to stay visible, and (2) I want the rectangle to have a border, and StaticText doesn't.)
I've thrown together a quick canvas subclass that does something similar with dragged text at http://rb.sgarman.net/sjgTextBox.rbp which may give you some clues as to how to start.

_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r5.1 Professional on Linux Ubuntu 9.04 Desktop
and REAL Studio 2010r1 Personal on Linux Ubuntu 9.10 Desktop
Occasional blog


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 6:17 pm 
Offline

Joined: Fri Sep 30, 2005 5:54 pm
Posts: 2055
Location: Great Falls, Montana USA
Steve,

Thanks as I saved it myself as I can use all the help I can. :)

_________________
Jonathon Bevar
REALDevelopment: http://www.semielectronics.com/realdevelopment
SemiElectronics http://www.semielectronics.com

RB2005 R4 Pro for Windows XP Pro/SP2
RB2010 R2.1 Studio Enterprise Edition


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 5:25 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
Steve,

Thanks! Your code is exactly what I was looking for!

Even though at this point I don't understand what you did (I still haven't figured out how classes and subclasses work <sigh>), I have experimented enough with modifying your code so that I am able to use it as a basis to do what I want to do (i.e., know which control is being moved and to what location).

Here's a "quick and dirty" way to modify your program to test whether "Hello," "Beautiful," and "World" are in the correct order, left to right:

Code:
Dim MyMin As Integer
  MyMin = Min(textBox1.Height, textBox2.Height)
  Mymin = Min(MyMin, textBox3.Height)
  If textBox1.Left < textBox3.Left And textBox3.Left < textBox2.Left And _
    Abs(textBox1.Top -  textBox2.Top) <= MyMin And _
    Abs(textBox2.Top -  textBox3.Top) <= MyMin And _
    Abs(textBox1.Top -  textBox3.Top) <= MyMin Then
    MsgBox "You Solved It!"
  End If
(The test is made upon each MouseUp for the three textBox controls.)

Just curious: I notice that your textBox controls have event procedures for MouseEnter, Mouse Exit, MouseMove, MouseUp, and MouseWheel, but not MouseDown. I can get along without it, but is there a reason for the absence of MouseDown?

Barry Traver


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 9:14 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3261
Location: England
barrytraver wrote:
I don't understand what you did (I still haven't figured out how classes and subclasses work <sigh>)
I'll try to knock together a blow-by-blow description of creating this immensely simple subclass later, but first I'll deal with the question with the shorter answer.

barrytraver wrote:
Just curious: I notice that your textBox controls have event procedures for MouseEnter, Mouse Exit, MouseMove, MouseUp, and MouseWheel, but not MouseDown. I can get along without it, but is there a reason for the absence of MouseDown?
Only that I didn't bother to create an event handler.

The sjgTextBox control is a subclass of Canvas and automatically exposes the canvas events that I haven't used.

However, I have code in MouseDown, MouseDrag and Paint of the subclass, so I would need to create and call an event handler for each of them if I wanted to make them available in the subclass.

_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r5.1 Professional on Linux Ubuntu 9.04 Desktop
and REAL Studio 2010r1 Personal on Linux Ubuntu 9.10 Desktop
Occasional blog


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 10:34 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3261
Location: England
Steve Garman wrote:
I'll try to knock together a blow-by-blow description of creating this immensely simple subclass later
Not very polished but it's up at rbjottings.blogspot.com

_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r5.1 Professional on Linux Ubuntu 9.04 Desktop
and REAL Studio 2010r1 Personal on Linux Ubuntu 9.10 Desktop
Occasional blog


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 3:56 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3261
Location: England
Steve Garman wrote:
I've thrown together a quick canvas subclass that does something similar with dragged text at http://rb.sgarman.net/sjgTextBox.rbp which may give you some clues as to how to start.
I'm told that at least one version of RB gives memory problems with
Code:
dim p as new Picture(0, 0, 2)
so I've changed the sample to use
Code:
dim p as new Picture(1, 1, 2)

_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r5.1 Professional on Linux Ubuntu 9.04 Desktop
and REAL Studio 2010r1 Personal on Linux Ubuntu 9.10 Desktop
Occasional blog


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 12:42 pm 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
Steve,

This is just a "thank you" for the help. Not only does your sample code provide what I needed to write my program, but also it provides a concrete example of subclassing that should get me closer to understanding how classes and subclasses work.

Barry


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 4:19 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
I'm still working on understanding classes, subclasses, etc. (although I've printed out the related chapter from the RB User's Guide), but the other thing I need to know (besides how to drag a control) for a REALbasic program I'm working on is how to add new controls while the RB program is running.

How is this done when you're using classes, subclasses, etc., using the approach at http://rb.sgarman.net/sjgTextBox.rbp ?

Barry Traver


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 5:11 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 520
Location: Philadelphia, PA
Jordan,

You said this:

Quote:
For a control, you can simply capture the mousedown event and then in the MouseMove event have the control's coordinate (top, left) track with the MouseMove's (X and Y). This will move the control until the MouseUp event is detected. Of course in the MouseUp you'd position the moved control exactly where you'd like it to appear.

The problem I'm running into is this: When I click on the control, the X and Y I get for MouseDown anf MouseMove is the position on the control, NOT the position in the Window. (And when I then move the mouse with the mouse down, X and Y don't change.) (Also when I click on the control, MouseDown, MouseMove, and MouseUp for the Window do not fire.)

I'm probably missing something simple, but I can't seem to get a normal drag of a control working.

Barry Traver


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 9:06 am 
Offline
User avatar

Joined: Thu Jun 29, 2006 7:15 pm
Posts: 898
Location: I miss Arizona, U.S.
In the MouseDown event of a control put:
Code:
Dim D As DragItem
D = NewDragItem(Me.Left, Me.Top, Me.Width, Me.Height)
D.Text = Me.Name
D.Drag
Return True

In the Window's Open event put:
Code:
Self.AcceptTextDrop

In the Window's DropObject event put:
Code:
//Where MyControl is the control you want to move.
If obj.TextAvailable Then
Select Case obj.Text
Case "MyControl"
MyControl.Left = obj.DropLeft
MyControl.Top = obj.DropTop
MyControl.Width = obj.DropWidth
MyControl.Height = obj.DropHeight
End Select
End If

Good luck!
-Jailout2000

_________________
My Website | GroupChat | My Battle.net Bot
Image


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: rebrandsoftware and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group