This commit is contained in:
Camilla Berglund 2014-02-13 01:58:50 +01:00
parent 4de19165c0
commit cca7589486
7 changed files with 53 additions and 66 deletions

View File

@ -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);
/*! @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] icons A pointer to the first element of an array of GLFWimage structs.
* @param[in] numicons The number of icons in the given array.
* @ingroup window
* @param[in] icons An array of @ref GLFWimage structs.
* @param[in] count The number of icons in the array.
*
* @note This function may only be called from the main thread.
*
* @note From all the given icons GLFW will automatically pick the most appropriate
* size for the different locations in which the application icon can occur. For
* example on Windows, if a larger and a smaller icon are given the larger icon
* will be used for the ALT-TAB screen and the smaller for the taskbar.
* @note From all the given icons GLFW will automatically pick the most
* appropriate size for the different locations in which the application icon
* can occur. For example on Windows, if a larger and a smaller icon are given
* 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
* icon size the icon will be automatically resized.
* @note If the icon does not exactly fit the operating systems requirements
* 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.
*

View File

@ -1042,9 +1042,9 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
*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)

View File

@ -542,7 +542,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, int* left, int* top, i
/*! @copydoc glfwSetWindowIcons
* @ingroup platform
*/
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int numicons);
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count);
/*! @copydoc glfwIconifyWindow
* @ingroup platform

View File

@ -759,14 +759,10 @@ static HICON createIcon(GLFWimage* image)
// first we need to convert RGBA to BGRA (yay Windows!)
// we also need to convert lines, because Windows wants bottom-to-top RGBA
BGRAData = malloc(image->width * image->height * 4);
if (!BGRAData)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
BGRAData = calloc(1, image->width * image->height * 4);
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 *src = image->pixels + 4 * i;
@ -801,19 +797,17 @@ static HICON createIcon(GLFWimage* image)
// 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* bestIcon = curIcon;
const double targetRatio = (double) targetWidth / targetHeight;
while (curIcon < icons + numicons)
while (curIcon < icons + count)
{
// always use exact match
if (curIcon->width == targetWidth && curIcon->height == targetHeight)
{
return curIcon;
}
// at least wide or high enough, ratio preferably as close as possible
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;
if (curDelta < 0)
{
curDelta = -curDelta;
}
if (bestDelta < 0)
{
bestDelta = -bestDelta;
}
// if our ratio is closer OR if the best icon so far isn't large
// 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)
{
if (curIcon->width * curIcon->height > bestIcon->width * bestIcon->height)
{
bestIcon = curIcon;
}
}
++curIcon;
curIcon++;
}
return bestIcon;
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
@ -1059,13 +1048,13 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
*bottom = rect.bottom - height;
}
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage *icons, int numicons)
void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count)
{
GLFWimage* normalicon;
GLFWimage* smallicon;
normalicon = bestFit(icons, numicons, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
smallicon = bestFit(icons, numicons, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
normalicon = bestFit(icons, count, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
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_SMALL, (LPARAM) createIcon(smallicon));

View File

@ -513,17 +513,18 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle,
_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;
_GLFW_REQUIRE_INIT();
if (numicons < 1)
if (count < 1)
{
_glfwInputError(GLFW_INVALID_VALUE, "No icons specified");
return;
}
_glfwPlatformSetWindowIcons(window, icons, numicons);
_glfwPlatformSetWindowIcons(window, icons, count);
}
GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)

View File

@ -1645,9 +1645,9 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
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)

View File

@ -63,7 +63,8 @@ const unsigned char icon_colors[5][4] = {
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;
int x, y;
char* pixels;
@ -73,17 +74,9 @@ static void set_icon(GLFWwindow* window, int icon_color) {
img.height = 16;
pixels = malloc(img.width * img.height * 4);
if (!pixels)
for (x = 0; x < 16; x++)
{
glfwTerminate();
fprintf(stderr, "Failed to allocate memory.\n");
exit(EXIT_FAILURE);
}
for (x = 0; x < 16; ++x)
{
for (y = 0; y < 16; ++y)
for (y = 0; y < 16; y++)
{
// 15 - y because we need to flip the icon
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)
{
GLFWwindow* window;
@ -146,6 +138,6 @@ int main(int argc, char** argv)
}
glfwTerminate();
return EXIT_SUCCESS;
exit(EXIT_SUCCESS);
}