GPWiki.org
GPWiki.org
It is currently Wed May 22, 2013 10:45 am

All times are UTC




Post new topic Reply to topic  [ 112 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: Sun Mar 22, 2009 11:07 pm 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Like most, I'm on a team developing out a mmorpg, my task is with the gui design and concepts. I've seen alot of text on the topics and a few examples from all over the web, including some from this site but none seem to help me on my issue.

Since I'm new to directx and vb, I've gotten pretty far already and now I'm stuck on the last aspect of the coding, which is z-order and focus. My issue is around trying to determine the clickable area and who should get focus.

On the drawing table, I wrote it the way I thought window objects had focus in windows. Example would be.

3. If the window shown doesn't have focus then get its zorder and eliminate all the windows above its zorder's areas (that overlap it), from its clickable area.

I think that's the correct way of handling it but I haven't been able to get that function to work. I'm to the point of starting all over, but if anyone has a functioning example source code of how to handle the window zorder focus and clickable areas, that would be great! :x


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 11:53 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
when a GUI object gets clicked upon, it gives a object_click event.

In the code for this event you can call the object's zorder function to bring it to the top. Argument may not be necessary.

from sketchy memory:

Code:
Private Sub Command1_Click()
  Call Command1.ZOrder(0)
  ''other stuff maybe?

End Sub

_________________
I ain't pushing no moon buttons.


Last edited by Jasmine on Mon Mar 23, 2009 12:00 am, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 11:57 pm 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Sorry, but that is for window event objects not directx objects created at runtime. Sorry if I wasn't clear on that. :( We are creating the GUI from the ground up, we do not want to use 3rd party libs. By Window, I mean a directx rect area classed as a window type object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:00 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
Would this be like you are drawing your own GUI objects all as rectangles within the same output window and you don't have click events on these... and you want an algorithm for custom click event?

ie, a function

Code:
Which_Object_Is_Under_The_Mouse_Cursor_At_Mouse_Coordinate(mouse_x as Integer, mouse_y as Integer) as Integer


and another function

Code:
Bring_The_Object_Number_In_The_Argument_To_The_Top(The_Argument as Integer) as Boolean

_________________
I ain't pushing no moon buttons.


Last edited by Jasmine on Mon Mar 23, 2009 12:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:04 am 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine wrote:
Would this be like you are drawing your own GUI objects all as rectangles within the same output window and you don't have click events on these... and you want an algorithm for custom click event?

ie, a function

Code:
Which_Object_Is_At(mouse_x as Integer, mouse_y as Integer) as Integer


Yes, but this area of coding is done, the problem is in determineing the area of clickable events for a given window.

So, example would be, say you have 3 windows (drawn RECTS) on the screen. window 1 is on top, window 2 middle and window 3 bottom. Window 1 overlaps window 2 and 3, window 2 only overlaps 3 and window 3 doesnt overlap anyone. How do you determine the click able of window 2 or window 3?

My Thought is ..

3. If the window shown doesn't have focus then get its zorder and eliminate all the windows above its zorder's areas (that overlap it), from its clickable area.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:11 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
This doesn't follow on how I read it :x

All you need is to create that first function I mentioned to return which rectangle is clicked, by:

1. testing if the click is within the bounds of a rectangle.
2. making sure you are NOT in the bounds of rectangles with lower Z-order. (Lower z-order means nearer the front)


The second function I mentioned just jiggles the Z-orders, which brings the chosen one to the top when it's redrawn.

_________________
I ain't pushing no moon buttons.


Last edited by Jasmine on Mon Mar 23, 2009 3:23 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:14 am 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine wrote:
This doesn't follow on how I read it :x

All you need is to create that first function to return which rectangle is clicked, by:

1. testing if the click is within the bounds of that rectangle
2. testing to make sure you are NOT in the bounds of rectangles with higher Z-order.


The second function I mentioned just jiggles the Z-orders, which brings it to the top when it's redrawn.



I think your 2. is where I'm stuck


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:16 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
The key to solving function one is sorting your objects by Z-order. The first one that contains the mouse cursor is then the one clicked --> bail out --> return number.

The key to solving function two is again to sort your objects by Z-order, and determine which subsequence is being rotated. And they are being rotated because you're using the same indices.

Always remember that rotations go well with modular arithmetic. :)

_________________
I ain't pushing no moon buttons.


Last edited by Jasmine on Mon Mar 23, 2009 12:24 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:20 am 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine wrote:
The key to solving function one is sorting your objects by Z-order. The first one that contains the mouse cursor is then the one clicked --> bail out --> return number.


Ok, so I have the zorder problem solved. The next aspect should be..?

1. check if x/y rect is in any intersecting rects of windows above it's zorder
a. if yes, then exit
b. if no, then give that window focus, update zorder

right?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:27 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
yes but it won't be an issue if they're sorted. You won't need to check for 'higher' rects because there are none if they're sorted. The bail out will catch the right one -- It will be the first rect in that sorted list that bounds the mouse coordinate.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:37 am 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine wrote:
yes but it won't be an issue if they're sorted. You won't need to check for 'higher' rects because there are none if they're sorted. The bail out will catch the right one -- It will be the first rect in that sorted list that bounds the mouse coordinate.


I'm not following that, can you provide an example.

Right now the zorderid is assigned to each window based on the the total number of windows open. The zorderlist is a collection of the those id's. I don't understand about the higher rects.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:42 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
I don't have time to write example code now. I'm going to sleep.

If nobody else replies I'll return tomorrow evening and help (18 hours from now) :)

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 12:46 am 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine wrote:
I don't have time to write example code now. I'm going to sleep.

If nobody else replies I'll return tomorrow evening and help (18 hours from now) :)


Thanks, example code is to much then a simple flowchart with english phrase of what should be doing would be great! thank!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 2:01 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
when you click, loop through the windows based on zorder. the window with the lowest zorder is the one that is clicked on

Code:
for i = 0 to window_zorder_count -1
    if intersectRect(dstrect, mouse_rect, window(window_zorder_list(i)).RECT) > 0 then
        'bring that window to the top
        exit for
    end if
next i

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 3:20 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6714
Location: Oxford, Englandshire
I my GUI project I used a linked list to order the windows.

The list becomes the Z order for the windows.

When checking for a click, work along the list keeping track of the last window whose rectangle co-ords encompass the mouse position. When you get to the end of the list, bring the node for last vaild window to the end of the list.

Draw the windows using the same list, job done.

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 4:32 pm 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Moglor wrote:
when you click, loop through the windows based on zorder. the window with the lowest zorder is the one that is clicked on

Code:
for i = 0 to window_zorder_count -1
    if intersectRect(dstrect, mouse_rect, window(window_zorder_list(i)).RECT) > 0 then
        'bring that window to the top
        exit for
    end if
next i



I don't understand this, why use IntersectRect and not PtInRect?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 5:41 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
Alright neruos, I'll make a little demo up for you now.

It won't be directx. It'll be short and simple so it's easier to see what it's doing.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 6:27 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
Code:
VERSION 5.00
Begin VB.Form Form1
   AutoRedraw      =   -1  'True
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Jasmine's Awesome GUI Demo"
   ClientHeight    =   9000
   ClientLeft      =   45
   ClientTop       =   345
   ClientWidth     =   12000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   600
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   800
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   435
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   2475
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Type rect
  X As Integer
  Y As Integer
  xL As Integer
  yL As Integer
  z As Integer
  colour As Long
End Type
Dim rect(255) As rect
Dim rects As Integer
Dim sort(255) As Integer
Dim dragx, dragy As Integer

Public Function WhichRect(ByVal X, ByVal Y)
WhichRect = 0: i = 1
Do
  j = sort(i)
  If X >= rect(j).X And Y >= rect(j).Y And X <= rect(j).X + rect(j).xL And Y <= rect(j).Y + rect(j).yL Then WhichRect = j
  i = i + 1
Loop While WhichRect = 0 And i <= rects
End Function

Public Function SendToFront(ByVal N)
S = rect(N).z
For i = 1 To S
  j = sort(i)
  rect(j).z = (rect(j).z Mod S) + 1
Next
DoSort
End Function

Public Sub DoSort()
For i = 1 To rects
  sort(rect(i).z) = i
Next
End Sub

Public Sub redraw()
Cls
For i = 1 To rects
  j = sort(rects - i + 1)
  Line (rect(j).X, rect(j).Y)-(rect(j).X + rect(j).xL, rect(j).Y + rect(j).yL), rect(j).colour, BF
  Form1.CurrentX = rect(j).X + rect(j).xL / 2
  Form1.CurrentY = rect(j).Y + rect(j).yL / 2
  Form1.Print rect(j).z
Next
Command1.Caption = rects & " GUI Object(s)"
End Sub


Public Sub MakeRect(ByVal X, ByVal Y, ByVal xL, ByVal yL, ByVal colour)
If rects < 255 Then
rects = rects + 1
rect(rects).X = X: rect(rects).Y = Y
rect(rects).xL = xL: rect(rects).yL = yL
rect(rects).z = rects
sort(rects) = rects
rect(rects).colour = colour
End If
End Sub

Public Sub DeleteRect(ByVal N)
If rects > 0 And N > 0 Then
S = rect(N).z
For i = S + 1 To rects
  j = sort(i)
  rect(j).z = rect(j).z - 1
Next
rect(N) = rect(rects)
rects = rects - 1
DoSort
End If
End Sub



Private Sub Form_Load()
Command1_Click
End Sub

Private Sub Command1_Click()
MakeRect 600 * Rnd, 400 * Rnd, 50 + Rnd * 200, 50 + Rnd * 200, RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
redraw
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1:
    dragx = X: dragy = Y
    SendToFront WhichRect(X, Y)
Case 2:
    DeleteRect WhichRect(X, Y)
End Select
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
  i = sort(1)
  rect(i).X = rect(i).X + X - dragx
  rect(i).Y = rect(i).Y + Y - dragy
  dragx = X: dragy = Y
  redraw
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
redraw
End Sub


_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 6:36 pm 
Ankle Nibbler

Joined: Sun Mar 22, 2009 10:55 pm
Posts: 130
Jasmine: That is exactly what I wanted! You didn't have to go thru the trouble, but it is much appreitated, I'm sure many others might benefit from this! :D

I do notice that you can drag the rects OUTSIDE the rect, can this be eliminated by doing a ptinrect over the current focus rect?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 7:40 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
neruos wrote:
Jasmine: That is exactly what I wanted! You didn't have to go thru the trouble, but it is much appreitated, I'm sure many others might benefit from this! :D

I do notice that you can drag the rects OUTSIDE the rect, can this be eliminated by doing a ptinrect over the current focus rect?


Yeah, the dragging wasn't really part of the demo. It was added only so you can move stuff around to see the zordering at work :P

This is the dragging code at the moment:
Code:
If Button = 1 Then
  i = sort(1)
  rect(i).X = rect(i).X + X - dragx
  rect(i).Y = rect(i).Y + Y - dragy
  dragx = X: dragy = Y
  redraw
End If


The dragging works by moving the highest rect whenever the mouse drags.

To perfect the dragging I'd create another variable to track which rectangle is being dragged, and set this in the mouse_down.

this is totally untested, but something like:

Code:
Dim DraggedRect as Integer

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1:
    dragx = X: dragy = Y
    DraggedRect = WhichRect(X, Y)
    SendToFront DraggedRect
Case 2:
    DeleteRect WhichRect(X, Y)
End Select
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 and DraggedRect>0 Then
  i = DraggedRect
  rect(i).X = rect(i).X + X - dragx
  rect(i).Y = rect(i).Y + Y - dragy
  dragx = X: dragy = Y
  redraw
End If
End Sub
 

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 112 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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® Forum Software © phpBB Group