X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5f331691d426fef30965f9dd802c9a4fc87d785b..88ef3a57a47f840adea9d38bc11cb30689a0838a:/contrib/src/ogl/oglmisc.cpp?ds=inline diff --git a/contrib/src/ogl/oglmisc.cpp b/contrib/src/ogl/oglmisc.cpp index 7de32c2c77..9904941314 100644 --- a/contrib/src/ogl/oglmisc.cpp +++ b/contrib/src/ogl/oglmisc.cpp @@ -6,13 +6,9 @@ // Created: 12/07/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "misc.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -49,7 +45,7 @@ wxBrush* g_oglWhiteBackgroundBrush; wxPen* g_oglBlackForegroundPen; wxCursor* g_oglBullseyeCursor = NULL; -char* oglBuffer = NULL; +wxChar* oglBuffer = NULL; wxList oglObjectCopyMapping(wxKEY_INTEGER); @@ -71,7 +67,7 @@ void wxOGLInitialize() OGLInitializeConstraintTypes(); // Initialize big buffer used when writing images - oglBuffer = new char[3000]; + oglBuffer = new wxChar[3000]; } @@ -83,6 +79,7 @@ void wxOGLCleanUp() oglBuffer = NULL; } oglBuffer = NULL; + if (g_oglBullseyeCursor) { delete g_oglBullseyeCursor; @@ -219,7 +216,7 @@ void oglCentreText(wxDC& dc, wxList *text_list, // Store text extents for speed double *widths = new double[n]; - wxNode *current = text_list->GetFirst(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); int i = 0; while (current) { @@ -281,7 +278,7 @@ void oglCentreText(wxDC& dc, wxList *text_list, i ++; } - delete widths; + delete[] widths; } // Centre a list of strings in the given box @@ -302,7 +299,7 @@ void oglCentreTextNoClipping(wxDC& dc, wxList *text_list, // Store text extents for speed double *widths = new double[n]; - wxNode *current = text_list->GetFirst(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); int i = 0; while (current) { @@ -340,7 +337,7 @@ void oglCentreTextNoClipping(wxDC& dc, wxList *text_list, } void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, - double m_xpos, double m_ypos, double width, double height, + double WXUNUSED(m_xpos), double WXUNUSED(m_ypos), double WXUNUSED(width), double WXUNUSED(height), double *actual_width, double *actual_height) { int n = text_list->GetCount(); @@ -358,8 +355,7 @@ void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, long max_width = 0; long current_width = 0; - wxNode *current = text_list->GetFirst(); - int i = 0; + wxObjectList::compatibility_iterator current = text_list->GetFirst(); while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); @@ -368,7 +364,6 @@ void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, if (current_width > max_width) max_width = current_width; current = current->GetNext(); - i ++; } *actual_height = n*char_height; @@ -377,15 +372,15 @@ void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, // Format a string to a list of strings that fit in the given box. // Interpret %n and 10 or 13 as a new line. -wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double height, int formatMode) +wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double WXUNUSED(height), int formatMode) { // First, parse the string into a list of words wxStringList word_list; // Make new lines into NULL strings at this point int i = 0; int j = 0; int len = text.Length(); - wxChar word[200]; word[0] = 0; - bool end_word = FALSE; bool new_line = FALSE; + wxChar word[400]; word[0] = 0; + bool end_word = false; bool new_line = false; while (i < len) { switch (text[i]) @@ -398,7 +393,7 @@ wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double else { if (text[i] == wxT('n')) - { new_line = TRUE; end_word = TRUE; i++; } + { new_line = true; end_word = true; i++; } else { word[j] = wxT('%'); j ++; word[j] = text[i]; j ++; i ++; } } @@ -406,16 +401,17 @@ wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double } case 10: { - new_line = TRUE; end_word = TRUE; i++; + new_line = true; end_word = true; i++; break; } case 13: { - new_line = TRUE; end_word = TRUE; i++; + new_line = true; end_word = true; i++; + break; } case wxT(' '): { - end_word = TRUE; + end_word = true; i ++; break; } @@ -426,33 +422,33 @@ wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double break; } } - if (i == len) end_word = TRUE; + if (i == len) end_word = true; if (end_word) { word[j] = 0; j = 0; word_list.Add(word); - end_word = FALSE; + end_word = false; } if (new_line) { word_list.Append(NULL); - new_line = FALSE; + new_line = false; } } // Now, make a list of strings which can fit in the box wxStringList *string_list = new wxStringList; wxString buffer; - wxStringListNode *node = word_list.GetFirst(); + wxStringList::compatibility_iterator node = word_list.GetFirst(); long x, y; while (node) { wxString oldBuffer(buffer); - wxChar *s = (wxChar *)node->GetData(); - if (!s) + wxString s = node->GetData(); + if (s.empty()) { // FORCE NEW LINE if (buffer.Length() > 0) @@ -505,9 +501,9 @@ void oglDrawFormattedText(wxDC& dc, wxList *text_list, dc.SetClippingRegion( (long)(m_xpos - width/2.0), (long)(m_ypos - height/2.0), - (long)width, (long)height); + (long)width+1, (long)height+1); // +1 to allow for rounding errors - wxNode *current = text_list->GetFirst(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); while (current) { wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); @@ -529,7 +525,7 @@ void oglFindPolylineCentroid(wxList *points, double *x, double *y) double xcount = 0; double ycount = 0; - wxNode *node = points->GetFirst(); + wxObjectList::compatibility_iterator node = points->GetFirst(); while (node) { wxRealPoint *point = (wxRealPoint *)node->GetData(); @@ -807,7 +803,7 @@ void UpdateListBox(wxListBox *item, wxList *list) if (!list) return; - wxNode *node = list->GetFirst(); + wxObjectList::compatibility_iterator node = list->GetFirst(); while (node) { wxChar *s = (wxChar *)node->GetData(); @@ -871,10 +867,12 @@ wxColour oglHexToColour(const wxString& hex) hex.Mid(0,2).ToLong(&r, 16); hex.Mid(2,2).ToLong(&g, 16); hex.Mid(4,2).ToLong(&b, 16); - return wxColour(r, g, b); + return wxColour((unsigned char)r, + (unsigned char)g, + (unsigned char)b); } else - return wxColour(0,0,0); + return *wxBLACK; } // RGB to 3-digit hex