void TetrisWidget::drawTextCentered(const Rect & inRect, const std::string & inText, int inFontSize, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QPainter & painter(*mPainter); // Set the new pen painter.setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); // Paint the stats title QFont textFont(painter.font()); textFont.setPointSize(inFontSize); textFont.setBold(true); painter.setFont(textFont); int textWidth = painter.fontMetrics().width(inText.c_str()); int textHeight = painter.fontMetrics().height(); int x = inRect.left() + (inRect.width() - textWidth)/2; int y = inRect.top() + (inRect.height() - textHeight)/2; QRect theTextRect(x, y, game()->gameGrid().columnCount() * squareWidth(),squareHeight()); painter.drawText(theTextRect, inText.c_str()); }
void TetrisWidget::drawTextRightAligned(const Rect & inRect, const std::string & inText, int inFontSize, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QPainter & painter(*mPainter); painter.setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); // Paint the stats title QFont textFont(painter.font()); textFont.setPointSize(inFontSize); textFont.setBold(true); painter.setFont(textFont); int textWidth = painter.fontMetrics().width(inText.c_str()); int textHeight = painter.fontMetrics().height(); int x = inRect.right() - textWidth - margin(); int y = inRect.top() + (inRect.height() - textHeight)/2; drawText(x, y, inText); }
void TetrisWidget::paintSquare(const Rect & inRect, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); QColor color(inColor.red(), inColor.green(), inColor.blue()); int x = inRect.x(); int y = inRect.y(); int width = inRect.width(); int height = inRect.height(); mPainter->fillRect(x + 1, y + 1, width - 2, height - 2, color); mPainter->setPen(color.light()); mPainter->drawLine(x, y + height - 1, x, y); mPainter->drawLine(x, y, x + width - 1, y); mPainter->setPen(color.dark()); mPainter->drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1); mPainter->drawLine(x + width - 1, y + height - 1, x + width - 1, y + 1); }
void BinaryFormatter::writeAttr(std::ostream& into, const SumoXMLAttr attr, const RGBColor& val) { BinaryFormatter::writeAttrHeader(into, attr, BF_COLOR); FileHelpers::writeByte(into, val.red()); FileHelpers::writeByte(into, val.green()); FileHelpers::writeByte(into, val.blue()); FileHelpers::writeByte(into, val.alpha()); }
/* Test the method 'interpolate'*/ TEST(RGBColor, test_interpolate) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); EXPECT_FLOAT_EQ(SUMOReal(1.5), colorResult.red()); EXPECT_FLOAT_EQ(SUMOReal(3), colorResult.green()); EXPECT_FLOAT_EQ(SUMOReal(2.5), colorResult.blue()); }
/* Test the method 'interpolate'*/ TEST(RGBColor, test_interpolate) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(3,4,1); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); EXPECT_EQ(2, colorResult.red()); EXPECT_EQ(3, colorResult.green()); EXPECT_EQ(2, colorResult.blue()); }
JSValue jsRGBColorRed(ExecState* exec, JSValue slotBase, const Identifier&) { JSRGBColor* castedThis = static_cast<JSRGBColor*>(asObject(slotBase)); UNUSED_PARAM(exec); RGBColor* imp = static_cast<RGBColor*>(castedThis->impl()); JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->red())); return result; }
/* Test the method 'interpolate' with a weight of 0 and lower*/ TEST(RGBColor, test_interpolate_weight_0) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, -1000); EXPECT_TRUE(colorResult==colorResult2); EXPECT_EQ(1, colorResult.red()); EXPECT_EQ(2, colorResult.green()); EXPECT_EQ(3, colorResult.blue()); }
/* Test the method 'interpolate' with a weight of 1 and higher*/ TEST(RGBColor, test_interpolate_weight_1) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(2,4,2); RGBColor colorResult = RGBColor::interpolate(color1, color2, 1); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, 1000); EXPECT_TRUE(colorResult==colorResult2); EXPECT_FLOAT_EQ(SUMOReal(2), colorResult.red()); EXPECT_FLOAT_EQ(SUMOReal(4), colorResult.green()); EXPECT_FLOAT_EQ(SUMOReal(2), colorResult.blue()); }
void TetrisWidget::drawLine(int x1, int y1, int x2, int y2, int inPenWidth, const RGBColor & inColor) { if (!mPainter.get()) { throw std::logic_error("Painter is not set."); } RestorePainter restorePainter(*mPainter); mPainter->setPen(QColor(inColor.red(), inColor.green(), inColor.blue())); mPainter->drawLine(x1, y1, x2, y2); }
static v8::Handle<v8::Value> redAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { RGBColor* imp = V8RGBColor::toNative(info.Holder()); RefPtr<CSSPrimitiveValue> result = imp->red(); v8::Handle<v8::Value> wrapper = result.get() ? v8::Handle<v8::Value>(DOMDataStore::getWrapper(result.get(), info.GetIsolate())) : v8Undefined(); if (wrapper.IsEmpty()) { wrapper = toV8(result.get(), info.Holder(), info.GetIsolate()); if (!wrapper.IsEmpty()) V8DOMWrapper::setNamedHiddenReference(info.Holder(), "red", wrapper); } return wrapper; }
/* Test the method 'interpolate' with a weight of 1 and higher*/ TEST(RGBColor, test_interpolate_weight_1) { RGBColor color1 = RGBColor(1,2,3); RGBColor color2 = RGBColor(3,4,1); RGBColor colorResult = RGBColor::interpolate(color1, color2, 0.5); RGBColor colorResult1 = RGBColor::interpolate(color1, color2, 0); RGBColor colorResult2 = RGBColor::interpolate(color1, color2, 1); EXPECT_TRUE(color1==colorResult1); EXPECT_TRUE(color2==colorResult2); EXPECT_EQ(2, colorResult.red()); EXPECT_EQ(3, colorResult.green()); EXPECT_EQ(2, colorResult.blue()); }
HSVColor RGB2HSV(const RGBColor & rgb) { double r = rgb.red() / 255.0; double g = rgb.green() / 255.0; double b = rgb.blue() / 255.0; // Calculate chroma double maxColor = Max(r, g, b); double minColor = Min(r, g, b); double chroma = maxColor - minColor; // Calculate hue double hue = 0; if (chroma != 0) { if (maxColor == r) { hue = (g - b / chroma) * 60.0; } else if (maxColor == g) { hue = (2 + (b - r) / chroma) * 60.0; } else // maxColor == b { assert(maxColor == b); hue = (4 + (r - g) / chroma) * 60.0; } if (hue < 0) { hue += 360.0; } assert(hue >= 0 && hue < 360); } double saturation = 0; if (maxColor != 0) { saturation = chroma / maxColor; } assert(saturation >= 0 && saturation <= 1); double value = maxColor; assert(value >= 0 && value <= 1); return HSVColor(static_cast<int>(0.5 + hue), static_cast<int>(0.5 + 100.0 * saturation), static_cast<int>(0.5 + 100.0 * value)); }
void GLHelper::drawText(const std::string& text, const Position& pos, const double layer, const double size, const RGBColor& col, const double angle, const int align, double width) { if (width <= 0) { width = size; } if (!initFont()) { return; }; glPushMatrix(); glAlphaFunc(GL_GREATER, 0.5); glEnable(GL_ALPHA_TEST); glTranslated(pos.x(), pos.y(), layer); glScaled(width / myFontSize, size / myFontSize, 1.); glRotated(-angle, 0, 0, 1); fonsSetAlign(myFont, align == 0 ? FONS_ALIGN_CENTER | FONS_ALIGN_MIDDLE : align); fonsSetColor(myFont, glfonsRGBA(col.red(), col.green(), col.blue(), col.alpha())); fonsDrawText(myFont, 0., 0., text.c_str(), nullptr); glPopMatrix(); }
FXColor MFXUtils::getFXColor(const RGBColor& col) { return FXRGBA(col.red(), col.green(), col.blue(), col.alpha()); }
void GLHelper::setColor(const RGBColor& c) { glColor4ub(c.red(), c.green(), c.blue(), c.alpha()); }
/* Test the method 'parseColor' with a longer String*/ TEST(RGBColor, test_parseColor_with_a_long_string) { RGBColor color = RGBColor::parseColor("1,2,3,5,432test"); EXPECT_FLOAT_EQ(SUMOReal(1), color.red()); EXPECT_FLOAT_EQ(SUMOReal(2), color.green()); EXPECT_FLOAT_EQ(SUMOReal(3), color.blue()); }
/* Test the method 'parseColor'*/ TEST(RGBColor, test_parseColor) { RGBColor color = RGBColor::parseColor("1,2,3"); EXPECT_FLOAT_EQ(SUMOReal(1), color.red()); EXPECT_FLOAT_EQ(SUMOReal(2), color.green()); EXPECT_FLOAT_EQ(SUMOReal(3), color.blue()); }
/* Test the method 'parseColor'*/ TEST(RGBColor, test_parseColor) { RGBColor color = RGBColor::parseColor("0,1,255"); EXPECT_EQ(0, color.red()); EXPECT_EQ(1, color.green()); EXPECT_EQ(255, color.blue()); }