UserControlの使い方

 

UserControlの使い方

説明

UserControlを使用すると様々な属性や情報の表示方法ができます:

  • ペン
  • 塗りつぶし
  • 材質
  • ゾーンカテゴリ
  • レイヤー
  • 断面形状
  • ビルディングマテリアル
  • テキストポップアップ
  • アイコンポップアップ
  • アイコンラジオボタン

ダイアログをGRCで記述する

'GDLG'  ID_UCDIALOG_ID  Modal         0    0  400  700  "UCTest" {
/* [  1] */		UserControl			102		2		50		28		257			/* pen */
/* [  2] */		UserControl			102		32		296		28		257			/* fill */
/* [  3] */		UserControl			102		62		296		28		257			/* material */
/* [  5] */		UserControl			102		92		296		28		257			/* zone cat */
/* [  6] */		UserControl			102		122		296		28		257			/* layer */
/* [  7] */		UserControl			102		152		296		28		257			/* profile */
/* [  8] */		UserControl			102		182		296		28		257			/* buildingmaterial */
/* [  9] */		UserControl			102		212		296		28		257 0x0005	/* text popup */
/* [ 10] */		UserControl			102		242		296		28		258			/* icon popup */
/* [ 11] */		UserControl			102		272		296		88		259			/* icon radiobutton */
/* [ 12] */		UserControl			102		362		296		28		261			/* line */
/* [ 13] */		UserControl			102		392		296		208		262			/* pen table */
/* [ 14] */		UserControl			102		602		50		28		263			/* popup */
}

ダイアログクラスを定義する

  • 必要なヘッダーをインクルード

// UCDialog.h

#include "APIEnvir.h"
#include "ACAPinc.h"
#include "APICommon.h"


#include "DG.h"
#include "DGModule.hpp"

#include "UC.h"
#include "UCModule.hpp"
#include "UCPopup.hpp"


class UCDialog
	: public DG::ModalDialog
	, public DG::PanelObserver
	, public DG::CompoundItemObserver
{
public:
	UCDialog();
	~UCDialog();

private:
	void Initialize();

private:

	enum {
		penID = 1,
		fillID,
		materialID,
		zonecatID,
		layerID,
		profileID,
		buildingmaterialID,

		textPopupID,
		uc258ID,
		uc259ID,
		uc261ID,
		uc262ID,
		popupMenuID,
	};

	UC::UC257 pen;
	UC::UC257 fill;
	UC::UC257 material;
	UC::UC257 zonecat;
	UC::UC257 layer;
	UC::UC257 profile;
	UC::UC257 buildingmaterial;

	UC::TextPopup textPopup;
	UC::UC258 uc258;
	UC::UC259 uc259;
	UC::UC261 uc261;
	UC::UC262 uc262;
	UC::PopupMenu popupMenu;

	DG::LeftText penText;
	DG::LeftText fillText;
	DG::LeftText materialText;
	DG::LeftText zonecatText;
	DG::LeftText layerText;
	DG::LeftText profileText;
	DG::LeftText buildingmaterialText;	
	DG::LeftText textPopupText;
	DG::LeftText uc258Text;
	DG::LeftText uc259Text;
	DG::LeftText uc261Text;
	DG::LeftText uc262Text;
	DG::LeftText popupMenuText;
};


ダイアログクラスを実装する

  • Initialize()で必要な設定を行う
  • UC259は1つの画像を等間隔のグリッドで区切って選択肢として表示します

// UCDialog.cpp


#include "UCDialog.h"


UCDialog::UCDialog()
	: DG::ModalDialog(ACAPI_GetOwnResModule(), ID_UCDIALOG_ID, ACAPI_GetOwnResModule())
	, pen(GetReference(), penID)
	, fill(GetReference(), fillID)
	, material(GetReference(), materialID)
	, zonecat(GetReference(), zonecatID)
	, layer(GetReference(), layerID)
	, profile(GetReference(), profileID)
	, buildingmaterial(GetReference(), buildingmaterialID)
	, textPopup(GetReference(), textPopupID)
	, uc258(GetReference(), uc258ID)
	, uc259(GetReference(), uc259ID)
	, uc261(GetReference(), uc261ID)
	, uc262(GetReference(), uc262ID)
	, popupMenu(GetReference(), popupMenuID)

	, penText(GetReference(), DG::Rect(2, 8, 100, 28))
	, fillText(GetReference(), DG::Rect(2, 38, 100, 58))
	, materialText(GetReference(), DG::Rect(2, 68, 100, 88))
	, zonecatText(GetReference(), DG::Rect(2, 98, 100, 118))
	, layerText(GetReference(), DG::Rect(2, 128, 100, 148))
	, profileText(GetReference(), DG::Rect(2, 158, 100, 178))
	, buildingmaterialText(GetReference(), DG::Rect(2, 188, 100, 208))
	, textPopupText(GetReference(), DG::Rect(2, 218, 100, 238))
	, uc258Text(GetReference(), DG::Rect(2, 248, 100, 268))
	, uc259Text(GetReference(), DG::Rect(2, 318, 100, 338))
	, uc261Text(GetReference(), DG::Rect(2, 368, 100, 388))
	, uc262Text(GetReference(), DG::Rect(2, 492, 100, 528))
	, popupMenuText(GetReference(), DG::Rect(2, 608, 100, 638))
{
	AttachToAllItems(*this);
	Initialize();
}


UCDialog::~UCDialog()
{
	DetachFromAllItems(*this);
}



void UCDialog::Initialize()
{
	GSErrCode err = NoError;
	API_UCCallbackType	ucb{};
	ucb.dialogID = GetId();

	//// set pen control
	penText.SetText("Pen:");
	penText.Show();

	pen.SetValue(1);
	pen.SetButtonType(UC::UC257::LargeButton);
	pen.SetHeaderType(UC::UC257::HasHeader);
	pen.SetPaletteType(UC::UC257::PlainPalette);
	pen.SetControlType(UC::UC257::Pen);
	pen.SetFontType(UC::UC257::SmallFont);

	ucb.type = APIUserControlType_Pen;
	ucb.itemID = penID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);


	// set fill control
	fillText.SetText("Fill:");
	fillText.Show();

	fill.SetValue(1);
	fill.SetButtonType(UC::UC257::LargeButton);
	fill.SetHeaderType(UC::UC257::HasHeader);
	fill.SetPaletteType(UC::UC257::PlainPalette);
	fill.SetControlType(UC::UC257::Fill);
	fill.SetFontType(UC::UC257::SmallFont);

	ucb.type = APIUserControlType_PolyFill;
	ucb.itemID = fillID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);

	// set material control
	materialText.SetText("Material:");
	materialText.Show();

	material.SetValue(1);
	material.SetButtonType(UC::UC257::LargeButton);
	material.SetHeaderType(UC::UC257::HasHeader);
	material.SetPaletteType(UC::UC257::PlainPalette);
	material.SetControlType(UC::UC257::Material);
	material.SetFontType(UC::UC257::SmallFont);

	ucb.type = APIUserControlType_Material;
	ucb.itemID = materialID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);

	// set zone category
	zonecatText.SetText("ZoneCat:");
	zonecatText.Show();

	zonecat.SetValue(1);
	zonecat.SetButtonType(UC::UC257::LargeButton);
	zonecat.SetHeaderType(UC::UC257::HasHeader);
	zonecat.SetPaletteType(UC::UC257::ScrollablePalette);
	zonecat.SetControlType(UC::UC257::ZoneCat);
	zonecat.SetFontType(UC::UC257::LargeFont);

	ucb.type = APIUserControlType_ZoneCategory;
	ucb.itemID = zonecatID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);

	// set layer control
	layerText.SetText("Layer:");
	layerText.Show();

	layer.SetValue(1);
	layer.SetButtonType(UC::UC257::LargeButton);
	layer.SetHeaderType(UC::UC257::HasHeader);
	layer.SetPaletteType(UC::UC257::ScrollablePalette);
	layer.SetControlType(UC::UC257::Layer);
	layer.SetFontType(UC::UC257::LargeFont);

	ucb.type = APIUserControlType_Layer;
	ucb.itemID = layerID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);


	// set profile control
	profileText.SetText("Profile:");
	profileText.Show();

	profile.SetValue(1);
	profile.SetButtonType(UC::UC257::LargeButton);
	profile.SetHeaderType(UC::UC257::HasHeader);
	profile.SetPaletteType(UC::UC257::ScrollablePalette);
	profile.SetControlType(UC::UC257::Profile);
	profile.SetFontType(UC::UC257::LargeFont);

	ucb.type = APIUserControlType_AllProfile;
	ucb.itemID = profileID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);

	// set building material control
	buildingmaterialText.SetText("BuildingMaterial:");
	buildingmaterialText.Show();

	buildingmaterial.SetValue(1);
	buildingmaterial.SetButtonType(UC::UC257::LargeButton);
	buildingmaterial.SetHeaderType(UC::UC257::HasHeader);
	buildingmaterial.SetPaletteType(UC::UC257::ScrollablePalette);
	buildingmaterial.SetControlType(UC::UC257::BuildingMat);
	buildingmaterial.SetFontType(UC::UC257::LargeFont);

	ucb.type = APIUserControlType_BuildingMaterial;
	ucb.itemID = buildingmaterialID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);


	// set textPopup
	textPopupText.SetText("TextPopup");
	textPopupText.Show();

	textPopup.Initialize("", 100, 1);
	textPopup.AppendItem("aaa");
	textPopup.AppendItem("bbb");
	textPopup.AppendItem("ccc");
	textPopup.SetValue(1);

	// set uc258
	uc258Text.SetText("UC258");
	uc258Text.Show();

	uc258.SetHeaderType(UC::UC258::HasHeader);
	uc258.SetPalettePosition(UC::UC258::OnMouseClickPos);
	uc258.SetPaletteFrame(UC::UC258::SimpleFrame);
	uc258.SetImage(DG::Icon(ACAPI_GetOwnResModule(), 10), 15, 3);


	// set uc259
	uc259Text.SetText("UC259");
	uc259Text.Show();

	uc259.SetImage(DG::Icon(ACAPI_GetOwnResModule(), 10), 15, 3);


	// set uc261
	uc261Text.SetText("UC261");
	uc261Text.Show();

	uc261.SetValue(1);
	uc261.SetButtonType(UC::UC261::LargeButton);
	uc261.SetHeaderType(UC::UC261::HasHeader);

	ucb.type = APIUserControlType_SymbolLine;
	ucb.itemID = uc261ID;
	err = ACAPI_Interface(APIIo_SetUserControlCallbackID, &ucb, NULL);


	// set uc262
	uc262Text.SetText("UC262");
	uc262Text.Show();

	uc262.Setup(255, 13, 20);	
	API_Attribute attr{};
	attr.header.typeID = API_PenID;
	for (API_AttributeIndex cellIndex = 1; cellIndex < 256; ++cellIndex)
	{
		attr.header.index = cellIndex;
		ACAPI_Attribute_Get(&attr);
		API_RGBColor rgbColor = attr.pen.rgb;
		Gfx::Color color(Gfx::Color::AsFloat, rgbColor.f_red, rgbColor.f_green, rgbColor.f_blue);
		UChar cellFlag = CCF262_USEDPEN;
		uc262.SetCellData(cellIndex, cellIndex, false, cellFlag, color.GetRed(), color.GetGreen(), color.GetBlue(), "", "");
	}
	uc262.SetValue(1);
	uc262.ShowAllPens(true);


	// set uc 263 popup menu
	popupMenuText.SetText("UC263");
	popupMenuText.Show();

	popupMenu.SetButtonType(UC::Popup::ArrowOnly);
	popupMenu.SetItemHeight(UC::Popup::Default);

	popupMenu.AppendItem();
	popupMenu.SetItemIcon(popupMenu.GetItemCount(), DG::Icon(ACAPI_GetOwnResModule(), ID_MENU_ICON));
	popupMenu.SetItemText(popupMenu.GetItemCount(), "ddd");

	popupMenu.AppendItem();
	popupMenu.SetItemIcon(popupMenu.GetItemCount(), DG::Icon(ACAPI_GetOwnResModule(), ID_MENU_ICON));
	popupMenu.SetItemText(popupMenu.GetItemCount(), "eee");

	popupMenu.AppendItem();
	popupMenu.SetItemIcon(popupMenu.GetItemCount(), DG::Icon(ACAPI_GetOwnResModule(), ID_MENU_ICON));
	popupMenu.SetItemText(popupMenu.GetItemCount(), "fff");

}