diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:56:41 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-04 11:59:33 -0800 |
commit | d577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch) | |
tree | 590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/win/iupwin_brush.c |
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/win/iupwin_brush.c')
-rwxr-xr-x | iup/src/win/iupwin_brush.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/iup/src/win/iupwin_brush.c b/iup/src/win/iupwin_brush.c new file mode 100755 index 0000000..228e6d4 --- /dev/null +++ b/iup/src/win/iupwin_brush.c @@ -0,0 +1,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); +} |