-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.c
More file actions
123 lines (102 loc) · 3.26 KB
/
helpers.c
File metadata and controls
123 lines (102 loc) · 3.26 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// helpers.c by Amash Shafi Jami
#include "helpers.h"
void MenuItemAssignTitle(MenuItemStruct* mis, LPCSTR szTitle){
StringCchPrintf(mis->szTitle,MENU_ITEM_CHAR_SIZE,_TEXT("%s"),szTitle);
}
void PopUpMenuItemAssignTitle(PopupMenuItemStruct* pmis, LPCSTR szTitle){
StringCchPrintf(pmis->szTitle,MENU_ITEM_CHAR_SIZE,_TEXT("%s"),szTitle);
}
void fndefPMISClickCallback(LPCSTR title){
printf("Menu Item %s Clicked!");
}
int getPMISAItemCount(PopupMenuItemStructArray* PMISA){
return PMISA->count;
}
PopupMenuItemStruct* GetBasePMIS(void){
PopupMenuItemStruct* basePMIS = (PopupMenuItemStruct*)malloc(sizeof(PopupMenuItemStruct));
basePMIS->ColScheme.Active = RGB(220,220,220);
basePMIS->ColScheme.Border = basePMIS->ColScheme.Active;
basePMIS->ColScheme.Passive = RGB(255,255,255);
basePMIS->OnClick = fndefPMISClickCallback;
PopUpMenuItemAssignTitle(basePMIS,"Popup Menu Item");
return basePMIS;
}
PopupMenuItemStructArray* getBasePMISA(void)
{
PopupMenuItemStructArray* pmisa =
(PopupMenuItemStructArray*)calloc(1, sizeof(PopupMenuItemStructArray));
pmisa->count = 0;
return pmisa;
}
void PMISA_AddEx(
PopupMenuItemStructArray* pmisa,
LPCSTR title,
OnClickCallback cb,
ColorSchemeStruct scheme
){
if (pmisa->count >= MAX_POPUP_ITEMS) return;
PopupMenuItemStruct* item =
(PopupMenuItemStruct*)malloc(sizeof(PopupMenuItemStruct));
PopUpMenuItemAssignTitle(item, title);
item->OnClick = cb;
item->ColScheme = scheme;
pmisa->array[pmisa->count++] = item;
}
MenuItemStruct* GetBaseMIS(void)
{
MenuItemStruct* baseMIS = (MenuItemStruct*)malloc(sizeof(MenuItemStruct));
baseMIS->cxOffset = 0;
baseMIS->isHovered = FALSE;
baseMIS->isRightMost = FALSE;
baseMIS->isStrLong = FALSE;
baseMIS->ColScheme.BorderWidth = 1;
baseMIS->cxTextPadding = 5;
baseMIS->ColScheme.Active = RGB(220,220,220);
baseMIS->ColScheme.Border = baseMIS->ColScheme.Active;
baseMIS->ColScheme.Passive = RGB(255,255,255);
baseMIS->hPopUp = NULL;
baseMIS->WidthFactor = 100;
MenuItemAssignTitle(baseMIS,"Menu Item");
return baseMIS;
}
BOOL fnIsPsuedoStringRequired(int maxChars, LPCSTR src){
int len = lstrlenA(src);
if (len <= maxChars) return FALSE;
return TRUE;
}
LPCSTR fnGetPseudoString(int maxChars, LPCSTR src)
{
static char out[256];
int len = lstrlenA(src);
if (len <= maxChars)
return src;
int left = (maxChars - 3) / 2;
int right = (maxChars - 3) - left;
CopyMemory(out, src, left);
out[left] = '.';
out[left+1] = '.';
out[left+2] = '.';
CopyMemory(out + left + 3, src + len - right, right);
out[maxChars] = '\0';
return out;
}
int fnGetCountCaps(LPCSTR string){
int iCaps = 0;
int iLen = lstrlenA(string);
for (int i = 0; i < iLen; i++)
{
if (isupper((unsigned char)string[i]))
iCaps++;
}
return iCaps;
}
int fnGetCountAve(LPCSTR string){
int iAve = 0;
int iLen = lstrlenA(string);
for (int i = 0; i < iLen; i++)
{
if (!isupper((unsigned char)string[i]))
iAve++;
}
return iAve;
}