mirror of
https://github.com/raysan5/raylib.git
synced 2026-11-25 09:01:47 -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 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;
|
||||
if (angle < 0) angle += 360;
|
||||
@ -138,11 +138,12 @@ int main(void)
|
||||
Color color = ColorFromHSV((float)i/sliceCount*360.0f, 0.75f, 0.9f);
|
||||
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;
|
||||
|
||||
// Draw the pie slice using raylib's DrawCircleSector function
|
||||
DrawCircleSector(center, currentRadius, startAngle, startAngle + sweepAngle, 120, color);
|
||||
// Draw the pie slice (DrawRing() for donut mode)
|
||||
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
|
||||
if (values[i] > 0)
|
||||
@ -154,16 +155,12 @@ int main(void)
|
||||
else labelText[0] = '\0';
|
||||
|
||||
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,
|
||||
center.y + sinf(midAngle*DEG2RAD)*labelRadius - textSize.y/2.0f };
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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 + 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 },
|
||||
"Inner Radius", NULL, & donutInnerRadius, 5.0f, radius - 10.0f);
|
||||
GuiEnable();
|
||||
|
||||
@ -1677,8 +1677,10 @@ int InitPlatform(void)
|
||||
// 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
|
||||
// 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;
|
||||
if (CORE.Window.screen.height > (unsigned int)workHeight) CORE.Window.screen.height = workHeight;
|
||||
// NOTE: Some window managers report a workarea that does not overlap the primary monitor
|
||||
// (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);
|
||||
if (!platform.handle)
|
||||
|
||||
@ -1877,6 +1877,9 @@ void ClosePlatform(void)
|
||||
// Clear required platform data
|
||||
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
|
||||
// If this ever changes, this code may have to be updated
|
||||
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
|
||||
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
|
||||
if (crop.x < 0) { crop.width += crop.x; crop.x = 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.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");
|
||||
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->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats");
|
||||
else
|
||||
{
|
||||
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
|
||||
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);
|
||||
offsetSize += ((int)crop.width*bytesPerPixel);
|
||||
memcpy(croppedData + offsetSize, ((unsigned char *)image->data) + (y*image->width + cropX)*bytesPerPixel, cropWidth*bytesPerPixel);
|
||||
offsetSize += (cropWidth*bytesPerPixel);
|
||||
}
|
||||
|
||||
/*
|
||||
// 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);
|
||||
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];
|
||||
//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 - cropY)*cropWidth + (x - cropX))*bytesPerPixel + i] = ((unsigned char *)image->data)[(y*image->width + x)*bytesPerPixel + i];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
RL_FREE(image->data);
|
||||
image->data = croppedData;
|
||||
image->width = (int)crop.width;
|
||||
image->height = (int)crop.height;
|
||||
image->width = cropWidth;
|
||||
image->height = cropHeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user