本文整理汇总了C++中SkScalarDiv函数的典型用法代码示例。如果您正苦于以下问题:C++ SkScalarDiv函数的具体用法?C++ SkScalarDiv怎么用?C++ SkScalarDiv使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SkScalarDiv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkPoint pts[2] = {
{ 0, 0 },
{ SkIntToScalar(100), SkIntToScalar(100) }
};
SkShader::TileMode tm = SkShader::kClamp_TileMode;
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
SkPaint paint;
paint.setAntiAlias(true);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
canvas->save();
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
// apply an increasing y perspective as we move to the right
SkMatrix perspective;
perspective.setIdentity();
perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1),
SkIntToScalar(500)));
perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
SkIntToScalar(10)));
shader->setLocalMatrix(perspective);
paint.setShader(shader);
canvas->drawRect(r, paint);
shader->unref();
canvas->translate(0, SkIntToScalar(120));
}
canvas->restore();
canvas->translate(SkIntToScalar(120), 0);
}
}
示例2: intersection
static IntersectionType intersection(const SkPoint& p1, const SkPoint& p2,
const SkPoint& p3, const SkPoint& p4,
SkPoint& res) {
// Store the values for fast access and easy
// equations-to-code conversion
SkScalar x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x();
SkScalar y1 = p1.y(), y2 = p2.y(), y3 = p3.y(), y4 = p4.y();
SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4);
// If d is zero, there is no intersection
if (SkScalarNearlyZero(d)) {
return kNone_IntersectionType;
}
// Get the x and y
SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2),
post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4);
// Compute the point of intersection
res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post), d),
SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post), d));
// Check if the x and y coordinates are within both lines
return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) ||
res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) ||
res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) ||
res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ?
kOut_IntersectionType : kIn_IntersectionType;
}
示例3: draw
void draw(SkCanvas* canvas,
const SkRect& rect,
const SkSize& deviceSize,
SkPaint::FilterLevel filterLevel,
SkImageFilter* input = NULL) {
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width());
SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height());
canvas->translate(rect.x(), rect.y());
canvas->scale(deviceScaleX, deviceScaleY);
canvas->translate(-rect.x(), -rect.y());
SkMatrix matrix;
matrix.setScale(SkScalarInvert(deviceScaleX),
SkScalarInvert(deviceScaleY));
SkAutoTUnref<SkImageFilter> imageFilter(
SkMatrixImageFilter::Create(matrix, filterLevel, input));
SkPaint filteredPaint;
filteredPaint.setImageFilter(imageFilter.get());
canvas->saveLayer(&rect, &filteredPaint);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = rect;
ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
canvas->drawOval(ovalRect, paint);
canvas->restore(); // for saveLayer
canvas->restore();
}
示例4: RGB_to_HSV
static SkScalar RGB_to_HSV(SkColor color, HSV_Choice choice) {
SkScalar red = SkIntToScalar(SkColorGetR(color));
SkScalar green = SkIntToScalar(SkColorGetG(color));
SkScalar blue = SkIntToScalar(SkColorGetB(color));
SkScalar min = SkMinScalar(SkMinScalar(red, green), blue);
SkScalar value = SkMaxScalar(SkMaxScalar(red, green), blue);
if (choice == kGetValue)
return value/255;
SkScalar delta = value - min;
SkScalar saturation = value == 0 ? 0 : SkScalarDiv(delta, value);
if (choice == kGetSaturation)
return saturation;
SkScalar hue;
if (saturation == 0)
hue = 0;
else {
SkScalar part60 = SkScalarDiv(60 * SK_Scalar1, delta);
if (red == value) {
hue = SkScalarMul(green - blue, part60);
if (hue < 0)
hue += 360 * SK_Scalar1;
}
else if (green == value)
hue = 120 * SK_Scalar1 + SkScalarMul(blue - red, part60);
else // blue == value
hue = 240 * SK_Scalar1 + SkScalarMul(red - green, part60);
}
SkASSERT(choice == kGetHue);
return hue;
}
示例5: SkXRayCrossesLine
bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2]) {
// Determine quick discards.
// Consider query line going exactly through point 0 to not
// intersect, for symmetry with SkXRayCrossesMonotonicCubic.
if (pt.fY == pts[0].fY)
return false;
if (pt.fY < pts[0].fY && pt.fY < pts[1].fY)
return false;
if (pt.fY > pts[0].fY && pt.fY > pts[1].fY)
return false;
if (pt.fX > pts[0].fX && pt.fX > pts[1].fX)
return false;
// Determine degenerate cases
if (SkScalarNearlyZero(pts[0].fY - pts[1].fY))
return false;
if (SkScalarNearlyZero(pts[0].fX - pts[1].fX))
// We've already determined the query point lies within the
// vertical range of the line segment.
return pt.fX <= pts[0].fX;
// Full line segment evaluation
SkScalar delta_y = pts[1].fY - pts[0].fY;
SkScalar delta_x = pts[1].fX - pts[0].fX;
SkScalar slope = SkScalarDiv(delta_y, delta_x);
SkScalar b = pts[0].fY - SkScalarMul(slope, pts[0].fX);
// Solve for x coordinate at y = pt.fY
SkScalar x = SkScalarDiv(pt.fY - b, slope);
return pt.fX <= x;
}
示例6: SkMinScalar
void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
if (rect.isEmpty() || !rect.isFinite()) {
this->setEmpty();
return;
}
if (!SkScalarsAreFinite(xRad, yRad)) {
xRad = yRad = 0; // devolve into a simple rect
}
if (xRad <= 0 || yRad <= 0) {
// all corners are square in this case
this->setRect(rect);
return;
}
if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) {
SkScalar scale = SkMinScalar(SkScalarDiv(rect.width(), xRad + xRad),
SkScalarDiv(rect.height(), yRad + yRad));
SkASSERT(scale < SK_Scalar1);
xRad = SkScalarMul(xRad, scale);
yRad = SkScalarMul(yRad, scale);
}
fRect = rect;
for (int i = 0; i < 4; ++i) {
fRadii[i].set(xRad, yRad);
}
fType = kSimple_Type;
if (xRad >= SkScalarHalf(fRect.width()) && yRad >= SkScalarHalf(fRect.height())) {
fType = kOval_Type;
// TODO: assert that all the x&y radii are already W/2 & H/2
}
SkDEBUGCODE(this->validate();)
}
示例7: SkMaxScalar
void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
SkScalar rightRad, SkScalar bottomRad) {
if (rect.isEmpty() || !rect.isFinite()) {
this->setEmpty();
return;
}
const SkScalar array[4] = { leftRad, topRad, rightRad, bottomRad };
if (!SkScalarsAreFinite(array, 4)) {
this->setRect(rect); // devolve into a simple rect
return;
}
leftRad = SkMaxScalar(leftRad, 0);
topRad = SkMaxScalar(topRad, 0);
rightRad = SkMaxScalar(rightRad, 0);
bottomRad = SkMaxScalar(bottomRad, 0);
SkScalar scale = SK_Scalar1;
if (leftRad + rightRad > rect.width()) {
scale = SkScalarDiv(rect.width(), leftRad + rightRad);
}
if (topRad + bottomRad > rect.height()) {
scale = SkMinScalar(scale, SkScalarDiv(rect.height(), topRad + bottomRad));
}
if (scale < SK_Scalar1) {
leftRad = SkScalarMul(leftRad, scale);
topRad = SkScalarMul(topRad, scale);
rightRad = SkScalarMul(rightRad, scale);
bottomRad = SkScalarMul(bottomRad, scale);
}
if (leftRad == rightRad && topRad == bottomRad) {
if (leftRad >= SkScalarHalf(rect.width()) && topRad >= SkScalarHalf(rect.height())) {
fType = kOval_Type;
} else if (0 == leftRad || 0 == topRad) {
// If the left and (by equality check above) right radii are zero then it is a rect.
// Same goes for top/bottom.
fType = kRect_Type;
leftRad = 0;
topRad = 0;
rightRad = 0;
bottomRad = 0;
} else {
fType = kSimple_Type;
}
} else {
fType = kNinePatch_Type;
}
fRect = rect;
fRadii[kUpperLeft_Corner].set(leftRad, topRad);
fRadii[kUpperRight_Corner].set(rightRad, topRad);
fRadii[kLowerRight_Corner].set(rightRad, bottomRad);
fRadii[kLowerLeft_Corner].set(leftRad, bottomRad);
SkDEBUGCODE(this->validate();)
}
示例8: onFindClickHandler
virtual Click* onFindClickHandler(SkScalar x, SkScalar y) {
int ix = (int)(SkScalarDiv(x * N, W));
int iy = (int)(SkScalarDiv(y * N, H));
if (ix >= 0 && iy >= 0) {
SkEvent evt("set-curr-index");
evt.setFast32(iy * N + ix);
this->sendEventToParents(evt);
}
return NULL;
}
示例9: SkScalarDiv
void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman,
const GrProcessor& proc) {
const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
GrTexture* colorTex = displacementMap.texture(1);
SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colorTex->width()));
SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colorTex->height()));
pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin());
}
示例10: Make2ConicalOutsideFlip
static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
return SkGradientShader::CreateTwoPointConical(center1, radius1,
center0, radius0,
data.fColors, data.fPos,
data.fCount, tm, 0, &localMatrix);
}
示例11: Make2ConicalTouchY
static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm, const SkMatrix& localMatrix) {
SkPoint center0, center1;
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
SkScalarAve(pts[0].fY, pts[1].fY));
center0.set(center1.fX, center1.fY + radius1 - radius0);
return SkGradientShader::CreateTwoPointConical(center0, radius0,
center1, radius1,
data.fColors, data.fPos,
data.fCount, tm, 0, &localMatrix);
}
示例12: SkDebugf
void SkSet::dump(SkAnimateMaker* maker) {
INHERITED::dump(maker);
if (dur != 1) {
#ifdef SK_CAN_USE_FLOAT
SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
#else
SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
#endif
}
//don't want double />\n's
SkDebugf("/>\n");
}
示例13: onDraw
virtual void onDraw(SkCanvas* canvas) {
canvas->clear(0x00000000);
SkRect srcRect = SkRect::MakeWH(96, 96);
SkSize deviceSize = SkSize::Make(16, 16);
draw(canvas,
srcRect,
deviceSize,
SkPaint::kNone_FilterLevel);
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
draw(canvas,
srcRect,
deviceSize,
SkPaint::kLow_FilterLevel);
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
draw(canvas,
srcRect,
deviceSize,
SkPaint::kMedium_FilterLevel);
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
draw(canvas,
srcRect,
deviceSize,
SkPaint::kHigh_FilterLevel);
SkBitmap bitmap;
bitmap.allocN32Pixels(16, 16);
bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00);
{
SkBitmapDevice bitmapDevice(bitmap);
SkCanvas bitmapCanvas(&bitmapDevice);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = SkRect::MakeWH(16, 16);
ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f));
bitmapCanvas.drawOval(ovalRect, paint);
}
SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRect, outRect));
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
draw(canvas,
srcRect,
deviceSize,
SkPaint::kHigh_FilterLevel,
source.get());
}
示例14: onClick
virtual bool onClick(Click* click) {
SkScalar center = this->width()/2;
fSaturation = SkScalarDiv(click->fCurr.fX - center, center/2);
center = this->height()/2;
fAngle = SkScalarDiv(click->fCurr.fY - center, center) * 180;
fDX += click->fCurr.fX - click->fPrev.fX;
fDY += click->fCurr.fY - click->fPrev.fY;
fScale = SkScalarDiv(click->fCurr.fX, this->width());
this->inval(NULL);
return true;
return this->INHERITED::onClick(click);
}
示例15: native_draw
static ECode native_draw(
/* [in] */ SkCanvas* canvas,
/* [in] */ SkRect& bounds,
/* [in] */ const SkBitmap* bitmap,
/* [in] */ ArrayOf<Byte>* chunkObj,
/* [in] */ const SkPaint* paint,
/* [in] */ Int32 destDensity,
/* [in] */ Int32 srcDensity)
{
ECode ec = NOERROR;
Int32 chunkSize = chunkObj->GetLength();
void* storage = chunkObj->GetPayload();
// need to deserialize the chunk
android::Res_png_9patch* chunk = static_cast<android::Res_png_9patch*>(storage);
assert(chunkSize == (Int32)chunk->serializedSize());
// this relies on deserialization being done in place
android::Res_png_9patch::deserialize(chunk);
if (destDensity == srcDensity || destDensity == 0
|| srcDensity == 0) {
// Logger::V(TAG, "Drawing unscaled 9-patch: (%g,%g)-(%g,%g)",
// SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
// SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom));
ec = NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
}
else {
canvas->save();
SkScalar scale = SkFloatToScalar(destDensity / (float)srcDensity);
canvas->translate(bounds.fLeft, bounds.fTop);
canvas->scale(scale, scale);
bounds.fRight = SkScalarDiv(bounds.fRight-bounds.fLeft, scale);
bounds.fBottom = SkScalarDiv(bounds.fBottom-bounds.fTop, scale);
bounds.fLeft = bounds.fTop = 0;
Logger::V(TAG, "Drawing scaled 9-patch: (%g,%g)-(%g,%g) srcDensity=%d destDensity=%d",
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom),
srcDensity, destDensity);
ec = NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
canvas->restore();
}
return ec;
}