mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 13:20:58 +00:00
Cleanup.
This commit is contained in:
parent
4de19165c0
commit
cca7589486
@ -1916,23 +1916,28 @@ GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height)
|
|||||||
*/
|
*/
|
||||||
GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom);
|
GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom);
|
||||||
|
|
||||||
/*! @brief Sets the application icons to use for the given window.
|
/*! @brief Sets the icons for the specified window.
|
||||||
|
*
|
||||||
|
* This function sets the icons to be used by the specified window.
|
||||||
|
*
|
||||||
* @param[in] window The window to set the icons for.
|
* @param[in] window The window to set the icons for.
|
||||||
* @param[in] icons A pointer to the first element of an array of GLFWimage structs.
|
* @param[in] icons An array of @ref GLFWimage structs.
|
||||||
* @param[in] numicons The number of icons in the given array.
|
* @param[in] count The number of icons in the array.
|
||||||
* @ingroup window
|
|
||||||
*
|
*
|
||||||
* @note This function may only be called from the main thread.
|
* @note This function may only be called from the main thread.
|
||||||
*
|
*
|
||||||
* @note From all the given icons GLFW will automatically pick the most appropriate
|
* @note From all the given icons GLFW will automatically pick the most
|
||||||
* size for the different locations in which the application icon can occur. For
|
* appropriate size for the different locations in which the application icon
|
||||||
* example on Windows, if a larger and a smaller icon are given the larger icon
|
* can occur. For example on Windows, if a larger and a smaller icon are given
|
||||||
* will be used for the ALT-TAB screen and the smaller for the taskbar.
|
* the larger icon will be used for the Alt+Tab screen and the smaller for the
|
||||||
|
* taskbar.
|
||||||
*
|
*
|
||||||
* @note If the icon does not exactly fit the operating systems requirements for the
|
* @note If the icon does not exactly fit the operating systems requirements
|
||||||
* icon size the icon will be automatically resized.
|
* for the icon size the icon will be automatically resized.
|
||||||
|
*
|
||||||
|
* @ingroup window
|
||||||
*/
|
*/
|
||||||
GLFWAPI void glfwSetWindowIcons(GLFWwindow* window, GLFWimage* icons, int numicons);
|
GLFWAPI void glfwSetWindowIcons(GLFWwindow* window, GLFWimage* icons, int count);
|
||||||
|
|
||||||
/*! @brief Iconifies the specified window.
|
/*! @brief Iconifies the specified window.
|
||||||
*
|
*
|
||||||
|
@ -1042,9 +1042,9 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|||||||
*bottom = contentRect.origin.y - frameRect.origin.y;
|
*bottom = contentRect.origin.y - frameRect.origin.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage *icons, int numicons)
|
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count)
|
||||||
{
|
{
|
||||||
/* TODO: implement this */
|
// TODO: Implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||||
|
@ -542,7 +542,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, i
|
|||||||
/*! @copydoc glfwSetWindowIcons
|
/*! @copydoc glfwSetWindowIcons
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
*/
|
*/
|
||||||
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int numicons);
|
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count);
|
||||||
|
|
||||||
/*! @copydoc glfwIconifyWindow
|
/*! @copydoc glfwIconifyWindow
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
|
@ -759,15 +759,11 @@ static HICON createIcon(GLFWimage* image)
|
|||||||
|
|
||||||
// first we need to convert RGBA to BGRA (yay Windows!)
|
// first we need to convert RGBA to BGRA (yay Windows!)
|
||||||
// we also need to convert lines, because Windows wants bottom-to-top RGBA
|
// we also need to convert lines, because Windows wants bottom-to-top RGBA
|
||||||
BGRAData = malloc(image->width * image->height * 4);
|
BGRAData = calloc(1, image->width * image->height * 4);
|
||||||
if (!BGRAData)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < image->width * image->height; i++) {
|
for (i = 0; i < image->width * image->height; i++)
|
||||||
unsigned char *dst = BGRAData + 4 * i;
|
{
|
||||||
|
unsigned char* dst = BGRAData + 4 * i;
|
||||||
unsigned char *src = image->pixels + 4 * i;
|
unsigned char *src = image->pixels + 4 * i;
|
||||||
|
|
||||||
dst[0] = src[2]; // copy blue channel
|
dst[0] = src[2]; // copy blue channel
|
||||||
@ -801,19 +797,17 @@ static HICON createIcon(GLFWimage* image)
|
|||||||
|
|
||||||
// Chooses the best fitting image given the images and desired size
|
// Chooses the best fitting image given the images and desired size
|
||||||
//
|
//
|
||||||
static GLFWimage* bestFit(GLFWimage *icons, const int numicons, const int targetWidth, const int targetHeight)
|
static GLFWimage* bestFit(GLFWimage* icons, const int count, const int targetWidth, const int targetHeight)
|
||||||
{
|
{
|
||||||
GLFWimage *curIcon = icons;
|
GLFWimage* curIcon = icons;
|
||||||
GLFWimage *bestIcon = curIcon;
|
GLFWimage* bestIcon = curIcon;
|
||||||
const double targetRatio = (double) targetWidth / targetHeight;
|
const double targetRatio = (double) targetWidth / targetHeight;
|
||||||
|
|
||||||
while (curIcon < icons + numicons)
|
while (curIcon < icons + count)
|
||||||
{
|
{
|
||||||
// always use exact match
|
// always use exact match
|
||||||
if (curIcon->width == targetWidth && curIcon->height == targetHeight)
|
if (curIcon->width == targetWidth && curIcon->height == targetHeight)
|
||||||
{
|
|
||||||
return curIcon;
|
return curIcon;
|
||||||
}
|
|
||||||
|
|
||||||
// at least wide or high enough, ratio preferably as close as possible
|
// at least wide or high enough, ratio preferably as close as possible
|
||||||
if (curIcon->width >= targetWidth || curIcon->height >= targetHeight)
|
if (curIcon->width >= targetWidth || curIcon->height >= targetHeight)
|
||||||
@ -824,14 +818,10 @@ static GLFWimage* bestFit(GLFWimage *icons, const int numicons, const int target
|
|||||||
double bestDelta = targetRatio - bestRatio;
|
double bestDelta = targetRatio - bestRatio;
|
||||||
|
|
||||||
if (curDelta < 0)
|
if (curDelta < 0)
|
||||||
{
|
|
||||||
curDelta = -curDelta;
|
curDelta = -curDelta;
|
||||||
}
|
|
||||||
|
|
||||||
if (bestDelta < 0)
|
if (bestDelta < 0)
|
||||||
{
|
|
||||||
bestDelta = -bestDelta;
|
bestDelta = -bestDelta;
|
||||||
}
|
|
||||||
|
|
||||||
// if our ratio is closer OR if the best icon so far isn't large
|
// if our ratio is closer OR if the best icon so far isn't large
|
||||||
// enough we'll become the new best icon
|
// enough we'll become the new best icon
|
||||||
@ -847,17 +837,16 @@ static GLFWimage* bestFit(GLFWimage *icons, const int numicons, const int target
|
|||||||
else if (bestIcon->width < targetWidth && bestIcon->height < targetHeight)
|
else if (bestIcon->width < targetWidth && bestIcon->height < targetHeight)
|
||||||
{
|
{
|
||||||
if (curIcon->width * curIcon->height > bestIcon->width * bestIcon->height)
|
if (curIcon->width * curIcon->height > bestIcon->width * bestIcon->height)
|
||||||
{
|
|
||||||
bestIcon = curIcon;
|
bestIcon = curIcon;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++curIcon;
|
curIcon++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestIcon;
|
return bestIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW internal API //////
|
////// GLFW internal API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -1059,13 +1048,13 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|||||||
*bottom = rect.bottom - height;
|
*bottom = rect.bottom - height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage *icons, int numicons)
|
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count)
|
||||||
{
|
{
|
||||||
GLFWimage* normalicon;
|
GLFWimage* normalicon;
|
||||||
GLFWimage* smallicon;
|
GLFWimage* smallicon;
|
||||||
|
|
||||||
normalicon = bestFit(icons, numicons, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
|
normalicon = bestFit(icons, count, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
|
||||||
smallicon = bestFit(icons, numicons, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
|
smallicon = bestFit(icons, count, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
|
||||||
|
|
||||||
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) createIcon(normalicon));
|
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) createIcon(normalicon));
|
||||||
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) createIcon(smallicon));
|
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) createIcon(smallicon));
|
||||||
|
@ -513,17 +513,18 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
|
|||||||
_glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
|
_glfwPlatformGetWindowFrameSize(window, left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwSetWindowIcons(GLFWwindow* handle, GLFWimage* icons, int numicons)
|
GLFWAPI void glfwSetWindowIcons(GLFWwindow* handle, GLFWimage* icons, int count)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
_GLFW_REQUIRE_INIT();
|
_GLFW_REQUIRE_INIT();
|
||||||
|
|
||||||
if (numicons < 1)
|
if (count < 1)
|
||||||
{
|
{
|
||||||
|
_glfwInputError(GLFW_INVALID_VALUE, "No icons specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwPlatformSetWindowIcons(window, icons, numicons);
|
_glfwPlatformSetWindowIcons(window, icons, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
|
GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
|
||||||
|
@ -1645,9 +1645,9 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|||||||
XFree(extents);
|
XFree(extents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage *icons, int numicons)
|
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count)
|
||||||
{
|
{
|
||||||
/* TODO: implement this */
|
// TODO: Implement this
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// a simple glfw logo
|
// a simple glfw logo
|
||||||
const char * const logo[] = {
|
const char* const logo[] = {
|
||||||
"................",
|
"................",
|
||||||
"................",
|
"................",
|
||||||
"...0000..0......",
|
"...0000..0......",
|
||||||
@ -54,16 +54,17 @@ const char * const logo[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const unsigned char icon_colors[5][4] = {
|
const unsigned char icon_colors[5][4] = {
|
||||||
{0x00, 0x00, 0x00, 0xff}, // black
|
{ 0x00, 0x00, 0x00, 0xff }, // black
|
||||||
{0xff, 0x00, 0x00, 0xff}, // red
|
{ 0xff, 0x00, 0x00, 0xff }, // red
|
||||||
{0x00, 0xff, 0x00, 0xff}, // green
|
{ 0x00, 0xff, 0x00, 0xff }, // green
|
||||||
{0xff, 0x00, 0xff, 0xff}, // blue
|
{ 0xff, 0x00, 0xff, 0xff }, // blue
|
||||||
{0xff, 0xff, 0xff, 0xff} // white
|
{ 0xff, 0xff, 0xff, 0xff } // white
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cur_icon_color = 0;
|
static int cur_icon_color = 0;
|
||||||
|
|
||||||
static void set_icon(GLFWwindow* window, int icon_color) {
|
static void set_icon(GLFWwindow* window, int icon_color)
|
||||||
|
{
|
||||||
GLFWimage img;
|
GLFWimage img;
|
||||||
int x, y;
|
int x, y;
|
||||||
char* pixels;
|
char* pixels;
|
||||||
@ -73,17 +74,9 @@ static void set_icon(GLFWwindow* window, int icon_color) {
|
|||||||
img.height = 16;
|
img.height = 16;
|
||||||
pixels = malloc(img.width * img.height * 4);
|
pixels = malloc(img.width * img.height * 4);
|
||||||
|
|
||||||
if (!pixels)
|
for (x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
for (y = 0; y < 16; y++)
|
||||||
|
|
||||||
fprintf(stderr, "Failed to allocate memory.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (x = 0; x < 16; ++x)
|
|
||||||
{
|
|
||||||
for (y = 0; y < 16; ++y)
|
|
||||||
{
|
{
|
||||||
// 15 - y because we need to flip the icon
|
// 15 - y because we need to flip the icon
|
||||||
if (logo[15 - y][x] == '0')
|
if (logo[15 - y][x] == '0')
|
||||||
@ -116,7 +109,6 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
@ -146,6 +138,6 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user