📄 menu.c
字号:
#include "GUI.h"
#include "Globalvars.h"
#include "pwin.h"
#include "guidebug.h"
#include "MainMenu.h"
//--------------------------------------------------
void DrawMenuItems(Pw_GC* gc, Pw_MENU* menu) {
int x, y, dy, dw, itemW;
int i;
// Pw_Coord w, h;
Pw_Window* win;
MENU_ITEM * itemrec;
GUI_ConstString * s;
int Checked;
win = Pw_GCGetWindow(gc);
// Pw_WindowGetSize(win, &w, &h);
dy = Pw_GCGetFontHeight(gc);
x = 7;/*(Pw_WindowGetX(win) + 7);// & 0xFFF8; */
if (menu->Title)
y = 2*dy;
else
y = dy + dy/2;
dw = Pw_WindowGetWidth(win) - 6;
itemrec = menu->Items;
for (i = 0; i < menu->NumItems; i++) {
if (i == menu->Selected) {
// Pw_DrawGrayTextBackgr(gc, x-2, y-dy+Pw_GCGetFontDescent(gc), dw-4, dy);
Pw_GCSetColor(gc, pw_white_pixel);
Pw_FillRect(gc, x-2, y-dy+Pw_GCGetFontDescent(gc), dw-4, dy);
Pw_GCSetColor(gc, pw_black_pixel);
}
else {
Pw_GCSetColor(gc, pw_black_pixel);
Pw_FillRect(gc, x-2, y-dy+Pw_GCGetFontDescent(gc), dw-4, dy);
Pw_GCSetColor(gc, pw_white_pixel);
}
// Pw_GCSetColor(gc, pw_white_pixel);
s = (GUI_ConstString *)itemrec->Item;
Pw_DrawString(gc, x+4, y, (char *) s);
itemW = Pw_GCGetStringWidth(gc, "OFF") + 8;
if (itemrec->Toggled) {
itemrec->OnSelection(&Checked);
if (Checked)
Pw_DrawString(gc, x + dw - itemW, y, (char *) "ON");
else
Pw_DrawString(gc, x + dw - itemW, y, (char *) "OFF");
}
itemrec++;
y += dy;
}
}
//--------------------------------------------------
void cbRepaintMenu (Pw_GC* gc) {
Pw_Window* win;
Pw_MENU * mnu;Pw_Coord w, h;
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
//GUI_Log3("Repeint ", (long) win, w, h);
mnu = (Pw_MENU *) Pw_WindowGetClientData(win);
Pw_GCSetFont(gc, mnu->Font);
Pw_DrawFrameRect(gc, 0, 0, w, h, 2, mnu->Title);
DrawMenuItems(gc, mnu);
}
//--------------------------------------------------
int cbMenuEventHandler (Pw_Event* event) {
Pw_Window* win;
Pw_MENU * mnu;
Pw_MENU * sub_menu;
Pw_uInt key;
MENU_ITEM * item;
//GUI_Log("MENU CALLBACK");
win = Pw_EventGetWindow(event);
mnu = Pw_WindowGetClientData(win);
switch (Pw_EventGetType(event)) {
case Pw_KeyPressEventType:
key = event->key.keycode;
switch (key) {
case DOWN_KEY :
if (mnu->Selected < (mnu->NumItems-1)) {
mnu->Selected++;
Pw_WindowRepaint(win);
// GUI_Log1("Selected ", mnu->Selected);
return TRUE;
}
break;
case UP_KEY :
if (mnu->Selected > 0) {
mnu->Selected--;
Pw_WindowRepaint(win);
// GUI_Log1("Selected ", mnu->Selected);
return TRUE;
}
break;
case ESC_KEY :
// GUI_Log1("Parent MENU ", (long)mnu->ParentMenu);
if (mnu->ParentMenu) {
Pw_WindowLeaveFocus(win);
Pw_WindowUnmap(win);
Pw_WindowMap(&(mnu->ParentMenu->mnuWin));
Pw_WindowSetFocus(&(mnu->ParentMenu->mnuWin));
Pw_WindowRepaint(Desktop);
return TRUE;
}
break;
case ENTER_KEY :
item = mnu->Items + mnu->Selected;
sub_menu = item->SubMenu;
if (sub_menu) {
Pw_WindowMap(&(sub_menu->mnuWin));
Pw_WindowSetFocus(&(sub_menu->mnuWin));
return TRUE;
}
else {
item = mnu->Items + mnu->Selected;
if (!item->Toggled) {
if (item->OnSelection != NULL) {
item->OnSelection(NULL);
return TRUE;
}
}
else {
item->OnSelection(NULL);
Pw_WindowRepaint(win);
}
}
break;
}
break;
}
return FALSE;
}
//--------------------------------------------------
int CreateMenu (Pw_MENU * menu, Pw_MENU * Owner, Pw_Window* Parent,
const MENU_ITEM * ItemData, char * aTitle, int itemcnt,
int x, int y, int w, int h){
menu->Font = F9x15_pwf;
menu->Title = aTitle;
menu->NumItems = itemcnt;
if (menu->Title)
h = Pw_FontGetHeight(menu->Font) * (menu->NumItems + 2);
else
h = Pw_FontGetHeight(menu->Font) * (menu->NumItems + 1) + 4;
Pw_WindowCreate(Parent, x, y, w, h, &menu->mnuWin);
Pw_WindowSetClientData(&(menu->mnuWin), menu);
Pw_WindowSetRepaintCallback(&(menu->mnuWin), cbRepaintMenu);
Pw_WindowSetEventCallback(&(menu->mnuWin), cbMenuEventHandler);
menu->ParentMenu = Owner;
menu->Items = ItemData;
menu->Selected = 0;
// Pw_WindowMap(&(menu->mnuWin));
Pw_WindowSetFocusAccept(&(menu->mnuWin), TRUE);
return TRUE;
}
/*
void SetToggleItemMenu (Pw_MENU * menu, int item) {
menu->IsToggle = TRUE;
if (menu->Items->OnSelection != NULL)
menu->Items->OnSelection(&(menu->Checked));
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -