diff --git a/libCompiler/src/main/assets/code_sample/complete_program/text_animate.pas b/libCompiler/src/main/assets/code_sample/complete_program/text_animate.pas new file mode 100644 index 00000000..6c25c75c --- /dev/null +++ b/libCompiler/src/main/assets/code_sample/complete_program/text_animate.pas @@ -0,0 +1,308 @@ +{ ------—— + Text animation on graphics + by: Mr Bee -- @pak_lebah +} + +uses CRT, Graph; + +const + // global value setup + THE_TEXT = 'PASCAL ON ANDROID'; + + V_MOTION = 20; + // motion speed + D_MOTION = 1; // motion delay + +type + // letter structure + + TLetter = record + l : string; + // character + x, y : integer; + // position + w, h : integer; + // dimension + c : integer; + // color + end; + + TLetters = array of TLetter; + +var + goSpread : boolean; + // motion direction + goStraight : boolean; + // animation mode + doneX, doneY, done : boolean; // anim state + +// spread letters all over the screen +procedure spread(var l : TLetters); +var + i : integer; +begin + for i := 0 to high(l) do + begin + // random all over the screen + l[i].x := random(getMaxX - l[i].w) + 1; + l[i].y := random(getMaxY - l[i].h) + 1; + l[i].c := random(getMaxColor) + 9; + end; +end; + +// gather all letters into a text +procedure gather(var l : TLetters); +var + tw, th : integer; + // text dimension + tx, ty : integer; + // text position + i : integer; + s : string; +begin + // compute text dimension + s := ''; + tw := 0; + for i := 0 to high(l) do s += l[i].l; + for i := 0 to high(l) do tw += l[i].w; + th := textHeight(s); + tx := random(getMaxX - tw) + 1; + ty := random(getMaxY - th) + 1; + // align text onto new position + tw := 0; + for i := 0 to high(l) do + begin + l[i].x := tx + tw; + l[i].y := ty; // horz aligned + l[i].c := random(getMaxColor) + 9; + tw += l[i].w; + end; +end; + +// animate on x position +procedure animX(var f, t : TLetters); +var + i, v : integer; +begin + v := V_MOTION; + doneX := true; + for i := 0 to high(f) do + begin + // move left + if f[i].x > t[i].x then + begin + f[i].x := f[i].x - v; + if f[i].x < t[i].x then + f[i].x := t[i].x; + end + // move right + else if f[i].x < t[i].x then + begin + f[i].x := f[i].x + v; + if f[i].x > t[i].x then + f[i].x := t[i].x + end + else + f[i].x := t[i].x; + // save state + doneX := doneX and (f[i].x = t[i].x); + end; +end; + +// animate on y position +procedure animY(var f, t : TLetters); +var + i, v : integer; +begin + v := V_MOTION; + doneY := true; + for i := 0 to high(f) do + begin + // move up + if f[i].y > t[i].y then + begin + f[i].y := f[i].y - v; + if f[i].y < t[i].y then + f[i].y := t[i].y; + end + // move down + else if f[i].y < t[i].y then + begin + f[i].y := f[i].y + v; + if f[i].y > t[i].y then + f[i].y := t[i].y + end + else + f[i].y := t[i].y; + // save state + doneY := doneY and (f[i].y = t[i].y); + end; +end; + +// animate text +procedure animate(var f, t : TLetters); +begin + if goStraight then + begin + if not doneX then animX(f, t); + if not doneY then animY(f, t); + end else + begin + if goSpread then + begin + // go vertical first + if not doneY then + animY(f, t) + else begin + if not doneX then + animX(f, t); + end; + end else + begin + // go horizontal first + if not doneX then + animX(f, t) + else begin + if not doneY then + animY(f, t); + end; + end; + end; + // state + done := doneX and doneY; +end; + +// print letters on the screen +procedure print(l : TLetters); +var + i : integer; +begin + for i := 0 to high(l) do + begin + setColor(l[i].c); + outTextXY(l[i].x, l[i].y, l[i].l); + end; +end; + +// convert string to animated letters +function toLetters(s : string) : TLetters; +var + i, w : integer; + l : TLetters; +begin + w := 1; + setLength(l, length(s)); + for i := 0 to length(s) - 1 do + begin + l[i].l := s[i + 1]; + l[i].w := textWidth(l[i].l) + 3; + l[i].h := textHeight(l[i].l) + 2; + l[i].x := w; + l[i].y := l[i].h; + l[i].c := random(getMaxColor) + 1; + // space doesn't have width + if l[i].l = ' ' then + l[i].w := textWidth('H') + 2; + // i is too thin + if upCase(l[i].l) = 'I' then + l[i].w := l[i].w + 2; + w += l[i].w; + end; + toLetters := l; +end; + +// remove text footprint +procedure clear(l : TLetters); +var + i : integer; +begin + clearBuffer; + for i := 0 to high(l) do + begin + setColor(-14803426); + outTextXY(l[i].x, l[i].y, l[i].l); + end; +end; + +// copy letter colors +procedure copyCol(var f, t : TLetters); +var + i : integer; +begin + for i := 0 to high(f) do + t[i].c := f[i].c; +end; + +// screen setup +procedure openScreen; +var + gd, gm : integer; +begin + randomize; + // setup graph mode + gd := detect; + setBufferEnable(true); + initGraph(gd, gm, ''); + setTextJustify(leftText, bottomText); + setTextStyle(gothicFont, horizDir, 3); +end; + +// screen closing +procedure closeScreen; +begin + closeGraph; +end; + +{+++ MAIN PROGRAM +++} + +var + f, t : TLetters; + //c: char = #0; + +begin + // setup + openScreen; + goSpread := true; + goStraight := true; + f := toLetters(THE_TEXT); + t := toLetters(THE_TEXT); + gather(f); // from (origin) + spread(t); // to (target) + + // animate + repeat + // draw + clear(t); + print(f); + drawBuffer; + delay(D_MOTION); + + // check done + if done then + begin + // switch destination + copyCol(t, f); + goSpread := not goSpread; + if goSpread then spread(t) + else gather(t); + + // freeze for 1 second + delay(1000); + + // reset state + doneX := false; + doneY := false; + done := false; + + // switch mode + if random(2) = 1 then + goStraight := not goStraight; + end; + + // motion + animate(f, t); + until keyPressed; + + // close down + closeScreen; +end. \ No newline at end of file diff --git a/libCompiler/src/main/java/com/duy/pascal/backend/ast/FunctionDeclaration.java b/libCompiler/src/main/java/com/duy/pascal/backend/ast/FunctionDeclaration.java index b4f46932..f06fadef 100644 --- a/libCompiler/src/main/java/com/duy/pascal/backend/ast/FunctionDeclaration.java +++ b/libCompiler/src/main/java/com/duy/pascal/backend/ast/FunctionDeclaration.java @@ -47,6 +47,7 @@ import com.duy.pascal.backend.types.RuntimeType; import com.duy.pascal.frontend.debug.CallStack; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -70,6 +71,8 @@ public class FunctionDeclaration extends AbstractCallableFunction { private boolean isProcedure = false; private boolean bodyDeclared; + private int modifier = Modifier.PUBLIC; + public FunctionDeclaration(String name, ExpressionContext parent, GrouperToken grouperToken, boolean isProcedure) throws ParsingException { parseHeader(name, parent, grouperToken, isProcedure); @@ -87,6 +90,14 @@ public FunctionDeclaration(ExpressionContext p) { this.argumentTypes = new RuntimeType[0]; } + public int getModifier() { + return modifier; + } + + public void setModifier(int modifier) { + this.modifier = modifier; + } + public void parseHeader(String name, ExpressionContext parent, GrouperToken grouperToken, boolean isProcedure) throws ParsingException { // DLog.d(TAG, "parseHeader() called with: name = [" + name + "], parent = [" + parent + "], grouperToken = [" + grouperToken + "], isProcedure = [" + isProcedure + "]"); diff --git a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/crt/ColorUtils.java b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/crt/ColorUtils.java index 7ed7fd66..9a7a4a08 100644 --- a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/crt/ColorUtils.java +++ b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/crt/ColorUtils.java @@ -76,14 +76,15 @@ public static int androidColorToPascalColor(int androidColor) { if (mapColorsAndroid.get(androidColor) != null) { return mapColorsAndroid.get(androidColor); } - return Color.rgb(Color.red(androidColor), Color.green(androidColor), - Color.blue(androidColor)); + return Color.argb(Color.alpha(androidColor), + Color.red(androidColor), Color.green(androidColor), Color.blue(androidColor)); } public static int pascalColorToAndroidColor(int pascalColor) { if (mapColorsPascal.get(pascalColor) != null) { return mapColorsPascal.get(pascalColor); } - return Color.rgb(Color.red(pascalColor), Color.green(pascalColor), Color.blue(pascalColor)); + return Color.argb(Color.alpha(pascalColor), + Color.red(pascalColor), Color.green(pascalColor), Color.blue(pascalColor)); } } diff --git a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphLib.java b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphLib.java index 32c5aee1..59f0041b 100644 --- a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphLib.java +++ b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphLib.java @@ -293,7 +293,7 @@ public void declareFunctions(ExpressionContextMixin parentContext) { @PascalMethod(description = "graph library") public void arc(int x, int y, int stAngle, int endAngle, int radius) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen() .addGraphObject(new ArcObject(x, y, stAngle, endAngle, radius)); @@ -307,7 +307,7 @@ public void arc(int x, int y, int stAngle, int endAngle, int radius) { @PascalMethod(description = "graph library") public void bar(int x1, int y1, int x2, int y2) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen() .addGraphObject(new BarObject(x1, y1, x2, y2)); } @@ -328,7 +328,7 @@ public int getMaxY() { @PascalMethod(description = "Initialize graphical system") public void initGraph(int driver, int mode, StringBuilder pathToDriver) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().setGraphicMode(true); } @@ -341,14 +341,14 @@ public void initGraph(int driver, int mode, StringBuilder pathToDriver) { @PascalMethod(description = "Draw a rectangle on the screen") public void rectangle(int x1, int y1, int x2, int y2) { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) handler.getConsoleView().getGraphScreen().addGraphObject(new RectangleObject(x1, y1, x2, y2)); } @PascalMethod(description = "graph library") public void line(int x1, int y1, int x2, int y2) { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) handler.getConsoleView().getGraphScreen().addGraphObject(new LineObject(x1, y1, x2, y2)); } @@ -358,7 +358,7 @@ public void line(int x1, int y1, int x2, int y2) { @PascalMethod(description = "graph library") public int getY() { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { return handler.getConsoleView().getYCursorPixel(); } else { return 0; @@ -371,7 +371,7 @@ public int getY() { @PascalMethod(description = "graph library") public int getX() { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { return handler.getConsoleView().getXCursorPixel(); } else { return 0; @@ -410,7 +410,7 @@ public void closeGraph() { @PascalMethod(description = "graph library") public int getColor() { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) return handler.getConsoleView().getForegroundGraphColor(); else return 0; //black @@ -471,7 +471,7 @@ public Integer graphResult() { @PascalMethod(description = "graph library") public void circle(int x, int y, int r) { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) handler.getConsoleView().getGraphScreen().addGraphObject(new CircleObject(x, y, r)); } @@ -483,7 +483,7 @@ public void circle(int x, int y, int r) { @PascalMethod(description = "graph library") public void lineTo(int x, int y) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { ConsoleCursor point = handler.getConsoleView().getCursorGraphic(); handler.getConsoleView().getGraphScreen().addGraphObject(new LineObject(point.x, point.y, x, y)); @@ -494,7 +494,7 @@ public void lineTo(int x, int y) { @PascalMethod(description = "graph library") public void ellipse(int x, int y, int start, int end, int rx, int ry) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new ArcEllipseObject(x, y, start, end, rx, ry)); } @@ -503,7 +503,7 @@ public void ellipse(int x, int y, int start, int end, int rx, int ry) { @PascalMethod(description = "graph library") public void fillEllipse(int x, int y, int rx, int ry) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new EllipseObject(x, y, rx, ry)); } @@ -519,7 +519,7 @@ public int getMaxColor() { @PascalMethod(description = "graph library") public void putPixel(int x, int y, int color) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new PixelObject(x, y, ColorUtils.pascalColorToAndroidColor(color))); @@ -529,7 +529,7 @@ public void putPixel(int x, int y, int color) { @PascalMethod(description = "graph library") public void setLineStyle(int style, int linePattern, int width) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { GraphScreen graphScreen = handler.getConsoleView().getGraphScreen(); graphScreen.setLineStyle(style); @@ -541,7 +541,7 @@ public void setLineStyle(int style, int linePattern, int width) { @PascalMethod(description = "graph library") public void outTextXY(int x, int y, StringBuilder text) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new TextGraphObject(text.toString(), x, y)); @@ -580,7 +580,7 @@ public void installUserFont(String path) { @PascalMethod(description = "graph library") public int getBkColor() { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) return handler.getConsoleView().getGraphScreen().getBackgroundColor(); else return 0; @@ -589,8 +589,9 @@ public int getBkColor() { @PascalMethod(description = "graph library") public void setBkColor(int color) { - if ( handler.getConsoleView() != null) + if (handler.getConsoleView() != null) { handler.getConsoleView().setGraphBackground(ColorUtils.pascalColorToAndroidColor(color)); + } } @@ -601,7 +602,7 @@ public void setBkColor(int color) { @PascalMethod(description = "graph library") public void setViewPort(int x1, int y1, int x2, int y2, boolean clip) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().setViewPort(x1, y1, x2, y2, clip); } @@ -610,7 +611,7 @@ public void setViewPort(int x1, int y1, int x2, int y2, boolean clip) { @PascalMethod(description = "graph library") public synchronized void setTextStyle(int fontID, int direction, int size) { // TODO: 09-Apr-17 - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { GraphScreen graphScreen = handler.getConsoleView().getGraphScreen(); graphScreen.setTextSize(size); @@ -623,7 +624,7 @@ public synchronized void setTextStyle(int fontID, int direction, int size) { @PascalMethod(description = "graph library") public void setFillStyle(int pattern, int color) { // TODO: 09-Apr-17 - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { GraphScreen graphScreen = handler.getConsoleView().getGraphScreen(); graphScreen.setFillPattern(pattern); @@ -641,7 +642,7 @@ public void setDirectVideo(boolean assess) { @PascalMethod(description = "Draw and fill a sector of an ellipse") public void sector(int x, int y, int start, int end, int rx, int ry) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new SectorObject(x, y, start, end, rx, ry)); } @@ -653,7 +654,7 @@ public void sector(int x, int y, int start, int end, int rx, int ry) { */ @PascalMethod(description = "Draw a pie-slice") public void pieSlice(int x, int y, int start, int end, int radius) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen().addGraphObject(new PieSliceObject(x, y, start, end, radius)); } @@ -709,7 +710,7 @@ public int getMaxMode() { @PascalMethod(description = "Set text placement style") public void setTextJustify(int horizontal, int vertical) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { TextJustify textJustify = handler.getConsoleView().getGraphScreen().getTextJustify(); textJustify.setHorizontal(horizontal); textJustify.setVertical(vertical); @@ -719,7 +720,7 @@ public void setTextJustify(int horizontal, int vertical) { @PascalMethod(description = "graph library") public void Bar3D(int x1, int y1, int x2, int y2, int depth, boolean topOn) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen() .addGraphObject(new Bar3DObject(x1, y1, x2, y2, depth, topOn)); } @@ -729,7 +730,7 @@ public void Bar3D(int x1, int y1, int x2, int y2, int depth, boolean topOn) { @PascalMethod(description = "graph library") public void FillEllipse(int x, int y, int rx, int ry) { DLog.d(TAG, "FillEllipse: "); - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { handler.getConsoleView().getGraphScreen() .addGraphObject(new FillEllipseObject(x, y, rx, ry)); } @@ -739,7 +740,7 @@ public void FillEllipse(int x, int y, int rx, int ry) { @PascalMethod(description = "graph library") public void FloodFill(int x, int y, int borderColorIndex) { DLog.d(TAG, "FloodFill: "); - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { GraphScreen graphScreen = handler.getConsoleView().getGraphScreen(); Bitmap graphBitmap = graphScreen.getGraphBitmap(); @@ -761,7 +762,7 @@ public void FloodFill(int x, int y, int borderColorIndex) { @PascalMethod(description = "graph library") public void SetTextJustify(int horizontal, int vertical) { - if ( handler.getConsoleView() != null) { + if (handler.getConsoleView() != null) { GraphScreen graphScreen = handler.getConsoleView().getGraphScreen(); TextPaint textPaint = graphScreen.getTextPaint(); diff --git a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphScreen.java b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphScreen.java index cebab208..28c5aedd 100644 --- a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphScreen.java +++ b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/GraphScreen.java @@ -56,9 +56,10 @@ public class GraphScreen { private ViewPort viewPort = new ViewPort(0, 0, width, height); private Paint mBackgroundPaint = new Paint(); - private TextPaint textPaint = new TextPaint(); - private LinePaint linePaint = new LinePaint(); - private FillPaint fillPaint = new FillPaint(); + + private TextPaint mTextPaint = new TextPaint(); + private LinePaint mLinePaint = new LinePaint(); + private FillPaint mFillPaint = new FillPaint(); /** * this object used to draw {@link GraphObject} @@ -76,13 +77,14 @@ public class GraphScreen { public GraphScreen(Context context, ConsoleView consoleView) { this.context = context; this.mConsoleView = consoleView; + //setup cursor paint mBackgroundPaint.setColor(Color.BLACK); - fillPaint.setStyle(Paint.Style.FILL); + mFillPaint.setStyle(Paint.Style.FILL); } public void setTextStyle(int textStyle) { - this.textPaint.setTextStyle(textStyle); + this.mTextPaint.setTextStyle(textStyle); } public void setLineWidth(int lineWidth) { @@ -102,11 +104,11 @@ public void setFillColor(int fillColor) { } public void setTextDirection(int textDirection) { - this.textPaint.setTextDirection(textDirection); + this.mTextPaint.setTextDirection(textDirection); } public void setTextSize(int textSize) { - textPaint.setTextSize(textSize * TextPaint.DEF_TEXT_SIZE); + mTextPaint.setTextSize(textSize * TextPaint.DEF_TEXT_SIZE); } public int getBackgroundColor() { @@ -155,7 +157,7 @@ private synchronized void invalidateBitmap() { } else { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); - canvas.drawBitmap(mPrimaryBitmap, 0, 0, textPaint); + canvas.drawBitmap(mPrimaryBitmap, 0, 0, mTextPaint); synchronized (mLock) { mPrimaryBitmap.recycle(); mPrimaryBitmap = bitmap; @@ -167,7 +169,7 @@ private synchronized void invalidateBitmap() { } else { Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvasBuffer = new Canvas(buffer); - canvasBuffer.drawBitmap(mBitmapBuffer, 0, 0, textPaint); + canvasBuffer.drawBitmap(mBitmapBuffer, 0, 0, mTextPaint); synchronized (mLock) { mBitmapBuffer.recycle(); mBitmapBuffer = buffer; @@ -198,11 +200,11 @@ public int getXCursor() { } public int getPaintColor() { - return textPaint.getColor(); + return mTextPaint.getColor(); } public void setPaintColor(int paintColor) { - this.textPaint.setColor(paintColor); + this.mTextPaint.setColor(paintColor); } public void closeGraph() { @@ -219,20 +221,13 @@ public void clear() { */ private void clearPrimaryBitmap() { synchronized (mLock) { - /* Canvas canvas = null; - if (mPrimaryBitmap != null) { - canvas = new Canvas(mPrimaryBitmap); - Paint paint = new Paint(); - paint.setColor(Color.BLACK); - canvas.drawRect(0, 0, mPrimaryBitmap.getWidth(), mPrimaryBitmap.getHeight(), paint); - }*/ if (ensurePrimaryNonNull()) { mPrimaryBitmap.eraseColor(Color.TRANSPARENT); } } } - public void setCursorPostion(int x, int y) { + public void setCursorPosition(int x, int y) { this.mCursor.setCoordinate(x, y); } @@ -245,8 +240,8 @@ public void addGraphObject(GraphObject graphObject) { graphObject.setLineWidth(lineWidth); graphObject.setLineStyle(lineStyle); - graphObject.setLineColor(textPaint.getColor()); - graphObject.setTextPaint(textPaint.clonePaint()); + graphObject.setLineColor(mTextPaint.getColor()); + graphObject.setTextPaint(mTextPaint.clonePaint()); graphObject.setAntiAlias(antiAlias); this.lastObject = graphObject; @@ -264,11 +259,11 @@ public Paint getBackgroundPaint() { } public void getTextBound(String text, Rect store) { - textPaint.getTextBounds(text, 0, text.length(), store); + mTextPaint.getTextBounds(text, 0, text.length(), store); } public TextPaint getTextPaint() { - return textPaint; + return mTextPaint; } /** @@ -280,12 +275,12 @@ public void setViewPort(int x1, int y1, int x2, int y2, boolean clip) { } public void setPaintStyle(int style, int pattern, int width) { - textPaint.setStrokeWidth(width); + mTextPaint.setStrokeWidth(width); } public synchronized void setFontID(int fontID) { - this.textPaint.setTextFontID(fontID); + this.mTextPaint.setTextFontID(fontID); Typeface font; switch (fontID) { case TextFont.DefaultFont: @@ -310,16 +305,16 @@ public synchronized void setFontID(int fontID) { font = Typeface.MONOSPACE; break; } - textPaint.setTextFont(font); + mTextPaint.setTextFont(font); } public TextJustify getTextJustify() { - return textPaint.getTextJustify(); + return mTextPaint.getTextJustify(); } public void setTextJustify(TextJustify textJustify) { - this.textPaint.setTextJustify(textJustify); + this.mTextPaint.setTextJustify(textJustify); } public void setLinePattern(int linePattern) { @@ -368,23 +363,12 @@ private boolean ensurePrimaryNonNull() { public void bufferToPrimary() { if (mBitmapBuffer != null) { -// ensurePrimaryNonNull(); -// Canvas canvas = new Canvas(mPrimaryBitmap); -// canvas.drawBitmap(mBitmapBuffer, 0, 0, null); -// this.mPrimaryBitmap = mBitmapBuffer.copy(mBitmapBuffer.getConfig(), true); this.mPrimaryBitmap = mBitmapBuffer.copy(mBitmapBuffer.getConfig(), true); } } public synchronized void clearBufferBitmap() { synchronized (mLock) { - /* Canvas canvas = null; - if (mBitmapBuffer != null) { - canvas = new Canvas(mBitmapBuffer); - Paint paint = new Paint(); - paint.setColor(Color.BLACK); - canvas.drawRect(0, 0, mBitmapBuffer.getWidth(), mBitmapBuffer.getHeight(), paint); - }*/ if (mBitmapBuffer != null) mBitmapBuffer.eraseColor(Color.TRANSPARENT); } } diff --git a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/model/GraphObject.java b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/model/GraphObject.java index 8c3162c3..5e8b909e 100644 --- a/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/model/GraphObject.java +++ b/libCompiler/src/main/java/com/duy/pascal/backend/builtin_libraries/graph/model/GraphObject.java @@ -90,6 +90,7 @@ public void setLineStyle(int lineStyle) { public void setLineColor(int color) { linePaint.setColor(color); + textPaint.setColor(color); } @@ -162,6 +163,7 @@ public void setFillStyle(Context context, int fillStyle, int color) { public abstract void draw(Canvas canvas); public void draw(Bitmap parent) { + Canvas canvas = new Canvas(parent); draw(canvas); } diff --git a/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/ConsoleView.java b/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/ConsoleView.java index de62fc69..76c71e51 100644 --- a/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/ConsoleView.java +++ b/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/ConsoleView.java @@ -939,7 +939,7 @@ public void clearGraphic() { //pascal public void setCursorGraphPosition(int x, int y) { - mGraphScreen.setCursorPostion(x, y); + mGraphScreen.setCursorPosition(x, y); } public ConsoleCursor getCursorGraphic() { diff --git a/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/TextRenderer.java b/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/TextRenderer.java index fafbbb61..0bbb0425 100644 --- a/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/TextRenderer.java +++ b/libCompiler/src/main/java/com/duy/pascal/frontend/view/exec_screen/console/TextRenderer.java @@ -44,11 +44,11 @@ public class TextRenderer implements ScreenObject { private int mCharDescent; private int mCharWidth; private int mTextMode = 0; - private Typeface typeface = Typeface.MONOSPACE; + private Typeface mTypeface = Typeface.MONOSPACE; private Paint mTextPaint = new Paint(); - private Paint backgroundPaint = new Paint(); - private int textColor = Color.WHITE; - private int textBackgroundColor = Color.BLACK; + private Paint mBackgroundPaint = new Paint(); + private int mTextColor = Color.WHITE; + private int mTextBackgroundColor = Color.BLACK; private int alpha = NORMAL_TEXT_ALPHA; private boolean fixedWidthFont; @@ -57,15 +57,15 @@ public TextRenderer(float textSize) { } public int getTextBackgroundColor() { - return textBackgroundColor; + return mTextBackgroundColor; } public void setTextBackgroundColor(int color) { - this.textBackgroundColor = color; + this.mTextBackgroundColor = color; } private void init(float textSize) { - mTextPaint.setTypeface(typeface); + mTextPaint.setTypeface(mTypeface); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); @@ -98,8 +98,8 @@ public void drawText(Canvas canvas, float x, float y, TextConsole[] text, int st for (int i = start; i < start + count; i++) { if (!fixedWidthFont) mCharWidth = (int) mTextPaint.measureText(text[i].getSingleString()); - backgroundPaint.setColor(text[i].getTextBackground()); - canvas.drawRect(x, y + mCharAscent, x + mCharWidth, y + mCharDescent, backgroundPaint); + mBackgroundPaint.setColor(text[i].getTextBackground()); + canvas.drawRect(x, y + mCharAscent, x + mCharWidth, y + mCharDescent, mBackgroundPaint); mTextPaint.setColor(text[i].getTextColor()); mTextPaint.setAlpha(text[i].getAlpha()); @@ -118,12 +118,12 @@ public void setTextSize(float textSize) { } public Typeface getTypeface() { - return typeface; + return mTypeface; } - public void setTypeface(Typeface typeface) { - this.typeface = typeface; - mTextPaint.setTypeface(typeface); + public void setTypeface(Typeface mTypeface) { + this.mTypeface = mTypeface; + mTextPaint.setTypeface(mTypeface); } public int getCharHeight() { @@ -160,11 +160,11 @@ public void setCharWidth(int mCharWidth) { public int getTextColor() { - return textColor; + return mTextColor; } - public void setTextColor(int textColor) { - this.textColor = textColor; + public void setTextColor(int mTextColor) { + this.mTextColor = mTextColor; } public int getTextMode() { @@ -195,7 +195,7 @@ public void draw(Canvas canvas) { } public int getBackgroundColor() { - return textBackgroundColor; + return mTextBackgroundColor; } public int getAlpha() { diff --git a/test_pascal/test_graph/test_tranfercent.pas b/test_pascal/test_graph/test_tranfercent.pas new file mode 100644 index 00000000..14b065e3 --- /dev/null +++ b/test_pascal/test_graph/test_tranfercent.pas @@ -0,0 +1,20 @@ +uses graph; +const + start : array[1..10] of PointType = + ((x : 439; y : 201), (x : 352; y : 196), (x : 320; y : 115), (x : 288; y : 196), + (x : 201; y : 201), (x : 268; y : 257), (x : 247; y : 341), (x : 320; y : 295), + (x : 393; y : 341), (x : 372; y : 257)); +var + gd, gm : integer; +begin + gd := Detect; + InitGraph(gd, gm, ''); + + SetBkColor(LightRed); + SetColor(Yellow); + + SetFillStyle(1, Yellow); + FillPoly(10, start); + readln; + closegraph; +end. \ No newline at end of file diff --git a/test_pascal/test_graph/test_tranfercent2.pas b/test_pascal/test_graph/test_tranfercent2.pas new file mode 100644 index 00000000..1b771256 --- /dev/null +++ b/test_pascal/test_graph/test_tranfercent2.pas @@ -0,0 +1,17 @@ +uses graph; +var + gd, gm : integer; +begin + gd := Detect; + InitGraph(gd, gm, ''); + + SetBkColor(LightRed); + SetColor(Yellow); + + SetFillStyle(1, 1401028352); + bar(0, 0, getMaxX div 3 * 2, getMaxY); + SetFillStyle(1, -1540161281); + bar(getMaxX div 3 , 0, getMaxX , getMaxY); + readln; + closegraph; +end. \ No newline at end of file