bool rGeometryUtil::CreateCircleVerticies(const rCircle2& circle, size_t segments, rImmediateBuffer& geometry, float zValue){ if (geometry.GeometryType() != rGeometryType::Triangles) return false; geometry.PushVertex(circle.center.x, circle.center.y, zValue); float step = 360.0f / (float)segments; unsigned short index = 1; rVector3 vertex; rVector3 circleCenter(circle.center.x, circle.center.y, zValue); for (float angle = 0.0f; angle <= 360.0f; angle += step){ float radians = rMath::DegreeToRad(angle); vertex.Set(std::cos(radians),std::sin(radians), 0.0f); vertex *= circle.radius; vertex += circleCenter; geometry.PushVertex(vertex); if (index > 1){ geometry.PushIndex(index, index - 1, 0); } index++; } return true; }
void Curve::changeBend(wxRealPoint bend) { try { _bend = bend; wxRealPoint p0 = _initStart, p1 = _initEnd, os, middle; if(abs(_bend.x - p0.x) < 0.0001) _bend.x += 0.0002; if(abs(_bend.y - p0.y) < 0.0001) _bend.y -= 0.0002; os = circleCenter(p0, p1, _bend); double R = distance(p0, os), D = distance(p0, p1), d; // Ograniczamy promien okregu do 1/2 odleglosci miedzy puntami poczatkowymi middle.x = (p1.x + p0.x) / 2.f; middle.y = (p1.y + p0.y) / 2.f; d = distance(middle, bend); if(d > D / 2.f) return; if(os.x < -900) return; // Wyznaczamy prosta przechodzaca przez dwa punkty. // Nalezy uwzglednic sytuacje, w ktorej wybrane punkty tworza prosta pionowa double a, b; if(abs(p1.x - p0.x) < 0.0001) p1.x += 0.001; if(abs(p1.y - p0.y) < 0.0001) p0.y += 0.001; a = (p1.y - p0.y) / (p1.x - p0.x); b = p0.y - p0.x * a; _points.clear(); int N = (int)(R / 0.01); if(N < 10) N = 10; for(int i = 0; i < N; ++i) { double x, y, fi; if(_bend.y < a * _bend.x + b) { wxRealPoint c = (p1.x > p0.x ? p0 : p1); double fi0 = abs(c.x - os.x) < 0.001 ? M_PI / 2.f : atan((c.y - os.y) / (c.x - os.x)); fi = i * M_PI / ((double)N / 2.f) + fi0; x = R * cos(fi) + os.x; y = R * sin(fi) + os.y; // Interesuja nas tylko punkty POD prosta y = ax + b if(y <= a * x + b) { _points.push_back(wxRealPoint(x, y)); } } else { wxRealPoint c = (p1.x > p0.x ? p1 : p0); double fi0 = abs(c.x - os.x) < 0.001 ? M_PI / 2.f : atan((c.y - os.y) / (c.x - os.x)); fi = i * M_PI / ((double)N / 2.f) + fi0 + M_PI; x = R * cos(fi) + os.x; y = R * sin(fi) + os.y; // Interesuja nas punkty NAD prosta y = ax + b if(y >= a * x + b) { _points.push_back(wxRealPoint(x, y)); } } } } catch(...) { } }
void clAuiGlossyTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { wxColour bgColour = wxColour(EditorConfigST::Get()->GetCurrentOutputviewBgColour()); wxColour penColour; wxColour textColour; bool isBgColourDark = DrawingUtils::IsDark(bgColour); if ( isBgColourDark ) { penColour = DrawingUtils::LightColour(bgColour, 4.0); } else { bgColour = *wxWHITE; penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); } textColour = EditorConfigST::Get()->GetCurrentOutputviewFgColour(); int curx = 0; // Allow the plugins to override the default colours clColourEvent colourEvent( wxEVT_COLOUR_TAB ); colourEvent.SetIsActiveTab( page.active ); colourEvent.SetPage( page.window ); if ( EventNotifier::Get()->ProcessEvent( colourEvent ) ) { bgColour = colourEvent.GetBgColour(); textColour = colourEvent.GetFgColour(); } // Allow the plugins to override the border colour wxColour originalPenColour = penColour; clColourEvent borderColourEvent( wxEVT_GET_TAB_BORDER_COLOUR ); if ( EventNotifier::Get()->ProcessEvent( borderColourEvent ) ) { penColour = borderColourEvent.GetBorderColour(); } wxGCDC gdc; if ( !DrawingUtils::GetGCDC(dc, gdc) ) return; m_penColour = penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen( penColour ); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr (in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width -= 1; #ifndef __WXMAC__ if ( page.active ) { rr.y -= 2; rr.height += 2; } #endif #ifdef __WXGTK__ rr.height += TAB_HEIGHT_SPACER; #else rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if (rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x; // since the above code above doesn't play well with WXDFB or WXCOCOA, // we'll just use a rectangle for the clipping region for now -- gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush( bgColour ); gdc.SetPen( penColour ); if ( page.active ) { path.AddRoundedRectangle(rr.x, rr.y, rr.width-1, rr.height, 6.5); gdc.GetGraphicsContext()->FillPath( path ); gdc.GetGraphicsContext()->StrokePath( path ); } else { if ( !m_bgColour.IsOk() ) { wxColour b, p; DoGetTabAreaBackgroundColour(b, p); m_bgColour = b; } DoDrawInactiveTabSeparator(gdc, rr); } if ( !page.active ) { // Draw a line at the bottom rect gdc.SetPen(penColour); gdc.DrawLine(in_rect.GetBottomLeft(), in_rect.GetBottomRight()); } wxString caption = page.caption; if ( caption.IsEmpty() ) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if ( page.active ) { fnt.SetWeight(wxFONTWEIGHT_BOLD); } gdc.SetFont( fnt ); wxSize ext = gdc.GetTextExtent( caption ); if ( caption == "Tp" ) caption.Clear(); /// Draw the bitmap if ( page.bitmap.IsOk() ) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight())/2)-TAB_Y_OFFSET; gdc.GetGraphicsContext()->DrawBitmap( page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text gdc.SetTextForeground( textColour ); gdc.GetGraphicsContext()->DrawText( page.caption, curx, (rr.y + (rr.height - ext.y)/2)-TAB_Y_OFFSET+TEXT_Y_SPACER); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if ( close_button_state != wxAUI_BUTTON_STATE_HIDDEN ) { int btny = (rr.y + (rr.height/2))-TAB_Y_OFFSET+TEXT_Y_SPACER; if ( close_button_state == wxAUI_BUTTON_STATE_PRESSED ) { curx += 1; btny += 1; } /// Defines the rectangle surrounding the X button wxRect xRect = wxRect(curx, btny - X_RADIUS, X_DIAMETER, X_DIAMETER); *out_button_rect = xRect; /// Defines the 'x' inside the circle wxPoint circleCenter( curx + X_RADIUS, btny); wxDouble xx_width = ::sqrt( ::pow(X_DIAMETER, 2.0) /2.0 ); wxDouble x_square = (circleCenter.x - (xx_width/2.0)); wxDouble y_square = (circleCenter.y - (xx_width/2.0)); wxPoint2DDouble ptXTopLeft(x_square, y_square); wxRect2DDouble insideRect(ptXTopLeft.m_x, ptXTopLeft.m_y, xx_width, xx_width); insideRect.Inset(1.0 , 1.0); // Shrink it by 1 pixle /// Draw the 'x' itself wxGraphicsPath xpath = gdc.GetGraphicsContext()->CreatePath(); xpath.MoveToPoint( insideRect.GetLeftTop() ); xpath.AddLineToPoint( insideRect.GetRightBottom()); xpath.MoveToPoint( insideRect.GetRightTop() ); xpath.AddLineToPoint( insideRect.GetLeftBottom() ); gdc.SetPen( wxPen(textColour, 1) ); gdc.GetGraphicsContext()->StrokePath( xpath ); curx += X_DIAMETER; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }
void clAuiMainNotebookTabArt::DrawTab(wxDC& dc, wxWindow* wnd, const wxAuiNotebookPage& page, const wxRect& in_rect, int close_button_state, wxRect* out_tab_rect, wxRect* out_button_rect, int* x_extent) { int curx = 0; wxGCDC gdc; if(!DrawingUtils::GetGCDC(dc, gdc)) return; wxColour penColour = page.active ? m_activeTabPenColour : m_penColour; wxGraphicsPath path = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); wxSize sz = GetTabSize(gdc, wnd, page.caption, page.bitmap, page.active, close_button_state, x_extent); wxRect rr(in_rect.GetTopLeft(), sz); rr.y += TAB_Y_OFFSET; rr.width -= 1; #ifndef __WXMAC__ if(page.active) { rr.y -= 2; rr.height += 2; } #endif #ifdef __WXGTK__ rr.height += TAB_HEIGHT_SPACER; #else rr.height += 4; #endif /// the tab start position (x) curx = rr.x + 7; // Set clipping region int clip_width = rr.width; if(rr.x + clip_width > in_rect.x + in_rect.width) clip_width = (in_rect.x + in_rect.width) - rr.x; gdc.SetClippingRegion(rr.x, rr.y, clip_width, rr.height); gdc.SetBrush(m_bgColour); gdc.SetPen(penColour); if(page.active) { gdc.SetBrush(m_activeTabBgColour); path.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, TAB_RADIUS); gdc.GetGraphicsContext()->FillPath(path); gdc.GetGraphicsContext()->StrokePath(path); } else { wxGraphicsPath outerPath = gdc.GetGraphicsContext()->CreatePath(); gdc.SetPen(penColour); outerPath.AddRoundedRectangle(rr.x, rr.y, rr.width - 1, rr.height, TAB_RADIUS); gdc.GetGraphicsContext()->StrokePath(outerPath); gdc.SetPen(m_innerPenColour); path.AddRoundedRectangle(rr.x + 1, rr.y + 1, rr.width - 3, rr.height - 1, TAB_RADIUS); gdc.GetGraphicsContext()->StrokePath(path); gdc.SetBrush(m_tabBgColour); gdc.GetGraphicsContext()->StrokePath(path); gdc.GetGraphicsContext()->FillPath(path); gdc.SetPen(penColour); } if(!page.active) { // Draw a line at the bottom rect gdc.SetPen(m_activeTabPenColour); gdc.DrawLine(in_rect.GetBottomLeft(), in_rect.GetBottomRight()); } wxString caption = page.caption; if(caption.IsEmpty()) { caption = "Tp"; } wxFont fnt = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); if(page.active) { fnt.SetWeight(wxFONTWEIGHT_BOLD); } gdc.SetFont(fnt); wxSize ext = gdc.GetTextExtent(caption); if(caption == "Tp") caption.Clear(); /// Draw the bitmap if(page.bitmap.IsOk()) { int bmpy = (rr.y + (rr.height - page.bitmap.GetHeight()) / 2) - TAB_Y_OFFSET; gdc.GetGraphicsContext()->DrawBitmap(page.bitmap, curx, bmpy, page.bitmap.GetWidth(), page.bitmap.GetHeight()); curx += page.bitmap.GetWidth(); curx += 3; } /// Draw the text wxColour textColour = page.active ? m_activeTabTextColour : m_tabTextColour; gdc.SetTextForeground(textColour); gdc.GetGraphicsContext()->DrawText( page.caption, curx, (rr.y + (rr.height - ext.y) / 2) - TAB_Y_OFFSET + TEXT_Y_SPACER); // advance the X offset curx += ext.x; curx += 3; /// Draw the X button on the tab if(close_button_state != wxAUI_BUTTON_STATE_HIDDEN) { int btny = (rr.y + (rr.height / 2)) - TAB_Y_OFFSET + TEXT_Y_SPACER; if(close_button_state == wxAUI_BUTTON_STATE_PRESSED) { curx += 1; btny += 1; } /// Defines the rectangle surrounding the X button wxRect xRect = wxRect(curx, btny - X_RADIUS, X_DIAMETER, X_DIAMETER); *out_button_rect = xRect; /// Defines the 'x' inside the circle wxPoint circleCenter(curx + X_RADIUS, btny); wxDouble xx_width = ::sqrt(::pow(X_DIAMETER, 2.0) / 2.0); wxDouble x_square = (circleCenter.x - (xx_width / 2.0)); wxDouble y_square = (circleCenter.y - (xx_width / 2.0)); wxPoint2DDouble ptXTopLeft(x_square, y_square); wxRect2DDouble insideRect(ptXTopLeft.m_x, ptXTopLeft.m_y, xx_width, xx_width); insideRect.Inset(1.0, 1.0); // Shrink it by 1 pixle /// Draw the 'x' itself wxGraphicsPath xpath = gdc.GetGraphicsContext()->CreatePath(); xpath.MoveToPoint(insideRect.GetLeftTop()); xpath.AddLineToPoint(insideRect.GetRightBottom()); xpath.MoveToPoint(insideRect.GetRightTop()); xpath.AddLineToPoint(insideRect.GetLeftBottom()); gdc.SetPen(wxPen(textColour, 1)); gdc.GetGraphicsContext()->StrokePath(xpath); curx += X_DIAMETER; } *out_tab_rect = rr; gdc.DestroyClippingRegion(); }