forked from XAYRGA/JAIMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visualizer.cs
95 lines (75 loc) · 3.09 KB
/
Visualizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing;
using System.Runtime;
using System.Runtime.InteropServices;
using SdlDotNet.Input;
using System.Diagnostics;
namespace JaiMaker
{
public static class Visualizer
{
static Thread RenderThread; //
static Surface IVideoSurface;
static SdlDotNet.Graphics.Font myfont;
static Process me;
public static void Init()
{
Events.TargetFps = 60; // 60 fps
Events.Quit += (QuitEventHandler); // pizzaz, to make it so when we press the exit button it does.
Events.Tick += (draw); // Drawing handler
Events.KeyboardDown += KeyDown; // a
Events.KeyboardUp += KeyUp;
myfont = new SdlDotNet.Graphics.Font("tahoma.ttf", 12); // Load the font
RenderThread = new Thread(new ThreadStart(startDrawWindowThread)); // Create render thread
me = Process.GetCurrentProcess();
RenderThread.Start(); // Start it
}
private static void startDrawWindowThread()
{
IVideoSurface = Video.SetVideoMode(800, 800, 16, false, false, false, true); // Initialize video surface, 800x800, 16 bit
Events.Run(); // Start the drawing / event loop
}
private static void KeyDown(object sender, KeyboardEventArgs kbe)
{
var channel = (byte)kbe.Key;
Console.WriteLine("key {0}", channel);
Keyboard.startSound((byte)(channel));
}
private static void KeyUp(object sender, KeyboardEventArgs kbe)
{
var channel = (byte)kbe.Key;
Keyboard.stopSound((byte)(channel));
}
private static void draw(object sender, TickEventArgs args)
{
IVideoSurface.Fill(Color.Black); // flush background black
Point HeaderPos = new Point(5, 5); // Point for header drawing
var HeaderText = myfont.Render("JAIMaker by XayrGA ", Color.White); // yay me.
Video.Screen.Blit(HeaderText, HeaderPos);
Point RAMPos = new Point(150, 5); // Point for header drawing
var ramstring = string.Format("MEM: {0}MB ", me.PrivateMemorySize / (1024 * 1024));
if (Root.currentProg != null && Root.currentBank != null)
{
ramstring = string.Format("MEM: {0}MB BNK: {1} PRG: {2}", me.PrivateMemorySize / (1024 * 1024), Root.currentBank.id, Root.ProgNumber);
}
var RAMText = myfont.Render(ramstring, Color.White); // yay me.
Video.Screen.Blit(RAMText, RAMPos);
RAMText.Dispose();
HeaderText.Dispose();
IVideoSurface.Update(); // Update the video surface.
}
private static void QuitEventHandler(object sender, QuitEventArgs args)
{
Environment.Exit(0x00);
Events.QuitApplication();
}
}
}