Implement BGFILL(string)

This commit is contained in:
otya128 committed 2017-07-22 12:41:40 +09:00
1 parent 57ef38a037
commit 5995fcb7b4
2 files changed
+47 -2

No files matched your search

+18
View File
@@ -213,6 +213,24 @@ class BG
chip[i + y * width].i = id;
}*/
}
void fill(int x, int y, int x2, int y2, ushort[] screendata)
{
import std.algorithm;
if(x > x2) swap(x, x2);
if(y > y2) swap(y, y2);
int index = 0;
if (screendata.length == 0)
{
fill(x, y, x2, y2, 0);
return;
}
for(; y <= y2; y++)
for(int i = x; i <= x2; i++)
{
chip[i + y * width] = BGChip(screendata[index] & 4095);
index = (index + 1) % screendata.length;
}
}
int get(int x, int y, int flag)
{
if (flag)
+29 -2
View File
@@ -2608,13 +2608,40 @@ class BuiltinFunction
}
return p.getBG(layer).rot;
}
static void BGFILL(PetitComputer p, int layer, int x, int y, int x2, int y2, int screendata)
static void BGFILL(PetitComputer p, int layer, int x, int y, int x2, int y2, Value sd)
{
if (!p.isValidLayer(layer))
{
throw new OutOfRange("BGFILL", 1);
}
p.getBG(layer).fill(x, y, x2, y2, screendata);
if (sd.type == ValueType.String)
{
wstring screendata = sd.castDString;
if (screendata.length % 4 != 0)
{
throw new IllegalFunctionCall("BGFILL", 6);
}
ushort[] screendatas = new ushort[screendata.length / 4];
for (int i = 0; i < screendata.length; i += 4)
{
ushort a;
auto b = screendata[i..i + 4];
if (!tryParse(b, 16, a))
{
throw new IllegalFunctionCall("BGFILL", 6);
}
screendatas[i / 4] = a;
}
p.getBG(layer).fill(x, y, x2, y2, screendatas);
}
else if (sd.isNumber)
{
p.getBG(layer).fill(x, y, x2, y2, sd.castInteger);
}
else
{
throw new TypeMismatch("BGFILL", 6);
}
}
static void BGPAGE(PetitComputer p, int page)
{