Skip to content

Commit 74751be

Browse files
committed
Toolkit can now read images
1 parent eb85864 commit 74751be

11 files changed

+728
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
cmake_minimum_required(VERSION 3.15)
99

10-
project( "Einstein" VERSION "2024.4.21" )
10+
project( "Einstein" VERSION "2024.4.22" )
1111

1212
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
1313
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")

Toolkit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ list (APPEND app_sources
3333
Toolkit/TToolkitPrototypes.h
3434
Toolkit/TToolkitScriptExt.cpp
3535
Toolkit/TToolkitScriptExt.h
36+
Toolkit/TTkHelpText.html
3637
)
3738

3839
build_with_fluid( TFLToolkitUI Toolkit )

Toolkit/SampleScripts/mpg.ns

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//
2+
// This little app calculates the range of a car in mpg,
3+
// "miles per gallon", based on the distance driven and
4+
// the number of gallons of gasoline used.
5+
//
6+
7+
kAppName := "MPG:WONKO";
8+
kAppSymbol := '|MPG:WONKO|;
9+
kAppLabel := "MPG";
10+
11+
// The main form can be moved around the screen
12+
newt.theForm := {
13+
viewBounds: {
14+
left: 0, top: 30, right: 180, bottom: 220
15+
},
16+
_proto: protoFloatNGo,
17+
recalculateMileage: func()
18+
begin
19+
local trip := wTrip.value;
20+
local gas := wGas.value;
21+
local mileage := 999;
22+
if gas > 0 then
23+
mileage := trip / gas;
24+
SetValue( wMileage, 'value, floor( mileage) );
25+
end
26+
};
27+
28+
// Give the app a little title bar
29+
wTitle := {
30+
_proto: protoStaticText,
31+
text: "MPG",
32+
viewBounds: {
33+
left: 61, top: 3, bottom: 22, right: 112
34+
},
35+
viewFont: ROM_fontSystem12Bold
36+
};
37+
AddStepForm( newt.theForm, wTitle);
38+
StepDeclare( newt.theForm, wTitle, 'wTitle);
39+
40+
// I want a headline, too
41+
wHeadline := {
42+
_proto: protoStaticText,
43+
text: "calculate your gas milage",
44+
viewBounds: {
45+
left: 11, top: 22, bottom: 41, right: 163
46+
},
47+
viewFont: ROM_fontSystem10Bold
48+
};
49+
AddStepForm( newt.theForm, wHeadline);
50+
StepDeclare( newt.theForm, wHeadline, 'wHeadline);
51+
52+
// Just because we can, here is a badly drawn icon
53+
wIcon := {
54+
viewClass: clPictureView,
55+
viewFlags: vVisible,
56+
viewFormat: vfFillWhite,
57+
viewJustify: vjCenterV + vjCenterH,
58+
icon: MakeIconFromFile("embedded:/mpg.png"),
59+
viewBounds: {
60+
left: 30, top: 88, bottom: 121, right: 64
61+
}
62+
};
63+
AddStepForm( newt.theForm, wIcon);
64+
StepDeclare( newt.theForm, wIcon, 'wIcon);
65+
66+
// Trip distance in miles since last fill up
67+
wTrip := {
68+
_proto: protoNumberPicker,
69+
preallocatedContext: 'wTrip,
70+
value: 0,
71+
maxValue: 9999,
72+
minValue: 0,
73+
viewBounds: {
74+
left: 51, top: 50, bottom: 81, right: 140
75+
},
76+
ClickDone: func()
77+
begin
78+
:recalculateMileage();
79+
end
80+
};
81+
AddStepForm( newt.theForm, wTrip);
82+
StepDeclare( newt.theForm, wTrip, 'wTrip);
83+
84+
// Amount of gasoline needed after trip for a complete refill
85+
wGas := {
86+
_proto: protoNumberPicker,
87+
value: 0,
88+
maxValue: 999,
89+
minValue: 0,
90+
viewBounds: {
91+
left: 73, top: 90, bottom: 121, right: 140
92+
},
93+
ClickDone: func()
94+
begin
95+
:recalculateMileage();
96+
end
97+
};
98+
AddStepForm( newt.theForm, wGas);
99+
StepDeclare( newt.theForm, wGas, 'wGas);
100+
101+
// Show the miles of range per gallon of gasoline used
102+
wMileage := {
103+
_proto: protoNumberPicker,
104+
value: 999,
105+
maxValue: 999,
106+
minValue: 0,
107+
viewBounds: {
108+
left: 73, top: 130, bottom: 161, right: 140
109+
}
110+
};
111+
AddStepForm( newt.theForm, wMileage);
112+
StepDeclare( newt.theForm, wMileage, 'wMileage);
113+
114+
wTripLabel := {
115+
_proto: protoStaticText,
116+
text: "mi",
117+
viewBounds: {
118+
left: 142, top: 62, bottom: 80, right: 166
119+
}
120+
};
121+
AddStepForm( newt.theForm, wTripLabel);
122+
StepDeclare( newt.theForm, wTripLabel, 'wTripLabel);
123+
124+
wGasLabel := {
125+
_proto: protoStaticText,
126+
text: "gal",
127+
viewBounds: {
128+
left: 142, top: 101, bottom: 120, right: 166
129+
}
130+
};
131+
AddStepForm( newt.theForm, wGasLabel);
132+
StepDeclare( newt.theForm, wGasLabel, 'wGasLabel);
133+
134+
wMileageLabel := {
135+
_proto: protoStaticText,
136+
text: "mpg",
137+
viewBounds: {
138+
left: 142, top: 141, bottom: 161, right: 168
139+
}
140+
};
141+
AddStepForm( newt.theForm, wMileageLabel);
142+
StepDeclare( newt.theForm, wMileageLabel, 'wMileageLabel);
143+

Toolkit/SampleScripts/mpg.png

1.22 KB
Loading

Toolkit/TFLSampleScripts.fl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ code_name {.cpp}
66
data kToolkitSampleScriptHelloWorld {public local filename {SampleScripts/HelloWorld.ns} textmode
77
}
88

9+
data kToolkitSampleScriptMPG {public local filename {SampleScripts/mpg.ns} textmode
10+
}
11+
12+
data kToolkitSampleImageMPG {public local filename {SampleScripts/mpg.png}
13+
}
14+
915
data kToolkitSampleScriptNativeFunction {public local filename {SampleScripts/NativeFunction.ns} textmode
1016
}
1117

12-
data kToolkitSampleScriptROMPatcher {selected public local filename {SampleScripts/ROMPatcher.ns} textmode
18+
data kToolkitSampleScriptROMPatcher {public local filename {SampleScripts/ROMPatcher.ns} textmode
1319
}

Toolkit/TFLScriptPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TFLScriptPanel::AddProtoTemplate(const char* protoName)
128128
{
129129
strcat(name, protoName);
130130
}
131-
// Trust the user with the text insert postion
131+
// Trust the user with the text insert position
132132
char buf[2048];
133133
snprintf(buf, sizeof(buf),
134134
"%s := {\n\t_proto: %s,\n\tviewBounds: RelBounds(10, 10, 100, 20)\n};\n"

Toolkit/TFLToolkitUI.fl

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ decl {\#include "Toolkit/TFLScriptPanel.h"} {public global
2121
decl {\#include <FL/fl_draw.H>} {private global
2222
}
2323

24+
decl {\#include <FL/Fl_Help_Dialog.H>} {private global
25+
}
26+
2427
decl {Fl_Menu_Item *wTKOpenRecentMenu[8];} {private global
2528
}
2629

30+
decl {Fl_Help_Dialog *tkHelpDialog = nullptr;} {private local
31+
}
32+
33+
data tkHelpText {private local filename {TTkHelpText.html} textmode
34+
}
35+
2736
class TFlDropButton {
2837
comment {// This button calls its callback with the text
2938
// that is dropped on it (for example, a filename)} open : {public Fl_Button}
@@ -64,10 +73,10 @@ if (mi)
6473
Function {CreateToolkitWindow(int x, int y)} {open
6574
} {
6675
Fl_Window wToolkitWindow {open
67-
xywh {270 164 720 600} type Double resizable
76+
xywh {282 267 720 600} type Double resizable
6877
code0 {wToolkitWindow->position(x, y);} visible
6978
} {
70-
Fl_Menu_Bar wToolkitMenubar {
79+
Fl_Menu_Bar wToolkitMenubar {open
7180
xywh {0 0 720 24} color 52
7281
code0 {o->box(FL_FREE_BOXTYPE);}
7382
class TFLMenuBar
@@ -154,13 +163,18 @@ Function {CreateToolkitWindow(int x, int y)} {open
154163
xywh {20 20 100 20}
155164
}
156165
MenuItem {} {
157-
label {Native Function}
166+
label {Miles Per Gallon}
158167
callback {gToolkit->LoadSampleCode(2);}
168+
xywh {20 20 100 20}
169+
}
170+
MenuItem {} {
171+
label {Native Function}
172+
callback {gToolkit->LoadSampleCode(3);}
159173
xywh {40 40 100 20}
160174
}
161175
MenuItem {} {
162176
label {ROM Patcher}
163-
callback {gToolkit->LoadSampleCode(3);}
177+
callback {gToolkit->LoadSampleCode(4);} selected
164178
xywh {40 40 100 20}
165179
}
166180
}
@@ -603,7 +617,12 @@ gToolkit->AppRun();}
603617
} {
604618
MenuItem {} {
605619
label {Toolkit Manual...}
606-
xywh {12 12 100 20} deactivate
620+
callback {if (!tkHelpDialog) {
621+
tkHelpDialog = new Fl_Help_Dialog();
622+
tkHelpDialog->value(tkHelpText);
623+
}
624+
tkHelpDialog->show();}
625+
xywh {12 12 100 20}
607626
}
608627
MenuItem {} {
609628
label {About Toolkit...}
@@ -612,21 +631,21 @@ gToolkit->AppRun();}
612631
}
613632
}
614633
Fl_Group wToolkitToolbar {
615-
xywh {0 24 720 37} box THIN_UP_BOX color 52
634+
xywh {0 24 720 32} box THIN_UP_BOX color 52
616635
code0 {o->box(FL_FREE_BOXTYPE);}
617636
} {
618637
Fl_Button wToolkitRun {
619638
label {@>}
620639
callback {gToolkit->UserActionRun();}
621-
xywh {10 30 32 20} color 52 labelsize 16 labelcolor 48 align 528
640+
xywh {10 28 32 24} color 52 labelsize 16 labelcolor 48 align 528
622641
code0 {o->box(FL_FREE_BOXTYPE);}
623642
code1 {o->down_box(FL_FREE_BOXTYPE);}
624643
code2 {o->clear_visible_focus();}
625644
}
626645
Fl_Button wToolkitStop {
627646
label {@square}
628647
callback {gToolkit->UserActionStop();}
629-
xywh {46 30 32 20} color 52 labelsize 10 labelcolor 48 align 528
648+
xywh {46 28 32 24} color 52 labelsize 10 labelcolor 48 align 528
630649
code0 {o->box(FL_FREE_BOXTYPE);}
631650
code1 {o->down_box(FL_FREE_BOXTYPE);}
632651
code2 {o->clear_visible_focus();}
@@ -635,14 +654,14 @@ gToolkit->AppRun();}
635654
label {@refresh}
636655
user_data 0L
637656
callback {gToolkit->UserActionDecompilePkg((char*)v);}
638-
tooltip {drop packes here to decompile them} xywh {678 30 32 20} color 52 labelsize 10 labelcolor 48 align 528
657+
tooltip {drop packes here to decompile them} xywh {678 28 32 24} color 52 labelsize 10 labelcolor 48 align 528
639658
code0 {o->box(FL_THIN_DOWN_BOX);}
640659
code1 {o->down_box(FL_FREE_BOXTYPE);}
641660
code2 {o->clear_visible_focus();}
642661
class TFlDropButton
643662
}
644663
Fl_Box {} {
645-
xywh {87 30 584 20} hide resizable
664+
xywh {87 30 584 26} hide resizable
646665
}
647666
}
648667
Fl_Group wToolkitFindGroup {open
@@ -691,7 +710,7 @@ gToolkit->AppRun();}
691710
}
692711
Fl_Button wToolkitFindHide {
693712
label X
694-
callback {gToolkit->UserActionFindHide();} selected
713+
callback {gToolkit->UserActionFindHide();}
695714
xywh {701 58 18 18} box FLAT_BOX down_box DOWN_BOX color 51 labelsize 11 hide
696715
}
697716
Fl_Button wToolkitReplaceNext {

Toolkit/TTkHelpText.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<html>
2+
<body>
3+
4+
<h1>NewtonScript Extensions</h1>
5+
6+
<h2>Globals</h2>
7+
8+
<b>MakeBinaryFromString(str, sym)</b>: Generate a binary object from an ASCII string.
9+
<br>
10+
<b>MakeBinaryFromARM(ARM_Instructions)</b>: Generate a binary function from ARM assembler text.
11+
Lines should be separated with \n characters.
12+
<br>
13+
<b>MakeBinaryFromARMFile(ARM_Assembler_Filename)</b>:
14+
<br>
15+
<b>PatchFileFromARM(ARM_Instructions, filename)</b>:
16+
<br>
17+
<b>AddStepForm(mainView, scrollClipper)</b>:
18+
<br>
19+
StepDeclare(mainView, scrollClipper, 'scrollClipper)</b>:
20+
<br>
21+
<b>_STDERR_</b>:
22+
<br>
23+
<b>_STDOUT_</b>:
24+
25+
<h2>FLTK extensions</h2>
26+
27+
<b>fltk:message(message)</b>: Open a message dialog box.
28+
<br>
29+
<b>fltk:choice(message, cancel_button, ok_button, opt_button)</b>:
30+
Open a user choice dialog box and return the selected button id.
31+
<br>
32+
<b>fltk:filechooser(message, pattern, filename, relative)</b>:
33+
Open a file chooser dialog. Returns filename or NIL.
34+
<br>
35+
36+
<h2>Host File Access extensions</h2>
37+
<b>file:new()</b>: Create a frame to access files on the host machine.
38+
<br>
39+
<b>file:open(filename, mode)</b>: Open a file, mode is 'read|'write|'readwrite|'append.
40+
<br>
41+
<b>file:isOpen()</b>: Returns nil or true.
42+
<br>
43+
<b>file:size()</b>: Returns file size in bytes.
44+
<br>
45+
<b>file:read(size)</b>: Read up to size bytes and return a binary object with the data.
46+
<br>
47+
<b>file:write(binaryObject)</b>: Write the content of a binary object to a file.
48+
<br>
49+
<b>file:seek(pos, mode)</b>: Set read position, mode is 'set|'cur|'end.
50+
<br>
51+
<b>file:tell()</b>: Return the current read position in the file.
52+
<br>
53+
<b>file:close()</b>: Closes a file, returns exception or true.
54+
<br>
55+
56+
</body>
57+
</html>

Toolkit/TToolkit.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ extern "C" {
149149
}
150150

151151
#include <FL/Fl_File_Chooser.H>
152+
#include <FL/Fl_PNG_Image.H>
152153
#include <FL/fl_ask.H>
153154

154155
#if TARGET_OS_WIN32
@@ -181,6 +182,7 @@ TToolkit::TToolkit(TFLApp* inApp) :
181182
mApp(inApp)
182183
{
183184
gToolkit = this;
185+
new Fl_PNG_Image("embedded:/mpg.png", kToolkitSampleImageMPG, sizeof(kToolkitSampleImageMPG));
184186
}
185187

186188
/**
@@ -1433,10 +1435,14 @@ TToolkit::LoadSampleCode(int n)
14331435
wScriptPanel->ClearDirty();
14341436
break;
14351437
case 2:
1436-
wScriptPanel->SetSourceCode(kToolkitSampleScriptNativeFunction);
1438+
wScriptPanel->SetSourceCode(kToolkitSampleScriptMPG);
14371439
wScriptPanel->ClearDirty();
14381440
break;
14391441
case 3:
1442+
wScriptPanel->SetSourceCode(kToolkitSampleScriptNativeFunction);
1443+
wScriptPanel->ClearDirty();
1444+
break;
1445+
case 4:
14401446
wScriptPanel->SetSourceCode(kToolkitSampleScriptROMPatcher);
14411447
wScriptPanel->ClearDirty();
14421448
break;

0 commit comments

Comments
 (0)