New topic: 

Selecting Objects in a Canvas (iOS iBuilder)

<http://forums.realsoftware.com/viewtopic.php?t=46774>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        simulanics          Post subject: Selecting Objects in a Canvas 
(iOS iBuilder)Posted: Thu Jan 31, 2013 11:03 pm                                 
Joined: Sun Aug 12, 2007 10:10 am
Posts: 986
Location: Boiling Springs, SC                When creating objects on a canvas, 
how do you select the object by clicking it. If many objects overlap on the 
canvas, the bottom-most object gets selected rather than the top-most (object 
being clicked).

Test:
1) Add a NavigationBar and a Button
2) drag the button over the navigationbar
3) click the button...and the navigationbar gets selected?!?

So... how do you select the "object being clicked"?

At the moment, I'm selecting objects from the Control list and setting Top/Left 
property values...would like to be able to click and drag them around without 
activating the bottom-most objects 

Download pre-beta test environment:
(Windows, Mac (Intel & Intel Carbon), Linux)
http://realdevspot.com/ibuilder/

About: If you wish to test building an app, add a button and a navigationbar, 
set the properties of both... and be sure to add an "appname" under the app 
tab...second screen before pushing build... ibuilder will generate gcc code and 
makefile to build native ios apps without using xcode 
**Note: All other ios controls were not added in the pre-beta test environment 
and the code window has been disabled...this is for canvas object test example 
only! Possibly an open-source project in the future...

Simulanics iBuilder (beta) Screenshot:
      
_________________
Matthew A. Combatti
Real Studio 2012 r1.2
Visit Real Studio Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Beta
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS
~All REAL Compatible~  
                             Top                charonn0          Post subject: 
Re: Selecting Objects in a Canvas (iOS iBuilder)Posted: Thu Jan 31, 2013 11:36 
pm                                 
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1102
Location: San Francisco, CA, USA                In your code that detects 
clicks, move the clicked object to the bottom of the list (I'm assuming an 
array.) This way, the last object in the array will always be the object most 
recently clicked, and the topmost object overlapping a point will be the one 
farthest down the array matching those coordinates. 

Objects can be moved backwards and forwards in the array to reflect which 
objects are on top of which; moving an object to the end of the array would 
bring the object to the top.      
_________________
Boredom Software  
                             Top                simulanics          Post 
subject: Re: Selecting Objects in a Canvas (iOS iBuilder)Posted: Thu Jan 31, 
2013 11:51 pm                                 
Joined: Sun Aug 12, 2007 10:10 am
Posts: 986
Location: Boiling Springs, SC                Currently I'm using the following 
method...how would I apply this technique...

Function MouseDown(X As Integer, Y As Integer) As Boolean
  // Find the object that is where the user just clicked
  
  mSelected = False
  
  For Each m As iosObject In mCanvasObjects
  If X >= m.Left And X <= m.Right And _
    Y >= m.Top And Y <= m.Bottom Then
  SelectedObject = m
  
  Return True
  End If
  Next
  
  DeselectAll
End Function


selectedobject is a computed property.its set is

Set
  Dim i as Integer
  DeselectAll
  i = -1
  
  For Each m As iosObject In mCanvasObjects
  If m Is value Then
  i = i + 1
  m.Selected = True
  
  End If
  Next
  
  
  mSelectedObject = value
  
  ObjectSelected(value)
  
  Invalidate(False)
End Set


I have sent you a link to the object classes to take a look at     
_________________
Matthew A. Combatti
Real Studio 2012 r1.2
Visit Real Studio Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Beta
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS
~All REAL Compatible~  
                             Top                simulanics          Post 
subject: Re: Selecting Objects in a Canvas (iOS iBuilder)Posted: Fri Feb 01, 
2013 12:18 am                                 
Joined: Sun Aug 12, 2007 10:10 am
Posts: 986
Location: Boiling Springs, SC                I've attempted to read the array 
backwards which works as such


mSelected = False

Dim b as integer = mCanvasObjects.Ubound
Dim m as CanvasObject
Dim i as integer

for i = 0 to mCanvasObjects.Ubound
  m = mCanvasObjects(mCanvasObjects.Ubound - i)
  If X >= m.Left And X <= m.Right And _
  Y >= m.Top And Y <= m.Bottom Then
  SelectedObject = m
  
  Return True
  End If
  
next i

DeselectAll


but is this an inefficient method? I'd like to be able to add a contextual menu 
to "bring forward" "send back" so I'd need to get the parent index of the 
control arrayed under the selected control as well :-/ perhaps comparing the 
x,y of all controls in the array and creating an array of controls in this 
index by order and "swapping" their order?      
_________________
Matthew A. Combatti
Real Studio 2012 r1.2
Visit Real Studio Developer's Spot!
Systems I Use:
Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Beta
Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/
Windows Server 2011/CentOS 5.4 /ReactOS/SimOS
~All REAL Compatible~  
                             Top                charonn0          Post subject: 
Re: Selecting Objects in a Canvas (iOS iBuilder)Posted: Fri Feb 01, 2013 12:25 
am                                 
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1102
Location: San Francisco, CA, USA                Use an index in your For...Next 
loops to search the objects array sequentially. Using For Each...Next is less 
useful when dealing with something you should treat like a stack. Use the array 
like a numbered list rather than a unordered group of objects.

e.g.
Function MouseDown(X As Integer, Y As Integer) As Boolean
  // Find the object that is where the user just clicked
  
  mSelected = False
  
  For i As Integer = UBound(mCanvasObjects) DownTo 0 'Use an index
  Dim m As iosObject = mCanvasObjects(i)
  If X >= m.Left And X <= m.Right And _
    Y >= m.Top And Y <= m.Bottom Then
  mCanvasObjects.Remove(i) 'remove from its place in the list
  mCanvasObject.Append(m) 'move it to the end
  
  Return True
  End If
  Next
  DeselectAll
End Function


You can then handle painting each object in proper order (back to front) by 
looping over the array again, but in reverse order.

Edit to add:
The initial ordering of the list is up to you. In your object classes the order 
is never changed unless an object is destroyed. Since For Each loops are done 
sequentially by RB anyway, the order in which objects are "found" in the array 
via For Each is the order in which they were created. So, the "older" object 
always comes first.      
_________________
Boredom Software  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to