void Sphere::DrawMe() { btTransform trans; getMotionState()->getWorldTransform(trans); GLfloat mat_amb_diff[] = { _color.GetR(), _color.GetG(), _color.GetB(), 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); glPushMatrix(); glTranslatef(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()); glutSolidSphere(_radius, 50, 50); glPopMatrix(); }
void Box::DrawMe() { translate(btVector3(15,0,0)); btTransform trans; getMotionState()->getWorldTransform(trans); GLfloat mat_amb_diff[] = { _color.GetR(), _color.GetG(), _color.GetB(), 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); glPushMatrix(); glTranslatef(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()); glutSolidCube(_side_size); glPopMatrix(); }
void Graphics::drawPoint(int x, int y, Color c) { glPushMatrix(); glLoadIdentity(); //glScalef(ScaleX,ScaleY,1.0f); glTranslatef(0.375f,0.375f,0); //DrawStuff glDisable(GL_TEXTURE_2D); glBegin(GL_POINTS); glColor4d(c.GetR(),c.GetG(),c.GetB(),c.GetA()); glVertex2d(x,y); glEnd(); glEnable(GL_TEXTURE_2D); glPopMatrix(); }
void AggDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) { data->ren_aa.color(agg::rgba((double)color.GetR()/ 256, (double)color.GetG()/256, (double)color.GetB()/256)); data->ras_aa.move_to(x1,y1); data->ras_aa.line_to(x2,y2); agg::path_storage path; path.move_to(x1, y1); path.line_to(x2, y2); agg::conv_stroke<agg::path_storage> stroke(path); stroke.line_cap(agg::round_cap); stroke.width(width); data->ras_aa.add_path(stroke); }
Image CreateBall(int r, Color color) { int rr = 2 * r; int r2 = r * r; ImageBuffer b(rr, rr); b.SetHotSpot(Point(4, 4)); for(int y = 0; y < rr; y++) for(int x = 0; x < rr; x++) { RGBA& a = b[y][x]; a.r = color.GetR(); a.g = color.GetG(); a.b = color.GetB(); int q = ((x - r) * (x - r) + (y - r) * (y - r)) * 256 / r2; a.a = q <= 255 ? q : 0; } return b; }
UCHAR ImageArray::GetUCharAtLCDMem(UINT x, UINT y) { UCHAR val = 0; if (x < GetColumns() && y < GetRows()) { Points points; m_packer->GetPoints(points, x, y); Points::iterator point = points.begin(); while (point != points.end()) { Color c; m_img->GetPixel((*point).GetX(), (*point).GetY(), &c); UCHAR gray = Gray(c.GetR(), c.GetG(), c.GetB()); val |= (m_packer->Pack(gray, (*point).GetPackOffset(), m_invert)); point++; } } return val; }
//================================================= // Helper Functions //================================================= Color OffsetColor(Color clr, short sOffset) { BYTE bRed = 0; BYTE bGreen = 0; BYTE bBlue = 0; short sOffsetR = sOffset; short sOffsetG = sOffset; short sOffsetB = sOffset; if((sOffset < -255) || (sOffset > 255)) return clr; // Get RGB components of specified color bRed = clr.GetR(); bGreen = clr.GetG(); bBlue = clr.GetB(); // Calculate max. allowed real offset if(sOffset > 0) { if((bRed + sOffset) > 255) sOffsetR = (255 - bRed); if((bGreen + sOffset) > 255) sOffsetG = (255 - bGreen); if((bBlue + sOffset) > 255) sOffsetB = (255 - bBlue); sOffset = min(min(sOffsetR, sOffsetG), sOffsetB); } else { if((bRed + sOffset) < 0) sOffsetR = -bRed; if((bGreen + sOffset) < 0) sOffsetG = -bGreen; if((bBlue + sOffset) < 0) sOffsetB = -bBlue; sOffset = max(max(sOffsetR, sOffsetG), sOffsetB); } return Color(clr.GetAlpha(), (BYTE)(bRed + sOffset), (BYTE)(bGreen + sOffset), (BYTE)(bBlue + sOffset)); }
void DrawAAP(PixelBlock& w, int x, int y, Color c) { if(!Rect(w.GetSize()).Contains(Rect(x, y, x + 6, y + 11))) return; dword *a = w.PointAdr(x, y); int d = w.LineDelta(); byte tr = c.GetR(); byte tg = c.GetG(); byte tb = c.GetB(); const byte *s = aa_packed; dword *t = a; byte *m; int alpha; for(;;) { dword c = *s++; if(c == 0) break; t += (c >> 3) & 15; switch(c & 7) { case 7: AAP_(6); case 6: AAP_(5); case 5: AAP_(4); case 4: AAP_(3); case 3: AAP_(2); case 2: AAP_(1); case 1: AAP_(0); } t += c & 7; s += c & 7; if(c & 0x80) { a += d; t = a; } } }
void Graphics::drawLine(Scalar x, Scalar y, Scalar x2, Scalar y2, Color c) { glPushMatrix(); Scalar width = x2-x; Scalar height = (y2-y); glTranslated(x+width/2, y+height/2,0); //DrawStuff glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glColor4d(c.GetR(),c.GetG(),c.GetB(),c.GetA()); glVertex2d(0-width/2,0-height/2); glVertex2d(width/2,height/2); glEnd(); glEnable(GL_TEXTURE_2D); glPopMatrix(); }
// heightFactor 값을 수정한다. // 이미 지형이 로딩된 상태라면, 높이 값을 heightFactor 값에 맞춰 // 수정한다. void cTerrainEditor::SetHeightFactor(const float heightFactor) { m_heightFactor = heightFactor; if (!IsLoaded()) return; // 아직 지형이 로딩되지 않아서 리턴한다. const wstring wfileName = common::str2wstr(m_heightMapFileName); Bitmap bmp(wfileName.c_str()); if (Ok != bmp.GetLastStatus()) return; const int VERTEX_COL_COUNT = m_grid.GetColVertexCount(); const int VERTEX_ROW_COUNT = m_grid.GetRowVertexCount(); const float WIDTH = m_grid.GetWidth(); const float HEIGHT = m_grid.GetHeight(); const float incX = (float)(bmp.GetWidth()-1) / (float)m_grid.GetColCellCount(); const float incY = (float)(bmp.GetHeight()-1) /(float)m_grid.GetRowCellCount(); sVertexNormTex *pv = (sVertexNormTex*)m_grid.GetVertexBuffer().Lock(); for (int i=0; i < VERTEX_COL_COUNT; ++i) { for (int k=0; k < VERTEX_ROW_COUNT; ++k) { sVertexNormTex *vtx = pv + (k*VERTEX_COL_COUNT) + i; Color color; bmp.GetPixel((int)(i*incX), (int)(k*incY), &color); const float h = ((color.GetR() + color.GetG() + color.GetB()) / 3.f) * heightFactor; vtx->p.y = h; } } m_grid.GetVertexBuffer().Unlock(); m_grid.CalculateNormals(); }
std::string MapPainterSVG::GetColorValue(const Color& color) { std::string result; if (color.IsSolid()) { result.reserve(7); } else { result.reserve(9); } result.append("#"); result.append(1,valueChar[(unsigned int)(color.GetR()*255)/16]); result.append(1,valueChar[(unsigned int)(color.GetR()*255)%16]); result.append(1,valueChar[(unsigned int)(color.GetG()*255)/16]); result.append(1,valueChar[(unsigned int)(color.GetG()*255)%16]); result.append(1,valueChar[(unsigned int)(color.GetB()*255)/16]); result.append(1,valueChar[(unsigned int)(color.GetB()*255)%16]); return result; }
hsl_t ColorToHSL(Color c) { using mid_t = float; //中间类型。 const u8 r(c.GetR()), g(c.GetG()), b(c.GetB()), min_color(min(min(r, g), b)), max_color(max(max(r, g), b)); mid_t h(0); // 此处 h 的值每 0x6 对应一个圆周。 mid_t s(0); decltype(hsl_t::l) l; if(min_color == max_color) l = decltype(hsl_t::l)(min_color) / 0x100; else { const unsigned p(max_color + min_color); l = decltype(hsl_t::l)(p) / 0x200; /* l = 0.2126 * r + 0.7152 * g + 0.0722 * b; // Rec. 601 luma; l = 0.299 * r + 0.588 * g + 0.114 * b; // Rec. 709 luma; */ // chroma * 256; const mid_t q(max_color - min_color); s = q / (p < 0x100 ? p : 0x200 - p); if(r == max_color) h = (g - b) / q; else if(g == max_color) h = (b - r) / q + 0x2; else if(b == max_color) h = (r - g) / q + 0x4; if(h < 0) h += 0x6; } return {h * 60, s, l}; }
void PromptButton::Draw(double opacity) { Color baseColor; if (!isEnabled) { baseColor = DisabledTextColor; } else if (isMouseDown) { baseColor = MouseDownTextColor; } else if (isMouseOver) { baseColor = MouseOverTextColor; } else { baseColor = NormalTextColor; } pTextFont->Draw(text, position, Color(opacity, baseColor.GetR(), baseColor.GetG(), baseColor.GetB())); }
void Graphics::fillRect(Rect r, Color c) { glPushMatrix(); glTranslated(r.getX()+(Scalar)r.getWidth()/2,r.getY()+(Scalar)r.getHeight()/2,0); //DrawStuff glRotated(r.getRot(),0,0,-1); int w = (int)r.getWidth(); int h = (int)r.getHeight(); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glColor4d(c.GetR(),c.GetG(),c.GetB(),c.GetA()); glVertex2d(-.5*w,-.5*h); glVertex2d(-.5*w,.5*h); glVertex2d(.5*w,.5*h); glVertex2d(.5*w,-.5*h); glEnd(); glEnable(GL_TEXTURE_2D); glPopMatrix(); }
Status XGraphics::DrawString(const WCHAR *str,INT len,const XFont *font,const RectF &rcf,const StringFormat *form,const Brush *br) { if(font->dwFontType&TRUETYPE_FONTTYPE) return Graphics::DrawString(str,len,font->font,rcf,form,br); else { HDC hdc=GetHDC(); HFONT hfontOld=(HFONT)SelectObject(hdc,font->hfont); RECT rc; Color col; COLORREF cref; SolidBrush *sbr=(SolidBrush*)br; sbr->GetColor(&col); cref=RGB(col.GetR(),col.GetG(),col.GetB()); rc.left=(LONG)rcf.X; rc.top=(LONG)rcf.Y; rc.right=rc.left+(LONG)rcf.Width; rc.bottom=rc.top+(LONG)rcf.Height; SetTextColor(hdc,cref); DrawText(hdc,str,len,&rc,DT_LEFT|DT_TOP); SelectObject(hdc,hfontOld); ReleaseHDC(hdc); } return Ok; }
void Film::WriteImage(string writeTo){ //output image to a file int r,g,b; Color temp; double max=255.0; writeTo.append(".ppm"); ofstream outf(writeTo.c_str()); if (!outf) { cerr<< "error opening file\n" << endl; exit(1); } cout<<"starting to write to image!"<<endl; outf<<"P3\n"<<m_width<<" "<<m_height<<"\n255"; for (int i=0; i<m_height; i++) { outf<<"\n"; for (int j=0; j<m_width;j++){ temp=m_image[m_width*i+j]; r=(int) max*temp.GetR(); g=(int) max*temp.GetG(); b=(int) max*temp.GetB(); outf<<setw(3)<<r<<setw(4)<<g<<setw(4)<<b<<" "; } } }
void CameraFeed::setColor(BYTE *Data,Color &C) { setRGB(Data,C.GetR(),C.GetG(),C.GetB()); }
void CameraFeed::setColor(int x,int y,Color &C) { setRGB(x,y,C.GetR(),C.GetG(),C.GetB()); }
void CCherryComboBox::SetDropDownListFontColor(Color fontColor) { m_textColor = RGB(fontColor.GetR(), fontColor.GetG(), fontColor.GetB()); CCherryFont::SetFontColor(fontColor); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static ULONG_PTR token; switch(message) { case WM_CREATE: { GdiplusStartup(&token, &input, NULL); backgroundBitmap = new Bitmap(L"background.jpg", FALSE); trace(L"bitmap size: %d,%d\n", backgroundBitmap->GetWidth(), backgroundBitmap->GetHeight()); // 背景画像の大きさに合わせてクライアント領域拡大 // クライアント領域のサイズと、ウインドウ領域のサイズを引き算して // メニューとかの大きさ調べるその差 + 本来の要素の高さ RECT windowRect, clientRect; ::GetWindowRect(hWnd, &windowRect); ::GetClientRect(hWnd, &clientRect); int diffHeight = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top); int diffWidth = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left); trace(L"diff height: %d, diff width: %d\n", diffHeight, diffWidth); ::MoveWindow(hWnd, windowRect.left, windowRect.top, backgroundBitmap->GetWidth() + diffWidth, backgroundBitmap->GetHeight() + diffHeight, TRUE); //HUDContainer *c = new HUDContainer(0, 0, 600, 600, 0); container->hudElements.push_back(new HUDItem(0, 0, 100, 100, 0)); container->hudElements.push_back(new HUDItem(500, 500, 100, 100, 1)); container->hudElements.push_back(new HUDItem(300, 500, 100, 100, 2)); container->hudElements.push_back(new HUDImageItem(400,400,3, L"hudelement.png")); // hudlayout.resファイル読み込み loadHudlayout(L"resource/hudlayout.res"); // メモリDCの作成 buffering.createSecondBuffer(::GetDC(hWnd), backgroundBitmap->GetWidth(), backgroundBitmap->GetHeight()); // 背景画像読み込み for(unsigned int x=0; x<backgroundBitmap->GetWidth(); x++){ for(unsigned int y=0; y<backgroundBitmap->GetHeight(); y++){ Color color; if(backgroundBitmap->GetPixel(x, y, &color) != ::Gdiplus::Ok){ trace(L"err\n"); } short r = color.GetR(); short g = color.GetG(); short b = color.GetB(); ::SetPixel(buffering.getBuffer(), x, y, RGB(r,g,b)); } } } break; case WM_LBUTTONDOWN: { int x = GET_X_LPARAM(lParam); int y = GET_Y_LPARAM(lParam); POINT pt = {x, y}; // ヒットしてるかどうか if(HUDItem *item = container->getHitTestItem(pt)){ ::trace(L"mouseL Hit!!\n"); // ヒットしてたら対象となるHUD要素を記憶 ::activeItem = item; mousePressedPt.x = pt.x; mousePressedPt.y = pt.y; // マウスクリックされたときのactiveitemの座標 mousePressedActiveItemPt.x = item->x; mousePressedActiveItemPt.y = item->y; // ストレッチモードの短形でクリックが押されているかどうか if(activeItem->hitTestStretchMode(pt)){ trace(L"Go Stretch Mode\n"); bStretchPos = activeItem->hitTestStretchMode(pt); ::bStretchMode = TRUE; }else{ ::bStretchMode = FALSE; } ::InvalidateRect(hWnd, NULL, FALSE); bDrag = TRUE; ::SetCapture(hWnd); }else{ ::trace(L"mouseL Not Hit!!\n"); bDrag = FALSE; ::ReleaseCapture(); } } break; case WM_MOUSEMOVE: { int x = GET_X_LPARAM(lParam); int y = GET_Y_LPARAM(lParam); ::trace(L"dragging: %d,%d now\n", x, y); if(bDrag && bStretchMode){ // 拡大縮小モード ::trace(L"stretch mode now\n"); ::trace(L"***DIFF: %d,%d", x - ::mousePressedPt.x, y - ::mousePressedPt.y); if(bStretchPos == STRETCH_BOTTOM_RIGHT){ // 左上固定拡大方式 activeItem->resizeTo(x - ::mousePressedPt.x, y - ::mousePressedPt.y); } if(bStretchPos == STRETCH_TOP_RIGHT){ // 左下固定拡大方式 int diffx = x - ::mousePressedPt.x; int diffy = y - ::mousePressedPt.y; activeItem->x += 0; // kotei activeItem->y += diffy; activeItem->width += diffx; activeItem->height -= diffy; } if(bStretchPos == STRETCH_TOP_LEFT){ // 右下固定拡大方式 int diffx = x - ::mousePressedPt.x; int diffy = y - ::mousePressedPt.y; activeItem->x += diffx; // kotei activeItem->y += diffy; activeItem->width -= diffx; activeItem->height -= diffy; } if(bStretchPos == STRETCH_BOTTOM_LEFT){ // 右上固定方式 int diffx = x - ::mousePressedPt.x; int diffy = y - ::mousePressedPt.y; activeItem->x += diffx; // kotei activeItem->y += 0; activeItem->width -= diffx; activeItem->height += diffy; } ::mousePressedPt.x = x; ::mousePressedPt.y = y; ::InvalidateRect(hWnd, NULL, FALSE); }else if(bDrag){ activeItem->moveTo(x - mousePressedPt.x, y - mousePressedPt.y); activeItem->correctRect(0, 0, buffering.width, buffering.height, true); ::trace(L"dragging: -> %d,%d now\n", activeItem->x, activeItem->y); ::mousePressedPt.x = x; ::mousePressedPt.y = y; // 画面を更新 ::InvalidateRect(hWnd, NULL, FALSE); } } break; case WM_LBUTTONUP: // ドラッグし終わったとき if(bDrag){ bDrag = FALSE; // ドラッギング状態を解除 ::ReleaseCapture(); trace(L"drag exit\n"); } if(bStretchMode){ bStretchMode = FALSE; bStretchPos = 0; } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = ::BeginPaint(hWnd, &ps); // 裏バッファから表へswap buffering.swap(); // 各オブジェクトの描画 container->draw(hdc); if(activeItem){ trace(L"drawing activeItem: %X\n", activeItem); activeItem->highlight(hdc); } ::EndPaint(hWnd, &ps); } break; case WM_CLOSE: ::DestroyWindow(hWnd); break; case WM_DESTROY: ::Gdiplus::GdiplusShutdown(token); ::PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); }
String ColorToHtml(Color color) { return Format("#%02X%02X%02X", color.GetR(), color.GetG(), color.GetB()); }
void CAggMemoryDC::LinearGradientRect( const RectF& rc, const Color& clrstart, const Color& clrend, bool bHorizontal/*=true*/) { // The gradient color array typedef agg::pod_auto_array<agg::rgba8, 256> color_array_type; // Gradient shape function (linear, radial, custom, etc) //----------------- typedef agg::gradient_xy gradient_func_type; // Span interpolator. This object is used in all span generators // that operate with transformations during iterating of the spans, // for example, image transformers use the interpolator too. //----------------- typedef agg::span_interpolator_linear<> interpolator_type; // Span allocator is an object that allocates memory for // the array of colors that will be used to render the // color spans. One object can be shared between different // span generators. //----------------- typedef agg::span_allocator<agg::rgba8> span_allocator_type; // Finally, the gradient span generator working with the agg::rgba8 // color type. // The 4-th argument is the color function that should have // the [] operator returning the color in range of [0...255]. // In our case it will be a simple look-up table of 256 colors. //----------------- typedef agg::span_gradient<agg::rgba8, interpolator_type, gradient_func_type, color_array_type> span_gradient_type; // The gradient scanline renderer type //----------------- typedef agg::renderer_scanline_aa<ren_base, span_allocator_type, span_gradient_type> renderer_gradient_type; // Common declarations (pixel format and basic renderer). //---------------- pixel_format pixf(m_rbuf); ren_base renb(pixf); // The gradient objects declarations //---------------- gradient_func_type gradient_func; // The gradient function agg::trans_affine gradient_mtx; // Affine transformer interpolator_type span_interpolator(gradient_mtx); // Span interpolator span_allocator_type span_allocator; // Span Allocator color_array_type color_array; // Gradient colors // Declare the gradient span itself. // The last two arguments are so called "d1" and "d2" // defining two distances in pixels, where the gradient starts // and where it ends. The actual meaning of "d1" and "d2" depands // on the gradient function. //---------------- span_gradient_type span_gradient(span_interpolator, gradient_func, color_array, bHorizontal ? rc.x : rc.y, bHorizontal ? rc.x+rc.Width : rc.y+rc.Height); // The gradient renderer //---------------- renderer_gradient_type ren_gradient(renb, span_allocator, span_gradient); fill_color_array(color_array, agg::rgba8(clrstart.GetR(), clrstart.GetG(), clrstart.GetB(), clrstart.GetA()), agg::rgba8(clrend.GetR(), clrend.GetG(), clrend.GetB(), clrend.GetA())); m_path.remove_all(); m_path.move_to(rc.x, rc.y); m_path.line_to(rc.x+rc.Width, rc.y); m_path.line_to(rc.x+rc.Width, rc.y+rc.Height); m_path.line_to(rc.x, rc.y+rc.Height); m_path.close_polygon(); m_ras_aa.reset(); m_ras_aa.clip_box(0, 0, m_rcUpdate.Width(), m_rcUpdate.Height()); m_ras_aa.add_path(m_transpath); agg::render_scanlines(m_ras_aa, m_sl, ren_gradient); }
void CAggMemoryDC::Bezier( const GraphTypes::PointFVector& points, const Color& clr, double width/*=2.0*/, bool bArrow/*=true*/, bool bDashed/*=false*/, REAL scale/*=1.0*/, const GraphTypes::Color& firstClrControlPoint, const GraphTypes::Color& lastClrControlPoint) { if (m_buf==0) return; pixel_format pixf(m_rbuf); ren_base renb(pixf); solid_renderer ren_solid(renb); GraphTypes::PointFVector::const_iterator itr=points.begin(); agg::curve_casteljau curve(points.size()); curve.approximation_scale(scale); for(; itr!=points.end();++itr) { curve.add_vertex((*itr).x, (*itr).y); } m_ras_aa.clip_box(0, 0, m_rcUpdate.Width(), m_rcUpdate.Height()); typedef agg::conv_dash<agg::curve_casteljau, agg::vcgen_markers_term> conv_dash_type; typedef agg::conv_stroke<agg::curve_casteljau, agg::vcgen_markers_term> conv_stroke_type; typedef agg::conv_stroke<conv_dash_type, agg::vcgen_markers_term> conv_dash_stroke_type; if(bDashed) { conv_dash_type dash(curve); conv_dash_stroke_type stroke(dash); stroke.width(width); double k = ::pow(stroke.width(), 0.7)*scale; if(bArrow) { // can't use AddPathWithArrowHead(m_ras_aa, stroke, m_mtx, 10, 3, 2, scale); agg::arrowhead ah; ah.head(0, (10-2) * k, 3 * k, 2 * k); typedef agg::conv_marker<agg::vcgen_markers_term, agg::arrowhead> arrow_type; // arrow must take markers before dash markers are added arrow_type arrow(dash.markers(), ah); dash.add_dash(k*4, k*4); dash.dash_start(k*4); stroke.shorten(k*(10-2)); typedef agg::conv_transform<conv_dash_stroke_type, agg::trans_affine> conv_trans_type; conv_trans_type pathtrans(stroke, m_mtx); m_ras_aa.add_path(pathtrans); typedef agg::conv_transform<arrow_type, agg::trans_affine> arrow_trans_type; arrow_trans_type arrowtrans(arrow, m_mtx); m_ras_aa.add_path(arrowtrans); } else { typedef agg::conv_transform<conv_dash_stroke_type, agg::trans_affine> conv_trans_type; dash.add_dash(k*4, k*4); dash.dash_start(k*4); conv_trans_type transstroke(stroke, m_mtx); m_ras_aa.add_path(transstroke); } } else { conv_stroke_type stroke(curve); stroke.width(width); if(bArrow) AddPathWithArrowHead(m_ras_aa, stroke, m_mtx, 10, 3, 2, scale); else { typedef agg::conv_transform<conv_stroke_type, agg::trans_affine> conv_trans_type; conv_trans_type transstroke(stroke, m_mtx); m_ras_aa.add_path(transstroke); } } ren_solid.color(agg::rgba8(clr.GetR(), clr.GetG(), clr.GetB(), clr.GetA())); agg::render_scanlines(m_ras_aa, m_sl, ren_solid); if (points.size() > 1) { if (firstClrControlPoint.GetValue()) { agg::ellipse el_start(points[0].x, points[0].y, 4 * scale, 4 * scale, 16); m_ras_aa.add_path(el_start); ren_solid.color(agg::rgba8(firstClrControlPoint.GetR(), firstClrControlPoint.GetG(), firstClrControlPoint.GetB(), firstClrControlPoint.GetA())); agg::render_scanlines(m_ras_aa, m_sl, ren_solid); } if (lastClrControlPoint.GetValue()) { agg::ellipse el_end(points[points.size() - 1].x, points[points.size() - 1].y, 4 * scale, 4 * scale, 16); m_ras_aa.add_path(el_end); ren_solid.color(agg::rgba8(lastClrControlPoint.GetR(), lastClrControlPoint.GetG(), lastClrControlPoint.GetB(), lastClrControlPoint.GetA())); agg::render_scanlines(m_ras_aa, m_sl, ren_solid); } } }
int Grayscale(const Color& c) { return (77 * c.GetR() + 151 * c.GetG() + 28 * c.GetB()) >> 8; }
void GLDraw::SetColor(Color c) { glColor3f(c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0); }
void SystemDraw::SetColor(Color c) { cairo_set_source_rgb(cr, c.GetR() / 255.0, c.GetG() / 255.0, c.GetB() / 255.0); }
void MapPainterAgg::DrawPath(const Projection& projection, const MapParameter& parameter, const Color& color, double width, const std::vector<double>& dash, LineStyle::CapStyle startCap, LineStyle::CapStyle endCap, size_t transStart, size_t transEnd) { agg::path_storage p; for (size_t i=transStart; i<=transEnd; i++) { if (i==transStart) { p.move_to(coordBuffer->buffer[i].GetX(), coordBuffer->buffer[i].GetY()); } else { p.line_to(coordBuffer->buffer[i].GetX(), coordBuffer->buffer[i].GetY()); } } renderer_aa->color(agg::rgba(color.GetR(), color.GetG(), color.GetB(), color.GetA())); if (dash.empty()) { agg::conv_stroke<agg::path_storage> stroke(p); stroke.width(width); if (startCap==LineStyle::capButt || endCap==LineStyle::capButt) { stroke.line_cap(agg::butt_cap); } else if (startCap==LineStyle::capSquare || endCap==LineStyle::capSquare) { stroke.line_cap(agg::square_cap); } else { stroke.line_cap(agg::round_cap); } rasterizer->add_path(stroke); agg::render_scanlines(*rasterizer,*scanlineP8,*renderer_aa); } else { agg::conv_dash<agg::path_storage> dasher(p); agg::conv_stroke<agg::conv_dash<agg::path_storage> > stroke(dasher); stroke.width(width); if (startCap==LineStyle::capButt || endCap==LineStyle::capButt) { stroke.line_cap(agg::butt_cap); } else if (startCap==LineStyle::capSquare || endCap==LineStyle::capSquare) { stroke.line_cap(agg::square_cap); } else { stroke.line_cap(agg::round_cap); } for (size_t i=0; i<dash.size(); i+=2) { dasher.add_dash(dash[i]*width,dash[i+1]*width); } rasterizer->add_path(stroke); agg::render_scanlines(*rasterizer,*scanlineP8,*renderer_aa); } // TODO: End point caps "dots" }
Color UIControl::getTrueColor(Color color) const { return hasAttr(STATE_ENABLED) ? color : Color(128, color.GetR(), color.GetG(), color.GetB()); }
Color_HSL RGB_to_HSL (Color c) { Color_HSL hsl; int Max, Min, Diff, Sum; // Of our RGB values, assign the highest value to Max, and the Smallest to Min if ( c.GetR() > c.GetG() ) { Max = c.GetR(); Min = c.GetG(); } else { Max = c.GetG(); Min = c.GetR(); } if ( c.GetB() > Max ) { Max = c.GetB(); } else if ( c.GetB() < Min ) { Min = c.GetB(); } Diff = Max - Min; Sum = Max + Min; // Luminance - a.k.a. Brightness - Adobe photoshop uses the logic that the // site VBspeed regards (regarded) as too primitive = superior decides the // level of brightness. hsl.l = (double)Max/255; // Saturation if ( Max == 0 ) hsl.s = 0; // Protecting from the impossible operation of division by zero. else hsl.s = (double)Diff/Max; // The logic of Adobe Photoshops is this simple. // Hue R is situated at the angel of 360 eller noll degrees; // G vid 120 degrees // B vid 240 degrees double q; if ( Diff == 0 ) q = 0; // Protecting from the impossible operation of division by zero. else q = (double)60/Diff; if ( Max == c.GetR() ) { if ( c.GetG() < c.GetB() ) { hsl.h = (double)(360 + q * (c.GetG() - c.GetB()))/360; } else { hsl.h = (double)(q * (c.GetG() - c.GetB()))/360; } } else if ( Max == c.GetG() ) { hsl.h = (double)(120 + q * (c.GetB() - c.GetR()))/360; } else if ( Max == c.GetB() ) { hsl.h = (double)(240 + q * (c.GetR() - c.GetG()))/360; } else { hsl.h = 0.0; } return hsl; }
void DrawPolyPolyPolygon(Draw& draw, const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, const int *disjunct_polygon_counts, int disjunct_polygon_count_count, Color color, int width, Color outline, uint64 pattern, Color doxor) { if(vertex_count == 0) return; #ifdef PLATFORM_WIN32_ //!!TODO if(PdfDraw *pdf = dynamic_cast<PdfDraw *>(&draw)) { pdf->DrawPolyPolyPolygon(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, disjunct_polygon_counts, disjunct_polygon_count_count, color, width, outline, pattern, doxor); return; } #endif // LOG("DrawPolyPolyPolygon: drawing = " << (draw.IsDrawing() ? "yes" : "no") // << ", backdraw = " << (draw.IsBack() ? "yes" : "no") // << ", " << (draw.Dots() ? "dots" : "pixels") // << ", printer = " << (draw.IsPrinter() ? "yes" : "no")); // LOG("#vertices = " << vertex_count << ", #subpolygons = " << subpolygon_count_count // << ", #disjunct polygons = " << disjunct_polygon_count_count); // LOG("color = " << Dump(color) << ", width = " << width << ", outline = " << Dump(outline) // << ", pattern = " << Dump(pattern) << ", doxor = " << doxor); #ifdef _DEBUG // for(int v = 0; v < vertex_count; v++) // if(abs2(vertices[v] - vertices[(v ? v : vertex_count) - 1]) >= 500 * 500) // NEVER(); #endif if(!dynamic_cast<SystemDraw *>(&draw)) { draw.DrawPolyPolyPolygon(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, disjunct_polygon_counts, disjunct_polygon_count_count, color, width, outline, pattern, doxor); return; } // TIMING("DrawPolyPolygon/hdc"); bool is_xor = !IsNull(doxor); #ifdef PLATFORM_X11 unsigned xor_pixel = (is_xor ? GetXPixel(doxor) : 0); XGCValues gcv; gcv.function = is_xor ? X11_ROP2_XOR : X11_ROP2_COPY; GC fill_gc = NULL; Image pattern_image; if(!IsNull(color)) { gcv.foreground = GetXPixel(color) ^ xor_pixel; int fmask = GCForeground | GCFunction; if(pattern) { pattern_image = GetPatternImage(pattern); gcv.stipple = pattern_image.GetMaskPixmap(); gcv.fill_style = FillStippled; fmask |= GCStipple | GCFillStyle; } fill_gc = XCreateGC(Xdisplay, draw.GetDrawable(), fmask, &gcv); } GC line_gc = NULL; if(!IsNull(outline)) { gcv.foreground = GetXPixel(outline) ^ xor_pixel; gcv.line_width = width; line_gc = XCreateGC(Xdisplay, draw.GetDrawable(), GCForeground | GCFunction | GCLineWidth, &gcv); Point offset = draw.GetOffset(); } #endif for(int i = 0; i < disjunct_polygon_count_count; i++, disjunct_polygon_counts++) { int poly = *disjunct_polygon_counts; int sub = 1; if(*subpolygon_counts < poly) if(disjunct_polygon_count_count > 1) { const int *se = subpolygon_counts; int total = 0; while(total < poly) total += *se++; sub = se - subpolygon_counts; } else sub = subpolygon_count_count; if(sub > poly) { vertices += poly; subpolygon_counts += sub; continue; } #if defined(PLATFORM_WIN32) #ifdef SYSTEMDRAW SystemDraw *w = dynamic_cast<SystemDraw *>(&draw); if(w) { SystemDraw& draw = *w; #endif if(pattern) { int old_rop = GetROP2(draw); HGDIOBJ old_brush = GetCurrentObject(draw, OBJ_BRUSH); word wpat[8] = { (byte)(pattern >> 56), (byte)(pattern >> 48), (byte)(pattern >> 40), (byte)(pattern >> 32), (byte)(pattern >> 24), (byte)(pattern >> 16), (byte)(pattern >> 8), (byte)(pattern >> 0), }; HBITMAP bitmap = CreateBitmap(8, 8, 1, 1, wpat); HBRUSH brush = ::CreatePatternBrush(bitmap); COLORREF old_bk = GetBkColor(draw); COLORREF old_fg = GetTextColor(draw); if(!is_xor) { SetROP2(draw, R2_MASKPEN); SelectObject(draw, brush); SetTextColor(draw, Black()); SetBkColor(draw, White()); DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, true, PEN_NULL, Null); SetROP2(draw, R2_MERGEPEN); SetTextColor(draw, color); SetBkColor(draw, Black()); } else { // xor fill with pattern data SetROP2(draw, R2_XORPEN); SelectObject(draw, brush); } DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, true, PEN_NULL, Null); SelectObject(draw, old_brush); SetTextColor(draw, old_fg); SetBkColor(draw, old_bk); SetROP2(draw, old_rop); DeleteObject(brush); DeleteObject(bitmap); if(!IsNull(outline)) { draw.SetColor(Null); draw.SetDrawPen(width, outline); ASSERT(sizeof(POINT) == sizeof(Point)); PolyPolygon(draw, (const POINT *)vertices, subpolygon_counts, sub); } } else { // simple fill // RTIMING("AreaTool::Fill(solid color)"); int out_wd = (IsNull(width) || IsNull(outline) ? PEN_NULL : width); Color out_co = Nvl(outline, Black); draw.SetDrawPen(out_wd, out_co); if(is_xor) { color = Color(color.GetR() ^ doxor.GetR(), color.GetG() ^ doxor.GetG(), color.GetB() ^ doxor.GetB()); SetROP2(draw, R2_XORPEN); } HGDIOBJ old_brush = 0; if(IsNull(color)) { static HGDIOBJ null_brush = GetStockObject(NULL_BRUSH); old_brush = SelectObject(draw, null_brush); } else draw.SetColor(color); DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, !IsNull(color), out_wd, out_co); if(old_brush) SelectObject(draw, old_brush); if(is_xor) SetROP2(draw, R2_COPYPEN); } #ifdef SYSTEMDRAW } #endif #elif defined(PLATFORM_X11) if(fill_gc) FillPolyPolygonRaw(fill_gc, draw.GetDrawable(), draw.GetClip(), draw.GetOffset(), vertices, poly, subpolygon_counts, sub); if(line_gc) DrawPolyPolygonRaw(line_gc, draw.GetDrawable(), draw.GetOffset(), vertices, poly, subpolygon_counts, sub); #else #error #endif vertices += poly; subpolygon_counts += sub; }