internal virtual void paint(javax.microedition.lcdui.Graphics g) { int old = g.Color; g.Color = color; if (marker == ' ') { for (int i = 0; i < x.Length - 1; i++) { g.drawLine(outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i]), outerInstance.getScreenX(x[i + 1]), outerInstance.getScreenY(y[i + 1])); } } else { for (int i = 0; i < x.Length - 1; i++) { drawSymbol(g, outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i]), marker); } } if (eu != null) { for (int i = 0; i < x.Length - 1; i++) { g.drawLine(outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i] - el[i]), outerInstance.getScreenX(x[i]), outerInstance.getScreenY(y[i] + eu[i])); g.drawLine(outerInstance.getScreenX(x[i]) - 3, outerInstance.getScreenY(y[i] - el[i]), outerInstance.getScreenX(x[i]) + 3, outerInstance.getScreenY(y[i] - el[i])); g.drawLine(outerInstance.getScreenX(x[i]) - 3, outerInstance.getScreenY(y[i] + eu[i]), outerInstance.getScreenX(x[i]) + 3, outerInstance.getScreenY(y[i] + eu[i])); } } g.Color = old; }
internal virtual void drawSymbol(javax.microedition.lcdui.Graphics g, int x, int y, char marker) { switch (marker) { case '+': g.drawLine(x, y - 3, x, y + 3); g.drawLine(x - 3, y, x + 3, y); break; case 'o': g.drawLine(x - 1, y - 3, x + 1, y - 3); g.drawLine(x + 1, y - 3, x + 3, y - 1); g.drawLine(x + 3, y - 1, x + 3, y + 1); g.drawLine(x + 3, y + 1, x + 1, y + 3); g.drawLine(x + 1, y + 3, x - 1, y + 3); g.drawLine(x - 1, y + 3, x - 3, y + 1); g.drawLine(x - 3, y + 1, x - 3, y - 1); g.drawLine(x - 3, y - 1, x - 1, y - 3); break; case 'x': g.drawLine(x - 3, y - 3, x + 3, y + 3); g.drawLine(x + 3, y - 3, x - 3, y + 3); break; case '*': default: g.drawLine(x, y - 3, x, y + 3); g.drawLine(x - 3, y, x + 3, y); g.drawLine(x - 2, y - 2, x + 2, y + 2); g.drawLine(x + 2, y - 2, x - 2, y + 2); break; } }
public static void centerText(javax.microedition.lcdui.Graphics g, string msg, double posY, double centerPos) { int sw = g.Font.stringWidth(msg); double posX = (centerPos) - sw / 2; double dy = 4.0, dx = 0.0; g.drawString(msg, (int)JMath.round(posX - dx), (int)JMath.round(posY - dy), g.BOTTOM | g.LEFT); }
public static void centerTextV(javax.microedition.lcdui.Graphics g, string msg, double posX, double centerPos) { int sw = g.Font.stringWidth(msg); double posY = (centerPos) + sw / 2; double dy = 0.0, dx = 0.0; Font oldFont = g.Font; g.drawString(msg, (int)posX, (int)posY, g.BOTTOM | g.LEFT); g.Font = oldFont; }
public virtual void drawLine(Line line, int color) { Image bufImage = Image.createImage(image.getWidth(), image.getHeight()); Graphics g = bufImage.getGraphics(); g.drawImage(image, 0, 0, 0); g.setColor(color); g.drawLine(line.getP1().getX(), line.getP1().getY(), line.getP2().getX(), line.getP2().getY()); image = bufImage; repaint(); }
public virtual void paint(Graphics g) { g.setColor(0xFFFFFF); g.fillRect(0, 0, getWidth(), getHeight()); if (message1 != null) { g.setColor(0x000000); g.drawString(message1, 1, 1, Graphics.TOP | Graphics.LEFT); g.drawString(message2, 1, 1 + g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT); } }
public virtual void drawCross(Point point, int color) { Image bufImage = Image.createImage(image.getWidth(), image.getHeight()); Graphics g = bufImage.getGraphics(); g.drawImage(image, 0, 0, 0); g.setColor(color); g.drawLine(point.getX() - 5, point.getY(), point.getX() + 5, point.getY()); g.drawLine(point.getX(), point.getY() - 5, point.getX(), point.getY() + 5); image = bufImage; repaint(); }
internal virtual void drawGraph(javax.microedition.lcdui.Graphics g) { int old = g.Color; g.Color = LIGHTGRAY; g.fillRect(0, 0, width, height); for (int i = 0; i < PlotLines.Count; i++) { PlotLine line = (PlotLine)PlotLines[i]; line.paint(g); } g.Color = old; drawAxis(g); }
public virtual void drawPoints(Point[] points, int color) { Image bufImage = Image.createImage(image.getWidth(), image.getHeight()); Graphics g = bufImage.getGraphics(); g.drawImage(image, 0, 0, 0); g.setColor(color); for (int i = 0; i < points.length - 1; i++) { g.drawLine(points[i].getX(), points[i].getY(), points[i].getX() + 1, points[i].getY()); } image = bufImage; repaint(); }
public virtual void drawLines(Line[] lines, int color) { Image bufImage = Image.createImage(image.getWidth(), image.getHeight()); Graphics g = bufImage.getGraphics(); g.drawImage(image, 0, 0, 0); g.setColor(color); for (int i = 0; i < lines.length - 1; i++) { g.drawLine(lines[i].getP1().getX(), lines[i].getP1().getY(), lines[i].getP2().getX(), lines[i].getP2().getY()); } image = bufImage; repaint(); }
public virtual void paint(Graphics g) { g.setColor(0xFFFFFF); g.fillRect(0, 0, getWidth(), getHeight()); if (image != null) { g.drawImage(image, getWidth() / 2, getHeight() / 2, Graphics.VCENTER | Graphics.HCENTER); } g.setColor(0x000000); for (int i = 0; i < log.Length; i++) { if (log[i] != null) { g.drawString(log[i], 0, i * logFont.getHeight(), Graphics.TOP | Graphics.LEFT); } } }
public virtual void paint(javax.microedition.lcdui.Graphics g) { setparam(); if (width < 100 || height < 100) { return; } drawGraph(g); if (pointerMode != PMODE_POINT) { drawStraightLine(g); } if (pointerMode != PMODE_LINE && xp >= 0) { drawPointer(g); } g.drawImage(ShowLine, width - xright + 3, ytop, g.LEFT | g.TOP); }
public virtual void drawMatrix(bool[][] matrix) { Image bufImage = Image.createImage(image.getWidth(), image.getHeight()); Graphics g = bufImage.getGraphics(); g.setColor(0xCCCCCC); for (int y = 0; y < matrix[0].Length; y++) { for (int x = 0; x < matrix.Length; x++) { if (matrix[x][y] == true) { g.drawLine(x, y, x + 1, y); } } } image = bufImage; repaint(); }
internal virtual void drawPointer(javax.microedition.lcdui.Graphics g) { g.Color = RED; fillCircle(g, xp, yp, 3); g.Color = WHITE; g.fillRect(xp, yp, 1, 1); double X = getXCoordinate(xp); if (plotmode == LOGLIN || plotmode == LOGLOG) { X = JMath.pow(10.0, X); } double Y = getYCoordinate(yp); if (plotmode == LINLOG || plotmode == LOGLOG) { Y = JMath.pow(10.0, Y); } drawMessage(g, xp, yp, new string[] { "X=" + fmt.ToString(X), "Y=" + fmt.ToString(Y) }); }
internal virtual void drawMessage(javax.microedition.lcdui.Graphics g, int xp, int yp, string[] msg) { double[] sw = new double[msg.Length]; for (int i = 0; i < sw.Length; i++) { sw[i] = g.Font.stringWidth(msg[i]); } int fh = g.Font.Height; int mw = (int)max(sw) + 10, mh = msg.Length * fh + 6; int xw = xp < width / 2 ? width - xright - mw : xleft; int yw = yp < height / 2 ? height - ybottom - mh : ytop; g.Color = WHITE; g.fillRect(xw, yw, mw, mh); g.Color = BLACK; for (int i = 0; i < msg.Length; i++) { g.drawString(msg[i], xw + 5, yw + (i + 1) * fh + 3, g.BOTTOM | g.LEFT); } }
public virtual void fillCircle(javax.microedition.lcdui.Graphics g, int x, int y, int r) { int r2 = r * r; for (int yd = y - r; yd < y + r; yd++) { if (yd >= 0 && yd < height) { int y2 = (yd - y) * (yd - y); for (int xd = x - r; xd < x + r; xd++) { if (xd >= 0 && xd < width) { if (y2 + (xd - x) * (xd - x) <= r2) { g.fillRect(xd, yd, 1, 1); } } } } } }
internal virtual void drawAxis(javax.microedition.lcdui.Graphics g) { g.Color = BLACK; int x2 = width - xright, y2 = height - ybottom; g.drawLine(xleft, ytop, x2, ytop); g.drawLine(xleft, ytop, xleft, y2); g.drawLine(x2, ytop, x2, y2); g.drawLine(xleft, y2, x2, y2); if (minx < 0 && 0 < maxx) { g.StrokeStyle = g.DOTTED; g.drawLine(getScreenX(0.0), getScreenY(miny), getScreenX(0.0), getScreenY(maxy)); g.StrokeStyle = g.SOLID; } if (miny < 0 && 0 < maxy) { g.StrokeStyle = g.DOTTED; g.drawLine(getScreenX(minx), getScreenY(0.0), getScreenX(maxx), getScreenY(0.0)); g.StrokeStyle = g.SOLID; } drawOrnaments(g); }
internal virtual void drawOrnaments(javax.microedition.lcdui.Graphics g) { int lenMajor = height / 40, i; double x = 0, y = 0; int axis_w = width - xleft - xright; int axis_h = height - ytop - ybottom; string label; int lenlabel = g.Font.stringWidth(" 00.00 "); int maxnumtics = axis_w / lenlabel; double dX = (maxx - minx) / ntx; double startx = minx; while ((maxx - minx) / dX > maxnumtics) { dX *= 2; startx = (int)(startx / dX + 0.5) * dX; if ((maxx - minx) / dX > maxnumtics) { dX *= 2.5; startx = (int)(startx / dX + 0.5) * dX; } } if (plotmode == LOGLIN || plotmode == LOGLOG) { while (Math.Abs((startx / dX) - JMath.round(startx / dX)) > 0.01) { startx += dX; } if (dX < 1.0) { dX = 1.0; } else if (dX == 2.5) { dX = 2.0; } startx = dX * JMath.floor(startx / dX); } int exponent = Math.Max(decExp(maxx), decExp(minx)) - 1; if (Math.Abs(exponent) < 2) { exponent = 0; } double scf = JMath.pow(10.0, (double)exponent); for (i = 0, x = startx; x <= maxx; i++, x += dX) { int xworld = getScreenX(x); if (xworld < xleft) { continue; } g.drawLine(xworld, ytop, xworld, ytop + lenMajor); g.drawLine(xworld, height - ybottom - lenMajor, xworld, height - ybottom); if ((plotmode == LOGLIN || plotmode == LOGLOG) && (dX < 1.5)) { for (int k = 2; k <= 9; k++) { int xk = getScreenX(x + JMath.log((double)k) / JMath.log(10.0)); if (xk > xleft && xk < xleft + width) { g.drawLine(xk, ytop, xk, ytop + lenMajor / 2); g.drawLine(xk, height - ybottom - lenMajor / 2, xk, height - ybottom); } } } if (plotmode == LOGLIN || plotmode == LOGLOG) { label = "10^"; } else { label = ""; } if (x + dX > maxx && exponent != 0) { label = "E" + exponent; } else { label += fmt.ToString(x / scf); } centerText(g, label, height - ybottom + 1.5 * g.Font.Height, xworld); } if (Xlabel_Renamed != null) { centerText(g, Xlabel_Renamed, height - ybottom + 3 * g.Font.Height, xleft + (width - xleft - xright) / 2); } if (Tlabel_Renamed != null) { centerText(g, Tlabel_Renamed, ytop - g.Font.Height / 2, xleft + (width - xleft - xright) / 2); } if (Ylabel_Renamed != null) { centerTextV(g, Ylabel_Renamed, g.Font.Height, ytop + (height - ytop - ybottom) / 2); } int hilabel = g.Font.Height; maxnumtics = (int)((axis_h) / (1.5 * hilabel)); double dY = (maxy - miny) / nty; double starty = miny; while ((maxy - miny) / dY > maxnumtics) { dY *= 2; starty = (int)(starty / dY + 0.5) * dY; if ((maxy - miny) / dY > maxnumtics) { dY *= 2.5; starty = (int)(starty / dY + 0.5) * dY; } } if (plotmode == LINLOG || plotmode == LOGLOG) { if (dY < 1.0) { dY = 1.0; } else if (dY == 2.5) { dY = 2.0; } starty = dY * JMath.floor(starty / dY); } exponent = Math.Max(decExp(maxy), decExp(miny)) - 1; if (Math.Abs(exponent) < 2) { exponent = 0; } scf = JMath.pow(10.0, (double)exponent); for (i = 0, y = starty; y <= maxy; i++, y += dY) { int yworld = getScreenY(y); if (yworld > height - ybottom) { continue; } g.drawLine(xleft, yworld, xleft + lenMajor, yworld); g.drawLine(xleft + axis_w, yworld, xleft + axis_w - lenMajor, yworld); if ((plotmode == LINLOG || plotmode == LOGLOG) && dY < 1.5) { for (int k = 2; k <= 9; k++) { int yk = getScreenY(y + JMath.log((double)k) / JMath.log(10.0)); if (yk > ytop && yk < ytop + height) { g.drawLine(xleft, yk, xleft + lenMajor / 2, yk); g.drawLine(xleft + axis_w, yk, xleft + axis_w - lenMajor / 2, yk); } } } if (plotmode == LINLOG || plotmode == LOGLOG) { label = "10^"; } else { label = ""; } if (y + dY > maxy && exponent != 0) { label = "E" + exponent; } else { label += fmt.ToString(y / scf); } g.drawString(label, xleft - g.Font.stringWidth(label) - 3, yworld + hilabel / 2 - 3, g.BOTTOM | g.LEFT); } }
internal virtual void drawStraightLine(javax.microedition.lcdui.Graphics g) { double xl = minx; double yl = a1 * xl + a0; if (yl > maxy) { yl = maxy; xl = (yl - a0) / a1; } else if (yl < miny) { yl = miny; xl = (yl - a0) / a1; } double xr = maxx; double yr = a1 * xr + a0; if (yr > maxy) { yr = maxy; xr = (yr - a0) / a1; } else if (yr < miny) { yr = miny; xr = (yr - a0) / a1; } if (xp >= 0 && pointerMode == PMODE_LINE) { double xm = getXCoordinate(xp); double ym = getYCoordinate(yp); int Xr = getScreenX(xr), Yr = getScreenY(yr), Xl = getScreenX(xl), Yl = getScreenY(yl); if ((xp - Xr) * (xp - Xr) + (yp - Yr) * (yp - Yr) < (xp - Xl) * (xp - Xl) + (yp - Yl) * (yp - Yl)) { a1 = (ym - yl) / (xm - xl); a0 = yl - a1 * xl; xr = maxx; yr = a1 * xr + a0; if (yr > maxy) { yr = maxy; xr = (yr - a0) / a1; } else if (yr < miny) { yr = miny; xr = (yr - a0) / a1; } } else { a1 = (yr - ym) / (xr - xm); a0 = yr - a1 * xr; xl = minx; yl = a1 * xl + a0; if (yl > maxy) { yl = maxy; xl = (yl - a0) / a1; } else if (yl < miny) { yl = miny; xl = (yl - a0) / a1; } } } g.Color = GREEN; g.drawLine(getScreenX(xl), getScreenY(yl), getScreenX(xr), getScreenY(yr)); g.Color = BLACK; if (pointerMode == PMODE_LINE) { drawMessage(g, xp, yp, new string[] { "a1=" + fmt.ToString(a1), "a0=" + fmt.ToString(a0) }); } }