using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using System.IO;
namespace Test
{
class menu
{
// DATE
public System.Windows.Point window = new System.Windows.Point(SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
public SolidColorBrush system_color = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0));
public void border_load(MainWindow form)
{
//border_draws(form, system_color, 4);
menu_main(form, 1);
}
public void border_draws(MainWindow form, SolidColorBrush colore, int selected)
{
int origHeight = Convert.ToInt32(window.Y);
int x = origHeight / 5;
int a1 = x - 95;
int sel = selected * x - 95;
int inizio = sel, medio = x, fine = origHeight;
int max = 80, min = 60 ,a= inizio, b=medio,c= origHeight;
Polyline Poly = form.menu_poly;
Poly.Stroke = colore;
Poly.StrokeThickness = 1.4;
Poly.FillRule = FillRule.EvenOdd;
System.Windows.Point Point1 = new System.Windows.Point(max, 0);
System.Windows.Point Point2 = new System.Windows.Point(max, a);
System.Windows.Point Point3 = new System.Windows.Point(min, a + 25);
System.Windows.Point Point4 = new System.Windows.Point(min, a + b + 25);
System.Windows.Point Point5 = new System.Windows.Point(max, a + b + 50);
System.Windows.Point Point6 = new System.Windows.Point(max, c);
PointCollection myPointCollection2 = new PointCollection();
myPointCollection2.Add(Point1);
myPointCollection2.Add(Point2);
myPointCollection2.Add(Point3);
myPointCollection2.Add(Point4);
myPointCollection2.Add(Point5);
myPointCollection2.Add(Point6);
Poly.Points = myPointCollection2;
form.menu_poly = Poly;
form.body_border.BorderBrush = colore;
}
public void menu_main(MainWindow form, int selected)
{
menu_button_color(form, system_color,"/graphics/demo.png");
menu_button_template(form);
menu_button_selected(form, selected);
border_draws(form, system_color, selected);
}
public void menu_button(MainWindow form)
{
}
public void menu_button_template(MainWindow form)
{
int height = Screen.PrimaryScreen.Bounds.Height;
int x = height / 5 - 10;
// BUTTONE 1
form.button_1.Margin = new Thickness(0, x, 0, 0);
form.button_2.Margin = new Thickness(0, x + x, 0, 0);
form.button_3.Margin = new Thickness(0, x + x + x, 0, 0);
form.button_4.Margin = new Thickness(0, x + x + x + x, 0, 0);
}
public void menu_button_selected(MainWindow form, int selected)
{
if (selected == 1)
{
form.button_1.Width = 60;
form.button_2.Width = 80;
form.button_3.Width = 80;
form.button_4.Width = 80;
}
if (selected == 2)
{
form.button_1.Width = 80;
form.button_2.Width = 60;
form.button_3.Width = 80;
form.button_4.Width = 80;
}
if (selected == 3)
{
form.button_1.Width = 80;
form.button_2.Width = 80;
form.button_3.Width = 60;
form.button_4.Width = 80;
}
if (selected == 4)
{
form.button_1.Width = 80;
form.button_2.Width = 80;
form.button_3.Width = 80;
form.button_4.Width = 60;
}
}
public void menu_button_color(MainWindow form, SolidColorBrush colore, String image)
{
System.Windows.Media.SolidColorBrush color = colore;
System.Drawing.Color myColor = System.Drawing.Color.FromArgb(color.Color.A,
color.Color.R,
color.Color.G,
color.Color.B);
Bitmap bmp_original = new Bitmap("C:/Users/Salvatore/Downloads/test.png");
bmp_original.MakeTransparent();
bmp_original.MakeTransparent(System.Drawing.Color.Transparent);
Bitmap bmp_new = new Bitmap(bmp_original);
bmp_new.MakeTransparent();
bmp_new.MakeTransparent(System.Drawing.Color.Transparent);
int height = bmp_original.Height, width = bmp_original.Width;
for (int y = 0; y< height; y++)
{
for (int x = 0; x < width; x++)
{
// prende il pixel
System.Drawing.Color p = bmp_original.GetPixel(x, y);
// estrae il colore ARGB
int a = p.A;
int r = p.R;
int g = p.G;
int b = p.B;
// setta il colore del pixel
if (a != 0)
bmp_new.SetPixel(x, y, myColor);
}
}
form.button_1_img.Source = BitmapToImageSource(bmp_new);
form.button_2_img.Source = BitmapToImageSource(bmp_new);
form.button_3_img.Source = BitmapToImageSource(bmp_new);
form.button_4_img.Source = BitmapToImageSource(bmp_new);
}
// ALTRI
BitmapImage BitmapToImageSource(Bitmap bitmap)
{
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
memory.Position = 0;
BitmapImage bitmapimage = new BitmapImage();
bitmapimage.BeginInit();
bitmapimage.StreamSource = memory;
bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
bitmapimage.EndInit();
return bitmapimage;
}
}
// END CLASS
}
}