Skip to content

Commit

Permalink
Toolkit can now read images
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Apr 4, 2024
1 parent eb85864 commit 74751be
Show file tree
Hide file tree
Showing 11 changed files with 728 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

cmake_minimum_required(VERSION 3.15)

project( "Einstein" VERSION "2024.4.21" )
project( "Einstein" VERSION "2024.4.22" )

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down
1 change: 1 addition & 0 deletions Toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ list (APPEND app_sources
Toolkit/TToolkitPrototypes.h
Toolkit/TToolkitScriptExt.cpp
Toolkit/TToolkitScriptExt.h
Toolkit/TTkHelpText.html
)

build_with_fluid( TFLToolkitUI Toolkit )
Expand Down
143 changes: 143 additions & 0 deletions Toolkit/SampleScripts/mpg.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// This little app calculates the range of a car in mpg,
// "miles per gallon", based on the distance driven and
// the number of gallons of gasoline used.
//

kAppName := "MPG:WONKO";
kAppSymbol := '|MPG:WONKO|;
kAppLabel := "MPG";

// The main form can be moved around the screen
newt.theForm := {
viewBounds: {
left: 0, top: 30, right: 180, bottom: 220
},
_proto: protoFloatNGo,
recalculateMileage: func()
begin
local trip := wTrip.value;
local gas := wGas.value;
local mileage := 999;
if gas > 0 then
mileage := trip / gas;
SetValue( wMileage, 'value, floor( mileage) );
end
};

// Give the app a little title bar
wTitle := {
_proto: protoStaticText,
text: "MPG",
viewBounds: {
left: 61, top: 3, bottom: 22, right: 112
},
viewFont: ROM_fontSystem12Bold
};
AddStepForm( newt.theForm, wTitle);
StepDeclare( newt.theForm, wTitle, 'wTitle);

// I want a headline, too
wHeadline := {
_proto: protoStaticText,
text: "calculate your gas milage",
viewBounds: {
left: 11, top: 22, bottom: 41, right: 163
},
viewFont: ROM_fontSystem10Bold
};
AddStepForm( newt.theForm, wHeadline);
StepDeclare( newt.theForm, wHeadline, 'wHeadline);

// Just because we can, here is a badly drawn icon
wIcon := {
viewClass: clPictureView,
viewFlags: vVisible,
viewFormat: vfFillWhite,
viewJustify: vjCenterV + vjCenterH,
icon: MakeIconFromFile("embedded:/mpg.png"),
viewBounds: {
left: 30, top: 88, bottom: 121, right: 64
}
};
AddStepForm( newt.theForm, wIcon);
StepDeclare( newt.theForm, wIcon, 'wIcon);

// Trip distance in miles since last fill up
wTrip := {
_proto: protoNumberPicker,
preallocatedContext: 'wTrip,
value: 0,
maxValue: 9999,
minValue: 0,
viewBounds: {
left: 51, top: 50, bottom: 81, right: 140
},
ClickDone: func()
begin
:recalculateMileage();
end
};
AddStepForm( newt.theForm, wTrip);
StepDeclare( newt.theForm, wTrip, 'wTrip);

// Amount of gasoline needed after trip for a complete refill
wGas := {
_proto: protoNumberPicker,
value: 0,
maxValue: 999,
minValue: 0,
viewBounds: {
left: 73, top: 90, bottom: 121, right: 140
},
ClickDone: func()
begin
:recalculateMileage();
end
};
AddStepForm( newt.theForm, wGas);
StepDeclare( newt.theForm, wGas, 'wGas);

// Show the miles of range per gallon of gasoline used
wMileage := {
_proto: protoNumberPicker,
value: 999,
maxValue: 999,
minValue: 0,
viewBounds: {
left: 73, top: 130, bottom: 161, right: 140
}
};
AddStepForm( newt.theForm, wMileage);
StepDeclare( newt.theForm, wMileage, 'wMileage);

wTripLabel := {
_proto: protoStaticText,
text: "mi",
viewBounds: {
left: 142, top: 62, bottom: 80, right: 166
}
};
AddStepForm( newt.theForm, wTripLabel);
StepDeclare( newt.theForm, wTripLabel, 'wTripLabel);

wGasLabel := {
_proto: protoStaticText,
text: "gal",
viewBounds: {
left: 142, top: 101, bottom: 120, right: 166
}
};
AddStepForm( newt.theForm, wGasLabel);
StepDeclare( newt.theForm, wGasLabel, 'wGasLabel);

wMileageLabel := {
_proto: protoStaticText,
text: "mpg",
viewBounds: {
left: 142, top: 141, bottom: 161, right: 168
}
};
AddStepForm( newt.theForm, wMileageLabel);
StepDeclare( newt.theForm, wMileageLabel, 'wMileageLabel);

Binary file added Toolkit/SampleScripts/mpg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion Toolkit/TFLSampleScripts.fl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ code_name {.cpp}
data kToolkitSampleScriptHelloWorld {public local filename {SampleScripts/HelloWorld.ns} textmode
}

data kToolkitSampleScriptMPG {public local filename {SampleScripts/mpg.ns} textmode
}

data kToolkitSampleImageMPG {public local filename {SampleScripts/mpg.png}
}

data kToolkitSampleScriptNativeFunction {public local filename {SampleScripts/NativeFunction.ns} textmode
}

data kToolkitSampleScriptROMPatcher {selected public local filename {SampleScripts/ROMPatcher.ns} textmode
data kToolkitSampleScriptROMPatcher {public local filename {SampleScripts/ROMPatcher.ns} textmode
}
2 changes: 1 addition & 1 deletion Toolkit/TFLScriptPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ TFLScriptPanel::AddProtoTemplate(const char* protoName)
{
strcat(name, protoName);
}
// Trust the user with the text insert postion
// Trust the user with the text insert position
char buf[2048];
snprintf(buf, sizeof(buf),
"%s := {\n\t_proto: %s,\n\tviewBounds: RelBounds(10, 10, 100, 20)\n};\n"
Expand Down
41 changes: 30 additions & 11 deletions Toolkit/TFLToolkitUI.fl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ decl {\#include "Toolkit/TFLScriptPanel.h"} {public global
decl {\#include <FL/fl_draw.H>} {private global
}

decl {\#include <FL/Fl_Help_Dialog.H>} {private global
}

decl {Fl_Menu_Item *wTKOpenRecentMenu[8];} {private global
}

decl {Fl_Help_Dialog *tkHelpDialog = nullptr;} {private local
}

data tkHelpText {private local filename {TTkHelpText.html} textmode
}

class TFlDropButton {
comment {// This button calls its callback with the text
// that is dropped on it (for example, a filename)} open : {public Fl_Button}
Expand Down Expand Up @@ -64,10 +73,10 @@ if (mi)
Function {CreateToolkitWindow(int x, int y)} {open
} {
Fl_Window wToolkitWindow {open
xywh {270 164 720 600} type Double resizable
xywh {282 267 720 600} type Double resizable
code0 {wToolkitWindow->position(x, y);} visible
} {
Fl_Menu_Bar wToolkitMenubar {
Fl_Menu_Bar wToolkitMenubar {open
xywh {0 0 720 24} color 52
code0 {o->box(FL_FREE_BOXTYPE);}
class TFLMenuBar
Expand Down Expand Up @@ -154,13 +163,18 @@ Function {CreateToolkitWindow(int x, int y)} {open
xywh {20 20 100 20}
}
MenuItem {} {
label {Native Function}
label {Miles Per Gallon}
callback {gToolkit->LoadSampleCode(2);}
xywh {20 20 100 20}
}
MenuItem {} {
label {Native Function}
callback {gToolkit->LoadSampleCode(3);}
xywh {40 40 100 20}
}
MenuItem {} {
label {ROM Patcher}
callback {gToolkit->LoadSampleCode(3);}
callback {gToolkit->LoadSampleCode(4);} selected
xywh {40 40 100 20}
}
}
Expand Down Expand Up @@ -603,7 +617,12 @@ gToolkit->AppRun();}
} {
MenuItem {} {
label {Toolkit Manual...}
xywh {12 12 100 20} deactivate
callback {if (!tkHelpDialog) {
tkHelpDialog = new Fl_Help_Dialog();
tkHelpDialog->value(tkHelpText);
}
tkHelpDialog->show();}
xywh {12 12 100 20}
}
MenuItem {} {
label {About Toolkit...}
Expand All @@ -612,21 +631,21 @@ gToolkit->AppRun();}
}
}
Fl_Group wToolkitToolbar {
xywh {0 24 720 37} box THIN_UP_BOX color 52
xywh {0 24 720 32} box THIN_UP_BOX color 52
code0 {o->box(FL_FREE_BOXTYPE);}
} {
Fl_Button wToolkitRun {
label {@>}
callback {gToolkit->UserActionRun();}
xywh {10 30 32 20} color 52 labelsize 16 labelcolor 48 align 528
xywh {10 28 32 24} color 52 labelsize 16 labelcolor 48 align 528
code0 {o->box(FL_FREE_BOXTYPE);}
code1 {o->down_box(FL_FREE_BOXTYPE);}
code2 {o->clear_visible_focus();}
}
Fl_Button wToolkitStop {
label {@square}
callback {gToolkit->UserActionStop();}
xywh {46 30 32 20} color 52 labelsize 10 labelcolor 48 align 528
xywh {46 28 32 24} color 52 labelsize 10 labelcolor 48 align 528
code0 {o->box(FL_FREE_BOXTYPE);}
code1 {o->down_box(FL_FREE_BOXTYPE);}
code2 {o->clear_visible_focus();}
Expand All @@ -635,14 +654,14 @@ gToolkit->AppRun();}
label {@refresh}
user_data 0L
callback {gToolkit->UserActionDecompilePkg((char*)v);}
tooltip {drop packes here to decompile them} xywh {678 30 32 20} color 52 labelsize 10 labelcolor 48 align 528
tooltip {drop packes here to decompile them} xywh {678 28 32 24} color 52 labelsize 10 labelcolor 48 align 528
code0 {o->box(FL_THIN_DOWN_BOX);}
code1 {o->down_box(FL_FREE_BOXTYPE);}
code2 {o->clear_visible_focus();}
class TFlDropButton
}
Fl_Box {} {
xywh {87 30 584 20} hide resizable
xywh {87 30 584 26} hide resizable
}
}
Fl_Group wToolkitFindGroup {open
Expand Down Expand Up @@ -691,7 +710,7 @@ gToolkit->AppRun();}
}
Fl_Button wToolkitFindHide {
label X
callback {gToolkit->UserActionFindHide();} selected
callback {gToolkit->UserActionFindHide();}
xywh {701 58 18 18} box FLAT_BOX down_box DOWN_BOX color 51 labelsize 11 hide
}
Fl_Button wToolkitReplaceNext {
Expand Down
57 changes: 57 additions & 0 deletions Toolkit/TTkHelpText.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<html>
<body>

<h1>NewtonScript Extensions</h1>

<h2>Globals</h2>

<b>MakeBinaryFromString(str, sym)</b>: Generate a binary object from an ASCII string.
<br>
<b>MakeBinaryFromARM(ARM_Instructions)</b>: Generate a binary function from ARM assembler text.
Lines should be separated with \n characters.
<br>
<b>MakeBinaryFromARMFile(ARM_Assembler_Filename)</b>:
<br>
<b>PatchFileFromARM(ARM_Instructions, filename)</b>:
<br>
<b>AddStepForm(mainView, scrollClipper)</b>:
<br>
StepDeclare(mainView, scrollClipper, 'scrollClipper)</b>:
<br>
<b>_STDERR_</b>:
<br>
<b>_STDOUT_</b>:

<h2>FLTK extensions</h2>

<b>fltk:message(message)</b>: Open a message dialog box.
<br>
<b>fltk:choice(message, cancel_button, ok_button, opt_button)</b>:
Open a user choice dialog box and return the selected button id.
<br>
<b>fltk:filechooser(message, pattern, filename, relative)</b>:
Open a file chooser dialog. Returns filename or NIL.
<br>

<h2>Host File Access extensions</h2>
<b>file:new()</b>: Create a frame to access files on the host machine.
<br>
<b>file:open(filename, mode)</b>: Open a file, mode is 'read|'write|'readwrite|'append.
<br>
<b>file:isOpen()</b>: Returns nil or true.
<br>
<b>file:size()</b>: Returns file size in bytes.
<br>
<b>file:read(size)</b>: Read up to size bytes and return a binary object with the data.
<br>
<b>file:write(binaryObject)</b>: Write the content of a binary object to a file.
<br>
<b>file:seek(pos, mode)</b>: Set read position, mode is 'set|'cur|'end.
<br>
<b>file:tell()</b>: Return the current read position in the file.
<br>
<b>file:close()</b>: Closes a file, returns exception or true.
<br>

</body>
</html>
8 changes: 7 additions & 1 deletion Toolkit/TToolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ extern "C" {
}

#include <FL/Fl_File_Chooser.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/fl_ask.H>

#if TARGET_OS_WIN32
Expand Down Expand Up @@ -181,6 +182,7 @@ TToolkit::TToolkit(TFLApp* inApp) :
mApp(inApp)
{
gToolkit = this;
new Fl_PNG_Image("embedded:/mpg.png", kToolkitSampleImageMPG, sizeof(kToolkitSampleImageMPG));
}

/**
Expand Down Expand Up @@ -1433,10 +1435,14 @@ TToolkit::LoadSampleCode(int n)
wScriptPanel->ClearDirty();
break;
case 2:
wScriptPanel->SetSourceCode(kToolkitSampleScriptNativeFunction);
wScriptPanel->SetSourceCode(kToolkitSampleScriptMPG);
wScriptPanel->ClearDirty();
break;
case 3:
wScriptPanel->SetSourceCode(kToolkitSampleScriptNativeFunction);
wScriptPanel->ClearDirty();
break;
case 4:
wScriptPanel->SetSourceCode(kToolkitSampleScriptROMPatcher);
wScriptPanel->ClearDirty();
break;
Expand Down
Loading

0 comments on commit 74751be

Please sign in to comment.