Object Drawing Priority on overlap? example reques
BlitzMax Forums/BlitzMax Beginners Area/Object Drawing Priority on overlap? example reques
| ||
Well, let's say you have multiple instance of the same object with a Draw() Method of their own. But whenever you draw all of the them the last one being drawn is on top of all the others. All Objects are Draggable yet whenever you select one you want it to have the priority over all the others.. and thus being on "top" How can I order the way my object are being drawn and so when one is selected it's the one with the priority so it should stay ontop.... list of orders.. order numbers... Hmmm, any though on this, a simple example is very very welcomed. Thanks guys! |
| ||
Well you might try making a sort of depth value. Then you could sort the objects by depth and cause each one to draw. This is just an idea there are probably better ways. :) |
| ||
I though of a way but I can't come up on how I would make it happen, basicly all objects have different Order Int that then when you click on a square it should bring it up on top of the other because it changes it's order to 0... headache... Graphics 800,600 Global ARect:TRect[] ARect=New TRect[3] For Local i:Int = 0 To ARect.Length-1 ARect[i]=New TRect Next ARect[0].Create(10,10,100,100) ARect[0].SColor(10,10,100) ARect[0].Order=0 ARect[1].Create(60,60,100,100) ARect[1].SColor(60,60,100) ARect[1].Order=1 ARect[2].Create(120,120,100,100) ARect[2].SColor(120,120,100) ARect[2].Order=2 Repeat For Local i2:Int=0 To ARect.Length-1 ARect[i2].Update() Next Cls For Local i3:Int=0 To ARect.Length-1 ARect[i3].Draw() Next SetColor(255,255,255) DrawText "A = "+ARect[0].Order,10,120 DrawText "B = "+ARect[1].Order,10,140 DrawText "C = "+ARect[2].Order,10,160 Flip Until KeyHit(KEY_ESCAPE) End Type TRect ' Vars Field X:Int, Y:Int Field Width:Int, Height:Int Field Order:Int Field r,g,b ' Create Method Create( sx:Int, sy:Int, sw:Int, sh:Int ) X=sx Y=sy Width=sw Height=sh End Method ' Color Method SColor(r2,g2,b2) r=r2 g=g2 b=b2 End Method ' Draw Method Draw() SetColor(r,g,b) DrawRect X, Y, Width, Height End Method ' Update Method Update() Local mx=MouseX() Local my=MouseY() If( mx < X + Width)And( mx > X)And( my < Y + Height )And( my > Y)Then If MouseHit(1)Then Order=0 EndIf EndIf End Method End Type problem is how to make it draw by order number...? |
| ||
You could put them in a list. When one is selected remove it from it's current position and add it to the bottom. BTW Have you actually bought Bmax now then? |
| ||
I tried to do that just now but I dunno what I'm doing wrong, there's no good tutorial on how to manipulate TList with almsot all commands in there... I'm trying to remove the last object and put it in first place.. Local test44:QGI_TWindow = WOrder.Last ListRemove(WOrder, WOrder.LastLink) ListAddFirst WOrder, test44 |
| ||
There are 100's of posts regarding TLists and their use. Anyway : |
| ||
oh that's how it works, thanks Tonyg. Yhea there are some posts about TList but I couldn't find one that answer most of my questions about TList. Plus there isn't much information on HOW TO USE TList commands in the manual. I mean I know how to make one how to add and delete entries but how to manipulate entries is something else. I understand everything in your code Tonyg except one part ttest( mylist.last() ) you get the last entry in the TList however what is ttest(), I would've never have though about using it like that, I just kept getting error.. unable to convert object amonsgt other error. I really appreciate when you do little example such as this, sorry for the trouble tonyg. (that way I can really see how to do things or what I really dont understand) Is this doable with an array by the way instead of using a TList and is an Array faster or it doesn't matter? |
| ||
I doubt the speed will matter but you will get different results. I'll use letters to avoid confusing the objects with their position in the list. (And the list will start at 1, for simplicity). I'm also assuming you draw the first object of a list first, and move in a forward direction. (In that case the object at the end of the list is drawn last and so on top. Tonyg might be doing it the wrong way round by adding the object to the start of the list, but the principle is the same.) Let's say you have objects A to E, with 1 being behind and 5 in front. If you want C to be in front, using the list method C will be plucked from its location at 3 and stored in a temp variable. The rest of the list will now update so D is now in 3, E is now in 4 and 5 is empty. Now C is added to the end of the list at 5. The final order is thus A B D E C Unlike lists, the elements of an array do not (automatically) update themselves when elements are added or remove. So if you had objects A to E in 1 to 5 again, and you removed C to a temp variable from 3. 3 is now empty, and D remains in 4 and E remains in 5. Now you cut and paste 5 into 3 to fill the gap, and put C into 5. Essentially you have swapped C and E in the array. The final order is thus A B E D C Either method will work for putting the current object on top. THe question is whether the order of the objects not on top counts. If not, use whichever method you find easiest. Here's a question for you... which method does Windows use for its windows? (Or seem to use anyway) |
| ||
Tonyg might be doing it the wrong way round by adding the object to the start of the list, but the principle is the same Just showing what was asked : I'm trying to remove the last object and put it in first place.. @Apollonius, 'Last' is a TList method. A method is like a function but works against a particular instance of a type(in this case Mylist). However, the method returns a base Object and not, in my case, a TTest object. Using : Local switchtemp:ttest = ttest(mylist.last() ) says : 'Return the last object on the list and convert it into a TTest object'. This conversion step is called 'Casting' and there has been lots of discussion about it. |
| ||
Ah sorry I missed that! I thought he wanted a particular object to move to the front, which would probably mean sending it to the last of the list. |