public void MouseMove(int x, int y) { // If our left mouse button is down, we can apply dragging // processing on our focused scene object. if (this.MouseLeftDown && this._curFocus != null) { this._curFocus.Drag(x, y); } // Make sure that we actually initialized the scene system. if (this._UIObject != null) { // Make sure that we actually have scene objects in our current state. if (this._UIObject[(int)LoL.State] != null) { // Loop through all possible values for the ZOrder. for (int z = ZOrder.GetHighZ(); z >= 0; z--) { // Loop through every scene object we have in our current state. foreach (var obj in this._UIObject[(int)LoL.State]) { // Does the object's ZIndex match the ZOrder? if (obj.Z == z) { // Is the object visible? if (obj.Visible) { // Did we move our mouse within the area of the scene object? if (x >= obj.Left && x <= obj.Left + obj.Width) { if (y >= obj.Top && y <= obj.Top + obj.Height) { // We did. Invoke appropriate event-handling methods. obj.MouseMove(x - obj.Left, y - obj.Top); // We assume we have the object we moused over. // Return so that we don't apply similar logic on scene objects that // should not receive this processing. return; } } } // This break will break out of the current loop through all the scene objects for a respective Z value. // It ensures we don't waste time looking for another object that can't exist. break; } } } } } }
public void MouseDown(string button, int x, int y) { // Set the states of the appropriate mouse button to pressed. switch (button) { case "left": this.MouseLeftDown = true; break; case "middle": this.MouseMiddleDown = true; break; case "right": this.MouseRightDown = true; break; } // Make sure that the scene system has actually been initialized. if (this._UIObject != null) { // Make sure that we actually have scene objects in our current state. if (this._UIObject[(int)LoL.State] != null) { // Loop through every possible ZOrder value. for (int z = ZOrder.GetHighZ(); z >= 0; z--) { // Loop through all the scene objects in our current state. foreach (var obj in this._UIObject[(int)LoL.State]) { // Does the ZIndex match the ZOrder? if (obj.Z == z) { // Make sure that the object is visible. if (obj.Visible) { // Did we click within the area of the scene object? if (x >= obj.Left && x <= obj.Left + obj.Width) { if (y >= obj.Top && y <= obj.Top + obj.Height) { //If we had a previous scene object, let that object // know that it no longer has the focus. if (this._curFocus != null) { this._curFocus.HasFocus = false; } // Assign this scene object as our currently focused scene object and // let it know that it has our focus. this._curFocus = obj; this._curFocus.HasFocus = true; // Invoke the appropriate event handling methods. this._curFocus.MouseDown(x - obj.Left, y - obj.Top); this._curFocus.BeginDrag(x - obj.Left, y - obj.Top); // We assume that we have the object we clicked on. // Return so that we don't apply similar logic on scene objects that // should not receive this processing. return; } } } // This break will break out of the current loop through all the scene objects for a respective Z value. // It ensures we don't waste time looking for another object that can't exist. break; } } } } } }