//axis aligned circle for setting up brushes for thick lines void rs_gdImageCircleForBrush(gdImagePtr im, int x, int y, int rad, RS_Color& color) { int gdc = ConvertColor(im, color); float rad2 = (float)rad*rad; for (int j = -rad, k = y+j; j <= rad; j++, k++) { float j_offset = j + 0.5f; float hlen = sqrt(rad2 - j_offset*j_offset); int solidwid = (int)hlen; if (solidwid) gdImageLine(im, x-solidwid, k, x+solidwid-1, k, gdc); float aalpha = hlen - solidwid; RS_Color ac = color; ac.alpha() = (int)(ac.alpha() * aalpha); int gdc2 = ConvertColor(im, ac); gdImageSetPixel(im, x-solidwid-1, k, gdc2); gdImageSetPixel(im, x+solidwid, k, gdc2); } }
gdImagePtr rs_gdImageThickLineBrush(int line_weight, RS_Color& color) { if (line_weight % 2 == 1) line_weight += 1; int sx = line_weight; int sy = line_weight; gdImagePtr brush = gdImageCreateTrueColor(sx, sy); int transparent = gdImageColorAllocateAlpha(brush, 0, 0, 0, 127); gdImageAlphaBlending(brush, 0); gdImageFilledRectangle(brush, 0, 0, sx, sy, transparent); //compute fractional alpha value for antialiasing effect //each pixel should be hit by line_weight / 2 number of circles //so the alpha is computed as 255 / line_weight * 2 RS_Color falpha = color; falpha.alpha() = falpha.alpha() / line_weight * 2 + 1; falpha.alpha() = (falpha.alpha() < 255)? falpha.alpha() : 255; //outer transparent circle -- for antialiased effect rs_gdImageCircleForBrush(brush, sx/2, sy/2, line_weight / 2, falpha); gdImageAlphaBlending(brush, 1); //inner non-transparent circle rs_gdImageCircleForBrush(brush, sx/2, sy/2, (line_weight - 2) / 2, color); return brush; }
/** * Sets the color shown in the combobox to the given color. */ void QG_ColorBox::setColor(const RS_Color& color) { currentColor = color; if (color.isByLayer() && showByLayer) { setCurrentItem(0); } else if (color.isByBlock() && showByLayer) { setCurrentItem(1); } else if (color==Qt::red) { setCurrentItem(0+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::yellow) { setCurrentItem(1+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::green) { setCurrentItem(2+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::cyan) { setCurrentItem(3+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::blue) { setCurrentItem(4+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::magenta) { setCurrentItem(5+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::white || color==Qt::black) { setCurrentItem(6+(int)showByLayer*2 + (int)showUnchanged); } else if (color==Qt::gray) { setCurrentItem(7+(int)showByLayer*2 + (int)showUnchanged); } else if (color==QColor(191,191,191)) { setCurrentItem(8+(int)showByLayer*2 + (int)showUnchanged); } else { setCurrentItem(9+(int)showByLayer*2 + (int)showUnchanged); } if (currentItem()!=9+(int)showByLayer*2 + (int)showUnchanged) { slotColorChanged(currentItem()); } }
void Doc_plugin_interface::getCurrentLayerProperties(QColor *c, DPI::LineWidth *w, DPI::LineType *t){ RS_Pen pen = docGr->getActiveLayer()->getPen(); RS_Color col = pen.getColor(); c->setRgb(col.red(), col.green(), col.blue()); *w = static_cast<DPI::LineWidth>(pen.getWidth()); *t = static_cast<DPI::LineType>(pen.getLineType()); }
void Doc_plugin_interface::getCurrentLayerProperties(QColor *c, QString *w, QString *t){ RS_Pen pen = docGr->getActiveLayer()->getPen(); RS_Color col = pen.getColor(); c->setRgb(col.red(), col.green(), col.blue()); w->clear(); w->append(Converter.lw2str(pen.getWidth())); t->clear(); t->append(Converter.lt2str(pen.getLineType())); }
void RS_GraphicView::setBackground(const RS_Color& bg) { background = bg; // bright background: if (bg.red()+bg.green()+bg.blue()>380) { foreground = RS_Color(0,0,0); } else { foreground = RS_Color(255,255,255); } }
int ConvertColor(gdImagePtr i, RS_Color& c) { return gdImageColorAllocateAlpha(i, c.red(), c.green(), c.blue(), 127 - c.alpha()/2 ); }
bool GeometryAdapter::EvalColor(const MdfModel::MdfString& exprstr, RS_Color& rscolor) { // TODO: needs an expression processor argument to eval expressions // string is in the form "AARRGGBB" const wchar_t* scolor = exprstr.c_str(); size_t len = wcslen(scolor); unsigned int color = 0; bool isConst = false; // try to check if the expression is constant int status = 0; if (len == 0) { // error or a color was not set // use transparent black which indicates "not set" rscolor = RS_Color(RS_Color::EMPTY_COLOR_RGBA); return true; } else if (len == 8) { status = swscanf(scolor, L"%8X", &color); } else if (len == 6) { status = swscanf(scolor, L"%6X", &color); // there was no alpha specified in the constant string, add it color |= 0xFF000000; } if (status != 1) { // if not constant try to evaluate as expression if (!m_exec) { _ASSERT(false); rscolor = RS_Color(0x000000FF); return true; } FdoExpression* expr = ObtainFdoExpression(&exprstr); // make sure we have a parsed expression if (!expr) { _ASSERT(false); rscolor = RS_Color(0x000000FF); return false; } try { FdoPtr<FdoLiteralValue> lval = m_exec->Evaluate(expr); color = (unsigned int)ExpressionHelper::GetAsInt32(lval.p); } catch (FdoException* e) { ProcessStylizerException(e, __LINE__, __WFILE__); rscolor = RS_Color(0x000000FF); return false; } catch (...) { return false; } } else { isConst = true; } rscolor.alpha() = color >> 24; rscolor.red() = (color >> 16) & 0xFF; rscolor.green() = (color >> 8) & 0xFF; rscolor.blue() = color & 0xFF; return isConst; }