X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f1802b55dc7cdcd972e1cdce5e512b267ca3b05..88ef3a57a47f840adea9d38bc11cb30689a0838a:/contrib/src/ogl/oglmisc.cpp?ds=inline diff --git a/contrib/src/ogl/oglmisc.cpp b/contrib/src/ogl/oglmisc.cpp index 169fc2c484..9904941314 100644 --- a/contrib/src/ogl/oglmisc.cpp +++ b/contrib/src/ogl/oglmisc.cpp @@ -6,15 +6,11 @@ // 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 +#include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -24,7 +20,9 @@ #include #endif -#include +#if wxUSE_PROLOGIO +#include +#endif #include @@ -32,20 +30,12 @@ #undef new #endif -#if wxUSE_IOSTREAMH -#include -#else -#include -#endif #include #include #include -#include -#include -#include -#include -#include +#include "wx/ogl/ogl.h" + wxFont* g_oglNormalFont; wxPen* g_oglBlackPen; @@ -55,7 +45,7 @@ wxBrush* g_oglWhiteBackgroundBrush; wxPen* g_oglBlackForegroundPen; wxCursor* g_oglBullseyeCursor = NULL; -char* oglBuffer = NULL; +wxChar* oglBuffer = NULL; wxList oglObjectCopyMapping(wxKEY_INTEGER); @@ -67,17 +57,17 @@ void wxOGLInitialize() g_oglNormalFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL); - g_oglBlackPen = new wxPen("BLACK", 1, wxSOLID); + g_oglBlackPen = new wxPen(wxT("BLACK"), 1, wxSOLID); - g_oglWhiteBackgroundPen = new wxPen("WHITE", 1, wxSOLID); - g_oglTransparentPen = new wxPen("WHITE", 1, wxTRANSPARENT); - g_oglWhiteBackgroundBrush = new wxBrush("WHITE", wxSOLID); - g_oglBlackForegroundPen = new wxPen("BLACK", 1, wxSOLID); + g_oglWhiteBackgroundPen = new wxPen(wxT("WHITE"), 1, wxSOLID); + g_oglTransparentPen = new wxPen(wxT("WHITE"), 1, wxTRANSPARENT); + g_oglWhiteBackgroundBrush = new wxBrush(wxT("WHITE"), wxSOLID); + g_oglBlackForegroundPen = new wxPen(wxT("BLACK"), 1, wxSOLID); OGLInitializeConstraintTypes(); // Initialize big buffer used when writing images - oglBuffer = new char[3000]; + oglBuffer = new wxChar[3000]; } @@ -89,6 +79,7 @@ void wxOGLCleanUp() oglBuffer = NULL; } oglBuffer = NULL; + if (g_oglBullseyeCursor) { delete g_oglBullseyeCursor; @@ -169,16 +160,17 @@ int FontSizeDialog(wxFrame *parent, int old_size) { if (old_size <= 0) old_size = 10; - char buf[40]; - sprintf(buf, "%d", old_size); - wxString ans = wxGetTextFromUser("Enter point size", "Font size", buf, parent); - if (ans == "") + wxString buf; + buf << old_size; + wxString ans = wxGetTextFromUser(wxT("Enter point size"), wxT("Font size"), buf, parent); + if (ans.Length() == 0) return 0; - int new_size = atoi(ans); + long new_size = 0; + ans.ToLong(&new_size); if ((new_size <= 0) || (new_size > 40)) { - wxMessageBox("Invalid point size!", "Error", wxOK); + wxMessageBox(wxT("Invalid point size!"), wxT("Error"), wxOK); return 0; } return new_size; @@ -210,7 +202,7 @@ void oglCentreText(wxDC& dc, wxList *text_list, double m_xpos, double m_ypos, double width, double height, int formatMode) { - int n = text_list->Number(); + int n = text_list->GetCount(); if (!text_list || (n == 0)) return; @@ -224,17 +216,17 @@ void oglCentreText(wxDC& dc, wxList *text_list, // Store text extents for speed double *widths = new double[n]; - wxNode *current = text_list->First(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); int i = 0; while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); widths[i] = current_width; if (current_width > max_width) max_width = current_width; - current = current->Next(); + current = current->GetNext(); i ++; } @@ -267,12 +259,12 @@ void oglCentreText(wxDC& dc, wxList *text_list, xOffset = 0.0; } - current = text_list->First(); + current = text_list->GetFirst(); i = 0; while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); double x; if ((formatMode & FORMAT_CENTRE_HORIZ) && (widths[i] < width)) @@ -282,18 +274,18 @@ void oglCentreText(wxDC& dc, wxList *text_list, double y = (double)(i*char_height + yoffset); line->SetX( x - xOffset ); line->SetY( y - yOffset ); - current = current->Next(); + current = current->GetNext(); i ++; } - delete widths; + delete[] widths; } // Centre a list of strings in the given box void oglCentreTextNoClipping(wxDC& dc, wxList *text_list, double m_xpos, double m_ypos, double width, double height) { - int n = text_list->Number(); + int n = text_list->GetCount(); if (!text_list || (n == 0)) return; @@ -307,17 +299,17 @@ void oglCentreTextNoClipping(wxDC& dc, wxList *text_list, // Store text extents for speed double *widths = new double[n]; - wxNode *current = text_list->First(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); int i = 0; while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); widths[i] = current_width; if (current_width > max_width) max_width = current_width; - current = current->Next(); + current = current->GetNext(); i ++; } @@ -327,28 +319,28 @@ void oglCentreTextNoClipping(wxDC& dc, wxList *text_list, double xoffset = (double)(m_xpos - width/2.0); - current = text_list->First(); + current = text_list->GetFirst(); i = 0; while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); double x = (double)((width - widths[i])/2.0 + xoffset); double y = (double)(i*char_height + yoffset); line->SetX( x - m_xpos ); line->SetY( y - m_ypos ); - current = current->Next(); + current = current->GetNext(); i ++; } delete widths; } 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->Number(); + int n = text_list->GetCount(); if (!text_list || (n == 0)) { @@ -363,17 +355,15 @@ void oglGetCentredTextExtent(wxDC& dc, wxList *text_list, long max_width = 0; long current_width = 0; - wxNode *current = text_list->First(); - int i = 0; + wxObjectList::compatibility_iterator current = text_list->GetFirst(); while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.GetTextExtent(line->GetText(), ¤t_width, &char_height); if (current_width > max_width) max_width = current_width; - current = current->Next(); - i ++; + current = current->GetNext(); } *actual_height = n*char_height; @@ -382,45 +372,46 @@ 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 = strlen(text); - char word[200]; word[0] = 0; - bool end_word = FALSE; bool new_line = FALSE; + int i = 0; int j = 0; int len = text.Length(); + wxChar word[400]; word[0] = 0; + bool end_word = false; bool new_line = false; while (i < len) { switch (text[i]) { - case '%': + case wxT('%'): { i ++; if (i == len) - { word[j] = '%'; j ++; } + { word[j] = wxT('%'); j ++; } else { - if (text[i] == 'n') - { new_line = TRUE; end_word = TRUE; i++; } + if (text[i] == wxT('n')) + { new_line = true; end_word = true; i++; } else - { word[j] = '%'; j ++; word[j] = text[i]; j ++; i ++; } + { word[j] = wxT('%'); j ++; word[j] = text[i]; j ++; i ++; } } break; } 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 ' ': + case wxT(' '): { - end_word = TRUE; + end_word = true; i ++; break; } @@ -431,47 +422,46 @@ 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; - char buffer[400]; - buffer[0] = 0; - wxNode *node = word_list.First(); + wxString buffer; + wxStringList::compatibility_iterator node = word_list.GetFirst(); long x, y; while (node) { wxString oldBuffer(buffer); - char *s = (char *)node->Data(); - if (!s) + wxString s = node->GetData(); + if (s.empty()) { // FORCE NEW LINE - if (strlen(buffer) > 0) + if (buffer.Length() > 0) string_list->Add(buffer); - buffer[0] = 0; + buffer.Empty(); } else { - if (buffer[0] != 0) - strcat(buffer, " "); + if (buffer.Length() != 0) + buffer += wxT(" "); - strcat(buffer, s); + buffer += s; dc.GetTextExtent(buffer, &x, &y); // Don't fit within the bounding box if we're fitting shape to contents @@ -481,14 +471,14 @@ wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double if (oldBuffer.Length() > 0) string_list->Add(oldBuffer); - buffer[0] = 0; - strcat(buffer, s); + buffer.Empty(); + buffer += s; } } - node = node->Next(); + node = node->GetNext(); } - if (buffer[0] != 0) + if (buffer.Length() != 0) string_list->Add(buffer); return string_list; @@ -511,15 +501,15 @@ 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->First(); + wxObjectList::compatibility_iterator current = text_list->GetFirst(); while (current) { - wxShapeTextLine *line = (wxShapeTextLine *)current->Data(); + wxShapeTextLine *line = (wxShapeTextLine *)current->GetData(); dc.DrawText(line->GetText(), WXROUND(xoffset + line->GetX()), WXROUND(yoffset + line->GetY())); - current = current->Next(); + current = current->GetNext(); } dc.DestroyClippingRegion(); @@ -535,17 +525,17 @@ void oglFindPolylineCentroid(wxList *points, double *x, double *y) double xcount = 0; double ycount = 0; - wxNode *node = points->First(); + wxObjectList::compatibility_iterator node = points->GetFirst(); while (node) { - wxRealPoint *point = (wxRealPoint *)node->Data(); + wxRealPoint *point = (wxRealPoint *)node->GetData(); xcount += point->x; ycount += point->y; - node = node->Next(); + node = node->GetNext(); } - *x = (xcount/points->Number()); - *y = (ycount/points->Number()); + *x = (xcount/points->GetCount()); + *y = (ycount/points->GetCount()); } /* @@ -813,12 +803,12 @@ void UpdateListBox(wxListBox *item, wxList *list) if (!list) return; - wxNode *node = list->First(); + wxObjectList::compatibility_iterator node = list->GetFirst(); while (node) { - char *s = (char *)node->Data(); + wxChar *s = (wxChar *)node->GetData(); item->Append(s); - node = node->Next(); + node = node->GetNext(); } } @@ -833,29 +823,32 @@ bool oglRoughlyEqual(double val1, double val2, double tol) */ // Array used in DecToHex conversion routine. -static char sg_HexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F' }; +static wxChar sg_HexArray[] = { wxT('0'), wxT('1'), wxT('2'), wxT('3'), + wxT('4'), wxT('5'), wxT('6'), wxT('7'), + wxT('8'), wxT('9'), wxT('A'), wxT('B'), + wxT('C'), wxT('D'), wxT('E'), wxT('F') +}; // Convert 2-digit hex number to decimal -unsigned int oglHexToDec(char* buf) +unsigned int oglHexToDec(wxChar* buf) { int firstDigit, secondDigit; - if (buf[0] >= 'A') - firstDigit = buf[0] - 'A' + 10; + if (buf[0] >= wxT('A')) + firstDigit = buf[0] - wxT('A') + 10; else - firstDigit = buf[0] - '0'; + firstDigit = buf[0] - wxT('0'); - if (buf[1] >= 'A') - secondDigit = buf[1] - 'A' + 10; + if (buf[1] >= wxT('A')) + secondDigit = buf[1] - wxT('A') + 10; else - secondDigit = buf[1] - '0'; + secondDigit = buf[1] - wxT('0'); return firstDigit * 16 + secondDigit; } // Convert decimal integer to 2-character hex string -void oglDecToHex(unsigned int dec, char *buf) +void oglDecToHex(unsigned int dec, wxChar *buf) { int firstDigit = (int)(dec/16.0); int secondDigit = (int)(dec - (firstDigit*16.0)); @@ -868,22 +861,24 @@ void oglDecToHex(unsigned int dec, char *buf) wxColour oglHexToColour(const wxString& hex) { if (hex.Length() == 6) - { - char buf[7]; - strncpy(buf, hex, 7); - unsigned int r = oglHexToDec((char *)buf); - unsigned int g = oglHexToDec((char *)(buf+2)); - unsigned int b = oglHexToDec((char *)(buf+4)); - return wxColour(r, g, b); - } - else - return wxColour(0,0,0); + { + long r, g, b; + r = g = b = 0; + hex.Mid(0,2).ToLong(&r, 16); + hex.Mid(2,2).ToLong(&g, 16); + hex.Mid(4,2).ToLong(&b, 16); + return wxColour((unsigned char)r, + (unsigned char)g, + (unsigned char)b); + } + else + return *wxBLACK; } // RGB to 3-digit hex wxString oglColourToHex(const wxColour& colour) { - char buf[7]; + wxChar buf[7]; unsigned int red = colour.Red(); unsigned int green = colour.Green(); unsigned int blue = colour.Blue();