diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 73c02c7..26b989f 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -1414,6 +1414,14 @@ class BuiltinFunction { return p.sprite.sppage; } + static void SPCLIP(PetitComputer p) + { + p.sprite.spclip; + } + static void SPCLIP(PetitComputer p, int x1, int y1, int x2, int y2) + { + p.sprite.spclip(x1, y1, x2, y2); + } static void BGMSTOP(PetitComputer p) { writeln("NOTIMPL:BGMSTOP"); diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index a9633c5..5c1ac05 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -401,7 +401,15 @@ class PetitComputer glViewport(x, currentDisplay.windowSize.height - h - y, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0, w, h, 0, 1024, -2048); + glOrtho(x, x + w, y + h, y, 1024, -2048); + } + void chRenderingDisplay(int i) + { + chScreen2(currentDisplay.rect[i].x, currentDisplay.rect[i].y, currentDisplay.rect[i].w, currentDisplay.rect[i].h); + } + void chRenderingDisplay(int i, int x, int y, int w, int h) + { + chScreen2(currentDisplay.rect[i].x + x, currentDisplay.rect[i].y + y, w, h); } Button[] buttonTable; Sprite sprite; @@ -466,6 +474,7 @@ class PetitComputer display(i); graphic.clip(false); graphic.clip(true); + this.sprite.spclip; } } diff --git a/SMILEBASIC/sprite.d b/SMILEBASIC/sprite.d index 94271ba..df3ba78 100644 --- a/SMILEBASIC/sprite.d +++ b/SMILEBASIC/sprite.d @@ -656,7 +656,13 @@ class Sprite } } } - float disw = 200f, dish = 120f, disw2 = 400f, dish2 = 240f; + float disw, dish, disw2, dish2; + disw = petitcom.currentDisplay.rect[0].w / 2; + disw2 = petitcom.currentDisplay.rect[0].w; + dish = petitcom.currentDisplay.rect[0].h / 2; + dish2 = petitcom.currentDisplay.rect[0].h; + petitcom.chRenderingDisplay(0, clipRect[0].x, clipRect[0].y, clipRect[0].w, clipRect[0].h); + glMatrixMode(GL_MODELVIEW); int dis; if(petitcom.xscreenmode == 2) { @@ -691,9 +697,10 @@ class Sprite dis = true; if (!visibles[1]) continue; - disw = 160f; - disw2 = 320f; - petitcom.chScreen(40, 0, 320, 240); + //display:1 + disw = petitcom.currentDisplay.rect[1].w / 2; + disw2 = petitcom.currentDisplay.rect[1].w; + petitcom.chRenderingDisplay(1, clipRect[1].x, clipRect[1].y, clipRect[1].w, clipRect[1].h); aspect = disw2 / dish2; } else @@ -703,9 +710,9 @@ class Sprite dis = false; if (!visibles[0]) continue; - disw = 200f; - disw2 = 400f; - petitcom.chScreen(0, 240, 400, 240); + disw = petitcom.currentDisplay.rect[0].w / 2; + disw2 = petitcom.currentDisplay.rect[0].w; + petitcom.chRenderingDisplay(0, clipRect[0].x, clipRect[0].y, clipRect[0].w, clipRect[0].h); aspect = disw2 / dish2; } } @@ -1127,4 +1134,22 @@ class Sprite id = spid(id); return sprites[id].var[var]; } + SDL_Rect[2] clipRect; + void spclip() + { + spclip(0, 0, petitcom.currentScreenWidth, petitcom.currentScreenHeight); + } + void spclip(int x1, int y1, int x2, int y2) + { + import std.algorithm : swap; + if (x1 > x2) + { + swap(x1, x2); + } + if (y1 > y2) + { + swap(y1, y2); + } + clipRect[petitcom.displaynum] = SDL_Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); + } }