blob: 228e6d4208d2822de8b978f9c21ef8e21d181e73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/** \file
* \brief Windows Brush Cache
*
* See Copyright Notice in "iup.h"
*/
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "iup.h"
#include "iup_array.h"
#include "iupwin_brush.h"
typedef struct _IwinBrush
{
HBRUSH hbrush;
COLORREF color;
} IwinBrush;
static Iarray* win_brushes = NULL;
HBRUSH iupwinBrushGet(COLORREF color)
{
int i, count = iupArrayCount(win_brushes);
/* If a brush with the desired color already exists... */
IwinBrush* brushes = (IwinBrush*)iupArrayGetData(win_brushes);
for (i = 0; i < count; i++)
{
if (brushes[i].color == color)
return brushes[i].hbrush;
}
/* If it doesn't exist, it should be created... */
brushes = (IwinBrush*)iupArrayInc(win_brushes);
brushes[i].color = color;
brushes[i].hbrush = CreateSolidBrush(color);
return brushes[i].hbrush;
}
void iupwinBrushInit(void)
{
win_brushes = iupArrayCreate(50, sizeof(IwinBrush));
}
void iupwinBrushFinish(void)
{
int i, count = iupArrayCount(win_brushes);
IwinBrush* brushes = (IwinBrush*)iupArrayGetData(win_brushes);
for (i = 0; i < count; i++)
{
DeleteObject(brushes[i].hbrush);
brushes[i].hbrush = NULL;
}
iupArrayDestroy(win_brushes);
}
|