Scoped enums.

This commit is contained in:
Leonardo Zide
2021-11-14 19:10:16 -08:00
parent 7d884e6b5f
commit 2a24933fa8
12 changed files with 80 additions and 78 deletions
+11 -11
View File
@@ -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;
+14 -14
View File
@@ -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)
+6 -6
View File
@@ -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
+9 -7
View File
@@ -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)
+9 -9
View File
@@ -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<int>(lcInterfaceColor::Count)];
extern std::vector<lcColor> gColorList;
extern lcColorGroup gColorGroups[LC_NUM_COLORGROUPS];
extern int gEdgeColor;
+2 -2
View File
@@ -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<int>(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<int>(InterfaceColor)]);
}
lcVertexBuffer lcContext::CreateVertexBuffer(int Size, const void* Data)
+6 -6
View File
@@ -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:
+1 -1
View File
@@ -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;
+6 -6
View File
@@ -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;
}
+1 -1
View File
@@ -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));
+11 -11
View File
@@ -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);
+4 -4
View File
@@ -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);
}