void drawText(xGraphics g, int x) { Font f = mContext.getFontSmall(); Font fLabel = mContext.getFontText(); // ma co phieu g.setColor(C.COLOR_WHITE); string s = "#" + mTrade.getCode(); g.drawString(mContext.getFontTextB(), s, x, 1); x += g.getStringWidth(mContext.getFontTextB(), s) + 5; // time if (mCandleCnt > 0) { g.setColor(C.COLOR_GRAY_DARK); g.fillRect(0, getH() - 12, getW(), 12); g.setColor(C.COLOR_WHITE); g.drawString(f, mTimeStart, 0 + 1, 0 + getH(), xGraphics.BOTTOM | xGraphics.LEFT); g.drawString(f, mTimeEnd, mChartXYs[2 * (mCandleCnt - 1)], 0 + getH() - 12, xGraphics.BOTTOM | xGraphics.LEFT); g.setColor(C.COLOR_WHITE); s = "KL: " + Utils.formatNumber(mTrade.getVolume(-1)); g.drawString(f, s, (getW() - Utils.getStringW(s, f)) / 2, getH(), xGraphics.BOTTOM); } g.setColor(C.GREY_LINE_COLOR); g.drawHorizontalLine(x, 0 + getH(), getW()); //=============cursor & some info======================== if (mCandleCnt > 0) { //x = getW() / 2; g.setColor(C.COLOR_GRAY_LIGHT); g.drawString(fLabel, mCurrentTrade, x, 0 + 1, xGraphics.LEFT);// xGraphics.HCENTER | xGraphics.TOP); g.setColor(C.COLOR_FADE_YELLOW0); g.drawVerticalLine(mChartXYs[2 * mCurrentTradeSel], 12, getH() - 26); //g.drawPoint(mChartXYs[2 * mCurrentTradeSel] - 2, mChartXYs[2 * mCurrentTradeSel + 1] - 4, 4); if (mChangedValue > 0) { g.setColor(C.COLOR_GREEN); } else if (mChangedValue == 0) { g.setColor(C.COLOR_YELLOW); } else { g.setColor(C.COLOR_RED); } g.drawString(fLabel, mChanged, mChartXYs[2 * mCurrentTradeSel], 26); } //===================================================== }
public void drawGrid(xGraphics g) { g.setColor(C.GREY_LINE_COLOR); int h = getH(); int w = getW(); int gH = h / 10; int gW = w / 10; int i = 0; int y = gH; int x = gW; for (i = 0; i < 9; i++) { g.drawLineDotHorizontal(0, y, getW() - 40); g.drawVerticalLine(x, 0, h); y += gH; x += gW; } }
public override void render(xGraphics g) { int mH = getH(); int mW = getW(); if (isHiding()) { return; } Share share = getShare(3); if (share == null) { return; } if (detectShareCursorChanged()) { share.calcIchimoku(); int newSize = mChartLineLength * 2; mLineTenkansen = allocMem(mLineTenkansen, newSize); mLineKijunsen = allocMem(mLineKijunsen, newSize); mLineChikou = allocMem(mLineChikou, newSize); mLineSpanA = allocMem(mLineSpanA, newSize + 1000); mLineSpanB = allocMem(mLineSpanB, newSize + 1000); int idx = share.mBeginIdx; pricesToYs(share.pTenkansen, idx, mLineTenkansen, mChartLineLength, false); pricesToYs(share.pKijunsen, idx, mLineKijunsen, mChartLineLength, false); pricesToYs(share.pChikouSpan, idx, mLineChikou, mChartLineLength, false); // correct the chikou length int chikouCnt = share.getCandleCount() - (int)mContext.mOptIchimokuTime2; mChikouLineLength = mChartLineLength; if (idx + mChikouLineLength > chikouCnt) { mChikouLineLength = chikouCnt - idx; } int kumoLen = mChartLineLength + (int)mContext.mOptIchimokuTime2; // shift 26 days ahead pricesToYs(share.pSpanA, idx, mLineSpanA, kumoLen, false); pricesToYs(share.pSpanB, idx, mLineSpanB, kumoLen, false); // kumo cloud uint[] colors = { 0x40f06070, 0x40f0f0f0 }; // bronw/white int t = mLineSpanA[1] > mLineSpanB[1] ? 0 : 1; xVectorInt vinters = new xVectorInt(100); xVectorInt vcolors = new xVectorInt(100); vinters.addElement(0); vcolors.addElement((int)colors[t]); for (int i = 0; i < kumoLen; i++) { int j = 2 * i + 1; if (t == 0) { if (mLineSpanA[j] < mLineSpanB[j]) { t = 1 - t; vinters.addElement(i); vcolors.addElement((int)colors[t]); } } else if (t == 1) { if (mLineSpanA[j] > mLineSpanB[j]) { t = 1 - t; vinters.addElement(i); vcolors.addElement((int)colors[t]); } } } //=========================== vinters.addElement(kumoLen - 1); vcolors.addElement(0); // dont care this time clearKumoCloud(); // create kumo cloud for (int i = 1; i < vinters.size(); i++) { int b = vinters.elementAt(i - 1); int e = vinters.elementAt(i); short[] cloud = new short[((e - b + 10) * 4)]; int j = 0; for (int k = b; k <= e; k++) { cloud[j++] = mLineSpanA[2 * k]; cloud[j++] = mLineSpanA[2 * k + 1]; } cloud[j++] = mLineSpanB[2 * e]; cloud[j++] = mLineSpanB[2 * e + 1]; for (int k = e; k >= b; k--) { cloud[j++] = mLineSpanB[2 * k]; cloud[j++] = mLineSpanB[2 * k + 1]; } mKumoCloud.addElement(cloud); mKumoCloudItemLength.addElement(j / 2); mKumoCloudColor.addElement(vcolors.elementAt(i - 1)); } } if (mChartLineLength == 0) { return; } //=============================================== // tenkansen: pink g.setColor(0xc0ff00ff); g.drawLines(mLineTenkansen, mChartLineLength); // kijunsen: g.setColor(0xc00050ff); g.drawLines(mLineKijunsen, mChartLineLength); // chikou if (mChikouLineLength > 0) { g.setColor(0xc0907070); g.drawLines(mLineChikou, mChikouLineLength); } // spanA g.setColor(0xb000a050); g.drawLines(mLineSpanA, mChartLineLength + (int)mContext.mOptIchimokuTime2); // spanB g.setColor(0xb0ff0000); g.drawLines(mLineSpanB, mChartLineLength + (int)mContext.mOptIchimokuTime2); // kumo cloud for (int i = 0; i < mKumoCloud.size(); i++) { short[] p = (short[])mKumoCloud.elementAt(i); if (p != null) { g.setColor(mKumoCloudColor.elementAt(i)); g.fillShapes(p, mKumoCloudItemLength.elementAt(i)); } } // info String sz; StringBuilder sb = Utils.sb; sb.Length = 0; int cur = share.getCursor(); int y = 24; if (mShouldDrawValue && cur >= 0 && cur < share.getCandleCount()) { g.setColor(0x60404040); if (cur - mContext.mOptIchimokuTime2 > 0) { int x0 = candleToX(cur - mContext.mOptIchimokuTime2); g.drawVerticalLine(x0, 0, getH()); } int x1 = candleToX(cur + mContext.mOptIchimokuTime2); g.drawVerticalLine(x1, 0, getH()); //==========draw 2 shadow vertical g.setColor(0xffffa000); sb.AppendFormat("Ichi({0},{1},{2})", (int)mContext.mOptIchimokuTime1, (int)mContext.mOptIchimokuTime2, (int)mContext.mOptIchimokuTime3); sz = sb.ToString(); g.drawString(mFont, sz, 130, y, 0); int x = 150 + g.getStringWidth(mFont, sz) + 10; String sz1; sz1 = formatPrice(share.pTenkansen[cur]); // tenkansen g.setColor(0xc0ff00ff); sb.Length = 0; sb.AppendFormat("Tenkan: {0}", sz1); sz = sb.ToString(); g.drawString(mFont, sz, x, y, 0); x += g.getStringWidth(mFont, sz) + 10; // kijun g.setColor(0xc00050ff); sz1 = formatPrice(share.pKijunsen[cur]); sb.Length = 0; sb.AppendFormat("Kijun: {0}", sz1); sz = sb.ToString(); g.drawString(mFont, sz, x, y, 0); x += g.getStringWidth(mFont, sz) + 10; // chikou g.setColor(0xc0a0a0a0); float chikou = 0; if (cur < share.getCandleCount() - mContext.mOptIchimokuTime2) { chikou = share.pChikouSpan[cur]; } sz1 = formatPrice(chikou); sb.Length = 0; sb.AppendFormat("Chikou: {0}", sz1); sz = sb.ToString(); g.drawString(mFont, sz, x, y, 0); x += g.getStringWidth(mFont, sz) + 10; // spanA g.setColor(0xff00a050); sz1 = formatPrice(share.pSpanA[cur]); sb.Length = 0; sb.AppendFormat("SpanA: {0}", sz1); sz = sb.ToString(); g.drawString(mFont, sz, x, y, 0); x += g.getStringWidth(mFont, sz) + 10; // spanB g.setColor(0xb0ff0000); sz1 = formatPrice(share.pSpanB[cur]); sb.Length = 0; sb.AppendFormat("SpanB: {0}", sz1); sz = sb.ToString(); g.drawString(mFont, sz, x, y, 0); } }
override public void render(xGraphics g) { //========================= if (viewState == VIEWSTATE_1_NHOMNGANH && chartG != null) { chartG.render(g); return; } g.setColor(C.COLOR_BLACK); g.clear(); if (isProcessing) { g.setColor(C.COLOR_ORANGE); g.drawStringInRect(mContext.getFontSmallB(), "Đang xử lý", 0, 0, getW(), getH(), xGraphics.HCENTER | xGraphics.VCENTER); return; } // title // [Hom nay] [1 Tuan] [1 Thang] [3 thang] [1 nam] // Tang | Giam | // VN30: +15%; GTDG: 30.1ti .Chart // if (mChanges.size() == 0) { calcChanged(mPeriod); } if (mChanges.size() == 0) { return; } float x, y; int buttonW = 80; int buttonH = 26; int gap = 4; x = (getW() - 6 * (buttonW + gap)) / 2; // button y = 2; mButtonPositions.removeAllElements(); mPeriods.removeAllElements(); string[] buttons = { "1 Ngày", "1 Tuần", "1 Tháng", "3 Tháng", "6 Tháng", "1 Năm" }; int[] periods = { 1, 5, 22, 67, 130, 260 }; for (int i = 0; i < buttons.Length; i++) { string s = buttons[i]; g.setColor(C.COLOR_GRAY_LIGHT); g.drawRect((int)x, 2, buttonW, buttonH); g.setColor(mPeriod == periods[i]?C.COLOR_ORANGE:C.COLOR_WHITE); g.drawStringInRect(mContext.getFontSmallB(), s, (int)x, (int)y, buttonW, buttonH, xGraphics.HCENTER | xGraphics.VCENTER); Rectangle rc = new Rectangle((int)x, 2, buttonW, buttonH); mButtonPositions.addElement(rc); mPeriods.addElement(periods[i]); x += buttonW + gap; } g.setColor(C.COLOR_GRAY_DARK); g.drawHorizontalLine(0, buttonH + 4, getW()); int columnH = ItemH; double maxPercent = 0; for (int i = 0; i < mChanges.size(); i++) { GroupChanges gc = (GroupChanges)mChanges.elementAt(i); if (Math.Abs(gc.changedPercent) > maxPercent) { maxPercent = Math.Abs(gc.changedPercent); } } //-------------------- int buttonY = 30; int drawH = getH() - buttonY; ItemH = getItemH(getH() - 40, mChanges.size()); float cellW = getW() / 2; float cellH = ItemH; maxPercent *= 1.15; // Left side int j = 0; y = buttonY + 4; int itemPerColumn = mChanges.size() / 2; for (int i = 0; i < itemPerColumn; i++) { GroupChanges gc = (GroupChanges)mChanges.elementAt(i); x = 2; //if (gc.changedPercent >= 0) { y = buttonY + 4 + j * cellH; cellW = (float)((Math.Abs(gc.changedPercent) / maxPercent) * getW() / 2); g.setColor(gc.changedPercent > 0?C.COLOR_GREEN_DARK:C.COLOR_RED); g.fillRectF(x, y, cellW, cellH - 2); // text g.setColor(C.COLOR_WHITE); if (gc.changedPercent >= 0) { string s = String.Format("{0} +{1:F2} %", gc.code, gc.changedPercent); g.drawString(mContext.getFontText(), s, (int)x, (int)(y + cellH / 2), xGraphics.VCENTER); } else { string s = String.Format("{0} {1:F2} %", gc.code, gc.changedPercent); g.drawString(mContext.getFontText(), s, (int)x, (int)(y + cellH / 2), xGraphics.VCENTER); } j++; gc.x = (int)x; gc.y = (int)y; gc.w = (int)getW() / 2 - 10; gc.h = (int)cellH; } } g.setColor(C.COLOR_GRAY_DARK); g.drawVerticalLine(getW() / 2, buttonY, getH()); // Right side j = 0; for (int i = itemPerColumn; i < mChanges.size(); i++) { GroupChanges gc = (GroupChanges)mChanges.elementAt(i); x = getW() / 2 + 2; //if (gc.changedPercent < 0) { y = buttonY + 4 + j * cellH; cellW = (float)((Math.Abs(gc.changedPercent) / maxPercent) * getW() / 2); g.setColor(gc.changedPercent > 0 ? C.COLOR_GREEN_DARK : C.COLOR_RED); g.fillRectF(x, y, cellW, cellH - 2); // text g.setColor(C.COLOR_WHITE); if (gc.changedPercent >= 0) { string s = String.Format("{0}: +{1:F2} %", gc.code, gc.changedPercent); g.drawString(mContext.getFontText(), s, (int)x, (int)(y + cellH / 2), xGraphics.VCENTER); } else { string s = String.Format("{0}: {1:F2} %", gc.code, gc.changedPercent); g.drawString(mContext.getFontText(), s, (int)x, (int)(y + cellH / 2), xGraphics.VCENTER); } j++; gc.x = (int)x; gc.y = (int)y; gc.w = (int)getW() / 2 - 10; gc.h = (int)cellH; } } }