From dd168ad22c595b39b08000c330f54126f197bccd Mon Sep 17 00:00:00 2001 From: Daniel Richard G Date: Wed, 2 Oct 2013 01:45:13 -0400 Subject: [PATCH] Use C99 integer types and C++ boolean types/values This change comprehensively replaces the use of Microsoft-standard integer and boolean types with their C99/C++ standard equivalents, as the latter is more appropriate for a cross-platform application. With matter-of-course exceptions in the Win32-specific code, the types/values have been converted as follows: QWORD --> uint64_t SQWORD --> int64_t DWORD --> uint32_t SDWORD --> int32_t WORD --> uint16_t SWORD --> int16_t BYTE --> uint8_t BOOL --> bool TRUE --> true FALSE --> false The following related changes are also included: * Added C99 integer type definitions for Windows, as stdint.h is not available prior to Visual Studio 2010 * Changed types of some variables in the SolveSpace class from 'int' to 'bool', as they actually represent boolean settings * Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean variables in the Registry * Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int() * TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names inspired by the OpenType spec) * RGB colors are packed into an integer of type uint32_t (nee DWORD), but in a few places, these were represented by an int; these have been corrected to uint32_t --- bitmapfont.table.h | 2 +- clipboard.cpp | 4 +- confscreen.cpp | 36 +++--- describescreen.cpp | 6 +- draw.cpp | 6 +- drawconstraint.cpp | 4 +- dsc.h | 7 +- export.cpp | 14 +- exportvector.cpp | 80 ++++++------ exposed/lib.cpp | 2 +- exposed/slvs.h | 8 +- expr.cpp | 8 +- expr.h | 4 +- file.cpp | 11 +- generate.cpp | 4 +- glhelper.cpp | 38 +++--- graphicswin.cpp | 8 +- groupmesh.cpp | 4 +- mesh.cpp | 8 +- mouse.cpp | 4 +- polygon.h | 8 +- sketch.h | 40 +++--- solvespace.cpp | 72 +++++------ solvespace.h | 191 ++++++++++++++------------- srf/boolean.cpp | 2 +- srf/surface.cpp | 4 +- srf/surface.h | 14 +- srf/surfinter.cpp | 2 +- srf/triangulate.cpp | 2 +- style.cpp | 66 +++++----- system.cpp | 4 +- textscreens.cpp | 46 +++---- textwin.cpp | 41 +++--- toolbar.cpp | 4 +- tools/ttf2c.cpp | 6 +- ttf.cpp | 306 ++++++++++++++++++++++---------------------- ui.h | 158 +++++++++++------------ view.cpp | 6 +- win32/w32main.cpp | 160 +++++++++++------------ 39 files changed, 703 insertions(+), 687 deletions(-) diff --git a/bitmapfont.table.h b/bitmapfont.table.h index 49daa2cf..6d65ba68 100644 --- a/bitmapfont.table.h +++ b/bitmapfont.table.h @@ -1,4 +1,4 @@ -static const BYTE FontTexture[256*16*16] = { +static const uint8_t FontTexture[256*16*16] = { 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, diff --git a/clipboard.cpp b/clipboard.cpp index 0ade8467..4af2399e 100644 --- a/clipboard.cpp +++ b/clipboard.cpp @@ -277,7 +277,7 @@ bool TextWindow::EditControlDoneForPaste(const char *s) { return true; } -void TextWindow::ScreenChangePasteTransformed(int link, DWORD v) { +void TextWindow::ScreenChangePasteTransformed(int link, uint32_t v) { char str[300]; switch(link) { case 't': @@ -300,7 +300,7 @@ void TextWindow::ScreenChangePasteTransformed(int link, DWORD v) { } } -void TextWindow::ScreenPasteTransformed(int link, DWORD v) { +void TextWindow::ScreenPasteTransformed(int link, uint32_t v) { SS.GW.GroupSelection(); switch(link) { case 'o': diff --git a/confscreen.cpp b/confscreen.cpp index 869c089d..30229f54 100644 --- a/confscreen.cpp +++ b/confscreen.cpp @@ -6,7 +6,7 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void TextWindow::ScreenChangeLightDirection(int link, DWORD v) { +void TextWindow::ScreenChangeLightDirection(int link, uint32_t v) { char str[1024]; sprintf(str, "%.2f, %.2f, %.2f", CO(SS.lightDir[v])); SS.TW.ShowEditControl(29+2*v, 8, str); @@ -14,7 +14,7 @@ void TextWindow::ScreenChangeLightDirection(int link, DWORD v) { SS.TW.edit.i = v; } -void TextWindow::ScreenChangeLightIntensity(int link, DWORD v) { +void TextWindow::ScreenChangeLightIntensity(int link, uint32_t v) { char str[1024]; sprintf(str, "%.2f", SS.lightIntensity[v]); SS.TW.ShowEditControl(29+2*v, 31, str); @@ -22,47 +22,47 @@ void TextWindow::ScreenChangeLightIntensity(int link, DWORD v) { SS.TW.edit.i = v; } -void TextWindow::ScreenChangeColor(int link, DWORD v) { +void TextWindow::ScreenChangeColor(int link, uint32_t v) { SS.TW.ShowEditControlWithColorPicker(9+2*v, 13, SS.modelColor[v]); SS.TW.edit.meaning = EDIT_COLOR; SS.TW.edit.i = v; } -void TextWindow::ScreenChangeChordTolerance(int link, DWORD v) { +void TextWindow::ScreenChangeChordTolerance(int link, uint32_t v) { char str[1024]; sprintf(str, "%.2f", SS.chordTol); SS.TW.ShowEditControl(37, 3, str); SS.TW.edit.meaning = EDIT_CHORD_TOLERANCE; } -void TextWindow::ScreenChangeMaxSegments(int link, DWORD v) { +void TextWindow::ScreenChangeMaxSegments(int link, uint32_t v) { char str[1024]; sprintf(str, "%d", SS.maxSegments); SS.TW.ShowEditControl(41, 3, str); SS.TW.edit.meaning = EDIT_MAX_SEGMENTS; } -void TextWindow::ScreenChangeCameraTangent(int link, DWORD v) { +void TextWindow::ScreenChangeCameraTangent(int link, uint32_t v) { char str[1024]; sprintf(str, "%.3f", 1000*SS.cameraTangent); SS.TW.ShowEditControl(47, 3, str); SS.TW.edit.meaning = EDIT_CAMERA_TANGENT; } -void TextWindow::ScreenChangeGridSpacing(int link, DWORD v) { +void TextWindow::ScreenChangeGridSpacing(int link, uint32_t v) { SS.TW.ShowEditControl(51, 3, SS.MmToString(SS.gridSpacing)); SS.TW.edit.meaning = EDIT_GRID_SPACING; } -void TextWindow::ScreenChangeDigitsAfterDecimal(int link, DWORD v) { +void TextWindow::ScreenChangeDigitsAfterDecimal(int link, uint32_t v) { char buf[128]; sprintf(buf, "%d", SS.UnitDigitsAfterDecimal()); SS.TW.ShowEditControl(55, 3, buf); SS.TW.edit.meaning = EDIT_DIGITS_AFTER_DECIMAL; } -void TextWindow::ScreenChangeExportScale(int link, DWORD v) { +void TextWindow::ScreenChangeExportScale(int link, uint32_t v) { char str[1024]; sprintf(str, "%.3f", (double)SS.exportScale); @@ -70,36 +70,36 @@ void TextWindow::ScreenChangeExportScale(int link, DWORD v) { SS.TW.edit.meaning = EDIT_EXPORT_SCALE; } -void TextWindow::ScreenChangeExportOffset(int link, DWORD v) { +void TextWindow::ScreenChangeExportOffset(int link, uint32_t v) { SS.TW.ShowEditControl(65, 3, SS.MmToString(SS.exportOffset)); SS.TW.edit.meaning = EDIT_EXPORT_OFFSET; } -void TextWindow::ScreenChangeFixExportColors(int link, DWORD v) { +void TextWindow::ScreenChangeFixExportColors(int link, uint32_t v) { SS.fixExportColors = !SS.fixExportColors; } -void TextWindow::ScreenChangeBackFaces(int link, DWORD v) { +void TextWindow::ScreenChangeBackFaces(int link, uint32_t v) { SS.drawBackFaces = !SS.drawBackFaces; InvalidateGraphics(); } -void TextWindow::ScreenChangeCheckClosedContour(int link, DWORD v) { +void TextWindow::ScreenChangeCheckClosedContour(int link, uint32_t v) { SS.checkClosedContour = !SS.checkClosedContour; InvalidateGraphics(); } -void TextWindow::ScreenChangeShadedTriangles(int link, DWORD v) { +void TextWindow::ScreenChangeShadedTriangles(int link, uint32_t v) { SS.exportShadedTriangles = !SS.exportShadedTriangles; InvalidateGraphics(); } -void TextWindow::ScreenChangePwlCurves(int link, DWORD v) { +void TextWindow::ScreenChangePwlCurves(int link, uint32_t v) { SS.exportPwlCurves = !SS.exportPwlCurves; InvalidateGraphics(); } -void TextWindow::ScreenChangeCanvasSizeAuto(int link, DWORD v) { +void TextWindow::ScreenChangeCanvasSizeAuto(int link, uint32_t v) { if(link == 't') { SS.exportCanvasSizeAuto = true; } else { @@ -108,7 +108,7 @@ void TextWindow::ScreenChangeCanvasSizeAuto(int link, DWORD v) { InvalidateGraphics(); } -void TextWindow::ScreenChangeCanvasSize(int link, DWORD v) { +void TextWindow::ScreenChangeCanvasSize(int link, uint32_t v) { double d; switch(v) { case 0: d = SS.exportMargin.left; break; @@ -136,7 +136,7 @@ void TextWindow::ScreenChangeCanvasSize(int link, DWORD v) { SS.TW.edit.i = v; } -void TextWindow::ScreenChangeGCodeParameter(int link, DWORD v) { +void TextWindow::ScreenChangeGCodeParameter(int link, uint32_t v) { char buf[1024] = ""; int row = 93; switch(link) { diff --git a/describescreen.cpp b/describescreen.cpp index f09570ef..20e488bf 100644 --- a/describescreen.cpp +++ b/describescreen.cpp @@ -6,11 +6,11 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -void TextWindow::ScreenUnselectAll(int link, DWORD v) { +void TextWindow::ScreenUnselectAll(int link, uint32_t v) { GraphicsWindow::MenuEdit(GraphicsWindow::MNU_UNSELECT_ALL); } -void TextWindow::ScreenEditTtfText(int link, DWORD v) { +void TextWindow::ScreenEditTtfText(int link, uint32_t v) { hRequest hr = { v }; Request *r = SK.GetRequest(hr); @@ -20,7 +20,7 @@ void TextWindow::ScreenEditTtfText(int link, DWORD v) { } #define gs (SS.GW.gs) -void TextWindow::ScreenSetTtfFont(int link, DWORD v) { +void TextWindow::ScreenSetTtfFont(int link, uint32_t v) { int i = (int)v; if(i < 0) return; if(i >= SS.fonts.l.n) return; diff --git a/draw.cpp b/draw.cpp index 46597497..0296e33d 100644 --- a/draw.cpp +++ b/draw.cpp @@ -61,7 +61,7 @@ void GraphicsWindow::Selection::Draw(void) { topLeft = topLeft.Minus(SS.GW.offset); glLineWidth(40); - DWORD rgb = Style::Color(Style::HOVERED); + uint32_t rgb = Style::Color(Style::HOVERED); glColor4d(REDf(rgb), GREENf(rgb), BLUEf(rgb), 0.2); glBegin(GL_LINES); glxVertex3v(topLeft); @@ -366,7 +366,7 @@ void GraphicsWindow::HitTestMakeSelection(Point2d mp) { Group *g = SK.GetGroup(activeGroup); SMesh *m = &(g->displayMesh); - DWORD v = m->FirstIntersectionWith(mp); + uint32_t v = m->FirstIntersectionWith(mp); if(v) { s.entity.v = v; } @@ -517,7 +517,7 @@ void GraphicsWindow::Paint(void) { BLUEf(SS.backgroundColor), 1.0f); } else { // Draw a different background whenever we're having solve problems. - DWORD rgb = Style::Color(Style::DRAW_ERROR); + uint32_t rgb = Style::Color(Style::DRAW_ERROR); glClearColor(0.4f*REDf(rgb), 0.4f*GREENf(rgb), 0.4f*BLUEf(rgb), 1.0f); // And show the text window, which has info to debug it ForceTextWindowShown(); diff --git a/drawconstraint.cpp b/drawconstraint.cpp index 7a42653e..81e230c9 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -562,8 +562,8 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { // Let's adjust the color of this constraint to have the same // rough luma as the point color, so that the constraint does not // stand out in an ugly way. - DWORD cd = Style::Color(Style::DATUM), - cc = Style::Color(Style::CONSTRAINT); + uint32_t cd = Style::Color(Style::DATUM), + cc = Style::Color(Style::CONSTRAINT); // convert from 8-bit color to a vector Vector vd = Vector::From(REDf(cd), GREENf(cd), BLUEf(cd)), vc = Vector::From(REDf(cc), GREENf(cc), BLUEf(cc)); diff --git a/dsc.h b/dsc.h index cbccb7e2..433b22b4 100644 --- a/dsc.h +++ b/dsc.h @@ -7,9 +7,6 @@ #ifndef __DSC_H #define __DSC_H -typedef unsigned long DWORD; -typedef unsigned char BYTE; - class Vector; class Vector4; class Point2d; @@ -232,8 +229,8 @@ public: int n; int elemsAllocated; - DWORD MaximumId(void) { - DWORD id = 0; + uint32_t MaximumId(void) { + uint32_t id = 0; int i; for(i = 0; i < n; i++) { diff --git a/export.cpp b/export.cpp index bcc95654..369fca6c 100644 --- a/export.cpp +++ b/export.cpp @@ -503,11 +503,11 @@ void VectorFileWriter::Output(SBezierLoopSetSet *sblss, SMesh *sm) { b = sbl->l.First(); if(!b || !Style::Exportable(b->auxA)) continue; - hStyle hs = { (DWORD)b->auxA }; + hStyle hs = { (uint32_t)b->auxA }; Style *stl = Style::Get(hs); double lineWidth = Style::WidthMm(b->auxA)*s; - DWORD strokeRgb = Style::Color(hs, true); - DWORD fillRgb = Style::FillColor(hs, true); + uint32_t strokeRgb = Style::Color(hs, true); + uint32_t fillRgb = Style::FillColor(hs, true); StartPath(strokeRgb, lineWidth, stl->filled, fillRgb); for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) { @@ -608,7 +608,7 @@ void SolveSpace::ExportMeshAsStlTo(FILE *f, SMesh *sm) { strcpy(str, "STL exported mesh"); fwrite(str, 1, 80, f); - DWORD n = sm->l.n; + uint32_t n = sm->l.n; fwrite(&n, 4, 1, f); double s = SS.exportScale; @@ -677,7 +677,7 @@ void SolveSpace::ExportAsPngTo(char *filename) { int w = (int)SS.GW.width, h = (int)SS.GW.height; // No guarantee that the back buffer contains anything valid right now, // so repaint the scene. And hide the toolbar too. - int prevShowToolbar = SS.showToolbar; + bool prevShowToolbar = SS.showToolbar; SS.showToolbar = false; SS.GW.Paint(); SS.showToolbar = prevShowToolbar; @@ -708,8 +708,8 @@ void SolveSpace::ExportAsPngTo(char *filename) { png_write_info(png_ptr, info_ptr); // Get the pixel data from the framebuffer - BYTE *pixels; pixels = (BYTE *)AllocTemporary(3*w*h); - BYTE **rowptrs; rowptrs = (BYTE **)AllocTemporary(h*sizeof(BYTE *)); + uint8_t *pixels; pixels = (uint8_t *)AllocTemporary(3*w*h); + uint8_t **rowptrs; rowptrs = (uint8_t **)AllocTemporary(h*sizeof(uint8_t *)); glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels); int y; diff --git a/exportvector.cpp b/exportvector.cpp index 4f7d74f5..f98dc33c 100644 --- a/exportvector.cpp +++ b/exportvector.cpp @@ -64,12 +64,12 @@ void DxfFileWriter::StartFile(void) { "ENTITIES\r\n"); } -void DxfFileWriter::StartPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void DxfFileWriter::StartPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { } -void DxfFileWriter::FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void DxfFileWriter::FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { } @@ -165,14 +165,14 @@ void EpsFileWriter::StartFile(void) { MmToPts(ptMax.y - ptMin.y)); } -void EpsFileWriter::StartPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void EpsFileWriter::StartPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { fprintf(f, "newpath\r\n"); prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE); } -void EpsFileWriter::FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void EpsFileWriter::FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { fprintf(f, " %.3f setlinewidth\r\n" " %.3f %.3f %.3f setrgbcolor\r\n" @@ -277,7 +277,7 @@ void PdfFileWriter::StartFile(void) { "%%%c%c%c%c\r\n", 0xe2, 0xe3, 0xcf, 0xd3); - xref[1] = (DWORD)ftell(f); + xref[1] = (uint32_t)ftell(f); fprintf(f, "1 0 obj\r\n" " << /Type /Catalog\r\n" @@ -286,7 +286,7 @@ void PdfFileWriter::StartFile(void) { " >>\r\n" "endobj\r\n"); - xref[2] = (DWORD)ftell(f); + xref[2] = (uint32_t)ftell(f); fprintf(f, "2 0 obj\r\n" " << /Type /Outlines\r\n" @@ -294,7 +294,7 @@ void PdfFileWriter::StartFile(void) { " >>\r\n" "endobj\r\n"); - xref[3] = (DWORD)ftell(f); + xref[3] = (uint32_t)ftell(f); fprintf(f, "3 0 obj\r\n" " << /Type /Pages\r\n" @@ -303,7 +303,7 @@ void PdfFileWriter::StartFile(void) { " >>\r\n" "endobj\r\n"); - xref[4] = (DWORD)ftell(f); + xref[4] = (uint32_t)ftell(f); fprintf(f, "4 0 obj\r\n" " << /Type /Page\r\n" @@ -318,35 +318,35 @@ void PdfFileWriter::StartFile(void) { MmToPts(ptMax.x - ptMin.x), MmToPts(ptMax.y - ptMin.y)); - xref[5] = (DWORD)ftell(f); + xref[5] = (uint32_t)ftell(f); fprintf(f, "5 0 obj\r\n" " << /Length 6 0 R >>\r\n" "stream\r\n"); - bodyStart = (DWORD)ftell(f); + bodyStart = (uint32_t)ftell(f); } void PdfFileWriter::FinishAndCloseFile(void) { - DWORD bodyEnd = (DWORD)ftell(f); + uint32_t bodyEnd = (uint32_t)ftell(f); fprintf(f, "endstream\r\n" "endobj\r\n"); - xref[6] = (DWORD)ftell(f); + xref[6] = (uint32_t)ftell(f); fprintf(f, "6 0 obj\r\n" " %d\r\n" "endobj\r\n", bodyEnd - bodyStart); - xref[7] = (DWORD)ftell(f); + xref[7] = (uint32_t)ftell(f); fprintf(f, "7 0 obj\r\n" " [/PDF /Text]\r\n" "endobj\r\n"); - xref[8] = (DWORD)ftell(f); + xref[8] = (uint32_t)ftell(f); fprintf(f, "8 0 obj\r\n" " << /Type /Font\r\n" @@ -357,13 +357,13 @@ void PdfFileWriter::FinishAndCloseFile(void) { " >>\r\n" "endobj\r\n"); - xref[9] = (DWORD)ftell(f); + xref[9] = (uint32_t)ftell(f); fprintf(f, "9 0 obj\r\n" " << /Creator (SolveSpace)\r\n" " >>\r\n"); - DWORD xrefStart = (DWORD)ftell(f); + uint32_t xrefStart = (uint32_t)ftell(f); fprintf(f, "xref\r\n" "0 10\r\n" @@ -390,8 +390,8 @@ void PdfFileWriter::FinishAndCloseFile(void) { } -void PdfFileWriter::StartPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void PdfFileWriter::StartPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { fprintf(f, "1 J 1 j " // round endcaps and joins "%.3f w " @@ -405,8 +405,8 @@ void PdfFileWriter::StartPath(DWORD strokeRgb, double lineWidth, prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE); } -void PdfFileWriter::FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void PdfFileWriter::FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { if(filled) { fprintf(f, "b\r\n"); @@ -480,14 +480,14 @@ void SvgFileWriter::StartFile(void) { // A little bit of extra space for the stroke width. } -void SvgFileWriter::StartPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) +void SvgFileWriter::StartPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) { fprintf(f, "str) == 0) continue; fprintf(fh, "%s=", SAVED[i].desc); switch(fmt) { case 'd': fprintf(fh, "%d", *((int *)p)); break; case 'b': fprintf(fh, "%d", *((bool *)p) ? 1 : 0); break; - case 'x': fprintf(fh, "%08x", *((DWORD *)p)); break; + case 'x': fprintf(fh, "%08x", *((uint32_t *)p)); break; case 'f': fprintf(fh, "%.20f", *((double *)p)); break; case 'N': fprintf(fh, "%s", ((NameStr *)p)->str); break; case 'P': fprintf(fh, "%s", (char *)p); break; @@ -360,10 +360,11 @@ void SolveSpace::LoadUsingTable(char *key, char *val) { for(i = 0; SAVED[i].type != 0; i++) { if(strcmp(SAVED[i].desc, key)==0) { void *p = SAVED[i].ptr; + unsigned int u = 0; switch(SAVED[i].fmt) { case 'd': *((int *)p) = atoi(val); break; case 'b': *((bool *)p) = (atoi(val) != 0); break; - case 'x': sscanf(val, "%x", (DWORD *)p); break; + case 'x': sscanf(val, "%x", &u); *((uint32_t *)p) = u; break; case 'f': *((double *)p) = atof(val); break; case 'N': ((NameStr *)p)->strcpy(val); break; diff --git a/generate.cpp b/generate.cpp index 815df5ec..0a8fa787 100644 --- a/generate.cpp +++ b/generate.cpp @@ -179,13 +179,13 @@ void SolveSpace::GenerateAll(int first, int last, bool andFindFree) { SK.param.MoveSelfInto(&prev); SK.entity.Clear(); - SDWORD inTime = GetMilliseconds(); + int32_t inTime = GetMilliseconds(); bool displayedStatusMessage = false; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); - SDWORD now = GetMilliseconds(); + int32_t now = GetMilliseconds(); // Display the status message if we've taken more than 400 ms, or // if we've taken 200 ms but we're not even halfway done, or if // we've already started displaying the status message. diff --git a/glhelper.cpp b/glhelper.cpp index 96b01761..d7f25df9 100644 --- a/glhelper.cpp +++ b/glhelper.cpp @@ -178,7 +178,7 @@ void glxFatLine(Vector a, Vector b, double width) } -void glxLockColorTo(DWORD rgb) +void glxLockColorTo(uint32_t rgb) { ColorLocked = false; glColor3d(REDf(rgb), GREENf(rgb), BLUEf(rgb)); @@ -190,21 +190,21 @@ void glxUnlockColor(void) ColorLocked = false; } -void glxColorRGB(DWORD rgb) +void glxColorRGB(uint32_t rgb) { // Is there a bug in some graphics drivers where this is not equivalent // to glColor3d? There seems to be... glxColorRGBa(rgb, 1.0); } -void glxColorRGBa(DWORD rgb, double a) +void glxColorRGBa(uint32_t rgb, double a) { if(!ColorLocked) glColor4d(REDf(rgb), GREENf(rgb), BLUEf(rgb), a); } -static void Stipple(BOOL forSel) +static void Stipple(bool forSel) { - static BOOL Init; + static bool Init; const int BYTES = (32*32)/8; static GLubyte HoverMask[BYTES]; static GLubyte SelMask[BYTES]; @@ -222,7 +222,7 @@ static void Stipple(BOOL forSel) } } } - Init = TRUE; + Init = true; } glEnable(GL_POLYGON_STIPPLE); @@ -233,7 +233,7 @@ static void Stipple(BOOL forSel) } } -static void StippleTriangle(STriangle *tr, BOOL s, DWORD rgb) +static void StippleTriangle(STriangle *tr, bool s, uint32_t rgb) { glEnd(); glDisable(GL_LIGHTING); @@ -249,19 +249,19 @@ static void StippleTriangle(STriangle *tr, BOOL s, DWORD rgb) glBegin(GL_TRIANGLES); } -void glxFillMesh(int specColor, SMesh *m, DWORD h, DWORD s1, DWORD s2) +void glxFillMesh(uint32_t specColor, SMesh *m, uint32_t h, uint32_t s1, uint32_t s2) { - DWORD rgbHovered = Style::Color(Style::HOVERED), - rgbSelected = Style::Color(Style::SELECTED); + uint32_t rgbHovered = Style::Color(Style::HOVERED), + rgbSelected = Style::Color(Style::SELECTED); glEnable(GL_NORMALIZE); - int prevColor = -1; + uint32_t prevColor = (uint32_t)-1; glBegin(GL_TRIANGLES); for(int i = 0; i < m->l.n; i++) { STriangle *tr = &(m->l.elem[i]); - int color; - if(specColor < 0) { + uint32_t color; + if(specColor & 0x80000000) { color = tr->meta.color; } else { color = specColor; @@ -296,10 +296,10 @@ void glxFillMesh(int specColor, SMesh *m, DWORD h, DWORD s1, DWORD s2) if((s1 != 0 && tr->meta.face == s1) || (s2 != 0 && tr->meta.face == s2)) { - StippleTriangle(tr, TRUE, rgbSelected); + StippleTriangle(tr, true, rgbSelected); } if(h != 0 && tr->meta.face == h) { - StippleTriangle(tr, FALSE, rgbHovered); + StippleTriangle(tr, false, rgbHovered); } } glEnd(); @@ -488,7 +488,7 @@ void glxCreateBitmapFont(void) // Place the font in our texture in a two-dimensional grid; 1d would // be simpler, but long skinny textures (256*16 = 4096 pixels wide) // won't work. - static BYTE MappedTexture[4*16*64*16]; + static uint8_t MappedTexture[4*16*64*16]; int a, i; for(a = 0; a < 256; a++) { int row = a / 4, col = a % 4; @@ -515,7 +515,7 @@ void glxCreateBitmapFont(void) void glxBitmapCharQuad(char c, double x, double y) { - BYTE b = (BYTE)c; + uint8_t b = (uint8_t)c; int w, h; if(b & 0x80) { @@ -563,10 +563,10 @@ void glxBitmapText(const char *str, Vector p) glDisable(GL_TEXTURE_2D); } -void glxDrawPixelsWithTexture(BYTE *data, int w, int h) +void glxDrawPixelsWithTexture(uint8_t *data, int w, int h) { #define MAX_DIM 32 - static BYTE Texture[MAX_DIM*MAX_DIM*3]; + static uint8_t Texture[MAX_DIM*MAX_DIM*3]; int i, j; if(w > MAX_DIM || h > MAX_DIM) oops(); diff --git a/graphicswin.cpp b/graphicswin.cpp index c1c6bdd9..62b1ed7c 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -249,13 +249,13 @@ void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) { double mo = (offset0.Minus(offsetf)).Magnitude()*scale; // Animate transition, unless it's a tiny move. - SDWORD dt = (mp < 0.01 && mo < 10) ? (-20) : - (SDWORD)(100 + 1000*mp + 0.4*mo); + int32_t dt = (mp < 0.01 && mo < 10) ? (-20) : + (int32_t)(100 + 1000*mp + 0.4*mo); // Don't ever animate for longer than 2000 ms; we can get absurdly // long translations (as measured in pixels) if the user zooms out, moves, // and then zooms in again. if(dt > 2000) dt = 2000; - SDWORD tn, t0 = GetMilliseconds(); + int32_t tn, t0 = GetMilliseconds(); double s = 0; Quaternion dq = quatf.Times(quat0.Inverse()); do { @@ -621,7 +621,7 @@ void GraphicsWindow::ForceTextWindowShown(void) { if(!showTextWindow) { showTextWindow = true; CheckMenuById(MNU_SHOW_TEXT_WND, true); - ShowTextWindow(TRUE); + ShowTextWindow(true); } } diff --git a/groupmesh.cpp b/groupmesh.cpp index 24199bc9..4bfacd29 100644 --- a/groupmesh.cpp +++ b/groupmesh.cpp @@ -448,7 +448,7 @@ void Group::DrawDisplayItems(int t) { // When we fill the mesh, we need to know which triangles are selected // or hovered, in order to draw them differently. - DWORD mh = 0, ms1 = 0, ms2 = 0; + uint32_t mh = 0, ms1 = 0, ms2 = 0; hEntity he = SS.GW.hover.entity; if(he.v != 0 && SK.GetEntity(he)->IsFace()) { mh = he.v; @@ -546,7 +546,7 @@ void Group::DrawFilledPaths(void) { // In an assembled loop, all the styles should be the same; so doesn't // matter which one we grab. SBezier *sb = &(sbls->l.elem[0].l.elem[0]); - hStyle hs = { (DWORD)sb->auxA }; + hStyle hs = { (uint32_t)sb->auxA }; Style *s = Style::Get(hs); if(s->filled) { // This is a filled loop, where the user specified a fill color. diff --git a/mesh.cpp b/mesh.cpp index 72ac223b..8bf94cae 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -324,12 +324,12 @@ bool SMesh::IsEmpty(void) { return (l.n == 0); } -DWORD SMesh::FirstIntersectionWith(Point2d mp) { +uint32_t SMesh::FirstIntersectionWith(Point2d mp) { Vector p0 = Vector::From(mp.x, mp.y, 0); Vector gn = Vector::From(0, 0, 1); double maxT = -1e12; - DWORD face = 0; + uint32_t face = 0; int i; for(i = 0; i < l.n; i++) { @@ -795,7 +795,7 @@ void SKdNode::OcclusionTestLine(SEdge orig, SEdgeList *sel, int cnt) { //----------------------------------------------------------------------------- void SKdNode::FindEdgeOn(Vector a, Vector b, int *n, int cnt, bool coplanarIsInter, bool *inter, bool *fwd, - DWORD *face) + uint32_t *face) { if(gt && lt) { double ac = a.Element(which), @@ -919,7 +919,7 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, int how, int n = 0; bool thisIntersects = false, fwd; - DWORD face; + uint32_t face; FindEdgeOn(a, b, &n, cnt, coplanarIsInter, &thisIntersects, &fwd, &face); diff --git a/mouse.cpp b/mouse.cpp index 49fdc759..97a8f561 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -689,7 +689,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) { } case CMNU_NEW_CUSTOM_STYLE: { - DWORD v = Style::CreateCustomStyle(); + uint32_t v = Style::CreateCustomStyle(); Style::AssignSelectionToStyle(v); break; } @@ -1291,7 +1291,7 @@ void GraphicsWindow::SpaceNavigatorMoved(double tx, double ty, double tz, // If we go five seconds without SpaceNavigator input, or if we've // switched groups, then consider that a new action and save an undo // point. - SDWORD now = GetMilliseconds(); + int32_t now = GetMilliseconds(); if(now - lastSpaceNavigatorTime > 5000 || lastSpaceNavigatorGroup.v != g->h.v) { diff --git a/polygon.h b/polygon.h index 6360dc52..a42165eb 100644 --- a/polygon.h +++ b/polygon.h @@ -122,8 +122,8 @@ public: }; typedef struct { - DWORD face; - int color; + uint32_t face; + uint32_t color; } STriMeta; class SPolygon { @@ -251,7 +251,7 @@ public: bool IsEmpty(void); void RemapFaces(Group *g, int remap); - DWORD FirstIntersectionWith(Point2d mp); + uint32_t FirstIntersectionWith(Point2d mp); }; // A linked list of triangles @@ -284,7 +284,7 @@ public: void FindEdgeOn(Vector a, Vector b, int *n, int cnt, bool coplanarIsInter, bool *inter, bool *fwd, - DWORD *face); + uint32_t *face); enum { NAKED_OR_SELF_INTER_EDGES = 100, SELF_INTER_EDGES = 200, diff --git a/sketch.h b/sketch.h index d6dd3ed9..61231ac6 100644 --- a/sketch.h +++ b/sketch.h @@ -26,7 +26,7 @@ class Equation; class hGroup { public: // bits 15: 0 -- group index - DWORD v; + uint32_t v; inline hEntity entity(int i); inline hParam param(int i); @@ -35,7 +35,7 @@ public: class hRequest { public: // bits 15: 0 -- request index - DWORD v; + uint32_t v; inline hEntity entity(int i); inline hParam param(int i); @@ -46,7 +46,7 @@ class hEntity { public: // bits 15: 0 -- entity index // 31:16 -- request index - DWORD v; + uint32_t v; inline bool isFromRequest(void); inline hRequest request(void); @@ -57,20 +57,20 @@ class hParam { public: // bits 15: 0 -- param index // 31:16 -- request index - DWORD v; + uint32_t v; inline hRequest request(void); }; class hStyle { public: - DWORD v; + uint32_t v; }; class EntityId { public: - DWORD v; // entity ID, starting from 0 + uint32_t v; // entity ID, starting from 0 }; class EntityMap { public: @@ -118,7 +118,7 @@ public: double valA; double valB; double valC; - DWORD color; + uint32_t color; struct { int how; @@ -242,8 +242,8 @@ public: void GenerateDisplayItems(void); void DrawDisplayItems(int t); void Draw(void); - DWORD GetLoopSetFillColor(SBezierLoopSet *sbls, - bool *allSame, Vector *errorAt); + uint32_t GetLoopSetFillColor(SBezierLoopSet *sbls, + bool *allSame, Vector *errorAt); void FillLoopSetAsPolygon(SBezierLoopSet *sbls); void DrawFilledPaths(void); @@ -527,7 +527,7 @@ public: class hConstraint { public: - DWORD v; + uint32_t v; inline hEquation equation(int i); }; @@ -666,7 +666,7 @@ public: class hEquation { public: - DWORD v; + uint32_t v; inline bool isFromConstraint(void); inline hConstraint constraint(void); @@ -729,9 +729,9 @@ public: }; int textOrigin; double textAngle; - DWORD color; + uint32_t color; bool filled; - DWORD fillColor; + uint32_t fillColor; bool visible; bool exportable; @@ -740,7 +740,7 @@ public: typedef struct { hStyle h; const char *cnfPrefix; - DWORD color; + uint32_t color; double width; } Default; static const Default Defaults[]; @@ -754,16 +754,16 @@ public: static void FreezeDefaultStyles(void); static void LoadFactoryDefaults(void); - static void AssignSelectionToStyle(DWORD v); - static DWORD CreateCustomStyle(void); + static void AssignSelectionToStyle(uint32_t v); + static uint32_t CreateCustomStyle(void); - static DWORD RewriteColor(DWORD rgb); + static uint32_t RewriteColor(uint32_t rgb); static Style *Get(hStyle hs); - static DWORD Color(hStyle hs, bool forExport=false); - static DWORD FillColor(hStyle hs, bool forExport=false); + static uint32_t Color(hStyle hs, bool forExport=false); + static uint32_t FillColor(hStyle hs, bool forExport=false); static float Width(hStyle hs); - static DWORD Color(int hs, bool forExport=false); + static uint32_t Color(int hs, bool forExport=false); static float Width(int hs); static double WidthMm(int hs); static double TextHeight(hStyle hs); diff --git a/solvespace.cpp b/solvespace.cpp index db3f3b92..1fc31d51 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -15,14 +15,14 @@ void SolveSpace::Init(char *cmdLine) { // Then, load the registry settings. int i; // Default list of colors for the model material - modelColor[0] = CnfThawDWORD(RGB(150, 150, 150), "ModelColor_0"); - modelColor[1] = CnfThawDWORD(RGB(100, 100, 100), "ModelColor_1"); - modelColor[2] = CnfThawDWORD(RGB( 30, 30, 30), "ModelColor_2"); - modelColor[3] = CnfThawDWORD(RGB(150, 0, 0), "ModelColor_3"); - modelColor[4] = CnfThawDWORD(RGB( 0, 100, 0), "ModelColor_4"); - modelColor[5] = CnfThawDWORD(RGB( 0, 80, 80), "ModelColor_5"); - modelColor[6] = CnfThawDWORD(RGB( 0, 0, 130), "ModelColor_6"); - modelColor[7] = CnfThawDWORD(RGB( 80, 0, 80), "ModelColor_7"); + modelColor[0] = CnfThawInt(RGB(150, 150, 150), "ModelColor_0"); + modelColor[1] = CnfThawInt(RGB(100, 100, 100), "ModelColor_1"); + modelColor[2] = CnfThawInt(RGB( 30, 30, 30), "ModelColor_2"); + modelColor[3] = CnfThawInt(RGB(150, 0, 0), "ModelColor_3"); + modelColor[4] = CnfThawInt(RGB( 0, 100, 0), "ModelColor_4"); + modelColor[5] = CnfThawInt(RGB( 0, 80, 80), "ModelColor_5"); + modelColor[6] = CnfThawInt(RGB( 0, 0, 130), "ModelColor_6"); + modelColor[7] = CnfThawInt(RGB( 80, 0, 80), "ModelColor_7"); // Light intensities lightIntensity[0] = CnfThawFloat(1.0f, "LightIntensity_0"); lightIntensity[1] = CnfThawFloat(0.5f, "LightIntensity_1"); @@ -37,12 +37,12 @@ void SolveSpace::Init(char *cmdLine) { // Chord tolerance chordTol = CnfThawFloat(2.0f, "ChordTolerance"); // Max pwl segments to generate - maxSegments = CnfThawDWORD(10, "MaxSegments"); + maxSegments = CnfThawInt(10, "MaxSegments"); // View units - viewUnits = (Unit)CnfThawDWORD((DWORD)UNIT_MM, "ViewUnits"); + viewUnits = (Unit)CnfThawInt((uint32_t)UNIT_MM, "ViewUnits"); // Number of digits after the decimal point - afterDecimalMm = CnfThawDWORD(2, "AfterDecimalMm"); - afterDecimalInch = CnfThawDWORD(3, "AfterDecimalInch"); + afterDecimalMm = CnfThawInt(2, "AfterDecimalMm"); + afterDecimalInch = CnfThawInt(3, "AfterDecimalInch"); // Camera tangent (determines perspective) cameraTangent = CnfThawFloat(0.3f/1e3f, "CameraTangent"); // Grid spacing @@ -52,19 +52,19 @@ void SolveSpace::Init(char *cmdLine) { // Export offset (cutter radius comp) exportOffset = CnfThawFloat(0.0f, "ExportOffset"); // Rewrite exported colors close to white into black (assuming white bg) - fixExportColors = CnfThawDWORD(1, "FixExportColors"); + fixExportColors = CnfThawBool(true, "FixExportColors"); // Draw back faces of triangles (when mesh is leaky/self-intersecting) - drawBackFaces = CnfThawDWORD(1, "DrawBackFaces"); + drawBackFaces = CnfThawBool(true, "DrawBackFaces"); // Check that contours are closed and not self-intersecting - checkClosedContour = CnfThawDWORD(1, "CheckClosedContour"); + checkClosedContour = CnfThawBool(true, "CheckClosedContour"); // Export shaded triangles in a 2d view - exportShadedTriangles = CnfThawDWORD(1, "ExportShadedTriangles"); + exportShadedTriangles = CnfThawBool(true, "ExportShadedTriangles"); // Export pwl curves (instead of exact) always - exportPwlCurves = CnfThawDWORD(0, "ExportPwlCurves"); + exportPwlCurves = CnfThawBool(false, "ExportPwlCurves"); // Background color on-screen - backgroundColor = CnfThawDWORD(RGB(0, 0, 0), "BackgroundColor"); + backgroundColor = CnfThawInt(RGB(0, 0, 0), "BackgroundColor"); // Whether export canvas size is fixed or derived from bbox - exportCanvasSizeAuto = CnfThawDWORD(1, "ExportCanvasSizeAuto"); + exportCanvasSizeAuto = CnfThawBool(true, "ExportCanvasSizeAuto"); // Margins for automatic canvas size exportMargin.left = CnfThawFloat(5.0f, "ExportMargin_Left"); exportMargin.right = CnfThawFloat(5.0f, "ExportMargin_Right"); @@ -77,11 +77,11 @@ void SolveSpace::Init(char *cmdLine) { exportCanvas.dy = CnfThawFloat( 5.0f, "ExportCanvas_Dy"); // Extra parameters when exporting G code gCode.depth = CnfThawFloat(10.0f, "GCode_Depth"); - gCode.passes = CnfThawDWORD(1, "GCode_Passes"); + gCode.passes = CnfThawInt(1, "GCode_Passes"); gCode.feed = CnfThawFloat(10.0f, "GCode_Feed"); gCode.plungeFeed = CnfThawFloat(10.0f, "GCode_PlungeFeed"); // Show toolbar in the graphics window - showToolbar = CnfThawDWORD(1, "ShowToolbar"); + showToolbar = CnfThawBool(true, "ShowToolbar"); // Recent files menus for(i = 0; i < MAX_RECENT; i++) { char name[100]; @@ -120,7 +120,7 @@ void SolveSpace::Exit(void) { // Model colors for(i = 0; i < MODEL_COLORS; i++) { sprintf(name, "ModelColor_%d", i); - CnfFreezeDWORD(modelColor[i], name); + CnfFreezeInt(modelColor[i], name); } // Light intensities CnfFreezeFloat((float)lightIntensity[0], "LightIntensity_0"); @@ -135,34 +135,34 @@ void SolveSpace::Exit(void) { // Chord tolerance CnfFreezeFloat((float)chordTol, "ChordTolerance"); // Max pwl segments to generate - CnfFreezeDWORD((DWORD)maxSegments, "MaxSegments"); + CnfFreezeInt((uint32_t)maxSegments, "MaxSegments"); // View units - CnfFreezeDWORD((DWORD)viewUnits, "ViewUnits"); + CnfFreezeInt((uint32_t)viewUnits, "ViewUnits"); // Number of digits after the decimal point - CnfFreezeDWORD((DWORD)afterDecimalMm, "AfterDecimalMm"); - CnfFreezeDWORD((DWORD)afterDecimalInch, "AfterDecimalInch"); + CnfFreezeInt((uint32_t)afterDecimalMm, "AfterDecimalMm"); + CnfFreezeInt((uint32_t)afterDecimalInch, "AfterDecimalInch"); // Camera tangent (determines perspective) CnfFreezeFloat((float)cameraTangent, "CameraTangent"); // Grid spacing CnfFreezeFloat(gridSpacing, "GridSpacing"); - // Export scale (a float, stored as a DWORD) + // Export scale CnfFreezeFloat(exportScale, "ExportScale"); // Export offset (cutter radius comp) CnfFreezeFloat(exportOffset, "ExportOffset"); // Rewrite exported colors close to white into black (assuming white bg) - CnfFreezeDWORD(fixExportColors, "FixExportColors"); + CnfFreezeBool(fixExportColors, "FixExportColors"); // Draw back faces of triangles (when mesh is leaky/self-intersecting) - CnfFreezeDWORD(drawBackFaces, "DrawBackFaces"); + CnfFreezeBool(drawBackFaces, "DrawBackFaces"); // Check that contours are closed and not self-intersecting - CnfFreezeDWORD(checkClosedContour, "CheckClosedContour"); + CnfFreezeBool(checkClosedContour, "CheckClosedContour"); // Export shaded triangles in a 2d view - CnfFreezeDWORD(exportShadedTriangles, "ExportShadedTriangles"); + CnfFreezeBool(exportShadedTriangles, "ExportShadedTriangles"); // Export pwl curves (instead of exact) always - CnfFreezeDWORD(exportPwlCurves, "ExportPwlCurves"); + CnfFreezeBool(exportPwlCurves, "ExportPwlCurves"); // Background color on-screen - CnfFreezeDWORD(backgroundColor, "BackgroundColor"); + CnfFreezeInt(backgroundColor, "BackgroundColor"); // Whether export canvas size is fixed or derived from bbox - CnfFreezeDWORD(exportCanvasSizeAuto, "ExportCanvasSizeAuto"); + CnfFreezeBool(exportCanvasSizeAuto, "ExportCanvasSizeAuto"); // Margins for automatic canvas size CnfFreezeFloat(exportMargin.left, "ExportMargin_Left"); CnfFreezeFloat(exportMargin.right, "ExportMargin_Right"); @@ -175,11 +175,11 @@ void SolveSpace::Exit(void) { CnfFreezeFloat(exportCanvas.dy, "ExportCanvas_Dy"); // Extra parameters when exporting G code CnfFreezeFloat(gCode.depth, "GCode_Depth"); - CnfFreezeDWORD(gCode.passes, "GCode_Passes"); + CnfFreezeInt(gCode.passes, "GCode_Passes"); CnfFreezeFloat(gCode.feed, "GCode_Feed"); CnfFreezeFloat(gCode.plungeFeed, "GCode_PlungeFeed"); // Show toolbar in the graphics window - CnfFreezeDWORD(showToolbar, "ShowToolbar"); + CnfFreezeBool(showToolbar, "ShowToolbar"); // And the default styles, colors and line widths and such. Style::FreezeDefaultStyles(); diff --git a/solvespace.h b/solvespace.h index 858c9633..4013103e 100644 --- a/solvespace.h +++ b/solvespace.h @@ -51,20 +51,29 @@ inline double ffabs(double v) { return (v > 0) ? v : (-v); } #define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#') -typedef unsigned __int64 QWORD; -typedef signed __int64 SQWORD; -typedef signed long SDWORD; -typedef signed short SWORD; - #include #include #include #include #include #include -#include // required for GL stuff -#include -#include +#ifdef WIN32 +# include // required by GL headers +#endif +#include +#include + +#ifdef WIN32 +// Define some useful C99 integer types. +typedef UINT64 uint64_t; +typedef INT64 int64_t; +typedef UINT32 uint32_t; +typedef INT32 int32_t; +typedef USHORT uint16_t; +typedef SHORT int16_t; +typedef UCHAR uint8_t; +typedef CHAR int8_t; +#endif inline double Random(double vmax) { return (vmax*rand()) / RAND_MAX; @@ -121,23 +130,23 @@ int SaveFileYesNoCancel(void); // Comma-separated value, like a spreadsheet would use #define CSV_PATTERN "CSV File (*.csv)\0*.csv\0All Files (*)\0*\0\0" #define CSV_EXT "csv" -BOOL GetSaveFile(char *file, const char *defExtension, const char *selPattern); -BOOL GetOpenFile(char *file, const char *defExtension, const char *selPattern); +bool GetSaveFile(char *file, const char *defExtension, const char *selPattern); +bool GetOpenFile(char *file, const char *defExtension, const char *selPattern); void GetAbsoluteFilename(char *file); void LoadAllFontFiles(void); void OpenWebsite(const char *url); -void CheckMenuById(int id, BOOL checked); -void RadioMenuById(int id, BOOL selected); -void EnableMenuById(int id, BOOL enabled); +void CheckMenuById(int id, bool checked); +void RadioMenuById(int id, bool selected); +void EnableMenuById(int id, bool enabled); void ShowGraphicsEditControl(int x, int y, char *s); void HideGraphicsEditControl(void); -BOOL GraphicsEditControlIsVisible(void); +bool GraphicsEditControlIsVisible(void); void ShowTextEditControl(int x, int y, char *s); void HideTextEditControl(void); -BOOL TextEditControlIsVisible(void); +bool TextEditControlIsVisible(void); void MoveTextScrollbarTo(int pos, int maxPos, int page); #define CONTEXT_SUBMENU (-1) @@ -146,14 +155,14 @@ void AddContextMenuItem(const char *legend, int id); void CreateContextSubmenu(void); int ShowContextMenu(void); -void ShowTextWindow(BOOL visible); +void ShowTextWindow(bool visible); void InvalidateText(void); void InvalidateGraphics(void); void PaintGraphics(void); void GetGraphicsWindowSize(int *w, int *h); void GetTextWindowSize(int *w, int *h); -SDWORD GetMilliseconds(void); -SQWORD GetUnixTime(void); +int32_t GetMilliseconds(void); +int64_t GetUnixTime(void); void dbp(const char *str, ...); #define DBPTRI(tri) \ @@ -162,16 +171,18 @@ void dbp(const char *str, ...); void SetWindowTitle(const char *str); void SetMousePointerToHand(bool yes); -void DoMessageBox(const char *str, int rows, int cols, BOOL error); +void DoMessageBox(const char *str, int rows, int cols, bool error); void SetTimerFor(int milliseconds); void ExitNow(void); void CnfFreezeString(const char *str, const char *name); -void CnfFreezeDWORD(DWORD v, const char *name); +void CnfFreezeInt(uint32_t v, const char *name); void CnfFreezeFloat(float v, const char *name); +void CnfFreezeBool(bool v, const char *name); void CnfThawString(char *str, int maxLen, const char *name); -DWORD CnfThawDWORD(DWORD v, const char *name); +uint32_t CnfThawInt(uint32_t v, const char *name); float CnfThawFloat(float v, const char *name); +bool CnfThawBool(bool v, const char *name); void *AllocTemporary(size_t n); void FreeTemporary(void *p); @@ -212,7 +223,7 @@ void glxAxisAlignedLineLoop(double l, double r, double t, double b); typedef void GLX_CALLBACK glxCallbackFptr(void); void glxTesselatePolygon(GLUtesselator *gt, SPolygon *p); void glxFillPolygon(SPolygon *p); -void glxFillMesh(int color, SMesh *m, DWORD h, DWORD s1, DWORD s2); +void glxFillMesh(uint32_t color, SMesh *m, uint32_t h, uint32_t s1, uint32_t s2); void glxDebugPolygon(SPolygon *p); void glxDrawEdges(SEdgeList *l, bool endpointsToo); void glxDebugMesh(SMesh *m); @@ -224,14 +235,14 @@ void glxWriteTextRefCenter(const char *str, double h, Vector t, Vector u, Vector glxLineFn *fn, void *fndata); double glxStrWidth(const char *str, double h); double glxStrHeight(double h); -void glxLockColorTo(DWORD rgb); +void glxLockColorTo(uint32_t rgb); void glxFatLine(Vector a, Vector b, double width); void glxUnlockColor(void); -void glxColorRGB(DWORD rgb); -void glxColorRGBa(DWORD rgb, double a); +void glxColorRGB(uint32_t rgb); +void glxColorRGBa(uint32_t rgb, double a); void glxDepthRangeOffset(int units); void glxDepthRangeLockToFront(bool yes); -void glxDrawPixelsWithTexture(BYTE *data, int w, int h); +void glxDrawPixelsWithTexture(uint8_t *data, int w, int h); void glxCreateBitmapFont(void); void glxBitmapText(const char *str, Vector p); void glxBitmapCharQuad(char c, double x, double y); @@ -340,8 +351,8 @@ public: typedef struct { bool onCurve; bool lastInContour; - SWORD x; - SWORD y; + int16_t x; + int16_t y; } FontPoint; typedef struct { @@ -388,9 +399,9 @@ public: Vector origin, u, v; int Getc(void); - BYTE GetBYTE(void); - WORD GetWORD(void); - DWORD GetDWORD(void); + uint8_t GetBYTE(void); + uint16_t GetUSHORT(void); + uint32_t GetULONG(void); void LoadGlyph(int index); bool LoadFontFromFile(bool nameOnly); @@ -448,10 +459,10 @@ public: void BezierAsPwl(SBezier *sb); void BezierAsNonrationalCubic(SBezier *sb, int depth=0); - virtual void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) = 0; - virtual void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb) = 0; + virtual void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) = 0; + virtual void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb) = 0; virtual void Bezier(SBezier *sb) = 0; virtual void Triangle(STriangle *tr) = 0; virtual void StartFile(void) = 0; @@ -460,10 +471,10 @@ public: }; class DxfFileWriter : public VectorFileWriter { public: - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -475,10 +486,10 @@ public: Vector prevPt; void MaybeMoveTo(Vector s, Vector f); - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -487,15 +498,15 @@ public: }; class PdfFileWriter : public VectorFileWriter { public: - DWORD xref[10]; - DWORD bodyStart; + uint32_t xref[10]; + uint32_t bodyStart; Vector prevPt; void MaybeMoveTo(Vector s, Vector f); - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -507,10 +518,10 @@ public: Vector prevPt; void MaybeMoveTo(Vector s, Vector f); - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -520,10 +531,10 @@ public: class HpglFileWriter : public VectorFileWriter { public: static double MmToHpglUnits(double mm); - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -532,10 +543,10 @@ public: }; class Step2dFileWriter : public VectorFileWriter { StepFileWriter sfw; - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -545,10 +556,10 @@ class Step2dFileWriter : public VectorFileWriter { class GCodeFileWriter : public VectorFileWriter { public: SEdgeList sel; - void StartPath( DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); - void FinishPath(DWORD strokeRgb, double lineWidth, - bool filled, DWORD fillRgb); + void StartPath( uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); + void FinishPath(uint32_t strokeRgb, double lineWidth, + bool filled, uint32_t fillRgb); void Triangle(STriangle *tr); void Bezier(SBezier *sb); void StartFile(void); @@ -629,50 +640,50 @@ public: // Little bits of extra configuration state enum { MODEL_COLORS = 8 }; - int modelColor[MODEL_COLORS]; - Vector lightDir[2]; - double lightIntensity[2]; - double ambientIntensity; - double chordTol; - int maxSegments; - double cameraTangent; - float gridSpacing; - float exportScale; - float exportOffset; - int fixExportColors; - int drawBackFaces; - int checkClosedContour; - int showToolbar; - DWORD backgroundColor; - int exportShadedTriangles; - int exportPwlCurves; - int exportCanvasSizeAuto; + uint32_t modelColor[MODEL_COLORS]; + Vector lightDir[2]; + double lightIntensity[2]; + double ambientIntensity; + double chordTol; + int maxSegments; + double cameraTangent; + float gridSpacing; + float exportScale; + float exportOffset; + bool fixExportColors; + bool drawBackFaces; + bool checkClosedContour; + bool showToolbar; + uint32_t backgroundColor; + bool exportShadedTriangles; + bool exportPwlCurves; + bool exportCanvasSizeAuto; struct { float left; float right; float bottom; float top; - } exportMargin; + } exportMargin; struct { float width; float height; float dx; float dy; - } exportCanvas; + } exportCanvas; struct { float depth; int passes; float feed; float plungeFeed; - } gCode; + } gCode; typedef enum { UNIT_MM = 0, UNIT_INCHES } Unit; - Unit viewUnits; - int afterDecimalMm; - int afterDecimalInch; + Unit viewUnits; + int afterDecimalMm; + int afterDecimalInch; char *MmToString(double v); double ExprToMm(Expr *e); @@ -761,7 +772,7 @@ public: Vector ptB; } extraLine; struct { - BYTE *fromFile; + uint8_t *fromFile; int w, h; int rw, rh; double scale; // pixels per mm diff --git a/srf/boolean.cpp b/srf/boolean.cpp index 71679586..30c02427 100644 --- a/srf/boolean.cpp +++ b/srf/boolean.cpp @@ -359,7 +359,7 @@ void SSurface::EdgeNormalsWithinSurface(Point2d auv, Point2d buv, Vector *pt, Vector *enin, Vector *enout, Vector *surfn, - DWORD auxA, + uint32_t auxA, SShell *shell, SShell *sha, SShell *shb) { // the midpoint of the edge diff --git a/srf/surface.cpp b/srf/surface.cpp index 70de69f1..85578365 100644 --- a/srf/surface.cpp +++ b/srf/surface.cpp @@ -490,7 +490,7 @@ typedef struct { } TrimLine; void SShell::MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, - int color) + uint32_t color) { // Make the extrusion direction consistent with respect to the normal // of the sketch we're extruding. @@ -610,7 +610,7 @@ typedef struct { } Revolved; void SShell::MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis, - int color) + uint32_t color) { SBezierLoop *sbl; diff --git a/srf/surface.h b/srf/surface.h index 6d6db79d..2706790a 100644 --- a/srf/surface.h +++ b/srf/surface.h @@ -58,12 +58,12 @@ class SShell; class hSSurface { public: - DWORD v; + uint32_t v; }; class hSCurve { public: - DWORD v; + uint32_t v; }; // Stuff for rational polynomial curves, of degree one to three. These are @@ -250,8 +250,8 @@ public: // when I copy things over. hSSurface newH; - int color; - DWORD face; + uint32_t color; + uint32_t face; int degm, degn; Vector ctrl[4][4]; @@ -279,7 +279,7 @@ public: void EdgeNormalsWithinSurface(Point2d auv, Point2d buv, Vector *pt, Vector *enin, Vector *enout, Vector *surfn, - DWORD auxA, + uint32_t auxA, SShell *shell, SShell *sha, SShell *shb); void FindChainAvoiding(SEdgeList *src, SEdgeList *dest, SPointList *avoid); SSurface MakeCopyTrimAgainst(SShell *parent, SShell *a, SShell *b, @@ -361,9 +361,9 @@ public: bool booleanFailed; void MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, - int color); + uint32_t color); void MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis, - int color); + uint32_t color); void MakeFromUnionOf(SShell *a, SShell *b); void MakeFromDifferenceOf(SShell *a, SShell *b); diff --git a/srf/surfinter.cpp b/srf/surfinter.cpp index a2681dfd..687e4c04 100644 --- a/srf/surfinter.cpp +++ b/srf/surfinter.cpp @@ -334,7 +334,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB, if(lsi.n == 0) continue; // Find the other surface that this curve trims. - hSCurve hsc = { (DWORD)se->auxA }; + hSCurve hsc = { (uint32_t)se->auxA }; SCurve *sc = shA->curve.FindById(hsc); hSSurface hother = (sc->surfA.v == srfA->h.v) ? sc->surfB : sc->surfA; diff --git a/srf/triangulate.cpp b/srf/triangulate.cpp index 30e5881e..3a511612 100644 --- a/srf/triangulate.cpp +++ b/srf/triangulate.cpp @@ -11,7 +11,7 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { if(l.n <= 0) return; - SDWORD in = GetMilliseconds(); + int32_t in = GetMilliseconds(); normal = Vector::From(0, 0, 1); diff --git a/style.cpp b/style.cpp index 73e38592..c647e551 100644 --- a/style.cpp +++ b/style.cpp @@ -74,7 +74,7 @@ void Style::CreateDefaultStyle(hStyle h) { Style ns; ZERO(&ns); - ns.color = CnfThawDWORD(d->color, CnfColor(d->cnfPrefix)); + ns.color = CnfThawInt(d->color, CnfColor(d->cnfPrefix)); ns.width = CnfThawFloat((float)(d->width), CnfWidth(d->cnfPrefix)); ns.widthAs = UNITS_AS_PIXELS; ns.textHeight = DEFAULT_TEXT_HEIGHT; @@ -121,20 +121,20 @@ void Style::LoadFactoryDefaults(void) { void Style::FreezeDefaultStyles(void) { const Default *d; for(d = &(Defaults[0]); d->h.v; d++) { - CnfFreezeDWORD(Color(d->h), CnfColor(d->cnfPrefix)); + CnfFreezeInt(Color(d->h), CnfColor(d->cnfPrefix)); CnfFreezeFloat((float)Width(d->h), CnfWidth(d->cnfPrefix)); } } -DWORD Style::CreateCustomStyle(void) { +uint32_t Style::CreateCustomStyle(void) { SS.UndoRemember(); - DWORD vs = max((DWORD)Style::FIRST_CUSTOM, SK.style.MaximumId() + 1); + uint32_t vs = max((uint32_t)Style::FIRST_CUSTOM, SK.style.MaximumId() + 1); hStyle hs = { vs }; (void)Style::Get(hs); return hs.v; } -void Style::AssignSelectionToStyle(DWORD v) { +void Style::AssignSelectionToStyle(uint32_t v) { bool showError = false; SS.GW.GroupSelection(); @@ -197,12 +197,12 @@ Style *Style::Get(hStyle h) { // A couple of wrappers, so that I can call these functions with either an // hStyle or with the integer corresponding to that hStyle.v. //----------------------------------------------------------------------------- -DWORD Style::Color(int s, bool forExport) { - hStyle hs = { (DWORD)s }; +uint32_t Style::Color(int s, bool forExport) { + hStyle hs = { (uint32_t)s }; return Color(hs, forExport); } float Style::Width(int s) { - hStyle hs = { (DWORD)s }; + hStyle hs = { (uint32_t)s }; return Width(hs); } @@ -210,7 +210,7 @@ float Style::Width(int s) { // If a color is almost white, then we can rewrite it to black, just so that // it won't disappear on file formats with a light background. //----------------------------------------------------------------------------- -DWORD Style::RewriteColor(DWORD rgbin) { +uint32_t Style::RewriteColor(uint32_t rgbin) { Vector rgb = Vector::From(REDf(rgbin), GREENf(rgbin), BLUEf(rgbin)); rgb = rgb.Minus(Vector::From(1, 1, 1)); if(rgb.Magnitude() < 0.4 && SS.fixExportColors) { @@ -227,7 +227,7 @@ DWORD Style::RewriteColor(DWORD rgbin) { //----------------------------------------------------------------------------- // Return the stroke color associated with our style as 8-bit RGB. //----------------------------------------------------------------------------- -DWORD Style::Color(hStyle h, bool forExport) { +uint32_t Style::Color(hStyle h, bool forExport) { Style *s = Get(h); if(forExport) { return RewriteColor(s->color); @@ -239,7 +239,7 @@ DWORD Style::Color(hStyle h, bool forExport) { //----------------------------------------------------------------------------- // Return the fill color associated with our style as 8-bit RGB. //----------------------------------------------------------------------------- -DWORD Style::FillColor(hStyle h, bool forExport) { +uint32_t Style::FillColor(hStyle h, bool forExport) { Style *s = Get(h); if(forExport) { return RewriteColor(s->fillColor); @@ -290,7 +290,7 @@ double Style::TextHeight(hStyle hs) { // if it's both shown and exportable. //----------------------------------------------------------------------------- bool Style::Exportable(int si) { - hStyle hs = { (DWORD)si }; + hStyle hs = { (uint32_t)si }; Style *s = Get(hs); return (s->exportable) && (s->visible); } @@ -331,25 +331,25 @@ char *Style::DescriptionString(void) { } -void TextWindow::ScreenShowListOfStyles(int link, DWORD v) { +void TextWindow::ScreenShowListOfStyles(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_LIST_OF_STYLES); } -void TextWindow::ScreenShowStyleInfo(int link, DWORD v) { +void TextWindow::ScreenShowStyleInfo(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_STYLE_INFO); SS.TW.shown.style.v = v; } -void TextWindow::ScreenLoadFactoryDefaultStyles(int link, DWORD v) { +void TextWindow::ScreenLoadFactoryDefaultStyles(int link, uint32_t v) { Style::LoadFactoryDefaults(); SS.TW.GoToScreen(SCREEN_LIST_OF_STYLES); } -void TextWindow::ScreenCreateCustomStyle(int link, DWORD v) { +void TextWindow::ScreenCreateCustomStyle(int link, uint32_t v) { Style::CreateCustomStyle(); } -void TextWindow::ScreenChangeBackgroundColor(int link, DWORD v) { - DWORD rgb = SS.backgroundColor; +void TextWindow::ScreenChangeBackgroundColor(int link, uint32_t v) { + uint32_t rgb = SS.backgroundColor; SS.TW.ShowEditControlWithColorPicker(v, 3, rgb); SS.TW.edit.meaning = EDIT_BACKGROUND_COLOR; } @@ -366,7 +366,7 @@ static int RoundUpToPowerOfTwo(int v) return 0; } -void TextWindow::ScreenBackgroundImage(int link, DWORD v) { +void TextWindow::ScreenBackgroundImage(int link, uint32_t v) { if(SS.bgImage.fromFile) MemFree(SS.bgImage.fromFile); SS.bgImage.fromFile = NULL; @@ -380,7 +380,7 @@ void TextWindow::ScreenBackgroundImage(int link, DWORD v) { f = fopen(importFile, "rb"); if(!f) goto err; - BYTE header[8]; + uint8_t header[8]; if (fread(header, 1, 8, f) != 8) goto err; if(png_sig_cmp(header, 0, 8)) goto err; @@ -402,14 +402,14 @@ void TextWindow::ScreenBackgroundImage(int link, DWORD v) { int w; w = (int)png_get_image_width(png_ptr, info_ptr); int h; h = (int)png_get_image_height(png_ptr, info_ptr); - BYTE **rows; rows = png_get_rows(png_ptr, info_ptr); + uint8_t **rows; rows = png_get_rows(png_ptr, info_ptr); // Round to next-highest powers of two, since the textures require - // that. And round up to 4, to guarantee DWORD alignment. + // that. And round up to 4, to guarantee 32-bit alignment. int rw; rw = max(4, RoundUpToPowerOfTwo(w)); int rh; rh = max(4, RoundUpToPowerOfTwo(h)); - SS.bgImage.fromFile = (BYTE *)MemAlloc(rw*rh*3); + SS.bgImage.fromFile = (uint8_t *)MemAlloc(rw*rh*3); for(int i = 0; i < h; i++) { memcpy(SS.bgImage.fromFile + ((h - 1) - i)*(rw*3), rows[i], w*3); } @@ -427,7 +427,7 @@ err: SS.later.showTW = true; } -void TextWindow::ScreenChangeBackgroundImageScale(int link, DWORD v) { +void TextWindow::ScreenChangeBackgroundImageScale(int link, uint32_t v) { char str[300]; sprintf(str, "%.3f", SS.bgImage.scale * SS.MmPerUnit()); SS.TW.edit.meaning = EDIT_BACKGROUND_IMG_SCALE; @@ -455,7 +455,7 @@ void TextWindow::ShowListOfStyles(void) { Printf(false, ""); - DWORD rgb = SS.backgroundColor; + uint32_t rgb = SS.backgroundColor; Printf(false, "%Ft background color (r, g, b)%E"); Printf(false, "%Ba %@, %@, %@ %Fl%D%f%Ll[change]%E", REDf(rgb), GREENf(rgb), BLUEf(rgb), @@ -486,7 +486,7 @@ void TextWindow::ShowListOfStyles(void) { } -void TextWindow::ScreenChangeStyleName(int link, DWORD v) { +void TextWindow::ScreenChangeStyleName(int link, uint32_t v) { hStyle hs = { v }; Style *s = Style::Get(hs); SS.TW.ShowEditControl(10, 12, s->name.str); @@ -494,7 +494,7 @@ void TextWindow::ScreenChangeStyleName(int link, DWORD v) { SS.TW.edit.meaning = EDIT_STYLE_NAME; } -void TextWindow::ScreenDeleteStyle(int link, DWORD v) { +void TextWindow::ScreenDeleteStyle(int link, uint32_t v) { SS.UndoRemember(); hStyle hs = { v }; Style *s = SK.style.FindByIdNoOops(hs); @@ -507,7 +507,7 @@ void TextWindow::ScreenDeleteStyle(int link, DWORD v) { InvalidateGraphics(); } -void TextWindow::ScreenChangeStyleWidthOrTextHeight(int link, DWORD v) { +void TextWindow::ScreenChangeStyleWidthOrTextHeight(int link, uint32_t v) { hStyle hs = { v }; Style *s = Style::Get(hs); double val = (link == 't') ? s->textHeight : s->width; @@ -534,7 +534,7 @@ void TextWindow::ScreenChangeStyleWidthOrTextHeight(int link, DWORD v) { EDIT_STYLE_WIDTH; } -void TextWindow::ScreenChangeStyleTextAngle(int link, DWORD v) { +void TextWindow::ScreenChangeStyleTextAngle(int link, uint32_t v) { hStyle hs = { v }; Style *s = Style::Get(hs); char str[300]; @@ -544,12 +544,12 @@ void TextWindow::ScreenChangeStyleTextAngle(int link, DWORD v) { SS.TW.edit.meaning = EDIT_STYLE_TEXT_ANGLE; } -void TextWindow::ScreenChangeStyleColor(int link, DWORD v) { +void TextWindow::ScreenChangeStyleColor(int link, uint32_t v) { hStyle hs = { v }; Style *s = Style::Get(hs); // Same function used for stroke and fill colors int row, col, em; - DWORD rgb; + uint32_t rgb; if(link == 's') { row = 15; col = 13; em = EDIT_STYLE_COLOR; @@ -566,7 +566,7 @@ void TextWindow::ScreenChangeStyleColor(int link, DWORD v) { SS.TW.edit.meaning = em; } -void TextWindow::ScreenChangeStyleYesNo(int link, DWORD v) { +void TextWindow::ScreenChangeStyleYesNo(int link, uint32_t v) { SS.UndoRemember(); hStyle hs = { v }; Style *s = Style::Get(hs); @@ -867,7 +867,7 @@ void TextWindow::ShowStyleInfo(void) { } } -void TextWindow::ScreenAssignSelectionToStyle(int link, DWORD v) { +void TextWindow::ScreenAssignSelectionToStyle(int link, uint32_t v) { Style::AssignSelectionToStyle(v); } diff --git a/system.cpp b/system.cpp index fe58a0f9..7f7d9703 100644 --- a/system.cpp +++ b/system.cpp @@ -45,10 +45,10 @@ bool System::WriteJacobian(int tag) { f = f->FoldConstants(); // Hash table (61 bits) to accelerate generation of zero partials. - QWORD scoreboard = f->ParamsUsed(); + uint64_t scoreboard = f->ParamsUsed(); for(j = 0; j < mat.n; j++) { Expr *pd; - if(scoreboard & ((QWORD)1 << (mat.param[j].v % 61)) && + if(scoreboard & ((uint64_t)1 << (mat.param[j].v % 61)) && f->DependsOn(mat.param[j])) { pd = f->PartialWrt(mat.param[j]); diff --git a/textscreens.cpp b/textscreens.cpp index 6093f8c4..df3b44c6 100644 --- a/textscreens.cpp +++ b/textscreens.cpp @@ -10,7 +10,7 @@ // A navigation bar that always appears at the top of the window, with a // link to bring us back home. //----------------------------------------------------------------------------- -void TextWindow::ScreenHome(int link, DWORD v) { +void TextWindow::ScreenHome(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_LIST_OF_GROUPS); } void TextWindow::ShowHeader(bool withNav) { @@ -42,11 +42,11 @@ void TextWindow::ShowHeader(bool withNav) { // The screen that shows a list of every group in the sketch, with options // to hide or show them, and to view them in detail. This is our home page. //----------------------------------------------------------------------------- -void TextWindow::ScreenSelectGroup(int link, DWORD v) { +void TextWindow::ScreenSelectGroup(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_GROUP_INFO); SS.TW.shown.group.v = v; } -void TextWindow::ScreenToggleGroupShown(int link, DWORD v) { +void TextWindow::ScreenToggleGroupShown(int link, uint32_t v) { hGroup hg = { v }; Group *g = SK.GetGroup(hg); g->visible = !(g->visible); @@ -54,7 +54,7 @@ void TextWindow::ScreenToggleGroupShown(int link, DWORD v) { // previously, so regenerate. SS.GenerateAll(); } -void TextWindow::ScreenShowGroupsSpecial(int link, DWORD v) { +void TextWindow::ScreenShowGroupsSpecial(int link, uint32_t v) { int i; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); @@ -66,7 +66,7 @@ void TextWindow::ScreenShowGroupsSpecial(int link, DWORD v) { } } } -void TextWindow::ScreenActivateGroup(int link, DWORD v) { +void TextWindow::ScreenActivateGroup(int link, uint32_t v) { hGroup hg = { v }; Group *g = SK.GetGroup(hg); g->visible = true; @@ -80,20 +80,20 @@ void TextWindow::ReportHowGroupSolved(hGroup hg) { SS.TW.shown.group.v = hg.v; SS.later.showTW = true; } -void TextWindow::ScreenHowGroupSolved(int link, DWORD v) { +void TextWindow::ScreenHowGroupSolved(int link, uint32_t v) { if(SS.GW.activeGroup.v != v) { ScreenActivateGroup(link, v); } SS.TW.GoToScreen(SCREEN_GROUP_SOLVE_INFO); SS.TW.shown.group.v = v; } -void TextWindow::ScreenShowConfiguration(int link, DWORD v) { +void TextWindow::ScreenShowConfiguration(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_CONFIGURATION); } -void TextWindow::ScreenShowEditView(int link, DWORD v) { +void TextWindow::ScreenShowEditView(int link, uint32_t v) { SS.TW.GoToScreen(SCREEN_EDIT_VIEW); } -void TextWindow::ScreenGoToWebsite(int link, DWORD v) { +void TextWindow::ScreenGoToWebsite(int link, uint32_t v) { OpenWebsite("http://solvespace.com/txtlink"); } void TextWindow::ShowListOfGroups(void) { @@ -154,7 +154,7 @@ void TextWindow::ShowListOfGroups(void) { // The screen that shows information about a specific group, and allows the // user to edit various things about it. //----------------------------------------------------------------------------- -void TextWindow::ScreenHoverConstraint(int link, DWORD v) { +void TextWindow::ScreenHoverConstraint(int link, uint32_t v) { if(!SS.GW.showConstraints) return; hConstraint hc = { v }; @@ -167,20 +167,20 @@ void TextWindow::ScreenHoverConstraint(int link, DWORD v) { SS.GW.hover.constraint = hc; SS.GW.hover.emphasized = true; } -void TextWindow::ScreenHoverRequest(int link, DWORD v) { +void TextWindow::ScreenHoverRequest(int link, uint32_t v) { SS.GW.hover.Clear(); hRequest hr = { v }; SS.GW.hover.entity = hr.entity(0); SS.GW.hover.emphasized = true; } -void TextWindow::ScreenSelectConstraint(int link, DWORD v) { +void TextWindow::ScreenSelectConstraint(int link, uint32_t v) { SS.GW.ClearSelection(); GraphicsWindow::Selection sel; ZERO(&sel); sel.constraint.v = v; SS.GW.selection.Add(&sel); } -void TextWindow::ScreenSelectRequest(int link, DWORD v) { +void TextWindow::ScreenSelectRequest(int link, uint32_t v) { SS.GW.ClearSelection(); GraphicsWindow::Selection sel; ZERO(&sel); @@ -189,7 +189,7 @@ void TextWindow::ScreenSelectRequest(int link, DWORD v) { SS.GW.selection.Add(&sel); } -void TextWindow::ScreenChangeGroupOption(int link, DWORD v) { +void TextWindow::ScreenChangeGroupOption(int link, uint32_t v) { SS.UndoRemember(); Group *g = SK.GetGroup(SS.TW.shown.group); @@ -218,14 +218,14 @@ void TextWindow::ScreenChangeGroupOption(int link, DWORD v) { SS.GW.ClearSuper(); } -void TextWindow::ScreenColor(int link, DWORD v) { +void TextWindow::ScreenColor(int link, uint32_t v) { SS.UndoRemember(); Group *g = SK.GetGroup(SS.TW.shown.group); SS.TW.ShowEditControlWithColorPicker(v, 3, g->color); SS.TW.edit.meaning = EDIT_GROUP_COLOR; } -void TextWindow::ScreenChangeExprA(int link, DWORD v) { +void TextWindow::ScreenChangeExprA(int link, uint32_t v) { Group *g = SK.GetGroup(SS.TW.shown.group); // There's an extra line for the skipFirst parameter in one-sided groups. @@ -237,13 +237,13 @@ void TextWindow::ScreenChangeExprA(int link, DWORD v) { SS.TW.edit.meaning = EDIT_TIMES_REPEATED; SS.TW.edit.group.v = v; } -void TextWindow::ScreenChangeGroupName(int link, DWORD v) { +void TextWindow::ScreenChangeGroupName(int link, uint32_t v) { Group *g = SK.GetGroup(SS.TW.shown.group); SS.TW.ShowEditControl(7, 12, g->DescriptionString()+5); SS.TW.edit.meaning = EDIT_GROUP_NAME; SS.TW.edit.group.v = v; } -void TextWindow::ScreenChangeGroupScale(int link, DWORD v) { +void TextWindow::ScreenChangeGroupScale(int link, uint32_t v) { Group *g = SK.GetGroup(SS.TW.shown.group); char str[1024]; @@ -252,7 +252,7 @@ void TextWindow::ScreenChangeGroupScale(int link, DWORD v) { SS.TW.edit.meaning = EDIT_GROUP_SCALE; SS.TW.edit.group.v = v; } -void TextWindow::ScreenDeleteGroup(int link, DWORD v) { +void TextWindow::ScreenDeleteGroup(int link, uint32_t v) { SS.UndoRemember(); hGroup hg = SS.TW.shown.group; @@ -497,7 +497,7 @@ void TextWindow::ShowGroupSolveInfo(void) { // how many steps to take in between current and finish, re-solving each // time. //----------------------------------------------------------------------------- -void TextWindow::ScreenStepDimFinish(int link, DWORD v) { +void TextWindow::ScreenStepDimFinish(int link, uint32_t v) { SS.TW.edit.meaning = EDIT_STEP_DIM_FINISH; char s[1024]; if(SS.TW.shown.dimIsDistance) { @@ -507,13 +507,13 @@ void TextWindow::ScreenStepDimFinish(int link, DWORD v) { } SS.TW.ShowEditControl(12, 12, s); } -void TextWindow::ScreenStepDimSteps(int link, DWORD v) { +void TextWindow::ScreenStepDimSteps(int link, uint32_t v) { char str[1024]; sprintf(str, "%d", SS.TW.shown.dimSteps); SS.TW.edit.meaning = EDIT_STEP_DIM_STEPS; SS.TW.ShowEditControl(14, 12, str); } -void TextWindow::ScreenStepDimGo(int link, DWORD v) { +void TextWindow::ScreenStepDimGo(int link, uint32_t v) { hConstraint hc = SS.TW.shown.constraint; Constraint *c = SK.constraint.FindByIdNoOops(hc); if(c) { @@ -567,7 +567,7 @@ void TextWindow::ShowStepDimension(void) { // thing). User gets to specify the radius, and whether the old untrimmed // curves are kept or deleted. //----------------------------------------------------------------------------- -void TextWindow::ScreenChangeTangentArc(int link, DWORD v) { +void TextWindow::ScreenChangeTangentArc(int link, uint32_t v) { switch(link) { case 'r': { char str[1024]; diff --git a/textwin.cpp b/textwin.cpp index 0c16169e..04d09416 100644 --- a/textwin.cpp +++ b/textwin.cpp @@ -85,7 +85,7 @@ void TextWindow::ShowEditControl(int halfRow, int col, char *s) { ShowTextEditControl(x - 3, y + 2, s); } -void TextWindow::ShowEditControlWithColorPicker(int halfRow, int col, DWORD rgb) +void TextWindow::ShowEditControlWithColorPicker(int halfRow, int col, uint32_t rgb) { char str[1024]; sprintf(str, "%.2f, %.2f, %.2f", REDf(rgb), GREENf(rgb), BLUEf(rgb)); @@ -133,7 +133,7 @@ void TextWindow::Printf(bool halfLine, const char *fmt, ...) { char fg = 'd'; int bg = 'd'; int link = NOT_A_LINK; - DWORD data = 0; + uint32_t data = 0; LinkFunction *f = NULL, *h = NULL; c = 0; @@ -151,7 +151,7 @@ void TextWindow::Printf(bool halfLine, const char *fmt, ...) { break; } case 'x': { - DWORD v = va_arg(vl, DWORD); + unsigned int v = va_arg(vl, unsigned int); sprintf(buf, "%08x", v); break; } @@ -237,10 +237,11 @@ void TextWindow::Printf(bool halfLine, const char *fmt, ...) { h = va_arg(vl, LinkFunction *); break; - case 'D': - data = va_arg(vl, DWORD); + case 'D': { + unsigned int v = va_arg(vl, unsigned int); + data = (uint32_t)v; break; - + } case '%': strcpy(buf, "%"); break; @@ -495,8 +496,8 @@ Vector TextWindow::HsvToRgb(Vector hsv) { return rgb; } -BYTE *TextWindow::HsvPattern2d(void) { - static BYTE Texture[256*256*3]; +uint8_t *TextWindow::HsvPattern2d(void) { + static uint8_t Texture[256*256*3]; static bool Init; if(!Init) { @@ -507,9 +508,9 @@ BYTE *TextWindow::HsvPattern2d(void) { Vector hsv = Vector::From(6.0*i/255.0, 1.0*j/255.0, 1); Vector rgb = HsvToRgb(hsv); rgb = rgb.ScaledBy(255); - Texture[p++] = (BYTE)rgb.x; - Texture[p++] = (BYTE)rgb.y; - Texture[p++] = (BYTE)rgb.z; + Texture[p++] = (uint8_t)rgb.x; + Texture[p++] = (uint8_t)rgb.y; + Texture[p++] = (uint8_t)rgb.z; } } Init = true; @@ -517,8 +518,8 @@ BYTE *TextWindow::HsvPattern2d(void) { return Texture; } -BYTE *TextWindow::HsvPattern1d(double h, double s) { - static BYTE Texture[256*4]; +uint8_t *TextWindow::HsvPattern1d(double h, double s) { + static uint8_t Texture[256*4]; int i, p; p = 0; @@ -526,9 +527,9 @@ BYTE *TextWindow::HsvPattern1d(double h, double s) { Vector hsv = Vector::From(6*h, s, 1.0*(255 - i)/255.0); Vector rgb = HsvToRgb(hsv); rgb = rgb.ScaledBy(255); - Texture[p++] = (BYTE)rgb.x; - Texture[p++] = (BYTE)rgb.y; - Texture[p++] = (BYTE)rgb.z; + Texture[p++] = (uint8_t)rgb.x; + Texture[p++] = (uint8_t)rgb.y; + Texture[p++] = (uint8_t)rgb.z; // Needs a padding byte, to make things four-aligned p++; } @@ -537,13 +538,13 @@ BYTE *TextWindow::HsvPattern1d(double h, double s) { void TextWindow::ColorPickerDone(void) { char str[1024]; - DWORD rgb = editControl.colorPicker.rgb; + uint32_t rgb = editControl.colorPicker.rgb; sprintf(str, "%.2f, %.2f, %.3f", REDf(rgb), GREENf(rgb), BLUEf(rgb)); EditControlDone(str); } bool TextWindow::DrawOrHitTestColorPicker(int how, bool leftDown, - double x, double y) + double x, double y) { bool mousePointerAsHand = false; @@ -555,7 +556,7 @@ bool TextWindow::DrawOrHitTestColorPicker(int how, bool leftDown, if(!editControl.colorPicker.show) return false; if(how == CLICK || (how == HOVER && leftDown)) InvalidateText(); - static const DWORD BaseColor[12] = { + static const uint32_t BaseColor[12] = { RGB(255, 0, 0), RGB( 0, 255, 0), RGB( 0, 0, 255), @@ -608,7 +609,7 @@ bool TextWindow::DrawOrHitTestColorPicker(int how, bool leftDown, for(i = 0; i < WIDTH/2; i++) { for(j = 0; j < HEIGHT; j++) { Vector rgb; - DWORD d; + uint32_t d; if(i == 0 && j < 8) { d = SS.modelColor[j]; rgb = Vector::From(REDf(d), GREENf(d), BLUEf(d)); diff --git a/toolbar.cpp b/toolbar.cpp index d1c05752..1ca0c5bf 100644 --- a/toolbar.cpp +++ b/toolbar.cpp @@ -8,9 +8,9 @@ #include "solvespace.h" #include -BYTE SPACER[1]; +uint8_t SPACER[1]; static const struct { - BYTE *image; + uint8_t *image; int menu; const char *tip; } Toolbar[] = { diff --git a/tools/ttf2c.cpp b/tools/ttf2c.cpp index 8b9a924b..c6e7c6da 100644 --- a/tools/ttf2c.cpp +++ b/tools/ttf2c.cpp @@ -10,8 +10,8 @@ int main(void) InitCommonControls(); // A monospaced font - HFONT font = CreateFont(16, 9, 0, 0, FW_REGULAR, FALSE, - FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + HFONT font = CreateFont(16, 9, 0, 0, FW_REGULAR, false, + false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL); @@ -20,7 +20,7 @@ int main(void) SelectObject(hdc, bitmap); SelectObject(hdc, font); - printf("static const BYTE FontTexture[256*16*16] = {\n"); + printf("static const uint8_t FontTexture[256*16*16] = {\n"); int c; for(c = 0; c < 128; c++) { diff --git a/ttf.cpp b/ttf.cpp index 779b94d4..699e44d6 100644 --- a/ttf.cpp +++ b/ttf.cpp @@ -67,23 +67,24 @@ int TtfFont::Getc(void) { //----------------------------------------------------------------------------- // Helpers to get 1, 2, or 4 bytes from the .ttf file. Big endian. +// The BYTE, USHORT and ULONG nomenclature comes from the OpenType spec. //----------------------------------------------------------------------------- -BYTE TtfFont::GetBYTE(void) { - return (BYTE)Getc(); +uint8_t TtfFont::GetBYTE(void) { + return (uint8_t)Getc(); } -WORD TtfFont::GetWORD(void) { - BYTE b0, b1; - b1 = (BYTE)Getc(); - b0 = (BYTE)Getc(); +uint16_t TtfFont::GetUSHORT(void) { + uint8_t b0, b1; + b1 = (uint8_t)Getc(); + b0 = (uint8_t)Getc(); return (b1 << 8) | b0; } -DWORD TtfFont::GetDWORD(void) { - BYTE b0, b1, b2, b3; - b3 = (BYTE)Getc(); - b2 = (BYTE)Getc(); - b1 = (BYTE)Getc(); - b0 = (BYTE)Getc(); +uint32_t TtfFont::GetULONG(void) { + uint8_t b0, b1, b2, b3; + b3 = (uint8_t)Getc(); + b2 = (uint8_t)Getc(); + b1 = (uint8_t)Getc(); + b0 = (uint8_t)Getc(); return (b3 << 24) | (b2 << 16) | (b1 << 8) | b0; } @@ -98,35 +99,35 @@ void TtfFont::LoadGlyph(int index) { int i; - SWORD contours = (SWORD)GetWORD(); - SWORD xMin = (SWORD)GetWORD(); - SWORD yMin = (SWORD)GetWORD(); - SWORD xMax = (SWORD)GetWORD(); - SWORD yMax = (SWORD)GetWORD(); + int16_t contours = (int16_t)GetUSHORT(); + int16_t xMin = (int16_t)GetUSHORT(); + int16_t yMin = (int16_t)GetUSHORT(); + int16_t xMax = (int16_t)GetUSHORT(); + int16_t yMax = (int16_t)GetUSHORT(); if(useGlyph['A'] == index) { scale = (1024*1024) / yMax; } if(contours > 0) { - WORD *endPointsOfContours = - (WORD *)AllocTemporary(contours*sizeof(WORD)); + uint16_t *endPointsOfContours = + (uint16_t *)AllocTemporary(contours*sizeof(uint16_t)); for(i = 0; i < contours; i++) { - endPointsOfContours[i] = GetWORD(); + endPointsOfContours[i] = GetUSHORT(); } - WORD totalPts = endPointsOfContours[i-1] + 1; + uint16_t totalPts = endPointsOfContours[i-1] + 1; - WORD instructionLength = GetWORD(); + uint16_t instructionLength = GetUSHORT(); for(i = 0; i < instructionLength; i++) { // We can ignore the instructions, since we're doing vector // output. (void)GetBYTE(); } - BYTE *flags = (BYTE *)AllocTemporary(totalPts*sizeof(BYTE)); - SWORD *x = (SWORD *)AllocTemporary(totalPts*sizeof(SWORD)); - SWORD *y = (SWORD *)AllocTemporary(totalPts*sizeof(SWORD)); + uint8_t *flags = (uint8_t *)AllocTemporary(totalPts*sizeof(uint8_t)); + int16_t *x = (int16_t *)AllocTemporary(totalPts*sizeof(int16_t)); + int16_t *y = (int16_t *)AllocTemporary(totalPts*sizeof(int16_t)); // Flags, that indicate format of the coordinates #define FLAG_ON_CURVE (1 << 0) @@ -141,7 +142,7 @@ void TtfFont::LoadGlyph(int index) { flags[i] = GetBYTE(); if(flags[i] & FLAG_REPEAT) { int n = GetBYTE(); - BYTE f = flags[i]; + uint8_t f = flags[i]; int j; for(j = 0; j < n; j++) { i++; @@ -154,10 +155,10 @@ void TtfFont::LoadGlyph(int index) { } // x coordinates - SWORD xa = 0; + int16_t xa = 0; for(i = 0; i < totalPts; i++) { if(flags[i] & FLAG_DX_IS_BYTE) { - BYTE v = GetBYTE(); + uint8_t v = GetBYTE(); if(flags[i] & FLAG_X_IS_POSITIVE) { xa += v; } else { @@ -167,7 +168,7 @@ void TtfFont::LoadGlyph(int index) { if(flags[i] & FLAG_X_IS_SAME) { // no change } else { - SWORD d = (SWORD)GetWORD(); + int16_t d = (int16_t)GetUSHORT(); xa += d; } } @@ -175,10 +176,10 @@ void TtfFont::LoadGlyph(int index) { } // y coordinates - SWORD ya = 0; + int16_t ya = 0; for(i = 0; i < totalPts; i++) { if(flags[i] & FLAG_DY_IS_BYTE) { - BYTE v = GetBYTE(); + uint8_t v = GetBYTE(); if(flags[i] & FLAG_Y_IS_POSITIVE) { ya += v; } else { @@ -188,7 +189,7 @@ void TtfFont::LoadGlyph(int index) { if(flags[i] & FLAG_Y_IS_SAME) { // no change } else { - SWORD d = (SWORD)GetWORD(); + int16_t d = (int16_t)GetUSHORT(); ya += d; } } @@ -201,7 +202,7 @@ void TtfFont::LoadGlyph(int index) { for(i = 0; i < totalPts; i++) { g->pt[i].x = x[i]; g->pt[i].y = y[i]; - g->pt[i].onCurve = (BYTE)(flags[i] & FLAG_ON_CURVE); + g->pt[i].onCurve = (uint8_t)(flags[i] & FLAG_ON_CURVE); if(i == endPointsOfContours[contour]) { g->pt[i].lastInContour = true; @@ -248,22 +249,22 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { try { // First, load the Offset Table - DWORD version = GetDWORD(); - WORD numTables = GetWORD(); - WORD searchRange = GetWORD(); - WORD entrySelector = GetWORD(); - WORD rangeShift = GetWORD(); + uint32_t version = GetULONG(); + uint16_t numTables = GetUSHORT(); + uint16_t searchRange = GetUSHORT(); + uint16_t entrySelector = GetUSHORT(); + uint16_t rangeShift = GetUSHORT(); // Now load the Table Directory; our goal in doing this will be to // find the addresses of the tables that we will need. - DWORD glyfAddr = (DWORD)-1, glyfLen; - DWORD cmapAddr = (DWORD)-1, cmapLen; - DWORD headAddr = (DWORD)-1, headLen; - DWORD locaAddr = (DWORD)-1, locaLen; - DWORD maxpAddr = (DWORD)-1, maxpLen; - DWORD nameAddr = (DWORD)-1, nameLen; - DWORD hmtxAddr = (DWORD)-1, hmtxLen; - DWORD hheaAddr = (DWORD)-1, hheaLen; + uint32_t glyfAddr = (uint32_t)-1, glyfLen; + uint32_t cmapAddr = (uint32_t)-1, cmapLen; + uint32_t headAddr = (uint32_t)-1, headLen; + uint32_t locaAddr = (uint32_t)-1, locaLen; + uint32_t maxpAddr = (uint32_t)-1, maxpLen; + uint32_t nameAddr = (uint32_t)-1, nameLen; + uint32_t hmtxAddr = (uint32_t)-1, hmtxLen; + uint32_t hheaAddr = (uint32_t)-1, hheaLen; for(i = 0; i < numTables; i++) { char tag[5] = "xxxx"; @@ -271,9 +272,9 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { tag[1] = (char)GetBYTE(); tag[2] = (char)GetBYTE(); tag[3] = (char)GetBYTE(); - DWORD checksum = GetDWORD(); - DWORD offset = GetDWORD(); - DWORD length = GetDWORD(); + uint32_t checksum = GetULONG(); + uint32_t offset = GetULONG(); + uint32_t length = GetULONG(); if(strcmp(tag, "glyf")==0) { glyfAddr = offset; @@ -302,9 +303,14 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { } } - if(glyfAddr == (DWORD)-1 || cmapAddr == (DWORD)-1 || headAddr == (DWORD)-1 || - locaAddr == (DWORD)-1 || maxpAddr == (DWORD)-1 || hmtxAddr == (DWORD)-1 || - nameAddr == (DWORD)-1 || hheaAddr == (DWORD)-1) + if(glyfAddr == (uint32_t)-1 || + cmapAddr == (uint32_t)-1 || + headAddr == (uint32_t)-1 || + locaAddr == (uint32_t)-1 || + maxpAddr == (uint32_t)-1 || + hmtxAddr == (uint32_t)-1 || + nameAddr == (uint32_t)-1 || + hheaAddr == (uint32_t)-1) { throw "missing table addr"; } @@ -313,19 +319,19 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // we need when we're giving the user a list to choose from. fseek(fh, nameAddr, SEEK_SET); - WORD nameFormat = GetWORD(); - WORD nameCount = GetWORD(); - WORD nameStringOffset = GetWORD(); + uint16_t nameFormat = GetUSHORT(); + uint16_t nameCount = GetUSHORT(); + uint16_t nameStringOffset = GetUSHORT(); // And now we're at the name records. Go through those till we find // one that we want. int displayNameOffset = 0, displayNameLength = 0; for(i = 0; i < nameCount; i++) { - WORD platformID = GetWORD(); - WORD encodingID = GetWORD(); - WORD languageID = GetWORD(); - WORD nameId = GetWORD(); - WORD length = GetWORD(); - WORD offset = GetWORD(); + uint16_t platformID = GetUSHORT(); + uint16_t encodingID = GetUSHORT(); + uint16_t languageID = GetUSHORT(); + uint16_t nameId = GetUSHORT(); + uint16_t length = GetUSHORT(); + uint16_t offset = GetUSHORT(); if(nameId == 4) { displayNameOffset = offset; @@ -342,7 +348,7 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { fseek(fh, nameAddr+nameStringOffset+displayNameOffset, SEEK_SET); int c = 0; for(i = 0; i < displayNameLength; i++) { - BYTE b = GetBYTE(); + uint8_t b = GetBYTE(); if(b && c < ((int)sizeof(name.str) - 2)) { name.str[c++] = b; } @@ -358,25 +364,25 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // loca table, 16- or 32-bit entries fseek(fh, headAddr, SEEK_SET); - DWORD headVersion = GetDWORD(); - DWORD headFontRevision = GetDWORD(); - DWORD headCheckSumAdj = GetDWORD(); - DWORD headMagicNumber = GetDWORD(); - WORD headFlags = GetWORD(); - WORD headUnitsPerEm = GetWORD(); - (void)GetDWORD(); // created time - (void)GetDWORD(); - (void)GetDWORD(); // modified time - (void)GetDWORD(); - WORD headXmin = GetWORD(); - WORD headYmin = GetWORD(); - WORD headXmax = GetWORD(); - WORD headYmax = GetWORD(); - WORD headMacStyle = GetWORD(); - WORD headLowestRecPPEM = GetWORD(); - WORD headFontDirectionHint = GetWORD(); - WORD headIndexToLocFormat = GetWORD(); - WORD headGlyphDataFormat = GetWORD(); + uint32_t headVersion = GetULONG(); + uint32_t headFontRevision = GetULONG(); + uint32_t headCheckSumAdj = GetULONG(); + uint32_t headMagicNumber = GetULONG(); + uint16_t headFlags = GetUSHORT(); + uint16_t headUnitsPerEm = GetUSHORT(); + (void)GetULONG(); // created time + (void)GetULONG(); + (void)GetULONG(); // modified time + (void)GetULONG(); + uint16_t headXmin = GetUSHORT(); + uint16_t headYmin = GetUSHORT(); + uint16_t headXmax = GetUSHORT(); + uint16_t headYmax = GetUSHORT(); + uint16_t headMacStyle = GetUSHORT(); + uint16_t headLowestRecPPEM = GetUSHORT(); + uint16_t headFontDirectionHint = GetUSHORT(); + uint16_t headIndexToLocFormat = GetUSHORT(); + uint16_t headGlyphDataFormat = GetUSHORT(); if(headMagicNumber != 0x5F0F3CF5) { throw "bad magic number"; @@ -385,43 +391,43 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // Load the hhea table, which contains the number of entries in the // horizontal metrics (hmtx) table. fseek(fh, hheaAddr, SEEK_SET); - DWORD hheaVersion = GetDWORD(); - WORD hheaAscender = GetWORD(); - WORD hheaDescender = GetWORD(); - WORD hheaLineGap = GetWORD(); - WORD hheaAdvanceWidthMax = GetWORD(); - WORD hheaMinLsb = GetWORD(); - WORD hheaMinRsb = GetWORD(); - WORD hheaXMaxExtent = GetWORD(); - WORD hheaCaretSlopeRise = GetWORD(); - WORD hheaCaretSlopeRun = GetWORD(); - WORD hheaCaretOffset = GetWORD(); - (void)GetWORD(); - (void)GetWORD(); - (void)GetWORD(); - (void)GetWORD(); - WORD hheaMetricDataFormat = GetWORD(); - WORD hheaNumberOfMetrics = GetWORD(); + uint32_t hheaVersion = GetULONG(); + uint16_t hheaAscender = GetUSHORT(); + uint16_t hheaDescender = GetUSHORT(); + uint16_t hheaLineGap = GetUSHORT(); + uint16_t hheaAdvanceWidthMax = GetUSHORT(); + uint16_t hheaMinLsb = GetUSHORT(); + uint16_t hheaMinRsb = GetUSHORT(); + uint16_t hheaXMaxExtent = GetUSHORT(); + uint16_t hheaCaretSlopeRise = GetUSHORT(); + uint16_t hheaCaretSlopeRun = GetUSHORT(); + uint16_t hheaCaretOffset = GetUSHORT(); + (void)GetUSHORT(); + (void)GetUSHORT(); + (void)GetUSHORT(); + (void)GetUSHORT(); + uint16_t hheaMetricDataFormat = GetUSHORT(); + uint16_t hheaNumberOfMetrics = GetUSHORT(); // Load the maxp table, which determines (among other things) the number // of glyphs in the font fseek(fh, maxpAddr, SEEK_SET); - DWORD maxpVersion = GetDWORD(); - WORD maxpNumGlyphs = GetWORD(); - WORD maxpMaxPoints = GetWORD(); - WORD maxpMaxContours = GetWORD(); - WORD maxpMaxComponentPoints = GetWORD(); - WORD maxpMaxComponentContours = GetWORD(); - WORD maxpMaxZones = GetWORD(); - WORD maxpMaxTwilightPoints = GetWORD(); - WORD maxpMaxStorage = GetWORD(); - WORD maxpMaxFunctionDefs = GetWORD(); - WORD maxpMaxInstructionDefs = GetWORD(); - WORD maxpMaxStackElements = GetWORD(); - WORD maxpMaxSizeOfInstructions = GetWORD(); - WORD maxpMaxComponentElements = GetWORD(); - WORD maxpMaxComponentDepth = GetWORD(); + uint32_t maxpVersion = GetULONG(); + uint16_t maxpNumGlyphs = GetUSHORT(); + uint16_t maxpMaxPoints = GetUSHORT(); + uint16_t maxpMaxContours = GetUSHORT(); + uint16_t maxpMaxComponentPoints = GetUSHORT(); + uint16_t maxpMaxComponentContours = GetUSHORT(); + uint16_t maxpMaxZones = GetUSHORT(); + uint16_t maxpMaxTwilightPoints = GetUSHORT(); + uint16_t maxpMaxStorage = GetUSHORT(); + uint16_t maxpMaxFunctionDefs = GetUSHORT(); + uint16_t maxpMaxInstructionDefs = GetUSHORT(); + uint16_t maxpMaxStackElements = GetUSHORT(); + uint16_t maxpMaxSizeOfInstructions = GetUSHORT(); + uint16_t maxpMaxComponentElements = GetUSHORT(); + uint16_t maxpMaxComponentDepth = GetUSHORT(); glyphs = maxpNumGlyphs; glyph = (Glyph *)MemAlloc(glyphs*sizeof(glyph[0])); @@ -430,11 +436,11 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // and advance width) of the font. fseek(fh, hmtxAddr, SEEK_SET); - WORD hmtxAdvanceWidth = 0; - SWORD hmtxLsb = 0; + uint16_t hmtxAdvanceWidth = 0; + int16_t hmtxLsb = 0; for(i = 0; i < min(glyphs, hheaNumberOfMetrics); i++) { - hmtxAdvanceWidth = GetWORD(); - hmtxLsb = (SWORD)GetWORD(); + hmtxAdvanceWidth = GetUSHORT(); + hmtxLsb = (int16_t)GetUSHORT(); glyph[i].leftSideBearing = hmtxLsb; glyph[i].advanceWidth = hmtxAdvanceWidth; @@ -449,14 +455,14 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // glyphs. fseek(fh, cmapAddr, SEEK_SET); - DWORD usedTableAddr = (DWORD)-1; + uint32_t usedTableAddr = (uint32_t)-1; - WORD cmapVersion = GetWORD(); - WORD cmapTableCount = GetWORD(); + uint16_t cmapVersion = GetUSHORT(); + uint16_t cmapTableCount = GetUSHORT(); for(i = 0; i < cmapTableCount; i++) { - WORD platformId = GetWORD(); - WORD encodingId = GetWORD(); - DWORD offset = GetDWORD(); + uint16_t platformId = GetUSHORT(); + uint16_t encodingId = GetUSHORT(); + uint32_t offset = GetULONG(); if(platformId == 3 && encodingId == 1) { // The Windows Unicode mapping is our preference @@ -464,7 +470,7 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { } } - if(usedTableAddr == (DWORD)-1) { + if(usedTableAddr == (uint32_t)-1) { throw "no used table addr"; } @@ -472,13 +478,13 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // which is us. fseek(fh, usedTableAddr, SEEK_SET); - WORD mapFormat = GetWORD(); - WORD mapLength = GetWORD(); - WORD mapVersion = GetWORD(); - WORD mapSegCountX2 = GetWORD(); - WORD mapSearchRange = GetWORD(); - WORD mapEntrySelector = GetWORD(); - WORD mapRangeShift = GetWORD(); + uint16_t mapFormat = GetUSHORT(); + uint16_t mapLength = GetUSHORT(); + uint16_t mapVersion = GetUSHORT(); + uint16_t mapSegCountX2 = GetUSHORT(); + uint16_t mapSearchRange = GetUSHORT(); + uint16_t mapEntrySelector = GetUSHORT(); + uint16_t mapRangeShift = GetUSHORT(); if(mapFormat != 4) { // Required to use format 4 per spec @@ -486,26 +492,26 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { } int segCount = mapSegCountX2 / 2; - WORD *endChar = (WORD *)AllocTemporary(segCount*sizeof(WORD)); - WORD *startChar = (WORD *)AllocTemporary(segCount*sizeof(WORD)); - WORD *idDelta = (WORD *)AllocTemporary(segCount*sizeof(WORD)); - WORD *idRangeOffset = (WORD *)AllocTemporary(segCount*sizeof(WORD)); + uint16_t *endChar = (uint16_t *)AllocTemporary(segCount*sizeof(uint16_t)); + uint16_t *startChar = (uint16_t *)AllocTemporary(segCount*sizeof(uint16_t)); + uint16_t *idDelta = (uint16_t *)AllocTemporary(segCount*sizeof(uint16_t)); + uint16_t *idRangeOffset = (uint16_t *)AllocTemporary(segCount*sizeof(uint16_t)); - DWORD *filePos = (DWORD *)AllocTemporary(segCount*sizeof(DWORD)); + uint32_t *filePos = (uint32_t *)AllocTemporary(segCount*sizeof(uint32_t)); for(i = 0; i < segCount; i++) { - endChar[i] = GetWORD(); + endChar[i] = GetUSHORT(); } - WORD mapReservedPad = GetWORD(); + uint16_t mapReservedPad = GetUSHORT(); for(i = 0; i < segCount; i++) { - startChar[i] = GetWORD(); + startChar[i] = GetUSHORT(); } for(i = 0; i < segCount; i++) { - idDelta[i] = GetWORD(); + idDelta[i] = GetUSHORT(); } for(i = 0; i < segCount; i++) { - filePos[i] = (DWORD)ftell(fh); - idRangeOffset[i] = GetWORD(); + filePos[i] = (uint32_t)ftell(fh); + idRangeOffset[i] = GetUSHORT(); } // So first, null out the glyph table in our in-memory representation @@ -516,16 +522,16 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { } for(i = 0; i < segCount; i++) { - WORD v = idDelta[i]; + uint16_t v = idDelta[i]; if(idRangeOffset[i] == 0) { int j; for(j = startChar[i]; j <= endChar[i]; j++) { if(j > 0 && j < (int)arraylen(useGlyph)) { // Don't create a reference to a glyph that we won't // store because it's bigger than the table. - if((WORD)(j + v) < glyphs) { + if((uint16_t)(j + v) < glyphs) { // Arithmetic is modulo 2^16 - useGlyph[j] = (WORD)(j + v); + useGlyph[j] = (uint16_t)(j + v); } } } @@ -534,11 +540,11 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { for(j = startChar[i]; j <= endChar[i]; j++) { if(j > 0 && j < (int)arraylen(useGlyph)) { int fp = filePos[i]; - fp += (j - startChar[i])*sizeof(WORD); + fp += (j - startChar[i])*sizeof(uint16_t); fp += idRangeOffset[i]; fseek(fh, fp, SEEK_SET); - useGlyph[j] = GetWORD(); + useGlyph[j] = GetUSHORT(); } } } @@ -548,15 +554,15 @@ bool TtfFont::LoadFontFromFile(bool nameOnly) { // relative to the beginning of the glyf table. fseek(fh, locaAddr, SEEK_SET); - DWORD *glyphOffsets = (DWORD *)AllocTemporary(glyphs*sizeof(DWORD)); + uint32_t *glyphOffsets = (uint32_t *)AllocTemporary(glyphs*sizeof(uint32_t)); for(i = 0; i < glyphs; i++) { if(headIndexToLocFormat == 1) { // long offsets, 32 bits - glyphOffsets[i] = GetDWORD(); + glyphOffsets[i] = GetULONG(); } else if(headIndexToLocFormat == 0) { // short offsets, 16 bits but divided by 2 - glyphOffsets[i] = GetWORD()*2; + glyphOffsets[i] = GetUSHORT()*2; } else { throw "bad headIndexToLocFormat"; } diff --git a/ui.h b/ui.h index 5e540092..c258d2d3 100644 --- a/ui.h +++ b/ui.h @@ -27,8 +27,8 @@ public: #define GREENf(v) (GREEN(v) / 255.0f) #define BLUEf(v) (BLUE (v) / 255.0f) typedef struct { - char c; - int color; + char c; + uint32_t color; } Color; static const Color fgColors[]; static const Color bgColors[]; @@ -51,14 +51,14 @@ public: int scrollPos; // The scrollbar position, in half-row units int halfRows; // The height of our window, in half-row units - BYTE text[MAX_ROWS][MAX_COLS]; - typedef void LinkFunction(int link, DWORD v); + uint8_t text[MAX_ROWS][MAX_COLS]; + typedef void LinkFunction(int link, uint32_t v); enum { NOT_A_LINK = 0 }; struct { char fg; int bg; int link; - DWORD data; + uint32_t data; LinkFunction *f; LinkFunction *h; } meta[MAX_ROWS][MAX_COLS]; @@ -71,7 +71,7 @@ public: // The row of icons at the top of the text window, to hide/show things typedef struct { bool *var; - BYTE *icon; + uint8_t *icon; const char *tip; } HideShowIcon; static HideShowIcon hideShowIcons[]; @@ -95,8 +95,8 @@ public: HideShowIcon *hoveredIcon, *tooltippedIcon; Vector HsvToRgb(Vector hsv); - BYTE *HsvPattern2d(void); - BYTE *HsvPattern1d(double h, double s); + uint8_t *HsvPattern2d(void); + uint8_t *HsvPattern1d(double h, double s); void ColorPickerDone(void); bool DrawOrHitTestColorPicker(int how, bool leftDown, double x, double y); @@ -206,17 +206,17 @@ public: int col; struct { - DWORD rgb; - double h, s, v; - bool show; - bool picker1dActive; - bool picker2dActive; + uint32_t rgb; + double h, s, v; + bool show; + bool picker1dActive; + bool picker2dActive; } colorPicker; } editControl; void HideEditControl(void); void ShowEditControl(int halfRow, int col, char *s); - void ShowEditControlWithColorPicker(int halfRow, int col, DWORD rgb); + void ShowEditControlWithColorPicker(int halfRow, int col, uint32_t rgb); void ClearSuper(void); @@ -240,82 +240,82 @@ public: // All of these are callbacks from the GUI code; first from when // we're describing an entity - static void ScreenEditTtfText(int link, DWORD v); - static void ScreenSetTtfFont(int link, DWORD v); - static void ScreenUnselectAll(int link, DWORD v); + static void ScreenEditTtfText(int link, uint32_t v); + static void ScreenSetTtfFont(int link, uint32_t v); + static void ScreenUnselectAll(int link, uint32_t v); // and the rest from the stuff in textscreens.cpp - static void ScreenSelectGroup(int link, DWORD v); - static void ScreenActivateGroup(int link, DWORD v); - static void ScreenToggleGroupShown(int link, DWORD v); - static void ScreenHowGroupSolved(int link, DWORD v); - static void ScreenShowGroupsSpecial(int link, DWORD v); - static void ScreenDeleteGroup(int link, DWORD v); + static void ScreenSelectGroup(int link, uint32_t v); + static void ScreenActivateGroup(int link, uint32_t v); + static void ScreenToggleGroupShown(int link, uint32_t v); + static void ScreenHowGroupSolved(int link, uint32_t v); + static void ScreenShowGroupsSpecial(int link, uint32_t v); + static void ScreenDeleteGroup(int link, uint32_t v); - static void ScreenHoverConstraint(int link, DWORD v); - static void ScreenHoverRequest(int link, DWORD v); - static void ScreenSelectRequest(int link, DWORD v); - static void ScreenSelectConstraint(int link, DWORD v); + static void ScreenHoverConstraint(int link, uint32_t v); + static void ScreenHoverRequest(int link, uint32_t v); + static void ScreenSelectRequest(int link, uint32_t v); + static void ScreenSelectConstraint(int link, uint32_t v); - static void ScreenChangeGroupOption(int link, DWORD v); - static void ScreenColor(int link, DWORD v); + static void ScreenChangeGroupOption(int link, uint32_t v); + static void ScreenColor(int link, uint32_t v); - static void ScreenShowListOfStyles(int link, DWORD v); - static void ScreenShowStyleInfo(int link, DWORD v); - static void ScreenDeleteStyle(int link, DWORD v); - static void ScreenChangeStyleYesNo(int link, DWORD v); - static void ScreenCreateCustomStyle(int link, DWORD v); - static void ScreenLoadFactoryDefaultStyles(int link, DWORD v); - static void ScreenAssignSelectionToStyle(int link, DWORD v); - static void ScreenBackgroundImage(int link, DWORD v); + static void ScreenShowListOfStyles(int link, uint32_t v); + static void ScreenShowStyleInfo(int link, uint32_t v); + static void ScreenDeleteStyle(int link, uint32_t v); + static void ScreenChangeStyleYesNo(int link, uint32_t v); + static void ScreenCreateCustomStyle(int link, uint32_t v); + static void ScreenLoadFactoryDefaultStyles(int link, uint32_t v); + static void ScreenAssignSelectionToStyle(int link, uint32_t v); + static void ScreenBackgroundImage(int link, uint32_t v); - static void ScreenShowConfiguration(int link, DWORD v); - static void ScreenShowEditView(int link, DWORD v); - static void ScreenGoToWebsite(int link, DWORD v); + static void ScreenShowConfiguration(int link, uint32_t v); + static void ScreenShowEditView(int link, uint32_t v); + static void ScreenGoToWebsite(int link, uint32_t v); - static void ScreenChangeFixExportColors(int link, DWORD v); - static void ScreenChangeBackFaces(int link, DWORD v); - static void ScreenChangeCheckClosedContour(int link, DWORD v); - static void ScreenChangePwlCurves(int link, DWORD v); - static void ScreenChangeCanvasSizeAuto(int link, DWORD v); - static void ScreenChangeCanvasSize(int link, DWORD v); - static void ScreenChangeShadedTriangles(int link, DWORD v); + static void ScreenChangeFixExportColors(int link, uint32_t v); + static void ScreenChangeBackFaces(int link, uint32_t v); + static void ScreenChangeCheckClosedContour(int link, uint32_t v); + static void ScreenChangePwlCurves(int link, uint32_t v); + static void ScreenChangeCanvasSizeAuto(int link, uint32_t v); + static void ScreenChangeCanvasSize(int link, uint32_t v); + static void ScreenChangeShadedTriangles(int link, uint32_t v); - static void ScreenStepDimSteps(int link, DWORD v); - static void ScreenStepDimFinish(int link, DWORD v); - static void ScreenStepDimGo(int link, DWORD v); + static void ScreenStepDimSteps(int link, uint32_t v); + static void ScreenStepDimFinish(int link, uint32_t v); + static void ScreenStepDimGo(int link, uint32_t v); - static void ScreenChangeTangentArc(int link, DWORD v); + static void ScreenChangeTangentArc(int link, uint32_t v); - static void ScreenPasteTransformed(int link, DWORD v); + static void ScreenPasteTransformed(int link, uint32_t v); - static void ScreenHome(int link, DWORD v); + static void ScreenHome(int link, uint32_t v); // These ones do stuff with the edit control - static void ScreenChangeExprA(int link, DWORD v); - static void ScreenChangeGroupName(int link, DWORD v); - static void ScreenChangeGroupScale(int link, DWORD v); - static void ScreenChangeLightDirection(int link, DWORD v); - static void ScreenChangeLightIntensity(int link, DWORD v); - static void ScreenChangeColor(int link, DWORD v); - static void ScreenChangeChordTolerance(int link, DWORD v); - static void ScreenChangeMaxSegments(int link, DWORD v); - static void ScreenChangeCameraTangent(int link, DWORD v); - static void ScreenChangeGridSpacing(int link, DWORD v); - static void ScreenChangeDigitsAfterDecimal(int link, DWORD v); - static void ScreenChangeExportScale(int link, DWORD v); - static void ScreenChangeExportOffset(int link, DWORD v); - static void ScreenChangeGCodeParameter(int link, DWORD v); - static void ScreenChangeStyleName(int link, DWORD v); - static void ScreenChangeStyleWidthOrTextHeight(int link, DWORD v); - static void ScreenChangeStyleTextAngle(int link, DWORD v); - static void ScreenChangeStyleColor(int link, DWORD v); - static void ScreenChangeBackgroundColor(int link, DWORD v); - static void ScreenChangeBackgroundImageScale(int link, DWORD v); - static void ScreenChangePasteTransformed(int link, DWORD v); - static void ScreenChangeViewScale(int link, DWORD v); - static void ScreenChangeViewOrigin(int link, DWORD v); - static void ScreenChangeViewProjection(int link, DWORD v); + static void ScreenChangeExprA(int link, uint32_t v); + static void ScreenChangeGroupName(int link, uint32_t v); + static void ScreenChangeGroupScale(int link, uint32_t v); + static void ScreenChangeLightDirection(int link, uint32_t v); + static void ScreenChangeLightIntensity(int link, uint32_t v); + static void ScreenChangeColor(int link, uint32_t v); + static void ScreenChangeChordTolerance(int link, uint32_t v); + static void ScreenChangeMaxSegments(int link, uint32_t v); + static void ScreenChangeCameraTangent(int link, uint32_t v); + static void ScreenChangeGridSpacing(int link, uint32_t v); + static void ScreenChangeDigitsAfterDecimal(int link, uint32_t v); + static void ScreenChangeExportScale(int link, uint32_t v); + static void ScreenChangeExportOffset(int link, uint32_t v); + static void ScreenChangeGCodeParameter(int link, uint32_t v); + static void ScreenChangeStyleName(int link, uint32_t v); + static void ScreenChangeStyleWidthOrTextHeight(int link, uint32_t v); + static void ScreenChangeStyleTextAngle(int link, uint32_t v); + static void ScreenChangeStyleColor(int link, uint32_t v); + static void ScreenChangeBackgroundColor(int link, uint32_t v); + static void ScreenChangeBackgroundImageScale(int link, uint32_t v); + static void ScreenChangePasteTransformed(int link, uint32_t v); + static void ScreenChangeViewScale(int link, uint32_t v); + static void ScreenChangeViewOrigin(int link, uint32_t v); + static void ScreenChangeViewProjection(int link, uint32_t v); bool EditControlDoneForStyles(const char *s); bool EditControlDoneForConfiguration(const char *s); @@ -643,7 +643,7 @@ public: CMNU_FIRST_STYLE = 0x40000000 }; void ContextMenuListStyles(void); - SDWORD contextMenuCancelTime; + int32_t contextMenuCancelTime; // The toolbar, in toolbar.cpp bool ToolbarDrawOrHitTest(int x, int y, bool paint, int *menu); @@ -690,7 +690,7 @@ public: bool KeyDown(int c); void EditControlDone(const char *s); - SDWORD lastSpaceNavigatorTime; + int32_t lastSpaceNavigatorTime; hGroup lastSpaceNavigatorGroup; void SpaceNavigatorMoved(double tx, double ty, double tz, double rx, double ry, double rz, bool shiftDown); diff --git a/view.cpp b/view.cpp index 58b355ea..ed2858c2 100644 --- a/view.cpp +++ b/view.cpp @@ -37,7 +37,7 @@ void TextWindow::ShowEditView(void) { Printf(false, "configuration screen."); } -void TextWindow::ScreenChangeViewScale(int link, DWORD v) { +void TextWindow::ScreenChangeViewScale(int link, uint32_t v) { char buf[1024]; sprintf(buf, "%.3f", SS.GW.scale * SS.MmPerUnit()); @@ -45,7 +45,7 @@ void TextWindow::ScreenChangeViewScale(int link, DWORD v) { SS.TW.ShowEditControl(12, 3, buf); } -void TextWindow::ScreenChangeViewOrigin(int link, DWORD v) { +void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) { char buf[1024]; sprintf(buf, "%s, %s, %s", SS.MmToString(-SS.GW.offset.x), @@ -56,7 +56,7 @@ void TextWindow::ScreenChangeViewOrigin(int link, DWORD v) { SS.TW.ShowEditControl(18, 3, buf); } -void TextWindow::ScreenChangeViewProjection(int link, DWORD v) { +void TextWindow::ScreenChangeViewProjection(int link, uint32_t v) { char buf[1024]; sprintf(buf, "%.3f, %.3f, %.3f", CO(SS.GW.projRight)); SS.TW.edit.meaning = EDIT_VIEW_PROJ_RIGHT; diff --git a/win32/w32main.cpp b/win32/w32main.cpp index fbd749a6..61c35361 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -5,24 +5,18 @@ // // Copyright 2008-2013 Jonathan Westhues. //----------------------------------------------------------------------------- -#include +#include "solvespace.h" +#include #include #include #include -#include -#include -#include -#include -#include -#include #ifdef HAVE_SPACEWARE_INPUT # include # include +# undef uint32_t // thanks but no thanks #endif -#include "solvespace.h" - #define FREEZE_SUBKEY "SolveSpace" #include "freeze.h" @@ -66,7 +60,7 @@ SiHdl SpaceNavigator = SI_NO_HANDLE; //----------------------------------------------------------------------------- HWND MessageWnd, OkButton; -BOOL MessageDone; +bool MessageDone; const char *MessageString; static LRESULT CALLBACK MessageProc(HWND hwnd, UINT msg, WPARAM wParam, @@ -75,13 +69,13 @@ static LRESULT CALLBACK MessageProc(HWND hwnd, UINT msg, WPARAM wParam, switch (msg) { case WM_COMMAND: if((HWND)lParam == OkButton && wParam == BN_CLICKED) { - MessageDone = TRUE; + MessageDone = true; } break; case WM_CLOSE: case WM_DESTROY: - MessageDone = TRUE; + MessageDone = true; break; case WM_PAINT: { @@ -130,10 +124,10 @@ HWND CreateWindowClient(DWORD exStyle, char *className, char *windowName, return h; } -void DoMessageBox(const char *str, int rows, int cols, BOOL error) +void DoMessageBox(const char *str, int rows, int cols, bool error) { - EnableWindow(GraphicsWnd, FALSE); - EnableWindow(TextWnd, FALSE); + EnableWindow(GraphicsWnd, false); + EnableWindow(TextWnd, false); HWND h = GetForegroundWindow(); // Register the window class for our dialog. @@ -168,14 +162,14 @@ void DoMessageBox(const char *str, int rows, int cols, BOOL error) WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE | BS_DEFPUSHBUTTON, (width - 70)/2, rows*SS.TW.LINE_HEIGHT + 20, 70, 25, MessageWnd, NULL, Instance, NULL); - SendMessage(OkButton, WM_SETFONT, (WPARAM)FixedFont, TRUE); + SendMessage(OkButton, WM_SETFONT, (WPARAM)FixedFont, true); - ShowWindow(MessageWnd, TRUE); + ShowWindow(MessageWnd, true); SetFocus(OkButton); MSG msg; DWORD ret; - MessageDone = FALSE; + MessageDone = false; while((ret = GetMessage(&msg, NULL, 0, 0)) != 0 && !MessageDone) { if((msg.message == WM_KEYDOWN && (msg.wParam == VK_RETURN || @@ -183,7 +177,7 @@ void DoMessageBox(const char *str, int rows, int cols, BOOL error) (msg.message == WM_KEYUP && (msg.wParam == VK_SPACE))) { - MessageDone = TRUE; + MessageDone = true; break; } @@ -192,8 +186,8 @@ void DoMessageBox(const char *str, int rows, int cols, BOOL error) } MessageString = NULL; - EnableWindow(TextWnd, TRUE); - EnableWindow(GraphicsWnd, TRUE); + EnableWindow(TextWnd, true); + EnableWindow(GraphicsWnd, true); SetForegroundWindow(GraphicsWnd); DestroyWindow(MessageWnd); } @@ -277,23 +271,29 @@ void ExitNow(void) { void CnfFreezeString(const char *str, const char *name) { FreezeStringF(str, FREEZE_SUBKEY, name); } -void CnfFreezeDWORD(DWORD v, const char *name) - { FreezeDWORDF(v, FREEZE_SUBKEY, name); } +void CnfFreezeInt(uint32_t v, const char *name) + { FreezeDWORDF((DWORD)v, FREEZE_SUBKEY, name); } void CnfFreezeFloat(float v, const char *name) { FreezeDWORDF(*((DWORD *)&v), FREEZE_SUBKEY, name); } +void CnfFreezeBool(bool v, const char *name) + { FreezeDWORDF((DWORD)v, FREEZE_SUBKEY, name); } + void CnfThawString(char *str, int maxLen, const char *name) { ThawStringF(str, maxLen, FREEZE_SUBKEY, name); } -DWORD CnfThawDWORD(DWORD v, const char *name) - { return ThawDWORDF(v, FREEZE_SUBKEY, name); } +uint32_t CnfThawInt(uint32_t v, const char *name) + { return (uint32_t)ThawDWORDF((DWORD)v, FREEZE_SUBKEY, name); } float CnfThawFloat(float v, const char *name) { DWORD d = ThawDWORDF(*((DWORD *)&v), FREEZE_SUBKEY, name); return *((float *)&d); } +bool CnfThawBool(bool v, const char *name) + { return ThawDWORDF((DWORD)v, FREEZE_SUBKEY, name) ? true : false; } + void SetWindowTitle(const char *str) { SetWindowText(GraphicsWnd, str); } @@ -324,7 +324,7 @@ void MoveTextScrollbarTo(int pos, int maxPos, int page) si.nMax = maxPos; si.nPos = pos; si.nPage = page; - SetScrollInfo(TextWndScrollBar, SB_CTL, &si, TRUE); + SetScrollInfo(TextWndScrollBar, SB_CTL, &si, true); } void HandleTextWindowScrollBar(WPARAM wParam, LPARAM lParam) @@ -479,11 +479,11 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int sw = r.right - r.left; GetClientRect(hwnd, &r); MoveWindow(TextWndScrollBar, r.right - sw, r.top, sw, - (r.bottom - r.top), TRUE); + (r.bottom - r.top), true); // If the window is growing, then the scrollbar position may // be moving, so it's as if we're dragging the scrollbar. HandleTextWindowScrollBar((WPARAM)-1, -1); - InvalidateRect(TextWnd, NULL, FALSE); + InvalidateRect(TextWnd, NULL, false); break; } @@ -502,7 +502,7 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return 1; } -static BOOL ProcessKeyDown(WPARAM wParam) +static bool ProcessKeyDown(WPARAM wParam) { if(GraphicsEditControlIsVisible() && wParam != VK_ESCAPE) { if(wParam == VK_RETURN) { @@ -510,9 +510,9 @@ static BOOL ProcessKeyDown(WPARAM wParam) memset(s, 0, sizeof(s)); SendMessage(GraphicsEditControl, WM_GETTEXT, 900, (LPARAM)s); SS.GW.EditControlDone(s); - return TRUE; + return true; } else { - return FALSE; + return false; } } if(TextEditControlIsVisible() && wParam != VK_ESCAPE) { @@ -522,7 +522,7 @@ static BOOL ProcessKeyDown(WPARAM wParam) SendMessage(TextEditControl, WM_GETTEXT, 900, (LPARAM)s); SS.TW.EditControlDone(s); } else { - return FALSE; + return false; } } @@ -564,7 +564,7 @@ static BOOL ProcessKeyDown(WPARAM wParam) case VK_EXECUTE: case VK_APPS: case VK_LWIN: - case VK_RWIN: return FALSE; + case VK_RWIN: return false; default: c = (int)wParam; @@ -584,13 +584,13 @@ static BOOL ProcessKeyDown(WPARAM wParam) } } - if(SS.GW.KeyDown(c)) return TRUE; + if(SS.GW.KeyDown(c)) return true; // No accelerator; process the key as normal. - return FALSE; + return false; } -void ShowTextWindow(BOOL visible) +void ShowTextWindow(bool visible) { ShowWindow(TextWnd, visible ? SW_SHOWNOACTIVATE : SW_HIDE); } @@ -630,32 +630,32 @@ void PaintGraphics(void) } void InvalidateGraphics(void) { - InvalidateRect(GraphicsWnd, NULL, FALSE); + InvalidateRect(GraphicsWnd, NULL, false); } -SDWORD GetMilliseconds(void) +int32_t GetMilliseconds(void) { LARGE_INTEGER t, f; QueryPerformanceCounter(&t); QueryPerformanceFrequency(&f); LONGLONG d = t.QuadPart/(f.QuadPart/1000); - return (SDWORD)d; + return (int32_t)d; } -SQWORD GetUnixTime(void) +int64_t GetUnixTime(void) { __time64_t ret; _time64(&ret); - return ret; + return (int64_t)ret; } void InvalidateText(void) { - InvalidateRect(TextWnd, NULL, FALSE); + InvalidateRect(TextWnd, NULL, false); } static void ShowEditControl(HWND h, int x, int y, char *s) { - MoveWindow(h, x, y, EDIT_WIDTH, EDIT_HEIGHT, TRUE); + MoveWindow(h, x, y, EDIT_WIDTH, EDIT_HEIGHT, true); ShowWindow(h, SW_SHOW); if(s) { SendMessage(h, WM_SETTEXT, 0, (LPARAM)s); @@ -673,9 +673,9 @@ void HideTextEditControl(void) { ShowWindow(TextEditControl, SW_HIDE); } -BOOL TextEditControlIsVisible(void) +bool TextEditControlIsVisible(void) { - return IsWindowVisible(TextEditControl); + return IsWindowVisible(TextEditControl) ? true : false; } void ShowGraphicsEditControl(int x, int y, char *s) { @@ -696,9 +696,9 @@ void HideGraphicsEditControl(void) { ShowWindow(GraphicsEditControl, SW_HIDE); } -BOOL GraphicsEditControlIsVisible(void) +bool GraphicsEditControlIsVisible(void) { - return IsWindowVisible(GraphicsEditControl); + return IsWindowVisible(GraphicsEditControl) ? true : false; } LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, @@ -709,7 +709,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, break; case WM_SIZE: - InvalidateRect(GraphicsWnd, NULL, FALSE); + InvalidateRect(GraphicsWnd, NULL, false); break; case WM_PAINT: { @@ -817,7 +817,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam, //----------------------------------------------------------------------------- // Common dialog routines, to open or save a file. //----------------------------------------------------------------------------- -BOOL GetOpenFile(char *file, const char *defExtension, const char *selPattern) +bool GetOpenFile(char *file, const char *defExtension, const char *selPattern) { OPENFILENAME ofn; @@ -831,18 +831,18 @@ BOOL GetOpenFile(char *file, const char *defExtension, const char *selPattern) ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - EnableWindow(GraphicsWnd, FALSE); - EnableWindow(TextWnd, FALSE); + EnableWindow(GraphicsWnd, false); + EnableWindow(TextWnd, false); BOOL r = GetOpenFileName(&ofn); - EnableWindow(TextWnd, TRUE); - EnableWindow(GraphicsWnd, TRUE); + EnableWindow(TextWnd, true); + EnableWindow(GraphicsWnd, true); SetForegroundWindow(GraphicsWnd); - return r; + return r ? true : false; } -BOOL GetSaveFile(char *file, const char *defExtension, const char *selPattern) +bool GetSaveFile(char *file, const char *defExtension, const char *selPattern) { OPENFILENAME ofn; @@ -856,29 +856,29 @@ BOOL GetSaveFile(char *file, const char *defExtension, const char *selPattern) ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; - EnableWindow(GraphicsWnd, FALSE); - EnableWindow(TextWnd, FALSE); + EnableWindow(GraphicsWnd, false); + EnableWindow(TextWnd, false); BOOL r = GetSaveFileName(&ofn); - EnableWindow(TextWnd, TRUE); - EnableWindow(GraphicsWnd, TRUE); + EnableWindow(TextWnd, true); + EnableWindow(GraphicsWnd, true); SetForegroundWindow(GraphicsWnd); - return r; + return r ? true : false; } int SaveFileYesNoCancel(void) { - EnableWindow(GraphicsWnd, FALSE); - EnableWindow(TextWnd, FALSE); + EnableWindow(GraphicsWnd, false); + EnableWindow(TextWnd, false); int r = MessageBox(GraphicsWnd, "The program has changed since it was last saved.\r\n\r\n" "Do you want to save the changes?", "SolveSpace", MB_YESNOCANCEL | MB_ICONWARNING); - EnableWindow(TextWnd, TRUE); - EnableWindow(GraphicsWnd, TRUE); + EnableWindow(TextWnd, true); + EnableWindow(GraphicsWnd, true); SetForegroundWindow(GraphicsWnd); switch(r) { @@ -916,7 +916,7 @@ void LoadAllFontFiles(void) } } -static void MenuById(int id, BOOL yes, BOOL check) +static void MenuById(int id, bool yes, bool check) { int i; int subMenu = -1; @@ -940,18 +940,18 @@ static void MenuById(int id, BOOL yes, BOOL check) } oops(); } -void CheckMenuById(int id, BOOL checked) +void CheckMenuById(int id, bool checked) { - MenuById(id, checked, TRUE); + MenuById(id, checked, true); } -void RadioMenuById(int id, BOOL selected) +void RadioMenuById(int id, bool selected) { // Windows does not natively support radio-button menu items - MenuById(id, selected, TRUE); + MenuById(id, selected, true); } -void EnableMenuById(int id, BOOL enabled) +void EnableMenuById(int id, bool enabled) { - MenuById(id, enabled, FALSE); + MenuById(id, enabled, false); } static void DoRecent(HMENU m, int base) { @@ -1050,7 +1050,7 @@ static void CreateMainWindows(void) GraphicsEditControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS, 50, 50, 100, 21, GraphicsWnd, NULL, Instance, NULL); - SendMessage(GraphicsEditControl, WM_SETFONT, (WPARAM)FixedFont, TRUE); + SendMessage(GraphicsEditControl, WM_SETFONT, (WPARAM)FixedFont, true); // The text window, with a comand line and some textual information // about the sketch. @@ -1077,7 +1077,7 @@ static void CreateMainWindows(void) TextEditControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, "", WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS, 50, 50, 100, 21, TextWnd, NULL, Instance, NULL); - SendMessage(TextEditControl, WM_SETFONT, (WPARAM)FixedFont, TRUE); + SendMessage(TextEditControl, WM_SETFONT, (WPARAM)FixedFont, true); // Now that all our windows exist, set up gl contexts. CreateGlContext(TextWnd, &TextGl); @@ -1092,17 +1092,17 @@ static void CreateMainWindows(void) #ifdef HAVE_SPACEWARE_INPUT //----------------------------------------------------------------------------- // Test if a message comes from the SpaceNavigator device. If yes, dispatch -// it appropriately and return TRUE. Otherwise, do nothing and return FALSE. +// it appropriately and return true. Otherwise, do nothing and return false. //----------------------------------------------------------------------------- -static BOOL ProcessSpaceNavigatorMsg(MSG *msg) { - if(SpaceNavigator == SI_NO_HANDLE) return FALSE; +static bool ProcessSpaceNavigatorMsg(MSG *msg) { + if(SpaceNavigator == SI_NO_HANDLE) return false; SiGetEventData sged; SiSpwEvent sse; SiGetEventWinInit(&sged, msg->message, msg->wParam, msg->lParam); int ret = SiGetEvent(SpaceNavigator, 0, &sged, &sse); - if(ret == SI_NOT_EVENT) return FALSE; + if(ret == SI_NOT_EVENT) return false; // So the device is a SpaceNavigator event, or a SpaceNavigator error. if(ret == SI_IS_EVENT) { @@ -1123,7 +1123,7 @@ static BOOL ProcessSpaceNavigatorMsg(MSG *msg) { if(button == SI_APP_FIT_BUTTON) SS.GW.SpaceNavigatorButtonUp(); } } - return TRUE; + return true; } #endif // HAVE_SPACEWARE_INPUT @@ -1139,8 +1139,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, // A monospaced font FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0, - FW_REGULAR, FALSE, - FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + FW_REGULAR, false, + false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); if(!FixedFont) FixedFont = (HFONT)GetStockObject(SYSTEM_FONT);