Skip to content

Commit

Permalink
Version : 1.2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zs-3 authored Nov 25, 2024
1 parent 72680a2 commit 19c1594
Show file tree
Hide file tree
Showing 46 changed files with 20,570 additions and 1,794 deletions.
2 changes: 1 addition & 1 deletion ZS.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# SharpDevelop 5.1
# SharpDevelop 5.2
VisualStudioVersion = 12.0.20827.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZS", "ZS\ZS.csproj", "{4EE83662-E2D1-4F91-AA0D-A69A80C63661}"
Expand Down
216 changes: 216 additions & 0 deletions ZS/Call.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
using Microsoft.SmallBasic.Library;
using System;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;

namespace ZS
{
/// <summary>
/// Use For Using Small Basic Sub As A Method.
/// </summary>
[SmallBasicType]
public static class ZSCall
{


private static Dictionary<Primitive, Primitive> Vars = new Dictionary<Primitive, Primitive>();

private static Assembly entryAssembly = Assembly.GetEntryAssembly();
private static Type mainModule = entryAssembly.EntryPoint.DeclaringType;
private static void Func(string funcName)
{
MethodInfo methodInfo = mainModule.GetMethod(funcName, BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
methodInfo.Invoke(null, null);
}

private static void SetVal(string Name, string Value)
{
FieldInfo fieldInfo = mainModule.GetField(Name, BindingFlags.NonPublic | BindingFlags.Static);
fieldInfo.SetValue(null, Value);
}

private static String GetVal(string Name)
{
FieldInfo fieldInfo = mainModule.GetField(Name, BindingFlags.NonPublic | BindingFlags.Static);
return fieldInfo.GetValue(null).ToString();
}

private static string GetCallingMethodName()
{
// Create a StackTrace object
StackTrace stackTrace = new StackTrace(true);

// Get the calling method from the stack trace
StackFrame frame = stackTrace.GetFrame(2); // 2 represents the method that called the current method
if (frame != null) {
MethodBase method = frame.GetMethod();
return method.Name;
}
return "Unknown";
}

/// <summary>
/// The Event Of Sub
/// </summary>
public static event SmallBasicCallback Function;

[HideFromIntellisense]
public static void AddValue(Primitive Name, Primitive Value)
{
Stack.PushValue(Name, Value);
}

/// <summary>
/// Gets The Value Sent To Stack
/// </summary>
/// <param name="Name">The name of stack</param>
/// <returns>Value sent </returns>
public static Primitive GetValue(Primitive Name)
{
return Stack.PopValue(Name);
}

/// <summary>
/// Return The Value to CallSub.
/// </summary>
/// <param name="Value">The Value To Return.</param>
public static void Return(Primitive Value)
{
Stack.PushValue("Return", Value);

}

/// <summary>
/// Return The Value to CallSubWithEvent
/// </summary>
/// <param name="Value">The Value To Return</param>
public static void Return2(Primitive Value)
{
Stack.PushValue("ReturnValue-Event", Value);

}

/// <summary>
/// Calls The Sub With Args.
/// </summary>
/// <param name="Sub">The Sub Name</param>
/// <param name="Values">The Values Of Args Seperated By ;.</param>
/// <returns>The Output Send Through Return.</returns>
public static Primitive CallSub(Primitive Sub, Primitive Values)
{
// Convert Primitive to string
string valuesString = Values.ToString();

// Split the input string by semicolon to get each stack name-value pair
string[] pairs = valuesString.Split(';');

foreach (string pair in pairs) {
// Split each pair by '=' to get the stack name and value
string[] keyValue = pair.Split('=');

if (keyValue.Length == 2) {
string stackName = keyValue[0].Trim();
string stackValue = keyValue[1].Trim();

// Add the value to the stack
AddValue(stackName, stackValue);
}
}
Func(Sub);
return GetValue("Return");
}

/// <summary>
/// Calls The Sub That Is Suscribed To Function Event With Args.
/// </summary>
/// <param name="Values">The Values Of Args Seperated By ;.</param>
/// <returns>The Output Send Through Return2.</returns>
public static Primitive CallSubWithEvent(Primitive Values)
{
// Convert Primitive to string
string valuesString = Values.ToString();

// Split the input string by semicolon to get each stack name-value pair
string[] pairs = valuesString.Split(';');

foreach (string pair in pairs) {
// Split each pair by '=' to get the stack name and value
string[] keyValue = pair.Split('=');

if (keyValue.Length == 2) {
string VarName = keyValue[0].Trim();
string Value = keyValue[1].Trim();

// Add the value to the stack
SetVal(VarName, Value);
}
}
Function.Invoke();
return GetValue("ReturnValue-Event");
}

/// <summary>
/// Calls The Sub With Args.
/// The Varibles decleared inside sub will be assinged with new arg value.
/// A Varible by name Return value will be returned.
/// </summary>
/// <param name="Values">The Values Of Args Seperated By ;.</param>
/// <param name="Sub">The Sub Name.</param>
/// <returns>The Output Send Through Return.</returns>
public static Primitive Call2(Primitive Sub,Primitive Values)
{
// Convert Primitive to string
string valuesString = Values.ToString();

// Split the input string by semicolon to get each stack name-value pair
string[] pairs = valuesString.Split(';');

foreach (string pair in pairs) {
// Split each pair by '=' to get the stack name and value
string[] keyValue = pair.Split('=');

if (keyValue.Length == 2) {
string VarName = keyValue[0].Trim();
string Value = keyValue[1].Trim();

// Add the value to the stack
SetVal(VarName, Value);
}
}
Func(Sub);
return GetVal("Return");
}

/// <summary>
/// Calls The Sub With Args.
/// The Varibles decleared inside sub will be assinged with new arg value.
/// A Varible by name Return_SubName value will be returned.
/// </summary>
/// <param name="Values">The Values Of Args Seperated By ;.</param>
/// <returns>The Output Send Through Return.</returns>
public static Primitive Call3(Primitive Sub,Primitive Values)
{
// Convert Primitive to string
string valuesString = Values.ToString();

// Split the input string by semicolon to get each stack name-value pair
string[] pairs = valuesString.Split(';');

foreach (string pair in pairs) {
// Split each pair by '=' to get the stack name and value
string[] keyValue = pair.Split('=');

if (keyValue.Length == 2) {
string VarName = keyValue[0].Trim();
string Value = keyValue[1].Trim();

// Add the value to the stack
SetVal(VarName, Value);
}
}
Func(Sub);
return GetVal("Return_" + Sub);
}
}
}
94 changes: 94 additions & 0 deletions ZS/Canvas.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Microsoft.SmallBasic.Library;
using System;
using ZS;
using System.Windows;
using System.Collections.Generic;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Media;

namespace ZS
{
/// <summary>
/// Manage Multiple Canvas And Functions.
/// Name For Small Basic Default Canvas Is "GWCanvas"
/// </summary>
[SmallBasicType]
public static class ZSCanvas
{

private static Dictionary<string, Canvas> _Canvas = new Dictionary<string, Canvas>();

static ZSCanvas()
{
Canvas GWCanvas = ZSWpf.GetGWCanvas();
_Canvas.Add("GWCanvas", GWCanvas);
}

/// <summary>
/// Create A New Canvas.
/// </summary>
/// <param name="Name">The New Canvas Name.</param>
public static void CreateCanvas(Primitive Name)
{
Window win = ZSWpf.Verify();
win.Dispatcher.Invoke(() => {
ZSReflection.InvokeMethod(typeof(GraphicsWindow), "SetWindowContent", null);
_Canvas.Add(Name, ZSWpf.GetGWCanvas());
});
}

/// <summary>
/// Set A Canvas to GW.
/// </summary>
/// <param name="Name"></param>
public static void SetCanvas(Primitive Name)
{
Canvas can = _Canvas[Name];
ZSWpf.SetGWCanvas(can);
}

/// <summary>
/// Hides a Canvas on the GraphicsWindow.
/// </summary>
/// <param name="Name"></param>
public static void HideCanvas(Primitive Name)
{
string canvasName = Name.ToString(); // Convert Primitive to string

// Check if the _Canvas dictionary is initialized
if (_Canvas == null) {
throw new Exception("_Canvas dictionary is not initialized.");
}

// Check if the canvas exists in the dictionary
if (_Canvas.ContainsKey(canvasName)) {
Canvas can = _Canvas[canvasName];

// Check if the canvas itself is null
if (can != null) {
can.Dispatcher.Invoke(() => {
can.Visibility = Visibility.Hidden;
});
} else {
throw new Exception("Canvas with name " + canvasName + " is null.");
}
} else {
throw new Exception("Canvas with name " + canvasName + " not found in _Canvas dictionary.");
}
}



/// <summary>
/// Shows A Canvas On GW.
/// </summary>
/// <param name="Name"></param>
public static void ShowCanvas(Primitive Name)
{
Canvas can = _Canvas[Name];
can.Visibility = Visibility.Visible;
}
}
}

Loading

0 comments on commit 19c1594

Please sign in to comment.