mirror of
https://github.com/raysan5/raylib.git
synced 2026-11-26 01:21:46 -05:00
Compare commits
4 Commits
9b6d185ef0
...
2e66d4080c
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e66d4080c | |||
| ab1dde8fbb | |||
| f400535eb6 | |||
| d9ff09c3c9 |
@ -101,7 +101,7 @@ int main(void)
|
|||||||
float dy = mousePos.y - center.y;
|
float dy = mousePos.y - center.y;
|
||||||
float distance = sqrtf(dx*dx + dy*dy);
|
float distance = sqrtf(dx*dx + dy*dy);
|
||||||
|
|
||||||
if (distance <= radius) // Inside the pie radius
|
if ((distance <= radius) && (!showDonut || distance >= donutInnerRadius)) // Inside the pie, outside the donut hole
|
||||||
{
|
{
|
||||||
float angle = atan2f(dy, dx)*RAD2DEG;
|
float angle = atan2f(dy, dx)*RAD2DEG;
|
||||||
if (angle < 0) angle += 360;
|
if (angle < 0) angle += 360;
|
||||||
@ -138,11 +138,12 @@ int main(void)
|
|||||||
Color color = ColorFromHSV((float)i/sliceCount*360.0f, 0.75f, 0.9f);
|
Color color = ColorFromHSV((float)i/sliceCount*360.0f, 0.75f, 0.9f);
|
||||||
float currentRadius = radius;
|
float currentRadius = radius;
|
||||||
|
|
||||||
// Make the hovered slice pop out by adding 5 pixels to its radius
|
// Make the hovered slice pop out by adding 20 pixels to its radius
|
||||||
if (i == hoveredSlice) currentRadius += 20.0f;
|
if (i == hoveredSlice) currentRadius += 20.0f;
|
||||||
|
|
||||||
// Draw the pie slice using raylib's DrawCircleSector function
|
// Draw the pie slice (DrawRing() for donut mode)
|
||||||
DrawCircleSector(center, currentRadius, startAngle, startAngle + sweepAngle, 120, color);
|
if (showDonut) DrawRing(center, donutInnerRadius, currentRadius, startAngle, startAngle + sweepAngle, 120, color);
|
||||||
|
else DrawCircleSector(center, currentRadius, startAngle, startAngle + sweepAngle, 120, color);
|
||||||
|
|
||||||
// Draw the label for the current slice
|
// Draw the label for the current slice
|
||||||
if (values[i] > 0)
|
if (values[i] > 0)
|
||||||
@ -154,16 +155,12 @@ int main(void)
|
|||||||
else labelText[0] = '\0';
|
else labelText[0] = '\0';
|
||||||
|
|
||||||
Vector2 textSize = MeasureTextEx(GetFontDefault(), labelText, 20, 1);
|
Vector2 textSize = MeasureTextEx(GetFontDefault(), labelText, 20, 1);
|
||||||
float labelRadius = radius*0.7f;
|
float labelRadius = showDonut? (donutInnerRadius + radius)/2.0f : radius*0.7f;
|
||||||
Vector2 labelPos = { center.x + cosf(midAngle*DEG2RAD)*labelRadius - textSize.x/2.0f,
|
Vector2 labelPos = { center.x + cosf(midAngle*DEG2RAD)*labelRadius - textSize.x/2.0f,
|
||||||
center.y + sinf(midAngle*DEG2RAD)*labelRadius - textSize.y/2.0f };
|
center.y + sinf(midAngle*DEG2RAD)*labelRadius - textSize.y/2.0f };
|
||||||
DrawText(labelText, (int)labelPos.x, (int)labelPos.y, 20, WHITE);
|
DrawText(labelText, (int)labelPos.x, (int)labelPos.y, 20, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw inner circle to create donut effect
|
|
||||||
// TODO: This is a hacky solution, better use DrawRing()
|
|
||||||
if (showDonut) DrawCircleV(center, donutInnerRadius, RAYWHITE);
|
|
||||||
|
|
||||||
startAngle += sweepAngle;
|
startAngle += sweepAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +173,7 @@ int main(void)
|
|||||||
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)panelPos.y + 12 + 70, 20, 20 }, "Show Percentages", &showPercentages);
|
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)panelPos.y + 12 + 70, 20, 20 }, "Show Percentages", &showPercentages);
|
||||||
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)panelPos.y + 12 + 100, 20, 20 }, "Make Donut", &showDonut);
|
GuiCheckBox((Rectangle){ panelPos.x + 20, (float)panelPos.y + 12 + 100, 20, 20 }, "Make Donut", &showDonut);
|
||||||
|
|
||||||
if (showDonut) GuiDisable();
|
if (!showDonut) GuiDisable();
|
||||||
GuiSliderBar((Rectangle){ panelPos.x + 80, (float)panelPos.y + 12 + 130, panelRect.width - 100, 30 },
|
GuiSliderBar((Rectangle){ panelPos.x + 80, (float)panelPos.y + 12 + 130, panelRect.width - 100, 30 },
|
||||||
"Inner Radius", NULL, & donutInnerRadius, 5.0f, radius - 10.0f);
|
"Inner Radius", NULL, & donutInnerRadius, 5.0f, radius - 10.0f);
|
||||||
GuiEnable();
|
GuiEnable();
|
||||||
|
|||||||
@ -1677,8 +1677,10 @@ int InitPlatform(void)
|
|||||||
// If the area requested by the user exceeds the maximum workable area, clamp it to that
|
// If the area requested by the user exceeds the maximum workable area, clamp it to that
|
||||||
// GLFW has a problem where if the window is greater than the workable area (this means
|
// GLFW has a problem where if the window is greater than the workable area (this means
|
||||||
// the taskbar / dockable areas) it won't show up if the window isn't fullscreen
|
// the taskbar / dockable areas) it won't show up if the window isn't fullscreen
|
||||||
if (CORE.Window.screen.width > (unsigned int)workWidth) CORE.Window.screen.width = workWidth;
|
// NOTE: Some window managers report a workarea that does not overlap the primary monitor
|
||||||
if (CORE.Window.screen.height > (unsigned int)workHeight) CORE.Window.screen.height = workHeight;
|
// (i.e. multi-monitor setups on X11), resulting in a zero/negative size, skip clamping then
|
||||||
|
if ((workWidth > 0) && (CORE.Window.screen.width > (unsigned int)workWidth)) CORE.Window.screen.width = workWidth;
|
||||||
|
if ((workHeight > 0) && (CORE.Window.screen.height > (unsigned int)workHeight)) CORE.Window.screen.height = workHeight;
|
||||||
|
|
||||||
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
|
platform.handle = glfwCreateWindow(CORE.Window.screen.width, CORE.Window.screen.height, (CORE.Window.title != 0)? CORE.Window.title : " ", NULL, NULL);
|
||||||
if (!platform.handle)
|
if (!platform.handle)
|
||||||
|
|||||||
@ -1877,6 +1877,9 @@ void ClosePlatform(void)
|
|||||||
// Clear required platform data
|
// Clear required platform data
|
||||||
if (platform.hwnd)
|
if (platform.hwnd)
|
||||||
{
|
{
|
||||||
|
// Disable cursor lock (if enabled) and unregister raw input devices
|
||||||
|
EnableCursor();
|
||||||
|
|
||||||
// SetWindowIcon uses the same resource for both ICON_BIG and ICON_SMALL
|
// SetWindowIcon uses the same resource for both ICON_BIG and ICON_SMALL
|
||||||
// If this ever changes, this code may have to be updated
|
// If this ever changes, this code may have to be updated
|
||||||
HICON icon = (HICON)SendMessage(platform.hwnd, WM_GETICON, ICON_BIG, (LPARAM)0);
|
HICON icon = (HICON)SendMessage(platform.hwnd, WM_GETICON, ICON_BIG, (LPARAM)0);
|
||||||
|
|||||||
@ -1268,48 +1268,58 @@ void ImageCrop(Image *image, Rectangle crop)
|
|||||||
// Security check to avoid program crash
|
// Security check to avoid program crash
|
||||||
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
|
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
|
||||||
|
|
||||||
|
crop.x = floorf(crop.x);
|
||||||
|
crop.y = floorf(crop.y);
|
||||||
|
crop.width = floorf(crop.width);
|
||||||
|
crop.height = floorf(crop.height);
|
||||||
|
|
||||||
// Security checks to validate crop rectangle
|
// Security checks to validate crop rectangle
|
||||||
if (crop.x < 0) { crop.width += crop.x; crop.x = 0; }
|
if (crop.x < 0) { crop.width += crop.x; crop.x = 0; }
|
||||||
if (crop.y < 0) { crop.height += crop.y; crop.y = 0; }
|
if (crop.y < 0) { crop.height += crop.y; crop.y = 0; }
|
||||||
if ((crop.x + crop.width) > image->width) crop.width = image->width - crop.x;
|
if ((crop.x + crop.width) > image->width) crop.width = image->width - crop.x;
|
||||||
if ((crop.y + crop.height) > image->height) crop.height = image->height - crop.y;
|
if ((crop.y + crop.height) > image->height) crop.height = image->height - crop.y;
|
||||||
if ((crop.x > image->width) || (crop.y > image->height))
|
if ((crop.x > image->width) || (crop.y > image->height) || (crop.width < 1) || (crop.height < 1))
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "IMAGE: Failed to crop, rectangle out of bounds");
|
TRACELOG(LOG_WARNING, "IMAGE: Failed to crop, rectangle out of bounds");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cropX = (int)crop.x;
|
||||||
|
int cropY = (int)crop.y;
|
||||||
|
int cropWidth = (int)crop.width;
|
||||||
|
int cropHeight = (int)crop.height;
|
||||||
|
|
||||||
if (image->mipmaps > 1) TRACELOG(LOG_WARNING, "Image manipulation only applied to base mipmap level");
|
if (image->mipmaps > 1) TRACELOG(LOG_WARNING, "Image manipulation only applied to base mipmap level");
|
||||||
if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
|
if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
|
int bytesPerPixel = GetPixelDataSize(1, 1, image->format);
|
||||||
|
|
||||||
unsigned char *croppedData = (unsigned char *)RL_MALLOC((int)(crop.width*crop.height)*bytesPerPixel);
|
unsigned char *croppedData = (unsigned char *)RL_MALLOC(cropWidth*cropHeight*bytesPerPixel);
|
||||||
|
|
||||||
// OPTION 1: Move cropped data line-by-line
|
// OPTION 1: Move cropped data line-by-line
|
||||||
for (int y = (int)crop.y, offsetSize = 0; y < (int)(crop.y + crop.height); y++)
|
for (int y = cropY, offsetSize = 0; y < cropY + cropHeight; y++)
|
||||||
{
|
{
|
||||||
memcpy(croppedData + offsetSize, ((unsigned char *)image->data) + (y*image->width + (int)crop.x)*bytesPerPixel, (int)crop.width*bytesPerPixel);
|
memcpy(croppedData + offsetSize, ((unsigned char *)image->data) + (y*image->width + cropX)*bytesPerPixel, cropWidth*bytesPerPixel);
|
||||||
offsetSize += ((int)crop.width*bytesPerPixel);
|
offsetSize += (cropWidth*bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// OPTION 2: Move cropped data pixel-by-pixel or byte-by-byte
|
// OPTION 2: Move cropped data pixel-by-pixel or byte-by-byte
|
||||||
for (int y = (int)crop.y; y < (int)(crop.y + crop.height); y++)
|
for (int y = cropY; y < cropY + cropHeight; y++)
|
||||||
{
|
{
|
||||||
for (int x = (int)crop.x; x < (int)(crop.x + crop.width); x++)
|
for (int x = cropX; x < cropX + cropWidth; x++)
|
||||||
{
|
{
|
||||||
//memcpy(croppedData + ((y - (int)crop.y)*(int)crop.width + (x - (int)crop.x))*bytesPerPixel, ((unsigned char *)image->data) + (y*image->width + x)*bytesPerPixel, bytesPerPixel);
|
//memcpy(croppedData + ((y - cropY)*cropWidth + (x - cropX))*bytesPerPixel, ((unsigned char *)image->data) + (y*image->width + x)*bytesPerPixel, bytesPerPixel);
|
||||||
for (int i = 0; i < bytesPerPixel; i++) croppedData[((y - (int)crop.y)*(int)crop.width + (x - (int)crop.x))*bytesPerPixel + i] = ((unsigned char *)image->data)[(y*image->width + x)*bytesPerPixel + i];
|
for (int i = 0; i < bytesPerPixel; i++) croppedData[((y - cropY)*cropWidth + (x - cropX))*bytesPerPixel + i] = ((unsigned char *)image->data)[(y*image->width + x)*bytesPerPixel + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RL_FREE(image->data);
|
RL_FREE(image->data);
|
||||||
image->data = croppedData;
|
image->data = croppedData;
|
||||||
image->width = (int)crop.width;
|
image->width = cropWidth;
|
||||||
image->height = (int)crop.height;
|
image->height = cropHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user