From 2a24933fa84bd913104dafcb89526eef1693a849 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 14 Nov 2021 19:10:16 -0800 Subject: [PATCH] Scoped enums. --- common/camera.cpp | 22 +++++++++++----------- common/image.cpp | 28 ++++++++++++++-------------- common/image.h | 12 ++++++------ common/lc_colors.cpp | 16 +++++++++------- common/lc_colors.h | 18 +++++++++--------- common/lc_context.cpp | 4 ++-- common/lc_scene.cpp | 12 ++++++------ common/lc_stringcache.cpp | 2 +- common/lc_texture.cpp | 12 ++++++------ common/lc_viewsphere.cpp | 2 +- common/light.cpp | 22 +++++++++++----------- common/piece.cpp | 8 ++++---- 12 files changed, 80 insertions(+), 78 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 7ce0fcc3..3474544d 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -542,7 +542,7 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const if (!IsSelected()) { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_CAMERA); + Context->SetInterfaceColor(lcInterfaceColor::Camera); Context->DrawIndexedPrimitives(GL_LINES, 40 + 24 + 24 + 4, GL_UNSIGNED_SHORT, 0); } @@ -552,14 +552,14 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const { Context->SetLineWidth(2.0f * LineWidth); if (IsFocused(LC_CAMERA_SECTION_POSITION)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); } else { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_CAMERA); + Context->SetInterfaceColor(lcInterfaceColor::Camera); } Context->DrawIndexedPrimitives(GL_LINES, 40, GL_UNSIGNED_SHORT, 0); @@ -568,14 +568,14 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const { Context->SetLineWidth(2.0f * LineWidth); if (IsFocused(LC_CAMERA_SECTION_TARGET)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); } else { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_CAMERA); + Context->SetInterfaceColor(lcInterfaceColor::Camera); } Context->DrawIndexedPrimitives(GL_LINES, 24, GL_UNSIGNED_SHORT, 40 * 2); @@ -584,19 +584,19 @@ void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const { Context->SetLineWidth(2.0f * LineWidth); if (IsFocused(LC_CAMERA_SECTION_UPVECTOR)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); } else { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_CAMERA); + Context->SetInterfaceColor(lcInterfaceColor::Camera); } Context->DrawIndexedPrimitives(GL_LINES, 24, GL_UNSIGNED_SHORT, (40 + 24) * 2); - Context->SetInterfaceColor(LC_COLOR_CAMERA); + Context->SetInterfaceColor(lcInterfaceColor::Camera); Context->SetLineWidth(LineWidth); float SizeY = tanf(LC_DTOR * m_fovy / 2) * Length; diff --git a/common/image.cpp b/common/image.cpp index f3f09667..00ae0aa6 100644 --- a/common/image.cpp +++ b/common/image.cpp @@ -5,7 +5,7 @@ static void CopyFromQImage(const QImage& Src, Image& Dest) { const bool Alpha = Src.hasAlphaChannel(); - Dest.Allocate(Src.width(), Src.height(), Alpha ? LC_PIXEL_FORMAT_R8G8B8A8 : LC_PIXEL_FORMAT_R8G8B8); + Dest.Allocate(Src.width(), Src.height(), Alpha ? lcPixelFormat::R8G8B8A8 : lcPixelFormat::R8G8B8); quint8* Bytes = (quint8*)Dest.mData; @@ -30,7 +30,7 @@ Image::Image() mData = nullptr; mWidth = 0; mHeight = 0; - mFormat = LC_PIXEL_FORMAT_INVALID; + mFormat = lcPixelFormat::Invalid; } Image::Image(Image&& Other) @@ -43,7 +43,7 @@ Image::Image(Image&& Other) Other.mData = nullptr; Other.mWidth = 0; Other.mHeight = 0; - Other.mFormat = LC_PIXEL_FORMAT_INVALID; + Other.mFormat = lcPixelFormat::Invalid; } Image::~Image() @@ -55,15 +55,15 @@ int Image::GetBPP() const { switch (mFormat) { - case LC_PIXEL_FORMAT_INVALID: + case lcPixelFormat::Invalid: return 0; - case LC_PIXEL_FORMAT_A8: + case lcPixelFormat::A8: return 1; - case LC_PIXEL_FORMAT_L8A8: + case lcPixelFormat::L8A8: return 2; - case LC_PIXEL_FORMAT_R8G8B8: + case lcPixelFormat::R8G8B8: return 3; - case LC_PIXEL_FORMAT_R8G8B8A8: + case lcPixelFormat::R8G8B8A8: return 4; } @@ -74,15 +74,15 @@ bool Image::HasAlpha() const { switch (mFormat) { - case LC_PIXEL_FORMAT_INVALID: + case lcPixelFormat::Invalid: return false; - case LC_PIXEL_FORMAT_A8: + case lcPixelFormat::A8: return true; - case LC_PIXEL_FORMAT_L8A8: + case lcPixelFormat::L8A8: return true; - case LC_PIXEL_FORMAT_R8G8B8: + case lcPixelFormat::R8G8B8: return false; - case LC_PIXEL_FORMAT_R8G8B8A8: + case lcPixelFormat::R8G8B8A8: return true; } @@ -95,7 +95,7 @@ void Image::FreeData() mData = nullptr; mWidth = 0; mHeight = 0; - mFormat = LC_PIXEL_FORMAT_INVALID; + mFormat = lcPixelFormat::Invalid; } void Image::Allocate(int Width, int Height, lcPixelFormat Format) diff --git a/common/image.h b/common/image.h index 880130e3..66a81d0b 100644 --- a/common/image.h +++ b/common/image.h @@ -4,13 +4,13 @@ #define LC_IMAGE_TRANSPARENT 0x2000 //#define LC_IMAGE_MASK 0x7000 -enum lcPixelFormat +enum class lcPixelFormat { - LC_PIXEL_FORMAT_INVALID, - LC_PIXEL_FORMAT_A8, - LC_PIXEL_FORMAT_L8A8, - LC_PIXEL_FORMAT_R8G8B8, - LC_PIXEL_FORMAT_R8G8B8A8 + Invalid, + A8, + L8A8, + R8G8B8, + R8G8B8A8 }; class Image diff --git a/common/lc_colors.cpp b/common/lc_colors.cpp index 06dfe361..b5ba6d22 100644 --- a/common/lc_colors.cpp +++ b/common/lc_colors.cpp @@ -10,16 +10,18 @@ lcColorGroup gColorGroups[LC_NUM_COLORGROUPS]; int gEdgeColor; int gDefaultColor; -lcVector4 gInterfaceColors[LC_NUM_INTERFACECOLORS] = // todo: make the colors configurable and include the grid and other hardcoded colors here as well. +lcVector4 gInterfaceColors[] = // todo: make the colors configurable and include the grid and other hardcoded colors here as well. { - lcVector4(0.898f, 0.298f, 0.400f, 1.000f), // LC_COLOR_SELECTED - lcVector4(0.400f, 0.298f, 0.898f, 1.000f), // LC_COLOR_FOCUSED - lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_CAMERA - lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // LC_COLOR_LIGHT - lcVector4(0.500f, 0.800f, 0.500f, 0.500f), // LC_COLOR_CONTROL_POINT - lcVector4(0.400f, 0.298f, 0.898f, 0.500f), // LC_COLOR_CONTROL_POINT_FOCUSED + lcVector4(0.898f, 0.298f, 0.400f, 1.000f), // lcInterfaceColor::Selected + lcVector4(0.400f, 0.298f, 0.898f, 1.000f), // lcInterfaceColor::Focused + lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // lcInterfaceColor::Camera + lcVector4(0.500f, 0.800f, 0.500f, 1.000f), // lcInterfaceColor::Light + lcVector4(0.500f, 0.800f, 0.500f, 0.500f), // lcInterfaceColor::ControlPoint + lcVector4(0.400f, 0.298f, 0.898f, 0.500f), // lcInterfaceColor::ControlPointFocused }; +LC_ARRAY_SIZE_CHECK(gInterfaceColors, lcInterfaceColor::Count); + static void GetToken(char*& Ptr, char* Token) { while (*Ptr && *Ptr <= 32) diff --git a/common/lc_colors.h b/common/lc_colors.h index 245acf80..c3d6e97f 100644 --- a/common/lc_colors.h +++ b/common/lc_colors.h @@ -33,18 +33,18 @@ struct lcColorGroup QString Name; }; -enum lcInterfaceColor +enum class lcInterfaceColor { - LC_COLOR_SELECTED, - LC_COLOR_FOCUSED, - LC_COLOR_CAMERA, - LC_COLOR_LIGHT, - LC_COLOR_CONTROL_POINT, - LC_COLOR_CONTROL_POINT_FOCUSED, - LC_NUM_INTERFACECOLORS + Selected, + Focused, + Camera, + Light, + ControlPoint, + ControlPointFocused, + Count }; -extern lcVector4 gInterfaceColors[LC_NUM_INTERFACECOLORS]; +extern lcVector4 gInterfaceColors[static_cast(lcInterfaceColor::Count)]; extern std::vector gColorList; extern lcColorGroup gColorGroups[LC_NUM_COLORGROUPS]; extern int gEdgeColor; diff --git a/common/lc_context.cpp b/common/lc_context.cpp index 2edda182..5af03f26 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -684,7 +684,7 @@ void lcContext::SetColorIndex(int ColorIndex) void lcContext::SetColorIndexTinted(int ColorIndex, lcInterfaceColor InterfaceColor, float Weight) { - const lcVector3 Color(gColorList[ColorIndex].Value * Weight + gInterfaceColors[InterfaceColor] * (1.0f - Weight)); + const lcVector3 Color(gColorList[ColorIndex].Value * Weight + gInterfaceColors[static_cast(InterfaceColor)] * (1.0f - Weight)); SetColor(lcVector4(Color, gColorList[ColorIndex].Value.w)); } @@ -705,7 +705,7 @@ void lcContext::SetEdgeColorIndexTinted(int ColorIndex, const lcVector4& Tint) void lcContext::SetInterfaceColor(lcInterfaceColor InterfaceColor) { - SetColor(gInterfaceColors[InterfaceColor]); + SetColor(gInterfaceColors[static_cast(InterfaceColor)]); } lcVertexBuffer lcContext::CreateVertexBuffer(int Size, const void* Data) diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index 745c3976..9ad75f50 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -195,11 +195,11 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy break; case lcRenderMeshState::Selected: - Context->SetColorIndexTinted(ColorIndex, LC_COLOR_SELECTED, 0.5f); + Context->SetColorIndexTinted(ColorIndex, lcInterfaceColor::Selected, 0.5f); break; case lcRenderMeshState::Focused: - Context->SetColorIndexTinted(ColorIndex, LC_COLOR_FOCUSED, 0.5f); + Context->SetColorIndexTinted(ColorIndex, lcInterfaceColor::Focused, 0.5f); break; case lcRenderMeshState::Faded: @@ -231,11 +231,11 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy break; case lcRenderMeshState::Selected: - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); break; case lcRenderMeshState::Focused: - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); break; case lcRenderMeshState::Highlighted: @@ -364,11 +364,11 @@ void lcScene::DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawF break; case lcRenderMeshState::Selected: - Context->SetColorIndexTinted(ColorIndex, LC_COLOR_SELECTED, 0.5f); + Context->SetColorIndexTinted(ColorIndex, lcInterfaceColor::Selected, 0.5f); break; case lcRenderMeshState::Focused: - Context->SetColorIndexTinted(ColorIndex, LC_COLOR_FOCUSED, 0.5f); + Context->SetColorIndexTinted(ColorIndex, lcInterfaceColor::Focused, 0.5f); break; case lcRenderMeshState::Faded: diff --git a/common/lc_stringcache.cpp b/common/lc_stringcache.cpp index e30c2832..90437528 100644 --- a/common/lc_stringcache.cpp +++ b/common/lc_stringcache.cpp @@ -45,7 +45,7 @@ void lcStringCache::CacheStrings(const QStringList& Strings) return; Image TextureImage; - TextureImage.Allocate(256, 256, LC_PIXEL_FORMAT_L8A8); + TextureImage.Allocate(256, 256, lcPixelFormat::L8A8); QImage Image(128, 128, QImage::Format_ARGB32); QPainter Painter; diff --git a/common/lc_texture.cpp b/common/lc_texture.cpp index c3e97bff..1335a010 100644 --- a/common/lc_texture.cpp +++ b/common/lc_texture.cpp @@ -53,7 +53,7 @@ void lcTexture::CreateGridTexture() { Image& GridImage = mImages[ImageLevel]; const int GridSize = 256 >> ImageLevel; - GridImage.Allocate(GridSize, GridSize, LC_PIXEL_FORMAT_A8); + GridImage.Allocate(GridSize, GridSize, lcPixelFormat::A8); if (Previous) { @@ -254,19 +254,19 @@ void lcTexture::Upload(lcContext* Context) switch (mImages[0].mFormat) { default: - case LC_PIXEL_FORMAT_INVALID: + case lcPixelFormat::Invalid: Format = 0; break; - case LC_PIXEL_FORMAT_A8: + case lcPixelFormat::A8: Format = GL_ALPHA; break; - case LC_PIXEL_FORMAT_L8A8: + case lcPixelFormat::L8A8: Format = GL_LUMINANCE_ALPHA; break; - case LC_PIXEL_FORMAT_R8G8B8: + case lcPixelFormat::R8G8B8: Format = GL_RGB; break; - case LC_PIXEL_FORMAT_R8G8B8A8: + case lcPixelFormat::R8G8B8A8: Format = GL_RGBA; break; } diff --git a/common/lc_viewsphere.cpp b/common/lc_viewsphere.cpp index 39140be6..f4b15381 100644 --- a/common/lc_viewsphere.cpp +++ b/common/lc_viewsphere.cpp @@ -83,7 +83,7 @@ void lcViewSphere::CreateResources(lcContext* Context) for (int ViewIdx = 0; ViewIdx < 6; ViewIdx++) { Image TextureImage; - TextureImage.Allocate(ImageSize, ImageSize, LC_PIXEL_FORMAT_A8); + TextureImage.Allocate(ImageSize, ImageSize, lcPixelFormat::A8); Painter.begin(&PainterImage); Painter.fillRect(0, 0, PainterImage.width(), PainterImage.height(), QColor(0, 0, 0)); diff --git a/common/light.cpp b/common/light.cpp index 57fdddfb..137349af 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -380,7 +380,7 @@ void lcLight::DrawSpotLight(lcContext* Context) const if (!IsSelected()) { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_LIGHT); + Context->SetInterfaceColor(lcInterfaceColor::Light); Context->DrawIndexedPrimitives(GL_LINES, 56 + 24 + 2, GL_UNSIGNED_SHORT, 0); } @@ -390,14 +390,14 @@ void lcLight::DrawSpotLight(lcContext* Context) const { Context->SetLineWidth(2.0f * LineWidth); if (IsFocused(LC_LIGHT_SECTION_POSITION)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); } else { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_LIGHT); + Context->SetInterfaceColor(lcInterfaceColor::Light); } Context->DrawIndexedPrimitives(GL_LINES, 56, GL_UNSIGNED_SHORT, 0); @@ -406,20 +406,20 @@ void lcLight::DrawSpotLight(lcContext* Context) const { Context->SetLineWidth(2.0f * LineWidth); if (IsFocused(LC_LIGHT_SECTION_TARGET)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); } else { Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_LIGHT); + Context->SetInterfaceColor(lcInterfaceColor::Light); } Context->DrawIndexedPrimitives(GL_LINES, 24, GL_UNSIGNED_SHORT, 56 * 2); Context->SetLineWidth(LineWidth); - Context->SetInterfaceColor(LC_COLOR_LIGHT); + Context->SetInterfaceColor(lcInterfaceColor::Light); float Radius = tanf(LC_DTOR * mSpotCutoff) * Length; @@ -514,11 +514,11 @@ void lcLight::DrawPointLight(lcContext* Context) const Context->SetWorldMatrix(lcMatrix44Translation(mPosition)); if (IsFocused(LC_LIGHT_SECTION_POSITION)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else if (IsSelected(LC_LIGHT_SECTION_POSITION)) - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); else - Context->SetInterfaceColor(LC_COLOR_LIGHT); + Context->SetInterfaceColor(lcInterfaceColor::Light); Context->SetVertexBufferPointer(Vertices); Context->SetVertexFormatPosition(3); diff --git a/common/piece.cpp b/common/piece.cpp index e8d477d4..6294b27d 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -559,9 +559,9 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const Context->SetWorldMatrix(WorldMatrix); if (IsFocused(LC_PIECE_SECTION_POSITION)) - Context->SetInterfaceColor(LC_COLOR_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::Focused); else - Context->SetInterfaceColor(LC_COLOR_SELECTED); + Context->SetInterfaceColor(lcInterfaceColor::Selected); Context->SetVertexBufferPointer(LineVerts); Context->SetVertexFormatPosition(3); @@ -626,9 +626,9 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const Context->SetIndexBufferPointer(Indices); if (IsFocused(LC_PIECE_SECTION_CONTROL_POINT_FIRST + ControlPointIdx)) - Context->SetInterfaceColor(LC_COLOR_CONTROL_POINT_FOCUSED); + Context->SetInterfaceColor(lcInterfaceColor::ControlPointFocused); else - Context->SetInterfaceColor(LC_COLOR_CONTROL_POINT); + Context->SetInterfaceColor(lcInterfaceColor::ControlPoint); Context->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); }