Skip to content

Commit 41e9995

Browse files
author
Mattias
committed
Code ported to github.
1 parent 106df05 commit 41e9995

16 files changed

+2084
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Manual entries
2+
puzzles.js
3+
14
## Ignore Visual Studio temporary files, build results, and
25
## files generated by popular Visual Studio add-ons.
36

Picross.sln

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Picross", "Picross\Picross.csproj", "{837C94CF-B0D5-44FF-A367-823F4BB43F97}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|x86 = Debug|x86
9+
Release|x86 = Release|x86
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{837C94CF-B0D5-44FF-A367-823F4BB43F97}.Debug|x86.ActiveCfg = Debug|x86
13+
{837C94CF-B0D5-44FF-A367-823F4BB43F97}.Debug|x86.Build.0 = Debug|x86
14+
{837C94CF-B0D5-44FF-A367-823F4BB43F97}.Release|x86.ActiveCfg = Release|x86
15+
{837C94CF-B0D5-44FF-A367-823F4BB43F97}.Release|x86.Build.0 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

Picross/GameMath.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Drawing;
3+
4+
namespace Picross
5+
{
6+
public static class GameMath
7+
{
8+
// Float stuff
9+
public static float Clamp(float min, float max, float value) {
10+
if (value <= min)
11+
return min;
12+
if (value >= max)
13+
return max;
14+
return value;
15+
}
16+
17+
public static float Lerp(float from, float to, float t) {
18+
return from + (to - from) * GameMath.Clamp(0, 1, t);
19+
}
20+
21+
// Color stuff
22+
public static Color Clamp(float min, float max, Color color, bool alpha = false) {
23+
return Color.FromArgb(
24+
(byte)Clamp(min, max, color.R),
25+
(byte)Clamp(min, max, color.G),
26+
(byte)Clamp(min, max, color.B),
27+
alpha ? (byte)Clamp(min, max, color.A) : color.A
28+
);
29+
}
30+
31+
public static Color Lerp(Color from, Color to, float t, bool alpha = false) {
32+
return Color.FromArgb(
33+
alpha ? (byte)Lerp(from.A, to.A, t) : from.A,
34+
(byte)Lerp(from.R, to.R, t),
35+
(byte)Lerp(from.G, to.G, t),
36+
(byte)Lerp(from.B, to.B, t)
37+
);
38+
}
39+
}
40+
}

Picross/Main.cs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Windows.Forms;
4+
5+
namespace Picross
6+
{
7+
class Main : Form
8+
{
9+
private static Size MinSize = new Size(665, 435);
10+
11+
SeaUserControl[] userControls;
12+
13+
public Main() {
14+
// Load and apply the settings
15+
Settings s = Settings.Get;
16+
this.StartPosition = FormStartPosition.Manual;
17+
this.Location = s.Position;
18+
this.ClientSize = new Size(s.Size);
19+
//this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
20+
this.Icon = Properties.Resources.EyesHybrid;
21+
this.MaximizeBox = false;
22+
23+
// Set some standard values
24+
this.Text = "Picross";
25+
26+
// Add the controls
27+
this.userControls = new SeaUserControl[1] { new MainControl() };
28+
foreach (SeaUserControl u in this.userControls) {
29+
u.Size = this.ClientSize;
30+
this.Controls.Add(u);
31+
u.OnResize();
32+
}
33+
this.userControls[0].Show();
34+
35+
// Locate the controls
36+
this.onResizeEnd(this, new EventArgs());
37+
38+
// Register events
39+
this.LocationChanged += (o, e) => { Settings.Get.Position = this.Location; };
40+
this.ResizeEnd += onResizeEnd;
41+
}
42+
43+
void onResizeEnd(object o, EventArgs e) {
44+
// Make sure its not too small
45+
this.ClientSize = new Size(Math.Max(this.ClientSize.Width, MinSize.Width), Math.Max(this.ClientSize.Height, MinSize.Height));
46+
47+
// Save the size to the settings
48+
Settings.Get.Size = new Point(this.ClientSize);
49+
50+
// Resize the user controls
51+
foreach (SeaUserControl u in this.userControls) {
52+
u.Size = this.ClientSize;
53+
u.OnResize();
54+
}
55+
}
56+
57+
/// <summary>
58+
/// Show usercontrol at index i and hide all others
59+
/// </summary>
60+
/// <param name="i">The index</param>
61+
public void ShowUserControl(int i) {
62+
foreach (SeaUserControl u in this.userControls)
63+
u.Hide();
64+
this.userControls[i].Show();
65+
this.userControls[i].Size = this.ClientSize;
66+
this.userControls[i].OnResize();
67+
}
68+
69+
public void LoadPuzzleFromFile(string filename) {
70+
((MainControl)this.userControls[0]).LoadPuzzleFromFile(filename);
71+
}
72+
}
73+
74+
class SeaUserControl : UserControl
75+
{
76+
public SeaUserControl() {
77+
this.Hide();
78+
}
79+
80+
/// <summary>
81+
/// Show usercontrol at index i and hide all others
82+
/// </summary>
83+
/// <param name="i">The index</param>
84+
public void ShowUserControl(int i) {
85+
((Main)this.Parent).ShowUserControl(i);
86+
}
87+
88+
/// <summary>
89+
/// This method gets called after the usercontrol is resized
90+
/// </summary>
91+
public virtual void OnResize() { }
92+
}
93+
}

0 commit comments

Comments
 (0)