// The raytracing process void CRenderingCore::RenderPixelBuffer() { /************************************************************** STRATEGY: 1. Run nested loop for the entire screen. **************************************************************/ m_pcamCurrent->Describe(); // 1. for (int y = 0; y < m_iPixelY; y++) { for (int x = 0; x < m_iPixelX; x++) { CColor colToUse; /**************************************************************** NESTED LOOP LOGIC: Calculate the X fraction Get the pixel ray for this screen coordinate fromt the camera Get the color for this ray. Plot the pixel with this color. ****************************************************************/ colToUse = Sample ((float)x, (float)y, 1); m_ppPixelBuffer[0][x][y] = ((float) (int)(colToUse.GetRed() * 1000.0f)) / 1000.0f; m_ppPixelBuffer[1][x][y] = ((float) (int)(colToUse.GetGreen() * 1000.0f)) / 1000.0f; m_ppPixelBuffer[2][x][y] = ((float) (int)(colToUse.GetBlue() * 1000.0f)) / 1000.0f; } } }
void CQTOpenGLUserFunctions::SetColor(const CColor& c_color) { const GLfloat pfColor[] = { c_color.GetRed() / 255.0f, c_color.GetGreen() / 255.0f, c_color.GetBlue() / 255.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, DEFAULT_SPECULAR); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, DEFAULT_SHININESS); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, DEFAULT_EMISSION); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, pfColor); }
buzzvm_state CBuzzController::Register(const std::string& str_key, const CColor& c_color) { buzzvm_pushs(m_tBuzzVM, buzzvm_string_register(m_tBuzzVM, str_key.c_str(), 1)); buzzvm_pusht(m_tBuzzVM); buzzobj_t tColorTable = buzzvm_stack_at(m_tBuzzVM, 1); buzzvm_gstore(m_tBuzzVM); TablePut(tColorTable, "red", c_color.GetRed()); TablePut(tColorTable, "green", c_color.GetGreen()); TablePut(tColorTable, "blue", c_color.GetBlue()); return m_tBuzzVM->state; }
buzzvm_state CBuzzController::TablePut(buzzobj_t t_table, SInt32 n_idx, const CColor& c_color) { buzzvm_push(m_tBuzzVM, t_table); buzzvm_pushi(m_tBuzzVM, n_idx); buzzvm_pusht(m_tBuzzVM); buzzobj_t tColorTable = buzzvm_stack_at(m_tBuzzVM, 1); buzzvm_tput(m_tBuzzVM); TablePut(tColorTable, "red", c_color.GetRed()); TablePut(tColorTable, "green", c_color.GetGreen()); TablePut(tColorTable, "blue", c_color.GetBlue()); return m_tBuzzVM->state; }
void CQTOpenGLUserFunctions::DrawPoint(const CVector3& c_position, const CColor& c_color, const Real f_point_diameter) { glDisable(GL_LIGHTING); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); glPointSize(f_point_diameter); glBegin(GL_POINTS); glVertex3f(c_position.GetX(), c_position.GetY(), c_position.GetZ()); glEnd(); glPointSize(1.0); glEnable(GL_LIGHTING); }
void CQTOpenGLUserFunctions::DrawText(const std::string& str_text, const CVector3& c_center_offset, const CColor& c_color) { glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); GetOpenGLWidget().renderText(c_center_offset.GetX(), c_center_offset.GetY(), c_center_offset.GetZ(), str_text.c_str()); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); }
void CQTOpenGLUserFunctions::DrawTriangle(const CVector3& c_center_offset, const CColor& c_color, const bool b_fill, const CQuaternion& c_orientation, Real f_base, Real f_height) { glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); if(b_fill) { glBegin(GL_POLYGON); } else { glBegin(GL_LINE_LOOP); } CVector3 cNormalDirection(0.0f, 0.0f, 1.0f); cNormalDirection.Rotate(c_orientation); glNormal3f(cNormalDirection.GetX(), cNormalDirection.GetY(), cNormalDirection.GetZ()); CVector3 cVertex(f_height * 0.5f, 0.0f, 0.0f); cVertex.Rotate(c_orientation); glVertex3f(cVertex.GetX() + c_center_offset.GetX(), cVertex.GetY() + c_center_offset.GetY(), cVertex.GetZ() + c_center_offset.GetZ()); cVertex.Set(-f_height * 0.5f, f_base * 0.5f, 0.0f); cVertex.Rotate(c_orientation); glVertex3f(cVertex.GetX() + c_center_offset.GetX(), cVertex.GetY() + c_center_offset.GetY(), cVertex.GetZ() + c_center_offset.GetZ()); cVertex.Set(-f_height * 0.5f, -f_base * 0.5f, 0.0f); cVertex.Rotate(c_orientation); glVertex3f(cVertex.GetX() + c_center_offset.GetX(), cVertex.GetY() + c_center_offset.GetY(), cVertex.GetZ() + c_center_offset.GetZ()); glEnd(); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); }
void CQTOpenGLUserFunctions::DrawCircle(Real f_radius, const CVector3& c_center_offset, const CColor& c_color, const bool b_fill, const CQuaternion& c_orientation, GLuint un_vertices) { glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); CVector3 cVertex(f_radius, 0.0f, 0.0f); CRadians cAngle(CRadians::TWO_PI / un_vertices); if(b_fill) { glBegin(GL_POLYGON); } else { glBegin(GL_LINE_LOOP); } CVector3 cNormalDirection(0.0f, 0.0f, 1.0f); cNormalDirection.Rotate(c_orientation); glNormal3f(cNormalDirection.GetX(), cNormalDirection.GetY(), cNormalDirection.GetZ()); /* Compute the quaternion defining the rotation of the vertices used to draw the circle. */ CQuaternion cVertexRotation; CVector3 cVertexRotationAxis(0.0f, 0.0f, 1.0f); cVertexRotationAxis.Rotate(c_orientation); cVertexRotation.FromAngleAxis(cAngle, cVertexRotationAxis); cVertex.Rotate(c_orientation); for(GLuint i = 0; i <= un_vertices; i++) { glVertex3f(cVertex.GetX() + c_center_offset.GetX(), cVertex.GetY() + c_center_offset.GetY(), cVertex.GetZ() + c_center_offset.GetZ()); cVertex.Rotate(cVertexRotation); } glEnd(); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); }
bool CTexture::FillTextureWithColor (unsigned int width, unsigned int height, const CColor& color) { if (m_Texture==NULL) { LOGGER->AddNewLog(ELL_ERROR,"CTexture::FillTextureWithColor-> m_Texture no ha sido creado aun "); return false; } HRESULT hr; D3DLOCKED_RECT lock; hr=m_Texture->LockRect(0, &lock, NULL, D3DLOCK_DISCARD); if(hr==D3D_OK) { uint8 *pTxtBuffer; // Bitmap buffer, texture buffer pTxtBuffer = (uint8*)lock.pBits; uint32 j = 0; for( uint32 cont = 0; cont< width * height; cont++) { //BLUE pTxtBuffer[cont*4 + 0] = (uint8)(color.GetBlue()*255); //GREEN pTxtBuffer[cont*4 + 1] = (uint8)(color.GetGreen()*255); //RED pTxtBuffer[cont*4 + 2] = (uint8)(color.GetRed()*255); //ALPHA pTxtBuffer[cont*4 + 3] = (uint8)(color.GetAlpha()*255); } hr=m_Texture->UnlockRect(0); } else { LOGGER->AddNewLog(ELL_ERROR,"CTexture::FillTextureWithColor->Error en la llamada lockRect"); return false; } m_Width = width; m_Height = height; return true; }
void CQTOpenGLUserFunctions::DrawSegment(const CVector3& c_end_point, const CVector3& c_start_point, const CColor& c_segment_color, const Real& f_line_width, bool b_draw_end_point, bool b_draw_start_point, const CColor& c_end_point_color, const CColor& c_start_point_color) { /* Draw the segment */ glDisable(GL_LIGHTING); glColor3ub(c_segment_color.GetRed(), c_segment_color.GetGreen(), c_segment_color.GetBlue()); glEnable (GL_LINE_SMOOTH); glLineWidth(f_line_width); glBegin(GL_LINES); glVertex3f(c_start_point.GetX(), c_start_point.GetY(), c_start_point.GetZ() ); glVertex3f(c_end_point.GetX(), c_end_point.GetY(), c_end_point.GetZ() ); glEnd(); /* Draw the end and start points if necessary */ if(b_draw_end_point) { DrawPoint(c_end_point, c_end_point_color, 5.0); } if(b_draw_start_point) { DrawPoint(c_start_point, c_start_point_color, 5.0); } glPointSize(1.0); glEnable(GL_LIGHTING); }
virtual void SaveAsImage(const std::string& str_path) { fipImage cImage(FIT_BITMAP, m_unPixelsPerMeter * m_cHalfArenaSize.GetX()*2, m_unPixelsPerMeter * m_cHalfArenaSize.GetY()*2, 24); Real fFactor = 1.0f / static_cast<Real>(m_unPixelsPerMeter); CVector2 cFloorPos; CColor cARGoSPixel; RGBQUAD tFIPPixel; for(UInt32 y = 0; y < cImage.getHeight(); ++y) { for(UInt32 x = 0; x < cImage.getWidth(); ++x) { cFloorPos.Set(x * fFactor, y * fFactor); cFloorPos -= m_cHalfArenaSize; cARGoSPixel = m_cLoopFunctions.GetFloorColor(cFloorPos); tFIPPixel.rgbRed = cARGoSPixel.GetRed(); tFIPPixel.rgbGreen = cARGoSPixel.GetGreen(); tFIPPixel.rgbBlue = cARGoSPixel.GetBlue(); cImage.setPixelColor(x, y, &tFIPPixel); } } if(!cImage.save(str_path.c_str())) { THROW_ARGOSEXCEPTION("Cannot save image \"" << str_path << "\" for floor entity."); } }
void CQTOpenGLUserFunctions::DrawText(const CVector3& c_position, const std::string& str_text, const CColor& c_color) { /* Save attributes */ glPushAttrib(GL_ENABLE_BIT); /* Disable lighting to make text color unaffected by light */ glDisable(GL_LIGHTING); /* Disable culling to make text visibile from any angle */ glDisable(GL_CULL_FACE); /* Set color */ glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); GetMainWindow(). GetOpenGLWidget(). renderText(c_position.GetX(), c_position.GetY(), c_position.GetZ(), str_text.c_str()); /* Restore saved attributes */ glPopAttrib(); }
void DX9SpriteBatch::Draw( ITextureBase *Texture2D, CRectangle &PositionInTexture, Vector2I &Origin, Vector2F &Position, float Rotation, Vector2F &Scale, CColor &Color, float ZOrder, eSpriteEffects SpriteEffect ) { CDX9Texture *tex = dynamic_cast<CDX9Texture *>(Texture2D); RECT src; src.left = PositionInTexture.Left(); src.right = PositionInTexture.Right(); src.top = PositionInTexture.Top(); src.bottom = PositionInTexture.Bottom(); D3DXVECTOR2 center(static_cast<float>(Origin.x), static_cast<float>(Origin.y)); D3DXVECTOR2 pos(Position.x - Origin.x, Position.y - Origin.y); D3DXMATRIX transform; DXCheck(D3DXMatrixTransformation2D(&transform, NULL, NULL, &D3DXVECTOR2(Scale.x, Scale.y), ¢er, Rotation, &pos)); if (SUCCEEDED(DXCheck(m_D3DSprite->SetTransform(&transform)))) { DXCheck(m_D3DSprite->Draw( tex->GetDxTexture(), &src, NULL, NULL, D3DCOLOR_RGBA(Color.GetRed(), Color.GetGreen(), Color.GetBlue(), Color.GetAlpha()) )); } }
void CQTOpenGLUserFunctions::DrawPolygon(const std::vector<CVector3>& vec_points, const CColor& c_color) { if (vec_points.size() > 2) { glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); glBegin(GL_POLYGON); for (UInt32 i = 0; i < vec_points.size(); ++i) { glVertex3f(vec_points[i].GetX(), vec_points[i].GetY(), vec_points[i].GetZ()); } glEnd(); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); } }
void CQTOpenGLUserFunctions::DrawCylinder(Real f_radius, Real f_height, const CVector3& c_center_offset, const CColor& c_color, const CQuaternion& c_orientation, GLuint un_vertices) { /* Draw top circle*/ CVector3 cCirclePos(0.0f, 0.0f, f_height * 0.5f); cCirclePos.Rotate(c_orientation); cCirclePos += c_center_offset; DrawCircle(f_radius, cCirclePos, c_color, true, c_orientation, un_vertices); /* Draw bottom circle*/ cCirclePos.Set(0.0f, 0.0f, -f_height * 0.5f); cCirclePos.Rotate(c_orientation); cCirclePos += c_center_offset; DrawCircle(f_radius, cCirclePos, c_color, true, c_orientation, un_vertices); /* Side surface */ CVector3 cVertex1(f_radius, 0.0f, f_height * 0.5f); CVector3 cVertex2(f_radius, 0.0f, -f_height * 0.5f); CRadians cAngle(CRadians::TWO_PI / un_vertices); /* Compute the quaternion defining the rotation of the vertices used to draw the side surface. */ CQuaternion cVertexRotation; CVector3 cVertexRotationAxis(0.0f, 0.0f, 1.0f); cVertexRotationAxis.Rotate(c_orientation); cVertexRotation.FromAngleAxis(cAngle, cVertexRotationAxis); glDisable(GL_LIGHTING); glColor3ub(c_color.GetRed(), c_color.GetGreen(), c_color.GetBlue()); glBegin(GL_QUAD_STRIP); /* Compute the normal direction of the starting edge. */ CVector3 cNormalDirection(cVertex1.GetX(), cVertex1.GetY(), 0.0f); cNormalDirection.Rotate(c_orientation); glNormal3f(cNormalDirection.GetX(), cNormalDirection.GetY(), cNormalDirection.GetZ()); /* Rotate the endpoints of the first edge.*/ cVertex1.Rotate(c_orientation); cVertex2.Rotate(c_orientation); for(GLuint i = 0; i <= un_vertices; i++) { glVertex3f(cVertex1.GetX() + c_center_offset.GetX(), c_center_offset.GetY() + cVertex1.GetY(), c_center_offset.GetZ() + cVertex1.GetZ() ); glVertex3f(cVertex2.GetX() + c_center_offset.GetX(), c_center_offset.GetY() + cVertex2.GetY(), c_center_offset.GetZ() + cVertex2.GetZ() ); /* Rotate the vertices and the normal direction, set the new normal. */ cVertex1.Rotate(cVertexRotation); cVertex2.Rotate(cVertexRotation); cNormalDirection.Rotate(cVertexRotation); glNormal3f(cNormalDirection.GetX(), cNormalDirection.GetY(), cNormalDirection.GetZ()); } glEnd(); glEnable(GL_LIGHTING); }
/////////////////////////////////////////////////////////////////////////////// // DrawVertical void CXScrollBar::DrawVertical() { TRACE(_T("in CXScrollBar::DrawVertical\n")); CClientDC dc(this); CMemDC memDC(&dc, &m_rectClient); CBrush brushFrame(FRAME_COLOR); CDC bitmapDC; bitmapDC.CreateCompatibleDC(&dc); CBitmap bitmap; // ===== draw Up arrow ===== VERIFY(bitmap.LoadBitmap(IDB_VERTICAL_SCROLLBAR_UPARROW)); CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap); // NOTE: thumb and arrow bitmaps are assumed to be same width and height CRect rectUpArrow(m_rectClient.left, m_rectClient.top, m_rectClient.right, m_rectClient.top + m_nBitmapHeight); memDC.StretchBlt(rectUpArrow.left, rectUpArrow.top, rectUpArrow.Width(), rectUpArrow.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectUpArrow, &brushFrame); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; int nChannelStart = m_rectClient.top + m_nBitmapHeight; int nChannelHeight = m_rectClient.Height() - 2*m_nBitmapHeight; // ===== draw channel ===== // save new thumb position TRACE(_T("m_nThumbTop=%d\n"), m_nThumbTop); m_rectThumb.left = m_rectClient.left; m_rectThumb.right = m_rectThumb.left + m_rectClient.Width(); m_rectThumb.top = m_rectClient.top + m_nThumbTop; m_rectThumb.bottom = m_rectThumb.top + m_nBitmapHeight; VERIFY(bitmap.LoadBitmap(IDB_VERTICAL_SCROLLBAR_CHANNEL)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectChannelDown(m_rectClient.left, m_rectThumb.top + m_nBitmapHeight/2, m_rectClient.right, nChannelStart + nChannelHeight); memDC.StretchBlt(rectChannelDown.left+1, rectChannelDown.top, rectChannelDown.Width()-1, rectChannelDown.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, 1, SRCCOPY); if (m_bChannelColor && m_bThumbColor) { // thumb has a color, so use same (lightened) color for channel CColor color; color.SetRGB(GetRValue(m_ThumbColor), GetGValue(m_ThumbColor), GetBValue(m_ThumbColor)); color.ToHLS(); float fLuminance = color.GetLuminance(); // use 80% L, 150% S for main color fLuminance = .80f; float fSaturation = color.GetSaturation(); fSaturation = 0.5f * fSaturation; float fHue = color.GetHue(); color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb3 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .87 L for second highlight color fLuminance = .87f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb2 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .92 L for first highlight color fLuminance = .92f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb1 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); BITMAP bm; bitmap.GetBitmap(&bm); // set highlight colors bitmapDC.SetPixel(0, 0, rgb1); bitmapDC.SetPixel(1, 0, rgb2); // set main color for (int x = 2; x < (bm.bmWidth); x++) { bitmapDC.SetPixel(x, 0, rgb3); } } CRect rectChannelUp(m_rectClient.left, nChannelStart, m_rectClient.right, m_rectThumb.top + m_nBitmapHeight/2); memDC.StretchBlt(rectChannelUp.left, rectChannelUp.top, rectChannelUp.Width(), rectChannelUp.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, 1, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // ===== draw down arrow ===== VERIFY(bitmap.LoadBitmap(IDB_VERTICAL_SCROLLBAR_DOWNARROW)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectDownArrow(m_rectClient.left, m_rectClient.bottom - m_nBitmapHeight, m_rectClient.right, m_rectClient.bottom); memDC.StretchBlt(rectDownArrow.left, rectDownArrow.top, rectDownArrow.Width()-1, rectDownArrow.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectDownArrow, &brushFrame); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // If there is nothing to scroll then don't show the thumb if (m_nRange) { // ===== draw thumb ===== VERIFY(bitmap.LoadBitmap(m_bThumbColor ? IDB_VERTICAL_SCROLLBAR_THUMB : IDB_VERTICAL_SCROLLBAR_THUMB_NO_COLOR)); pOldBitmap = bitmapDC.SelectObject(&bitmap); COLORREF rgbThumb = m_bThumbHover ? m_ThumbHoverColor : m_ThumbColor; COLORREF rgbPrev = 0; // add desired color to thumb for (int x = 0; x < m_nBitmapWidth; x++) { for (int y = 0; y < m_nBitmapHeight; y++) { COLORREF rgb = bitmapDC.GetPixel(x, y); switch (rgb) { case THUMB_MASK_COLOR: if (m_bThumbColor) { bitmapDC.SetPixel(x, y, rgbThumb); } break; case THUMB_GRIPPER_MASK_COLOR: bitmapDC.SetPixel(x, y, m_bThumbGripper ? THUMB_GRIPPER_COLOR : rgbPrev); break; case THUMB_UP_TRANSPARENT_MASK_COLOR: bitmapDC.SetPixel(x, y, memDC.GetPixel(x, nChannelStart)); break; case THUMB_DOWN_TRANSPARENT_MASK_COLOR: bitmapDC.SetPixel(x, y, memDC.GetPixel(x, nChannelStart+nChannelHeight-1)); break; default: break; } rgbPrev = rgb; } } memDC.StretchBlt(m_rectThumb.left, m_rectThumb.top, m_rectThumb.Width(), m_rectThumb.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; } else { m_rectThumb = CRect(-1,-1,-1,-1); } memDC.FrameRect(&m_rectClient, &brushFrame); }
/////////////////////////////////////////////////////////////////////////////// // DrawHorizontal void CXScrollBar::DrawHorizontal() { TRACE(_T("in CXScrollBar::DrawHorizontal\n")); CClientDC dc(this); CMemDC memDC(&dc, &m_rectClient); CBrush brushFrame(FRAME_COLOR); CDC bitmapDC; bitmapDC.CreateCompatibleDC(&dc); CBitmap bitmap; // ===== draw left arrow ===== VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_LEFTARROW)); CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap); // NOTE: thumb and arrow bitmaps are assumed to be same width and height CRect rectLeftArrow(m_rectClient.left, m_rectClient.top, m_rectClient.left + m_nBitmapWidth, m_rectClient.bottom); memDC.StretchBlt(rectLeftArrow.left, rectLeftArrow.top+1, rectLeftArrow.Width(), rectLeftArrow.Height()-1, &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectLeftArrow, &brushFrame); int nChannelStart = m_rectClient.left + m_nBitmapWidth; int nChannelWidth = m_rectClient.Width() - 2*m_nBitmapWidth; if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // ===== draw channel ===== // save new thumb position TRACE(_T("m_nThumbLeft=%d\n"), m_nThumbLeft); m_rectThumb.left = m_rectClient.left + m_nThumbLeft; m_rectThumb.right = m_rectThumb.left + m_nBitmapWidth; m_rectThumb.top = m_rectClient.top; m_rectThumb.bottom = m_rectThumb.top + m_rectClient.Height(); VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_CHANNEL)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectChannelRight(m_rectThumb.left + m_nBitmapWidth/2, m_rectClient.top, nChannelStart + nChannelWidth, m_rectClient.bottom); memDC.StretchBlt(rectChannelRight.left, rectChannelRight.top+1, rectChannelRight.Width(), rectChannelRight.Height()-1, &bitmapDC, 0, 0, 1, m_nBitmapHeight, SRCCOPY); if (m_bChannelColor && m_bThumbColor) { // thumb has a color, so use same (lightened) color for channel CColor color; color.SetRGB(GetRValue(m_ThumbColor), GetGValue(m_ThumbColor), GetBValue(m_ThumbColor)); color.ToHLS(); float fLuminance = color.GetLuminance(); // use 80% L, 150% S for main color fLuminance = .80f; float fSaturation = color.GetSaturation(); fSaturation = 0.5f * fSaturation; float fHue = color.GetHue(); color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb3 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .87 L for second highlight color fLuminance = .87f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb2 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .92 L for first highlight color fLuminance = .92f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb1 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); BITMAP bm; bitmap.GetBitmap(&bm); // set highlight colors bitmapDC.SetPixel(0, 0, rgb1); bitmapDC.SetPixel(0, 1, rgb2); // set main color for (int y = 2; y < (bm.bmHeight); y++) { bitmapDC.SetPixel(0, y, rgb3); } } CRect rectChannelLeft(nChannelStart, m_rectClient.top, m_rectThumb.left + m_nBitmapWidth/2, m_rectClient.bottom); memDC.StretchBlt(rectChannelLeft.left, rectChannelLeft.top+1, rectChannelLeft.Width(), rectChannelLeft.Height()-1, &bitmapDC, 0, 0, 1, m_nBitmapHeight, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // ===== draw right arrow ===== VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_RIGHTARROW)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectRightArrow(m_rectClient.right - m_nBitmapWidth, m_rectClient.top, m_rectClient.right, m_rectClient.bottom); memDC.StretchBlt(rectRightArrow.left, rectRightArrow.top+1, rectRightArrow.Width(), rectRightArrow.Height()-1, &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectRightArrow, &brushFrame); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // If there is nothing to scroll then don't show the thumb if (m_nRange) { // ===== draw thumb ===== if (m_bThumbColor) { VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_THUMB)); } else { VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_THUMB_NO_COLOR)); } pOldBitmap = bitmapDC.SelectObject(&bitmap); COLORREF rgbThumb = m_ThumbColor; if (m_bThumbHover) { rgbThumb = m_ThumbHoverColor; } COLORREF rgbPrev = 0; // add desired color to thumb for (int x = 0; x < m_nBitmapWidth; x++) { for (int y = 0; y < m_nBitmapHeight; y++) { COLORREF rgb = bitmapDC.GetPixel(x, y); if (m_bThumbColor && (rgb == THUMB_MASK_COLOR)) { bitmapDC.SetPixel(x, y, rgbThumb); } else if (rgb == THUMB_GRIPPER_MASK_COLOR) { if (m_bThumbGripper) { bitmapDC.SetPixel(x, y, THUMB_GRIPPER_COLOR); } else { bitmapDC.SetPixel(x, y, rgbPrev); } } else if (rgb == THUMB_LEFT_TRANSPARENT_MASK_COLOR) { COLORREF rgbLeftChannel = memDC.GetPixel(nChannelStart, y); bitmapDC.SetPixel(x, y, rgbLeftChannel); } else if (rgb == THUMB_RIGHT_TRANSPARENT_MASK_COLOR) { COLORREF rgbRightChannel = memDC.GetPixel(nChannelStart+nChannelWidth-1, y); bitmapDC.SetPixel(x, y, rgbRightChannel); } rgbPrev = rgb; } } memDC.StretchBlt(m_rectThumb.left, m_rectThumb.top, m_rectThumb.Width(), m_rectThumb.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; } else { m_rectThumb = CRect(-1,-1,-1,-1); } memDC.FrameRect(&m_rectClient, &brushFrame); }