示例#1
0
pascal void main(short message,MenuHandle theMenu,Rect *menuRect,Point hitPt,short *whichItem)
#endif
{
	short	i,j;
	short	currentItem;
	Rect	r;
	OSErr	err;
	long	response;
	#if TARGET_API_MAC_CARBON
	MenuTrackingData	*trackingData;
	HiliteMenuItemData	*hiliteData;
	#endif
	
	switch (message)
	{
		case kMenuDrawMsg:
			/* メニューの描画 */
			err=Gestalt(gestaltAppearanceAttr,&response);
			if (err==noErr && (response & (kGestaltMask << gestaltAppearanceExists)))
			{
				/* Appearance Managerのバージョンが1.0.1以降かどうか */
				err=Gestalt(gestaltAppearanceVersion,&response);
				if (err==noErr && response>=0x0101)
					#if powerc
						if (DrawThemeMenuBackground != nil)
					#endif
					err=DrawThemeMenuBackground(menuRect,kThemeMenuTypePopUp);
			}
			
			/* チェック */
			for (i=0; i<kRows; i++)
				for (j=0; j<kColumns; j++)
				{
					short	markChar;
					
					GetItemRect(&r,menuRect,i*kColumns+j);
					DrawItem(&r,i,j);
					GetItemMark(theMenu,i*kColumns+j+1,&markChar);
					if (markChar != noMark)
					{
						InsetRect(&r,2,2);
						PenMode(srcXor);
						FrameRect(&r);
						PenNormal();
					}
				}
			break;
		
		#if TARGET_API_MAC_CARBON
		case kMenuFindItemMsg:
			trackingData=(MenuTrackingData *)whichItem;
			
			currentItem=0;
			if (PtInRect(hitPt,menuRect))
			{
				for (i=0; i<kRows; i++)
					for (j=0; j<kColumns; j++)
					{
						GetItemRect(&r,menuRect,i*kColumns+j);
						if (PtInRect(hitPt,&r))
						{
							currentItem=i*kColumns+j+1;
							break;
						}
					}
			}
			trackingData->itemSelected = currentItem;
			trackingData->itemUnderMouse = currentItem;
			break;
		
		case kMenuHiliteItemMsg:
			hiliteData=(HiliteMenuItemData *)whichItem;
			
			if (hiliteData->previousItem != 0)
			{
				GetItemRect(&r,menuRect,hiliteData->previousItem-1);
				InsetRect(&r,1,1);
				PenMode(srcXor);
				FrameRect(&r);
				PenNormal();
			}
			if (hiliteData->newItem != 0)
			{
				GetItemRect(&r,menuRect,hiliteData->newItem-1);
				InsetRect(&r,1,1);
				PenMode(srcXor);
				FrameRect(&r);
				PenNormal();
			}
			break;
		#else
		case mChooseMsg:
			/* メニューの選択(反転) */
			currentItem=0;
			if (PtInRect(hitPt,menuRect))
			{
				for (i=0; i<kRows; i++)
					for (j=0; j<kColumns; j++)
					{
						GetItemRect(&r,menuRect,i*kColumns+j);
						if (PtInRect(hitPt,&r))
						{
							currentItem=i*kColumns+j+1;
							break;
						}
					}
			}
			if (currentItem!=*whichItem)
			{
				if (currentItem!=0)
				{
					GetItemRect(&r,menuRect,currentItem-1);
					InsetRect(&r,1,1);
					PenMode(srcXor);
					FrameRect(&r);
					PenNormal();
				}
				if (*whichItem!=0)
				{
					GetItemRect(&r,menuRect,*whichItem-1);
					InsetRect(&r,1,1);
					PenMode(srcXor);
					FrameRect(&r);
					PenNormal();
				}
				*whichItem=currentItem;
			}
			break;
		#endif
		
		case kMenuSizeMsg:
			/* メニューのサイズを設定 */
			#if TARGET_API_MAC_CARBON
			SetMenuWidth(theMenu,kRows*kItemWidth);
			SetMenuHeight(theMenu,kColumns*kItemHeight);
			#else
			(**theMenu).menuWidth=kRows*kItemWidth;
			(**theMenu).menuHeight=kColumns*kItemHeight;
			#endif
			break;
		
		case kMenuPopUpMsg:
			/* ポップアップのRectを計算 */
			/* theMenu		メニューへのハンドル
			   whichItem	最初に選ばれているアイテム
			   hitPt		ポップアップメニューの左上
			   menuRect		ポップアップのRectを入れて返す */
			/* なぜかhitPtのhとvは入れ代わっている */
			SetRect(menuRect,hitPt.v,hitPt.h,hitPt.v+kRows*kItemWidth,hitPt.h+kColumns*kItemHeight);
			break;
		
		case kMenuThemeSavvyMsg:
			*whichItem=kThemeSavvyMenuResponse;
			break;
	}
}
示例#2
0
MenuMapOptions::MenuMapOptions(std::shared_ptr<Settings> &settings, std::shared_ptr<AcedSharedDLL::Map> &currentMap) : Menu((std::shared_ptr<AcedSharedDLL::BaseSettings>)settings) {
	SetMap(currentMap);

	SetMenuHeader(std::string("Map Options"));
	SetId(AcedSharedDLL::STATES::EDITORMAPOPTIONS);
	int widestItem = settings->GetFontWidth(GetMenuHeader());

	auto itemStoreCurrentWidth = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreCurrentWidth->SetMenuItemText(std::string("Current Width:"));

	//might need to delete this tempval char array? mmm looks to be in stack so should die when method finishs....
	std::string tempVal;
	tempVal = std::to_string(GetMap()->GetMapWidth());

	itemStoreCurrentWidth->InitMenuItemProperty(tempVal);
	itemStoreCurrentWidth->SetMenuItemTargetable(false);
	if (widestItem < settings->GetFontWidth(itemStoreCurrentWidth->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreCurrentWidth->GetMenuItemText());
	}
	AddMenuItem(itemStoreCurrentWidth);





	auto itemStoreNewWidth = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreNewWidth->InitMenuItemProperty("");
	itemStoreNewWidth->SetOptionId(AcedSharedDLL::OPTIONTYPES::WIDTHOPTION);
	itemStoreNewWidth->SetMenuItemText(std::string("New Width:"));
	if (widestItem < settings->GetFontWidth(itemStoreNewWidth->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreNewWidth->GetMenuItemText());
	}
	AddMenuItem(itemStoreNewWidth);




	auto itemStoreCurrentHeight = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreCurrentHeight->SetMenuItemText(std::string("Current Height:"));

	tempVal = std::to_string(GetMap()->GetMapHeight());

	itemStoreCurrentHeight->InitMenuItemProperty(tempVal);
	itemStoreCurrentHeight->SetMenuItemTargetable(false);
	if (widestItem < settings->GetFontWidth(itemStoreCurrentHeight->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreCurrentHeight->GetMenuItemText());
	}
	AddMenuItem(itemStoreCurrentHeight);






	auto itemStoreNewHeight = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreNewHeight->InitMenuItemProperty("");
	itemStoreNewHeight->SetOptionId(AcedSharedDLL::OPTIONTYPES::HEIGHTOPTION);
	itemStoreNewHeight->SetMenuItemText(std::string("New Height:"));
	if (widestItem < settings->GetFontWidth(itemStoreNewHeight->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreNewHeight->GetMenuItemText());
	}
	AddMenuItem(itemStoreNewHeight);




	auto itemStoreSave = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreSave->SetId(AcedSharedDLL::STATES::SAVE);
	itemStoreSave->SetMenuItemText(std::string("Save"));
	if (widestItem < settings->GetFontWidth(itemStoreSave->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreSave->GetMenuItemText());
	}
	AddMenuItem(itemStoreSave);

	auto itemStoreReturn = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreReturn->SetId(AcedSharedDLL::STATES::RETURN);
	itemStoreReturn->SetMenuItemText(std::string("Return"));
	if (widestItem < settings->GetFontWidth(itemStoreReturn->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreReturn->GetMenuItemText());
	}
	AddMenuItem(itemStoreReturn);

	widestItem += (AcedSharedDLL::Constants::TileSize() * 4);

	SetMenuX((settings->GetScreenWidth() / 2) - (widestItem / 2) - (AcedSharedDLL::Constants::TileSize() * 4));
	SetMenuY(100);

	SetMenuHeaderX((settings->GetScreenWidth() / 2) - (widestItem / 2) - (AcedSharedDLL::Constants::TileSize() * 4));
	SetMenuHeaderY(50 + AcedSharedDLL::Constants::TileSize());
	SetMenuHeaderHeight(50 - AcedSharedDLL::Constants::TileSize());

	int i = 0;
	int xloc = settings->GetScreenWidth() / 2;
	int yloc = 100 + AcedSharedDLL::Constants::TileSize();
	int yspacing = AcedSharedDLL::Constants::TileSize() * 2;

	auto menuSize = GetMenuItems().size();
	for (i = 0; i < menuSize; i++)
	{
		GetMenuItems()[i]->SetMenuItemX(xloc);
		GetMenuItems()[i]->SetMenuItemPropertyX(xloc + (settings->GetFontWidth(GetMenuItems()[i]->GetMenuItemText()) / 2) + (AcedSharedDLL::Constants::TileSize() * 1));
		GetMenuItems()[i]->SetMenuItemY(yloc);
		yloc = yloc + yspacing;
	}

	SetMenuWidth(settings->GetScreenWidth() - (2 * GetMenuX()));
	SetMenuHeaderWidth(settings->GetScreenWidth() - (2 * GetMenuX()));
	SetMenuHeight(yloc - GetMenuY());

	SetCurrentSelection();
}
示例#3
0
	void MenuEditor::InitMenu(){
		SetFont(al_load_font("arial.ttf", 30, 0));

		SetMenuHeader("Editor Menu");
		SetId(STATES::EDITORMAINMENU);
		
		MenuItem* itemStore = new MenuItem;
		itemStore->SetId(STATES::RETURN);
		itemStore->SetMenuItemText("Return");
		AddMenuItem(itemStore);

		itemStore = new MenuItem;
		itemStore->SetId(STATES::NEW);
		itemStore->SetMenuItemText("New Map");
		AddMenuItem(itemStore);

		itemStore = new MenuItem;
		itemStore->SetId(STATES::SAVE);
		itemStore->SetMenuItemText("Save Map");
		AddMenuItem(itemStore);

		itemStore = new MenuItem;
		itemStore->SetId(STATES::LOAD);
		itemStore->SetMenuItemText("Load Map");
		AddMenuItem(itemStore);

		itemStore = new MenuItem;
		itemStore->SetId(STATES::MAPOPTIONS);
		itemStore->SetMenuItemText("Map Options");
		AddMenuItem(itemStore);

		itemStore = new MenuItem;
		itemStore->SetId(STATES::OPTIONS);
		itemStore->SetMenuItemText("Options");
		AddMenuItem(itemStore);

		/*itemStore = new MenuItem;
		itemStore->SetId(STATES::ABOUT);
		itemStore->SetMenuItemText("About");
		AddMenuItem(itemStore);*/
		
	

		itemStore = new MenuItem;
		itemStore->SetId(STATES::MAINMENU);
		itemStore->SetMenuItemText("Quit");
		AddMenuItem(itemStore);


		SetMenuX(300);
		SetMenuY(100);
		SetMenuWidth(250);
		SetMenuHeight(400);
	
		SetMenuHeaderX(300);
		SetMenuHeaderY(50);
		SetMenuHeaderWidth(250);
		SetMenuHeaderHeight(50);

		int i = 0;
		int xloc = 425;
		int yloc = 110;
		int yspacing = 50;
		for(i = 0; i < GetMenuItems().size(); i++)
		{
			//printf("%i\n",yloc);
			GetMenuItems()[i]->SetMenuItemX(xloc);
			GetMenuItems()[i]->SetMenuItemY(yloc);
			yloc = yloc + yspacing;
		}
		SetMenuHeight(yloc-GetMenuY());

		SetCurrentSelection();
	}
示例#4
0
MenuGameMain::MenuGameMain(std::shared_ptr<Settings> &settings) : Menu((std::shared_ptr<AcedSharedDLL::BaseSettings>)settings) {

	SetMenuHeader(std::string("Game Main Menu"));
	SetId(AcedSharedDLL::STATES::EDITORMAINMENU);
	int widestItem = settings->GetFontWidth(GetMenuHeader());

	auto itemStoreNew = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreNew->SetId(AcedSharedDLL::STATES::NEW);
	itemStoreNew->SetMenuItemText(std::string("New Map"));
	if (widestItem < settings->GetFontWidth(itemStoreNew->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreNew->GetMenuItemText());
	}
	AddMenuItem(itemStoreNew);


	auto itemStoreLoad = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreLoad->SetId(AcedSharedDLL::STATES::LOAD);
	itemStoreLoad->SetMenuItemText(std::string("Load Map"));
	if (widestItem < settings->GetFontWidth(itemStoreLoad->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreLoad->GetMenuItemText());
	}
	AddMenuItem(itemStoreLoad);

	auto itemStoreEdit = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreEdit->SetId(AcedSharedDLL::STATES::EDITORMAINMENU);
	itemStoreEdit->SetMenuItemText(std::string("Edit Mode"));
	if (widestItem < settings->GetFontWidth(itemStoreEdit->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreEdit->GetMenuItemText());
	}
	AddMenuItem(itemStoreEdit);

	auto itemStoreOptions = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreOptions->SetId(AcedSharedDLL::STATES::OPTIONS);
	itemStoreOptions->SetMenuItemText(std::string("Options"));
	if (widestItem < settings->GetFontWidth(itemStoreOptions->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreOptions->GetMenuItemText());
	}
	AddMenuItem(itemStoreOptions);


	auto itemStoreQuit = std::shared_ptr<AcedSharedDLL::MenuItem>(new AcedSharedDLL::MenuItem());
	itemStoreQuit->SetId(AcedSharedDLL::STATES::QUIT);
	itemStoreQuit->SetMenuItemText(std::string("Quit"));
	if (widestItem < settings->GetFontWidth(itemStoreQuit->GetMenuItemText())) {
		widestItem = settings->GetFontWidth(itemStoreQuit->GetMenuItemText());
	}
	AddMenuItem(itemStoreQuit);

	widestItem += (AcedSharedDLL::Constants::TileSize() * 4);

	SetMenuX((settings->GetScreenWidth() / 2) - (widestItem / 2) - (AcedSharedDLL::Constants::TileSize() * 4));
	SetMenuY(100);

	SetMenuHeaderX((settings->GetScreenWidth() / 2) - (widestItem / 2) - (AcedSharedDLL::Constants::TileSize() * 4));
	SetMenuHeaderY(50 + AcedSharedDLL::Constants::TileSize());
	SetMenuHeaderHeight(50 - AcedSharedDLL::Constants::TileSize());

	int i = 0;
	int xloc = settings->GetScreenWidth() /2;
	int yloc = 100 + AcedSharedDLL::Constants::TileSize();
	int yspacing = AcedSharedDLL::Constants::TileSize()*2;

	auto menuSize = GetMenuItems().size();
	for (i = 0; i < menuSize; i++)
	{
		GetMenuItems()[i]->SetMenuItemX(xloc);
		GetMenuItems()[i]->SetMenuItemY(yloc);
		yloc = yloc + yspacing;
	}

	SetMenuWidth(settings->GetScreenWidth() - (2 * GetMenuX()));
	SetMenuHeaderWidth(settings->GetScreenWidth() - (2 * GetMenuX()));
	SetMenuHeight(yloc - GetMenuY());


	SetCurrentSelection();
}
示例#5
0
void MenuOptions::InitMenu() {
    SetFont(al_load_font("arial.ttf", 30, 0));

    SetMenuHeader("Options");
    SetId(STATES::EDITOROPTIONS);




    MenuItem* itemStore = new MenuItem;
    itemStore->SetMenuItemText("Current Width:");


    //might need to delete this tempval char array? mmm looks to be in stack so should die when method finishs....
    char tempVal[10];
    sprintf_s(tempVal, "%i", GetSettings()->GetScreenWidth());


    itemStore->InitMenuItemProperty(al_ustr_new(tempVal));
    itemStore->SetMenuItemTargetable(false);
    AddMenuItem(itemStore);





    itemStore = new MenuItem;
    itemStore->InitMenuItemProperty(al_ustr_new(""));
    itemStore->SetOptionId(OPTIONTYPES::WIDTHOPTION);
    itemStore->SetMenuItemText("New Width:");
    AddMenuItem(itemStore);




    itemStore = new MenuItem;
    itemStore->SetMenuItemText("Current Height:");

    sprintf_s(tempVal, "%i", GetSettings()->GetScreenHeight());

    itemStore->InitMenuItemProperty(al_ustr_new(tempVal));
    itemStore->SetMenuItemTargetable(false);
    AddMenuItem(itemStore);






    itemStore = new MenuItem;
    itemStore->InitMenuItemProperty(al_ustr_new(""));
    itemStore->SetOptionId(OPTIONTYPES::HEIGHTOPTION);
    itemStore->SetMenuItemText("New Height:");
    AddMenuItem(itemStore);




    itemStore = new MenuItem;
    itemStore->SetId(STATES::SAVE);
    itemStore->SetMenuItemText("Save");
    AddMenuItem(itemStore);

    itemStore = new MenuItem;
    itemStore->SetId(STATES::RETURN);
    itemStore->SetMenuItemText("Return");
    AddMenuItem(itemStore);



    SetMenuX(200);
    SetMenuY(100);
    SetMenuWidth(400);
    SetMenuHeight(400);

    SetMenuHeaderX(200);
    SetMenuHeaderY(50);
    SetMenuHeaderWidth(400);
    SetMenuHeaderHeight(50);

    int i = 0;
    int xloc = 355;
    int yloc = 110;
    int yspacing = 50;
    for(i = 0; i < GetMenuItems().size(); i++)
    {
        GetMenuItems()[i]->SetMenuItemX(xloc);
        GetMenuItems()[i]->SetMenuItemPropertyX(400+100);
        GetMenuItems()[i]->SetMenuItemY(yloc);
        yloc = yloc + yspacing;
    }
    SetMenuHeight(yloc-GetMenuY());

    SetCurrentSelection();
}