Beispiel #1
0
void Renderer::DrawPoint(Point point, int subWindow)
{
    int pixelStart = PosToIndex((point.Position()));
    
    Color color = point.GetColor();
    
    if(pixelStart >= 0 && pixelStart + 2 <= (sSubwindowSize.mX) * (sSubwindowSize.mY) * 3)
    {
        if(subWindow == sSubWindow1)
        {
            sPixelBuffer1[pixelStart] = color.GetRed();
            sPixelBuffer1[pixelStart + 1] = color.GetGreen();
            sPixelBuffer1[pixelStart + 2] = color.GetBlue();
        }
        else if(subWindow == sSubWindow2)
        {
            sPixelBuffer2[pixelStart] = color.GetRed();
            sPixelBuffer2[pixelStart + 1] = color.GetGreen();
            sPixelBuffer2[pixelStart + 2] = color.GetBlue();

        }
        else if(subWindow == sSubWindow3)
        {
            sPixelBuffer3[pixelStart] = color.GetRed();
            sPixelBuffer3[pixelStart + 1] = color.GetGreen();
            sPixelBuffer3[pixelStart + 2] = color.GetBlue();

        }
    }
    else
    {
        throw out_of_range("Point outside of pixel buffer range");
    }
}
Beispiel #2
0
  size_t
  TerminalDisplay::WriteWrappedElement(const Text& Element, size_t TextOffset,
                                       size_t WriteOffset, size_t Requested) {
    size_t Start = TextOffset;
    size_t Remaining = Requested;

    size_t Available = Element.length() - Start;
    if (Requested == (size_t) -1) {
      Requested = Available;
    }

    if (Available > 0) {
      if (Available < Remaining) {
        Remaining = Available;
      }

      while (Remaining > 0) {
        size_t numThisLine = Remaining;

        // How much can this line hold?
        size_t numToEOL = GetWidth() - ((Start + WriteOffset) % GetWidth());
        if (!numToEOL) {
          MoveDown();
          ++fWritePos.fLine;
          MoveFront();
          fWritePos.fCol = 0;
          numToEOL = GetWidth();
        }
        if (numThisLine > numToEOL) {
          numThisLine = numToEOL;
        }

        if (GetContext()->GetColorizer()) {
          // We only write same-color chunks; how long is it?
          const std::vector<char>& Colors = Element.GetColors();
          char ThisColor = Colors[Start];
          size_t numSameColor = 1;
          while (numSameColor < numThisLine
                 && ThisColor == Colors[Start + numSameColor])
            ++numSameColor;
          numThisLine = numSameColor;

          if (ThisColor != fPrevColor) {
            Color C;
            GetContext()->GetColorizer()->GetColor(ThisColor, C);
            SetColor(ThisColor, C);
            fPrevColor = ThisColor;
          }
        }

        WriteRawString(Element.GetText().c_str() + Start, numThisLine);
        fWritePos = IndexToPos(PosToIndex(fWritePos) + numThisLine);
        if (numThisLine == numToEOL) {
          ActOnEOL();
        }

        Start += numThisLine;
        Remaining -= numThisLine;
      }
    }

    if (Requested == Available) {
      size_t VisL = fWriteLen / GetWidth();
      size_t Wrote = WriteOffset + TextOffset + Requested;
      size_t WroteL = Wrote / GetWidth();
      size_t NumToEOL = GetWidth() - (Wrote % GetWidth());
      if (fWriteLen > Wrote && NumToEOL > 0) {
        // Wrote less and not at EOL
        EraseToRight();
      }
      if (WroteL < VisL) {
        Pos prevWC = GetCursor();
        MoveFront();
        fWritePos.fCol = 0;
        for (size_t l = WroteL + 1; l <= VisL; ++l) {
          MoveDown();
          ++fWritePos.fLine;
          EraseToRight();
        }
        Move(prevWC);
      }
    }
    return Remaining;
  }