Skip to content

Commit

Permalink
Added TextDisplay.row and TextDisplay.column.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeStrout committed Oct 23, 2021
1 parent 9eea8cb commit 645e761
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Note that **all APIs should mimic [Mini Micro](https://miniscript.org/wiki/Mini_
- ~~full support for Sprite.tint including alpha~~
- ~~Sound.loop, Sound.stop, Sound.stopAll~~
- ~~basic screen handling: fullscreen mode, window size, window.backColor~~
- builds for Mac, Windows, Linux (PC), and Raspberry Pi
- manual builds for Mac, Windows, Linux (PC), and Raspberry Pi

# Medium Priority

- Display class, display(n), Display.install
- Bounds class, with its connections to Sprite (in progress)
- ~~Bounds class, with its connections to Sprite~~
- ~~Image.pixel, Image.setPixel~~
- SolidColor display
- Text display (in progress)
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion soda/soda.xcodeproj/xcshareddata/xcschemes/soda.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "tests/text.ms"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "tests/window.ms"
Expand Down
48 changes: 46 additions & 2 deletions soda/src/SodaIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ static IntrinsicResult intrinsic_spriteClass(Context *context, IntrinsicResult p
//--------------------------------------------------------------------------------
ValueDict textDisplayClass;
static Intrinsic *i_textDisplay_clear = nullptr;
static Intrinsic *i_textDisplay_column = nullptr;
static Intrinsic *i_textDisplay_row = nullptr;
static Intrinsic *i_textDisplay_columns = nullptr;
static Intrinsic *i_textDisplay_rows = nullptr;

Expand All @@ -504,6 +506,20 @@ static IntrinsicResult intrinsic_textDisplay_clear(Context *context, IntrinsicRe
return IntrinsicResult::Null;
}

static IntrinsicResult intrinsic_textDisplay_column(Context *context, IntrinsicResult partialResult) {
//Value self = context->GetVar("self");
// Note: for now, we'll just always access the main text display.
// When we support multiple text displays, we'll need to be more discriminating.
return IntrinsicResult(SdlGlue::mainTextDisplay->GetColumn());
}

static IntrinsicResult intrinsic_textDisplay_row(Context *context, IntrinsicResult partialResult) {
//Value self = context->GetVar("self");
// Note: for now, we'll just always access the main text display.
// When we support multiple text displays, we'll need to be more discriminating.
return IntrinsicResult(SdlGlue::mainTextDisplay->GetRow());
}

static IntrinsicResult intrinsic_textDisplay_columns(Context *context, IntrinsicResult partialResult) {
//Value self = context->GetVar("self");
// Note: for now, we'll just always access the main text display.
Expand All @@ -518,12 +534,40 @@ static IntrinsicResult intrinsic_textDisplay_rows(Context *context, IntrinsicRes
return IntrinsicResult(SdlGlue::mainTextDisplay->rows);
}

static bool textDisplayAssignOverride(ValueDict& spriteMap, MiniScript::Value key, Value value) {
// If the value hasn't changed, do nothing.
Value curVal = spriteMap.Lookup(key, Value::null);
if (curVal == value) return not value.IsNull(); // (block the assignment, unless actually assigning null)

String keyStr = key.ToString();
if (keyStr == "row") {
// Note: for now, we'll just always access the main text display.
// When we support multiple text displays, we'll need to be more discriminating.
SdlGlue::mainTextDisplay->SetRow((int)value.IntValue());
return true; // (block the assignment)
} else if (keyStr == "column") {
// Note: for now, we'll just always access the main text display.
// When we support multiple text displays, we'll need to be more discriminating.
SdlGlue::mainTextDisplay->SetColumn((int)value.IntValue());
return true; // (block the assignment)
}
return false; // allow the assignment
}

static IntrinsicResult intrinsic_textDisplayClass(Context *context, IntrinsicResult partialResult) {
if (textDisplayClass.Count() == 0) {
i_textDisplay_clear = Intrinsic::Create("");
i_textDisplay_clear->code = &intrinsic_textDisplay_clear;
textDisplayClass.SetValue("clear", i_textDisplay_clear->GetFunc());

i_textDisplay_column = Intrinsic::Create("");
i_textDisplay_column->code = &intrinsic_textDisplay_column;
textDisplayClass.SetValue("column", i_textDisplay_column->GetFunc());

i_textDisplay_row = Intrinsic::Create("");
i_textDisplay_row->code = &intrinsic_textDisplay_row;
textDisplayClass.SetValue("row", i_textDisplay_row->GetFunc());

i_textDisplay_columns = Intrinsic::Create("");
i_textDisplay_columns->code = &intrinsic_textDisplay_columns;
textDisplayClass.SetValue("columns", i_textDisplay_columns->GetFunc());
Expand All @@ -532,8 +576,7 @@ static IntrinsicResult intrinsic_textDisplayClass(Context *context, IntrinsicRes
i_textDisplay_rows->code = &intrinsic_textDisplay_rows;
textDisplayClass.SetValue("rows", i_textDisplay_rows->GetFunc());

textDisplayClass.SetValue("row", Value::zero);
textDisplayClass.SetValue("column", Value::zero);

}
return IntrinsicResult(textDisplayClass);
}
Expand All @@ -543,6 +586,7 @@ static IntrinsicResult intrinsic_textDisplayInstance(Context *context, Intrinsic
if (textDisplayInstance.type != ValueType::Map) {
ValueDict text;
text.SetValue(Value::magicIsA, textDisplayClass);
text.SetAssignOverride(textDisplayAssignOverride);
textDisplayInstance = text;
}
return IntrinsicResult(textDisplayInstance);
Expand Down
5 changes: 5 additions & 0 deletions soda/src/TextDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class TextDisplay {

void NoteWindowSizeChange(int newWidth, int newHeight);

int GetRow() const { return cursorY; }
void SetRow(int value) { cursorY = value < 0 ? 0 : (value >= rows ? rows-1 : value); }
int GetColumn() const { return cursorX; }
void SetColumn(int value) { cursorX = value < 0 ? 0 : (value >= cols ? cols-1 : value); }

int rows;
int cols;
Color textColor;
Expand Down

0 comments on commit 645e761

Please sign in to comment.