mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-04 04:06:05 +13:00
Using layered window for cubes
This commit is contained in:
parent
a1c2ff035a
commit
76512162d2
7 changed files with 134 additions and 270 deletions
49
ShareX/CompanionCube.cs
Normal file
49
ShareX/CompanionCube.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2015 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX
|
||||
{
|
||||
public class CompanionCube
|
||||
{
|
||||
public bool IsActive { get; set; }
|
||||
public Point Location { get; set; }
|
||||
public Size Size { get; set; }
|
||||
public Rectangle Rectangle => new Rectangle(Location, Size);
|
||||
public int Speed { get; set; }
|
||||
|
||||
public CompanionCube(int size, int speed)
|
||||
{
|
||||
Size = new Size(size, size);
|
||||
Speed = speed;
|
||||
IsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.Properties;
|
||||
using ShareX.ScreenCaptureLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -39,40 +40,19 @@ public static class CompanionCubeManager
|
|||
{
|
||||
public static bool IsActive { get; set; }
|
||||
public static int CubeCount { get; } = 50;
|
||||
public static List<CompanionCube> Cubes { get; private set; }
|
||||
|
||||
private static List<CompanionCubeForm> cubes;
|
||||
private static CompanionCubesForm cubesForm;
|
||||
private static Timer timer;
|
||||
private static Stopwatch startTime;
|
||||
private static TimeSpan previousElapsed;
|
||||
private static Rectangle screen;
|
||||
|
||||
static CompanionCubeManager()
|
||||
{
|
||||
cubes = new List<CompanionCubeForm>();
|
||||
timer = new Timer();
|
||||
timer.Interval = 10;
|
||||
timer.Tick += Timer_Tick;
|
||||
}
|
||||
|
||||
public static void Toggle()
|
||||
{
|
||||
if (!IsActive)
|
||||
{
|
||||
IsActive = true;
|
||||
|
||||
screen = CaptureHelpers.GetScreenWorkingArea();
|
||||
|
||||
for (int i = 0; i < CubeCount; i++)
|
||||
{
|
||||
CompanionCubeForm cube = new CompanionCubeForm(MathHelpers.Random(200, 500), MathHelpers.Random(50, 100));
|
||||
cube.CubeLocation = new Point(MathHelpers.Random(screen.X, screen.X + screen.Width - cube.CubeSize),
|
||||
MathHelpers.Random(screen.Y - cube.CubeSize - 500, screen.Y - cube.CubeSize));
|
||||
cube.Show();
|
||||
cubes.Add(cube);
|
||||
}
|
||||
|
||||
startTime = Stopwatch.StartNew();
|
||||
timer.Start();
|
||||
Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -80,21 +60,58 @@ public static void Toggle()
|
|||
}
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (!IsActive)
|
||||
{
|
||||
IsActive = true;
|
||||
screen = CaptureHelpers.GetScreenWorkingArea();
|
||||
|
||||
if (cubesForm != null) cubesForm.Close();
|
||||
cubesForm = new CompanionCubesForm();
|
||||
cubesForm.Show();
|
||||
|
||||
Cubes = new List<CompanionCube>(CubeCount);
|
||||
|
||||
for (int i = 0; i < CubeCount; i++)
|
||||
{
|
||||
CompanionCube cube = new CompanionCube(MathHelpers.Random(50, 100), MathHelpers.Random(200, 500));
|
||||
cube.Location = new Point(MathHelpers.Random(screen.X, screen.X + screen.Width - cube.Size.Width),
|
||||
MathHelpers.Random(screen.Y - cube.Size.Height, screen.Y - cube.Size.Height + 500));
|
||||
Cubes.Add(cube);
|
||||
}
|
||||
|
||||
previousElapsed = TimeSpan.Zero;
|
||||
startTime = Stopwatch.StartNew();
|
||||
|
||||
timer = new Timer();
|
||||
timer.Interval = 10;
|
||||
timer.Tick += Timer_Tick;
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
if (IsActive)
|
||||
{
|
||||
timer.Stop();
|
||||
|
||||
foreach (CompanionCubeForm cube in cubes)
|
||||
if (timer != null)
|
||||
{
|
||||
if (cube != null && cube.IsActive)
|
||||
{
|
||||
cube.Close();
|
||||
}
|
||||
timer.Dispose();
|
||||
timer = null;
|
||||
}
|
||||
|
||||
cubes.Clear();
|
||||
if (cubesForm != null)
|
||||
{
|
||||
cubesForm.Close();
|
||||
cubesForm = null;
|
||||
}
|
||||
|
||||
if (Cubes != null)
|
||||
{
|
||||
Cubes.Clear();
|
||||
Cubes = null;
|
||||
}
|
||||
|
||||
IsActive = false;
|
||||
}
|
||||
|
@ -105,34 +122,51 @@ private static void Timer_Tick(object sender, EventArgs e)
|
|||
TimeSpan elapsed = startTime.Elapsed - previousElapsed;
|
||||
previousElapsed = startTime.Elapsed;
|
||||
|
||||
foreach (CompanionCubeForm cube in cubes)
|
||||
foreach (CompanionCube cube in Cubes)
|
||||
{
|
||||
if (!cube.IsActive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int velocityY = (int)(cube.Gravity * elapsed.TotalSeconds);
|
||||
Point newLoc = new Point(cube.CubeLocation.X, cube.CubeLocation.Y + velocityY);
|
||||
Rectangle newRect = new Rectangle(newLoc, new Size(cube.CubeSize, cube.CubeSize));
|
||||
int velocityY = (int)(cube.Speed * elapsed.TotalSeconds);
|
||||
Point newLocation = new Point(cube.Location.X, cube.Location.Y + velocityY);
|
||||
Rectangle newRectangle = new Rectangle(newLocation, cube.Size);
|
||||
bool intersect = false;
|
||||
|
||||
foreach (CompanionCubeForm cube2 in cubes)
|
||||
foreach (CompanionCube cube2 in Cubes)
|
||||
{
|
||||
if (cube != cube2 && cube2.IsActive && (newRect.IntersectsWith(cube2.CubeRectangle) || cube.CubeRectangle.IntersectsWith(cube2.CubeRectangle)))
|
||||
if (cube != cube2 && cube2.IsActive && (newRectangle.IntersectsWith(cube2.Rectangle) || cube.Rectangle.IntersectsWith(cube2.Rectangle)))
|
||||
{
|
||||
intersect = true;
|
||||
newLoc = new Point(cube.CubeLocation.X, cube2.CubeLocation.Y - cube.CubeSize);
|
||||
newLocation = new Point(cube.Location.X, cube2.Location.Y - cube.Size.Height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!intersect && newLoc.Y + cube.CubeSize > screen.Y + screen.Height)
|
||||
if (!intersect && newLocation.Y + cube.Size.Height > screen.Y + screen.Height)
|
||||
{
|
||||
newLoc = new Point(cube.CubeLocation.X, screen.Height - cube.CubeSize);
|
||||
newLocation = new Point(cube.Location.X, screen.Height - cube.Size.Height);
|
||||
}
|
||||
|
||||
cube.CubeLocation = newLoc;
|
||||
cube.Location = newLocation;
|
||||
}
|
||||
|
||||
DrawCubes();
|
||||
}
|
||||
|
||||
private static void DrawCubes()
|
||||
{
|
||||
using (Bitmap companionCube = Resources.CompanionCube)
|
||||
using (Bitmap surface = new Bitmap(screen.Width, screen.Height))
|
||||
using (Graphics g = Graphics.FromImage(surface))
|
||||
{
|
||||
foreach (CompanionCube cube in Cubes)
|
||||
{
|
||||
g.DrawImage(companionCube, new Rectangle(CaptureHelpers.ScreenToClient(cube.Location), cube.Size));
|
||||
}
|
||||
|
||||
cubesForm.SelectBitmap(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,9 +148,7 @@ private void rtb_LinkClicked(object sender, LinkClickedEventArgs e)
|
|||
|
||||
private void AboutForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
#if STEAM
|
||||
CompanionCubeManager.Stop();
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Animation
|
||||
|
@ -235,13 +233,11 @@ private void cLogo_Draw(Graphics g)
|
|||
|
||||
private void cLogo_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
#if STEAM
|
||||
if (e.Button == MouseButtons.Middle)
|
||||
{
|
||||
CompanionCubeManager.Toggle();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!isEasterEggStarted)
|
||||
{
|
||||
|
|
56
ShareX/Forms/CompanionCubeForm.Designer.cs
generated
56
ShareX/Forms/CompanionCubeForm.Designer.cs
generated
|
@ -1,56 +0,0 @@
|
|||
namespace ShareX
|
||||
{
|
||||
partial class CompanionCubeForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// CompanionCubeForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Gainsboro;
|
||||
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
|
||||
this.ClientSize = new System.Drawing.Size(284, 261);
|
||||
this.DoubleBuffered = true;
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.Name = "CompanionCubeForm";
|
||||
this.ShowInTaskbar = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
|
||||
this.Text = "CompanionCubeForm";
|
||||
this.TopMost = true;
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CompanionCubeForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.CompanionCubeForm_Load);
|
||||
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.CompanionCubeForm_MouseClick);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -24,7 +24,6 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
@ -36,51 +35,18 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
namespace ShareX
|
||||
{
|
||||
public partial class CompanionCubeForm : Form
|
||||
public class CompanionCubesForm : LayeredForm
|
||||
{
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
private Point cubeLocation;
|
||||
|
||||
public Point CubeLocation
|
||||
public CompanionCubesForm()
|
||||
{
|
||||
get
|
||||
{
|
||||
return cubeLocation;
|
||||
}
|
||||
set
|
||||
{
|
||||
cubeLocation = value;
|
||||
Location = cubeLocation;
|
||||
}
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
Bounds = CaptureHelpers.GetScreenBounds();
|
||||
Shown += CompanionCubesForm_Shown;
|
||||
}
|
||||
|
||||
public int CubeSize { get; private set; }
|
||||
public Rectangle CubeRectangle => new Rectangle(CubeLocation, new Size(CubeSize, CubeSize));
|
||||
public int Gravity { get; private set; }
|
||||
|
||||
public CompanionCubeForm(int gravity, int size)
|
||||
private void CompanionCubesForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
CubeSize = size;
|
||||
Gravity = gravity;
|
||||
InitializeComponent();
|
||||
BackgroundImage = (Bitmap)ImageHelpers.ResizeImage(Resources.CompanionCube, CubeSize, CubeSize);
|
||||
}
|
||||
|
||||
private void CompanionCubeForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
Size = new Size(CubeSize, CubeSize);
|
||||
}
|
||||
|
||||
private void CompanionCubeForm_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
IsActive = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CompanionCubeForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
IsActive = false;
|
||||
this.ShowActivate();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -97,6 +97,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CompanionCube.cs" />
|
||||
<Compile Include="CompanionCubeManager.cs" />
|
||||
<Compile Include="Controls\BeforeUploadControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
|
@ -122,12 +123,9 @@
|
|||
<Compile Include="Forms\ClipboardFormatForm.Designer.cs">
|
||||
<DependentUpon>ClipboardFormatForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\CompanionCubeForm.cs">
|
||||
<Compile Include="Forms\CompanionCubesForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\CompanionCubeForm.Designer.cs">
|
||||
<DependentUpon>CompanionCubeForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\EncoderProgramForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
@ -547,9 +545,6 @@
|
|||
<EmbeddedResource Include="Forms\ClipboardFormatForm.zh-CN.resx">
|
||||
<DependentUpon>ClipboardFormatForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\CompanionCubeForm.resx">
|
||||
<DependentUpon>CompanionCubeForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\EncoderProgramForm.de.resx">
|
||||
<DependentUpon>EncoderProgramForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
|
Loading…
Reference in a new issue