?? iconmenu.c
字號:
/*-----------------------------------------------------------
函數 icon_menu : 圖標式菜單
-----------------------------------------------------------*/
#include <hanenv.h>
unsigned _Cdecl icon_menu(menu)
ICON_MENU *menu; /* 圖標式菜單 */
{
int mouse_x,mouse_y; /* 鼠標光標的位置 */
unsigned key = 0; /* 鍵盤鍵碼及返回碼 */
/*-- 查詢鼠標光標的位置及鼠標按鈕狀態 -----------------*/
key = get_mouse_status(&mouse_x,&mouse_y);
/*-- 如果鼠標移動了 -----------------------------------*/
if(mouse_x != menu->mouse_x || mouse_y != menu->mouse_y)
{
int i;
/*-- 查看每個菜單條目中的圖標范圍 -----------------*/
for(i=0;i<menu->icon_count;i++)
/*-- 如果鼠標光標進入了某個圖標的范圍 ---------*/
if(mouse_enter(menu->icons[i].x,menu->icons[i].y,
menu->icons[i].x+menu->icons[i].width,
menu->icons[i].y+menu->icons[i].high)
&& i != menu->current)
{
/*-- 如果當前條目有圖標繪制函數,抹去圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,NO);
/*-- 修正當前菜單條目 ---------------------*/
menu->current = i;
/*-- 如果當前條目有圖標繪制函數,重畫圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,YES);
/*-- 顯示新當前菜單條目的說明 -------------*/
_Bar(menu->x,menu->y,menu->width,_Ytimes*CHAR_HIGH,_TitleBk,0xffff0000);
drawxystr(menu->x,menu->y,_TitleColor,menu->icons[menu->current].title);
}
/*-- 記下鼠標光標的新位置 -------------------------*/
menu->mouse_x = mouse_x;
menu->mouse_y = mouse_y;
}
/*-- 如果允許使用鍵盤控制圖標式菜單并且有鍵按下 -------*/
if(menu->arrow_ctrl && bioskey(1))
{
/*-- 讀鍵盤緩沖區中的鍵盤碼 -----------------------*/
key = geth();
/*-- 如果是向前移動鍵 -----------------------------*/
if(key == menu->forward1 || key == menu->forward2)
{
/*-- 如果當前菜單條目有圖標繪制函數,抹去圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,NO);
/*-- 調整當前菜單條目 -------------------------*/
if(menu->current == menu->icon_count-1)
menu->current = 0;
else
menu->current++;
/*-- 如果當前菜單條目有圖標繪制函數,重畫圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,YES);
/*-- 顯示新當前菜單條目的說明 -----------------*/
_Bar(menu->x,menu->y,menu->width,_Ytimes*CHAR_HIGH,_TitleBk,0xffff0000);
drawxystr(menu->x,menu->y,_TitleColor,menu->icons[menu->current].title);
}
/*-- 如果是向后移動鍵 -----------------------------*/
else if(key == menu->backward1 || key == menu->backward2)
{
/*-- 如果當前菜單條目有圖標繪制函數,抹去圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,NO);
/*-- 調整當前菜單條目 -------------------------*/
if(menu->current == 0)
menu->current = menu->icon_count-1;
else
menu->current--;
/*-- 如果當前菜單條目有圖標繪制函數,重畫圖標 --*/
if(menu->icons[menu->current].draw_icon)
(*(menu->icons[menu->current].draw_icon))(menu->icons+menu->current,YES);
/*-- 顯示新當前菜單條目的說明 -----------------*/
_Bar(menu->x,menu->y,menu->width,_Ytimes*CHAR_HIGH,_TitleBk,0xffff0000);
drawxystr(menu->x,menu->y,_TitleColor,menu->icons[menu->current].title);
}
/*-- 如果是項目選擇鍵 -----------------------------*/
else if(key == menu->press_key1 || key == menu->press_key2)
{
/*-- 如果當前菜單條目有對應處理函數,調用之 ----*/
if(menu->icons[menu->current].fun)
return (*(menu->icons[menu->current].fun))(menu->icons[menu->current]);
/*-- 否則返回當前條目的返回鍵碼 ---------------*/
else
return menu->icons[menu->current].key;
}
}
/*-- 如果按下了鼠標左鍵且鼠標光標在當前圖標上 ---------*/
if(key == LEFT_BUTTON &&
mouse_enter(menu->icons[menu->current].x,
menu->icons[menu->current].y,
menu->icons[menu->current].x+menu->icons[menu->current].width,
menu->icons[menu->current].y+menu->icons[menu->current].high))
{
/*-- 如果當前菜單條目有對應處理函數,調用之 --------*/
if(menu->icons[menu->current].fun)
return (*(menu->icons[menu->current].fun))(menu->icons[menu->current]);
/*-- 否則返回當前條目的返回鍵碼 -------------------*/
else
return menu->icons[menu->current].key;
}
/*-- 返回0表示此次應繼續對圖標式菜單進行操作 ----------*/
return key;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -