Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------------
- // 2 App Positioning Handler
- // ------------------------------------------------------------
- // Needs to: onMouseClick->GetPositionOfMouse->FindWhatIcon->onMouseDrag->MoveIcon->SaveIconPos
- package BlockOSPackage
- {
- // Detects when the left mouse button is pushed down
- function GuiMouseEventCtrl::onMouseDown(%this, %mod, %pos, %click)
- {
- // Check if it's the BlockOS control
- if(%this.getName() $= "BlockOS_MouseCapture")
- {
- // Get the icon the mouse clicked on
- %obj = getIconFromPos(%pos);
- if(isObject(%obj))
- {
- // Store the icon object
- BlockOS_MouseCapture.selectedIcon = %obj;
- BlockOS_MouseCapture.selectedIcon.originalPos = %obj.position;
- }
- }
- // Make sure we don't break everything else by parenting the function
- parent::onMouseDown(%this, %mod, %pos, %click);
- }
- // This function is called when a user drags the mouse
- function GuiMouseEventCtrl::onMouseDragged(%this, %bool, %pos, %x)
- {
- // Check if it's the BlockOS control
- if(%this.getName() $= "BlockOS_MouseCapture")
- {
- // Find what icon the user clicked on in the previous function
- %obj = BlockOS_MouseCapture.selectedIcon;
- // Some maths that put the cursor to the center of the icon for movement
- %x = getWord(%pos, 0) - (getWord(BlockOS_MouseCapture.selectedIcon.extent, 0) / 2);
- %y = getWord(%pos, 1) - (getWord(BlockOS_MouseCapture.selectedIcon.extent, 1) / 2);
- // Moves the icon as the mouse moves
- %obj.position = %x SPC %y;
- }
- // Make sure we don't break everything else by parenting the function
- parent::onMouseDragged(%this, %bool, %pos, %x);
- }
- // This function is called when the user let's go of the left mouse button
- function GuiMouseEventCtrl::onMouseUp(%this, %mod, %pos, %click)
- {
- // Again, to check if it's the BlockOS control
- if(%this.getName() $= "BlockOS_MouseCapture")
- {
- // Now, if the user has not dragged the icon
- if(BlockOS_MouseCapture.selectedIcon.position $= BlockOS_MouseCapture.selectedIcon.originalPos)
- {
- // We run the icon's command
- eval(BlockOS_MouseCapture.selectedIcon.command);
- }
- else
- {
- // If the user has dragged the icon, we run a check to see if it's in a valid place
- schedule(100, 0, BlockOSIconValidation, BlockOS_MouseCapture.selectedIcon);
- // We then save these to the desktop.dat file
- schedule(500, 0, BlockOS_SaveIconPositions);
- }
- // Clears the selected icon from the control
- BlockOS_MouseCapture.selectedIcon = "";
- }
- // Make sure we don't break everything else by parenting the function
- parent::onMouseUp(%this, %mod, %pos, %click);
- }
- // This function is called when the right mouse button is pressed
- function GuiMouseEventCtrl::onRightMouseDown(%this, %mod, %pos, %click)
- {
- // Again, to check if it's the BlockOS control
- if(%this.getName() $= "BlockOS_MouseCapture")
- {
- // Get the icon the mouse clicked on
- %object = getIconFromPos(%pos);
- if(isObject(%object))
- {
- // If this icon does have a right click menu,
- if(!%object.disableRightClick)
- {
- // this generates the menu
- generateRightClickMenu(%object);
- }
- }
- }
- // Make sure we don't break everything else by parenting the function
- parent::onRightMouseDown(%this, %mod, %pos, %click);
- }
- // This function is called when the right mouse button is released, however we currently don't have a use for it
- // but it's here anyway :D
- function GuiMouseEventCtrl::onRightMouseUp(%this, %mod, %pos, %click)
- {
- if(%this.getName() $= "BlockOS_MouseCapture")
- {
- }
- parent::onRightMouseUp(%this, %mod, %pos, %click);
- }
- };
- // Start the mouse functions
- activatePackage(BlockOSPackage);
- // This is the function we use to check if the icon is in a valid position
- function BlockOSIconValidation(%iconObject)
- {
- // Get the x and y positions of the icon
- %x = getWord(%iconObject.position, 0);
- %y = getWord(%iconObject.position, 1);
- // Check if the icon is on top of the bin
- if(getIconFromPos(%iconObject.position).getName() $= "bin")
- {
- // Just so the bin can't delete itself
- if(%iconObject.getName() !$= "bin")
- {
- // Check if the icon is default
- if(!%iconObject.noDelete)
- {
- // If not delete the icon from the canvas
- %iconObject.delete();
- %isSorted = true;
- }
- }
- }
- // If the icon is on top of the sidebar
- if(%x < 100)
- {
- // Snap it into the sidebar
- addToSideBar(%iconObject);
- %isSorted = true;
- }
- // If it isn't in on the sidebar
- if(%x > 100 && %iconObject.isSidebar)
- {
- // Remove it if it's on it.
- removeFromSideBar(%iconObject);
- }
- // If the icon is overlapping the top bar
- if(%y < 30 && !%iconObject.isSidebar)
- {
- // snap the icon back to it's original position
- %iconObject.position = %iconObject.originalPos;
- %isSorted = true;
- }
- // This simply snaps the icons to the 66x66px grid
- %x = mRound(%x / 66) * 66;
- %y = mRound(%y / 66) * 66;
- // if the icon is not sorted by any of the previous code
- if(!%isSorted)
- {
- // Put it where the user requested
- %iconObject.position = %x SPC %y;
- }
- }
- function getIconFromPos(%pos)
- {
- // Get the X and Y positions of the cursor
- %mouseX = getWord(%pos, 0);
- %mouseY = getWord(%pos, 1);
- // Loop through all of the icons
- for(%i = 0; %i < BOS_IconGroup.getCount(); %i++)
- {
- // For each one, get the X and Y positions and dimensions
- %obj = BOS_IconGroup.getObject(%i);
- %iconXpos = getWord(%obj.position, 0);
- %iconYpos = getWord(%obj.position, 1);
- %iconXDimension = getWord(%obj.extent, 0);
- %iconYDimension = getWord(%obj.extent, 1);
- // Check if the cursor is within the area of the icon
- if(%mouseX >= %iconXpos && %mouseY >= %iconYpos && %mouseX < %iconXpos + %iconXDimension && %mouseY < %iconYpos + %iconYDimension)
- {
- // If it is, return the icon object
- return %obj;
- }
- }
- // If we haven't found one there, return false
- return false;
- }
- function mRound(%a)
- {
- // Either round up or down
- if(%a - mFloor(%a) > 0.5)
- return mCeil(%a);
- else
- return mFloor(%a);
- }
- // Gui Component
- new GuiMouseEventCtrl(BlockOS_MouseCapture) {
- profile = "GuiDefaultProfile";
- horizSizing = "width";
- vertSizing = "height";
- position = "0 0";
- extent = "640 480";
- minExtent = "8 2";
- visible = "1";
- lockMouse = "0";
- };
Advertisement
Add Comment
Please, Sign In to add comment