From 3eaee11c981f09cd9aa34461a0bce5bb3e3b7d11 Mon Sep 17 00:00:00 2001 From: otya128 Date: Sat, 3 Dec 2016 20:13:39 +0900 Subject: [PATCH] implement GCIRCLE X,Y,R,S,E,C --- SMILEBASIC/builtinfunctions.d | 2 +- SMILEBASIC/graphic.d | 58 ++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/SMILEBASIC/builtinfunctions.d b/SMILEBASIC/builtinfunctions.d index 71823e7..4c67fa4 100644 --- a/SMILEBASIC/builtinfunctions.d +++ b/SMILEBASIC/builtinfunctions.d @@ -326,7 +326,7 @@ class BuiltinFunction static void GCIRCLE(PetitComputer p, int x, int y, int r, DefaultValue!(int, false) color) { color.setDefaultValue(p.graphic.gcolor); - p.graphic.gcircle(p.graphic.useGRP, x, y, r, 0, 360, 0, cast(int)color); + p.graphic.gcircle(p.graphic.useGRP, x, y, r, cast(int)color); } static void GCIRCLE(PetitComputer p, int x, int y, int r, int sr, int er, DefaultValue!(int, false) flag, DefaultValue!(int, false) color) { diff --git a/SMILEBASIC/graphic.d b/SMILEBASIC/graphic.d index b123386..8fcccf3 100644 --- a/SMILEBASIC/graphic.d +++ b/SMILEBASIC/graphic.d @@ -182,15 +182,45 @@ class Graphic } } Paint paint; + //(x+r,y):0° + //(x,y+r):90° void drawCircle(int x, int y, int r, int startr, int endr, int flag) { import std.math : sin, cos, PI; int count = r; - glBegin(GL_LINE_LOOP); + if (flag) + { + glBegin(GL_LINE_LOOP); + glVertex2i(x, y); + } + else + { + glBegin(GL_LINE_STRIP); + } + startr = startr % 360; + endr = endr % 360; + if (startr > endr) + { + endr += 360; + } + for (int i = 0; i <= r; i++) + { + //float a = i * (360f / count); + float angle = (cast(float)i / count) * ((endr - startr) / 180f) * PI + (startr / 180f * PI); + glVertex2f(cos(angle) * r + x, sin(angle) * r + y); + } + glEnd(); + } + void drawCircle(int x, int y, int r) + { + import std.math : sin, cos, PI; + int count = r; + glBegin(GL_LINE_STRIP); for (int i = 0; i <= r; i++) { //float a = i * (360f / r); - glVertex2f(sin(cast(float)i / count * 2f * PI) * r + x, cos(cast(float)i / count * 2f * PI) * r + y); + float angle = cast(float)i / count * 2f * PI; + glVertex2f(cos(angle) * r + x, sin(angle) * r + y); } glEnd(); } @@ -289,7 +319,13 @@ class Graphic } } break; - case DrawType.CIRCLE: + case DrawType.CIRCLE1: + { + glColor4ubv(cast(ubyte*)&dm.color); + drawCircle(dm.x, dm.y, dm.circle.r); + } + break; + case DrawType.CIRCLE2: { glColor4ubv(cast(ubyte*)&dm.color); drawCircle(dm.x, dm.y, dm.circle.r, dm.circle.startr, dm.circle.endr, dm.circle.flag); @@ -321,7 +357,8 @@ class Graphic LINE, FILL, BOX, - CIRCLE, + CIRCLE1, + CIRCLE2,//startangle, endangle TRI, PAINT, } @@ -406,6 +443,17 @@ class Graphic { sendDrawMessage(DrawType.PAINT, cast(byte)page, cast(short)x, cast(short)y, color); } + void gcircle(int page, int x, int y, int r, uint color) + { + DrawMessage dm; + dm.page = cast(byte)page; + dm.x = cast(short)x; + dm.y = cast(short)y; + dm.circle.r = cast(short)r; + dm.color = color; + dm.type = DrawType.CIRCLE1; + sendDrawMessage(dm); + } void gcircle(int page, int x, int y, int r, int startr, int endr, int flag, uint color) { DrawMessage dm; @@ -417,7 +465,7 @@ class Graphic dm.circle.endr = cast(short)endr; dm.circle.flag = cast(short)flag; dm.color = color; - dm.type = DrawType.CIRCLE; + dm.type = DrawType.CIRCLE2; sendDrawMessage(dm); } int gprio;