static CGShadingRef CGShadingRefForRadialGradient(const SVGPaintServerRadialGradient* server)
{
    CGPoint center = CGPoint(server->gradientCenter());
    CGPoint focus = CGPoint(server->gradientFocal());
    double radius = server->gradientRadius();

    double fdx = focus.x - center.x;
    double fdy = focus.y - center.y;

    // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy)
    // to the point of intersection of the line through (fx, fy) and the circle.
    if (sqrtf(fdx * fdx + fdy * fdy) > radius) { 
        double angle = atan2(focus.y * 100.0, focus.x * 100.0);
        focus.x = cos(angle) * radius;
        focus.y = sin(angle) * radius;
    }

    CGFunctionCallbacks callbacks = {0, cgGradientCallback, NULL};
    CGFloat domainLimits[2] = {0, 1};
    CGFloat rangeLimits[8] = {0, 1, 0, 1, 0, 1, 0, 1};
    CGFunctionRef shadingFunction = CGFunctionCreate((void *)server, 1, domainLimits, 4, rangeLimits, &callbacks);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGShadingRef shading = CGShadingCreateRadial(colorSpace, focus, 0, center, radius, shadingFunction, true, true);
    CGColorSpaceRelease(colorSpace);
    CGFunctionRelease(shadingFunction);
    return shading;
}
static CGShadingRef CGShadingRefForLinearGradient(const SVGPaintServerLinearGradient* server)
{
    CGPoint start = CGPoint(server->gradientStart());
    CGPoint end = CGPoint(server->gradientEnd());

    CGFunctionCallbacks callbacks = {0, cgGradientCallback, NULL};
    CGFloat domainLimits[2] = {0, 1};
    CGFloat rangeLimits[8] = {0, 1, 0, 1, 0, 1, 0, 1};
    CGFunctionRef shadingFunction = CGFunctionCreate((void *)server, 1, domainLimits, 4, rangeLimits, &callbacks);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGShadingRef shading = CGShadingCreateAxial(colorSpace, start, end, shadingFunction, true, true);
    CGColorSpaceRelease(colorSpace);
    CGFunctionRelease(shadingFunction);
    return shading;
}
Exemplo n.º 3
0
void TextRenderView::draw()
{
  // renders with no background, only text
  drawStringWithColorAndFormat(
    this->getContent(),
    this->getTextColor(),
    CGPoint( this->getGlobalBounds().getX() + 10, this->getGlobalBounds().getY() + this->getBounds().getHeight()/2) );
  // cerr << "Color Red" << this->getTextColor().getRed() << endl;
  // cerr << "should have drawn text" << endl;

  callDrawOnSubViews();

}
Exemplo n.º 4
0
void TextInputView::draw()
{
  // Draw the rect
  drawRectWithColor(this->getGlobalBounds(), this->getColor());
  // Split up and draw the text based on the size of the rectangle
  // 
  _lines.empty(); // start anew
  _lines.resize(0);
  string temp = "";
  int cnt = 0;
  const int maxChars = getMaxCharsPerLine();
  const int maxLines = getMaxLines();
  for (string::iterator it = _content.begin(); it != _content.end(); ++it)
  {
    if (_lines.size() >= maxLines )
    {
      break;
    }
    temp += (*it);
    cnt++;
    if (cnt >= maxChars)
    {
      _lines.push_back(temp);
      temp.clear();
      cnt = 0;
    }
  }
  // add a cursor if has focus
  // Currently the cursor is always at the end,
  // this will change when we make it so that the
  // position can be set with a mouse click or the
  // arrow keys
  if ( getHasFocus() )
  {
    if (temp.length() > 0)
    {
      temp += "~"; // there is more to push, so stick the cursor on the last line
    }
    // hell, this seems to work okay visually...
  }
  _lines.push_back(temp); // push the rest

  CGRect bounds = this->getGlobalBounds();
  int x = bounds.getX() + 5;
  int y = bounds.getY() + 14;

  for(vector<string>::iterator it = _lines.begin(); it != _lines.end(); ++it)
  {
    drawStringWithColorAndFormat(
      (*it), this->getTextColor(), CGPoint( x, y), "small fixed");
    y += this->getLineSpacing();
  }

  // Draw the border
  if (getHasFocus())
    drawBorderWithColor(bounds, CGColor(0.0,0.0,0.6,1.0));
  else
    drawBorderWithColor(bounds, CGColor(0.0,0.0,0.0,1.0));

  // Draw the subviews
  this->callDrawOnSubViews();

}