10 #define menu_free_item(item) if(item) free(item->str)
12 extern int* get_tex_flag_address();
16 void draw_menu(Menu
* menu
)
20 int border
= 1, margin
= 2, check_box_width
= 15, item_height
= 7, letter_width
= 4;// inter_line = 1;
24 for(i
=0; i
< menu
->items_number
; i
++) {
25 tmp
= strlen(menu
->items
[i
]->str
) * letter_width
;
26 if(menu
->items
[i
]->type
== CHECK_BOX
) tmp
+= check_box_width
;
28 if(tmp
> longest
) longest
= tmp
;
31 box
.left
= (WIDTH
/2) - (longest
/2) - margin
- border
;
32 box
.right
= box
.left
+ longest
+ 2*margin
+ 2*border
;
33 box
.bottom
= (HEIGHT
/2) + (menu
->items_number
* item_height
)/2 /*+ margin*/ + border
;
34 box
.top
= HEIGHT
- box
.bottom
;
36 Bdisp_AreaClr_VRAM(&box
);
38 Bdisp_AreaReverseVRAM(box
.left
, box
.top
, box
.right
, box
.bottom
);
40 Bdisp_AreaReverseVRAM(box
.left
+ border
, box
.top
+ border
, box
.right
- border
, box
.bottom
- border
);
42 while (key
!= KEY_CTRL_EXIT
) {
43 for(i
=0; i
< menu
->items_number
; i
++) {
44 PrintMini(box
.left
+ border
+ margin
, box
.top
+ margin
+ item_height
*i
, (unsigned char*)menu
->items
[i
]->str
, MINI_OVER
);
45 if(menu
->items
[i
]->type
== CHECK_BOX
) {
46 if((menu
->items
[i
]->action
.val
.value
)) {
47 if(*(menu
->items
[i
]->action
.val
.value
)) PrintMini(box
.right
- border
- margin
- (check_box_width
/2) , box
.top
+ margin
+ item_height
*i
, (unsigned char*)"[x]", MINI_OVER
);
48 else PrintMini(box
.right
- border
- margin
- (check_box_width
/2) , box
.top
+ margin
+ item_height
*i
, (unsigned char*)"[ ]", MINI_OVER
);
52 PrintMini(box
.left
+ border
+ margin
, box
.top
+ margin
+ item_height
*cursor_y
, (unsigned char*)menu
->items
[cursor_y
]->str
, MINI_REV
);
53 if(menu
->items
[cursor_y
]->type
== CHECK_BOX
) {
54 if((menu
->items
[cursor_y
]->action
.val
.value
)) {
55 if(*(menu
->items
[cursor_y
]->action
.val
.value
)) PrintMini(box
.right
- border
- margin
- (check_box_width
/2) , box
.top
+ margin
+ item_height
*cursor_y
, (unsigned char*)"[x]", MINI_OVER
);
56 else PrintMini(box
.right
- border
- margin
- (check_box_width
/2) , box
.top
+ margin
+ item_height
*cursor_y
, (unsigned char*)"[ ]", MINI_OVER
);
61 if (key
== KEY_CTRL_DOWN
&& cursor_y
< menu
->items_number
-1) cursor_y
++;
62 if (key
== KEY_CTRL_UP
&& cursor_y
> 0) cursor_y
--;
64 if (key
== KEY_CTRL_EXE
) {
66 if(menu
->items
[cursor_y
]->type
== CHECK_BOX
) {
67 if(menu
->items
[cursor_y
]->action
.val
.value
!= NULL
) { //Changing the state of the variable, as a boolean
68 if(*(menu
->items
[cursor_y
]->action
.val
.value
)) *(menu
->items
[cursor_y
]->action
.val
.value
) = 0;
69 else *(menu
->items
[cursor_y
]->action
.val
.value
) = 1;
71 if (menu
->items
[cursor_y
]->action
.val
.save_function
!= NULL
) (*menu
->items
[cursor_y
]->action
.val
.save_function
)();
74 else if(menu
->items
[cursor_y
]->type
== FUNCTION_CALL
) {
75 if(menu
->items
[cursor_y
]->action
.function
!= NULL
) {
76 (*(menu
->items
[cursor_y
]->action
.function
))(); //Calling the function
88 menu
.items
= malloc(sizeof(Menu_Item
*) * number
);
90 menu
.items
[0] = menu_create_item("About", FUNCTION_CALL
, menu_about
, (void*)NULL
);
91 menu
.items
[1] = menu_create_item("Pretty Print", CHECK_BOX
, get_tex_flag_address(), save_config
);
92 if(menu
.items
[0] && menu
.items
[1]) menu
.items_number
= number
;
94 menu_free_item(menu
.items
[0]);
95 menu_free_item(menu
.items
[1]);
100 menu_free_item(menu
.items
[0]);
101 menu_free_item(menu
.items
[1]);
109 PrintMini(12, 6, (unsigned char*)"Eigenmath symbolic maths", MINI_OVER
);
110 PrintMini(51, 14, (unsigned char*)"engine", MINI_OVER
);
111 PrintMini(12, 22, (unsigned char*)"Ported by Mike.", MINI_OVER
);
112 PrintMini(12, 30, (unsigned char*)"Enhanced by Nemh and the", MINI_OVER
);
113 PrintMini(38, 38, (unsigned char*)"PC community.", MINI_OVER
);
114 PrintMini(40, 46, (unsigned char*)"Early build", MINI_OVER
);
115 PrintMini(12, 54, (unsigned char*)"See : http://huit.re/eigen", MINI_OVER
);
120 Menu_Item
* menu_create_item(const char* str
, Menu_Item_Type type
, void* other
, void* save_func
)
122 Menu_Item
* item
= malloc(sizeof(Menu_Item
));
123 if(item
== NULL
) return NULL
;
125 item
->str
= malloc(sizeof(char)*(strlen(str
) + 1));
126 if(item
->str
== NULL
) {
130 else strcpy(item
->str
, str
);
134 if(type
== CHECK_BOX
) {
135 item
->action
.val
.value
= other
;
136 item
->action
.val
.save_function
= save_func
;
138 else if(type
== FUNCTION_CALL
) item
->action
.function
= other
;
145 memory_save(CONFIG_FILE
, (int*)get_tex_flag_address(), 4);
150 if(memory_exists(CONFIG_FILE
)) *(int*)(get_tex_flag_address()) = *((int*)memory_load(CONFIG_FILE
));