void TextSegment::Paint(Graphics &g, TextArea *theTextArea, int theStartChar, int theEndChar, int xpos, int ypos, int lineHeight) { int aSelStartChar = theTextArea->mSelStartChar - mAbsStartChar; int aSelEndChar = theTextArea->mSelEndChar - mAbsStartChar; if(theStartChar > aSelStartChar) aSelStartChar = theStartChar; if(theEndChar < aSelEndChar) aSelEndChar = theEndChar; g.SetColor(mColor); g.SetFont(mFont); bool fullSelection = aSelStartChar==theStartChar && aSelEndChar==theEndChar; if(!fullSelection) g.DrawString(mText, theStartChar, theEndChar - theStartChar, xpos, ypos); if(aSelEndChar > aSelStartChar) { int x = xpos + mFont->GetStringWidth(mText,theStartChar,aSelStartChar-theStartChar); int aWidth = mFont->GetStringWidth(mText,aSelStartChar,aSelEndChar-aSelStartChar); g.SetColor(theTextArea->mSelColor.GetBackgroundColor(g)); g.FillRect(x,0,aWidth,lineHeight); g.SetColor(theTextArea->mSelColor.GetForegroundColor(g,mColor)); g.DrawString(mText,aSelStartChar,aSelEndChar-aSelStartChar,x,ypos); } }
void BadUserItem::Paint(Graphics &g, ListArea *theListArea) { int aColor = theListArea->GetTextColor(); if(mSelected) aColor = theListArea->GetSelColor().GetForegroundColor(g,aColor); int aPaintCol = 0; bool drawSelection = mSelected; if(!mIsSimple) { aPaintCol = ((MultiListArea*)theListArea)->GetColumnPaintContext(); if(aPaintCol!=-1) drawSelection = false; } if(drawSelection) { g.SetColor(theListArea->GetSelColor().GetBackgroundColor(g)); g.FillRect(0,0,theListArea->GetPaintColumnWidth(),mFont->GetHeight()); if(!mIsSimple) return; } if(aPaintCol<0 || aPaintCol>5) return; g.SetColor(aColor); g.SetFont(mFont); g.DrawString(mColStr[aPaintCol],0,0); }
void TextImage::Paint(Graphics &g, TextArea *theTextArea) { if(theTextArea->mSelStartChar<=mAbsStartChar && theTextArea->mSelEndChar>=mAbsEndChar) { g.SetColor(theTextArea->mSelColor.GetBackgroundColor(g)); g.FillRect(mx,0,mWidth,mLine->mHeight); } g.DrawImage(mImage,mx,my); }
/////////////////////////////////////////////////////////////////////////////// // Paint: Draw the credits. /////////////////////////////////////////////////////////////////////////////// void ScrollingTextComponent::Paint(Graphics &g) { Component::Paint(g); // Draw the background. g.SetFont(GetDefaultFont()); g.SetColor(0xFFFFFF); g.FillRect(2,2,Width()-4,Height()-4); // Draw the frame. g.ApplyColorSchemeColor(StandardColor_3DHilight); g.DrawRect(0,0,Width(),Height()); g.DrawRect(1,1,Width()-1,Height()-1); g.ApplyColorSchemeColor(StandardColor_3DShadow); g.DrawRect(0, 0,Width()-1,Height()-1); // Draw the text. int nTop = mScrollTop; CreditsList::iterator Itr = mLines.begin(); while (Itr != mLines.end()) { CreditLineInfo& LineInfo = *Itr; int nStrHt = g.GetFont()->GetHeight(); if (nTop < Height() / 3) g.SetColor(DimColor(LineInfo.GetColor(), nTop * 100 / (Height() / 3))); else if (Height() - nTop <= nStrHt) g.SetColor(0xFFFFFF); else if (nTop > (Height() * 2 / 3) - nStrHt) g.SetColor(DimColor(LineInfo.GetColor(), ((Height() - (nTop + nStrHt)) * 100 / (Height() / 3)))); else g.SetColor(LineInfo.GetColor()); if (g.GetColor() != 0xFFFFFF && nTop > 2 && nTop < Height() - nStrHt - 2) { int nStrWd = g.GetFont()->GetStringWidth(LineInfo.GetLine()); g.DrawString(LineInfo.GetLine(), (Width() - nStrWd) / 2, nTop); } nTop += nStrHt; ++Itr; } mTotalTextHeight = nTop - mScrollTop; }
void Font::DrawString(const Graphics& g, const Brush& brush, const string& s, int len, int x, int y, int w, int h, int flags){ int xx = x; int yy = y; int rr = x + w; int bb = y + h; //g.DrawRect(Pens::Blue, x, y, w, h); if(len < 0) len = s.length(); vector<int> ws, cs; int wi = 0, c = 0; for (int i = 0; i<len;){ char_type cc; int rs = READ_CHAR(&cc, s.c_str() + i, len-i); if (rs>0) i += rs; else break; bool n = cc == L'\n' || cc == 0x0085 || cc == 0x2028 || cc == 0x2029; //if (!n && cc != L'\r') PutChar(cc); int ww = n ? 0 : map[cc]->width; if ((flags & FontFlag_NoWrap) == 0 && (n || (w >= 0 && wi + ww>w))){ if (c == 0){ ws.push_back(ww); cs.push_back(1); wi = 0; c = 0; } else{ ws.push_back(wi); cs.push_back(c); wi = ww; c = 1; if (n){ wi = 0; } } } else { wi += ww; c++; } } if (c > 0){ ws.push_back(wi); cs.push_back(c); } int rh = cs.size()*face->size->metrics.y_ppem; // real height // vertical alignment switch ((flags >> 2) & 3) { case 1: yy += (h-rh) / 2; break; case 2: yy += h-rh; break; } //bool clip_not_whole = (flags & FontFlag_ClipNotWhole) != 0; glUniform1i(Program::CurrentShader()->useTex2, 1); int line = -1; int row = 0; yy -= face->size->metrics.y_ppem; for (int i = 0; i < len; ){ if (row == 0){ line++; xx = x; yy += face->size->metrics.y_ppem; switch (flags & 0x03) { case 1: xx += (w - ws[line]) / 2; break; case 2: xx += w - ws[line]; break; } } char_type cc; int rs = READ_CHAR(&cc, s.c_str() + i, len - i); if (rs>0) i += rs; else return; if (++row == cs[line]) row = 0; if (cc == L'\r') continue; bool n = cc == L'\n' || cc == 0x0085 || cc == 0x2028 || cc == 0x2029; // new line if (!n){ Char& c = *map[cc]; Rect& r = c.bounds; float ss = TEXTURE_SIZE; float L = r.Left() / ss; float T = ((int)r.Top() % TEXTURE_SIZE) / ss; float R = r.Right() / ss; float B = T + c.height / ss; float ps[] = { L, T, R, T, R, B, L, B }; glEnableVertexAttribArray(TEXCOORD_ATTRIB_LOC); glVertexAttribPointer(TEXCOORD_ATTRIB_LOC, 2, GL_FLOAT, GL_FALSE, 0, ps); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[r.Top() / TEXTURE_SIZE]); glActiveTexture(GL_TEXTURE0); g.FillRect(brush, xx + c.left, yy - c.top, c.width, c.height); glDisableVertexAttribArray(TEXCOORD_ATTRIB_LOC); //glUniform1i(Program::CurrentShader()->useTex2, 0); //g.DrawRect(Pens::Green, xx + c.left, yy - c.top, c.width, c.height); //glUniform1i(Program::CurrentShader()->useTex2, 1); xx += c.width; } } glUniform1i(Program::CurrentShader()->useTex2, 0); }