-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
20,570 additions
and
1,794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.