月別アーカイブ: 2014年3月

stylebook についてのメモ

  • コンポーネントをドロップするのはなぜか構造ペイン
  • XE4以降には「スタイルの構造を表す」ペインと「スタイルの作成」のペインが無くなっている
  • 新規スタイルの作成は構造ペインのTStylecontainerにコンポーネントをドロップ
  • スタイル設計フォームで、StyleName に Tを除いたクラス名が含まれている必要がある。例えばTLabelのスタイルは、LabelBlue や BigLabel001とか。この条件を満たさないとStyleLookup プロパティコンボから選択できない。
  • プロパティ も StyleName で識別している
  • データには Item.StylesData['depth'] := 等でアクセス
  • TListboxItem の Itemdata.bitmap は、TImage の Stylename を icon にして配置

http://edn.embarcadero.com/article/42832

エンバラデロのサンプルコード


//---------------------------------------------------------------------------

// This software is Copyright (c) 2012 Embarcadero Technologies, Inc.
// You may only use this software if you are an authorized licensee
// of Delphi, C++Builder or RAD Studio (Embarcadero Products).
// This software is considered a Redistributable as defined under
// the software license agreement that comes with the Embarcadero Products
// and is subject to that software license agreement.

//---------------------------------------------------------------------------
unit customlistfrm;

interface

uses
  System.SysUtils, System.Variants, System.Classes, System.Types, System.UITypes,
  System.Rtti, FMX.Forms, FMX.Dialogs, FMX.Types, FMX.Layouts, FMX.Styles, FMX.StdCtrls,
  FMX.ListBox, FMX.Objects, FMX.Controls, FMX.Edit, FMX.Effects;

type
  TfrmCustomList = class(TForm)
    ListBox1: TListBox;
    Resources1: TStyleBook;
    OpenDialog1: TOpenDialog;
    InfoLabel: TLabel;
    Label1: TLabel;
    Button2: TButton;
    Button3: TButton;
    CheckBox1: TCheckBox;
    Image1: TImage;
    Image2: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure CheckBox1Change(Sender: TObject);
  private
    { Private declarations }
    procedure DoInfoClick(Sender: TObject);
    procedure DoVisibleChange(Sender: TObject);
  public
    { Public declarations }
  end;

var
  frmCustomList: TfrmCustomList;

implementation

{$R *.fmx}

procedure TfrmCustomList.Button1Click(Sender: TObject);
var
  Item: TListBoxItem;
  I: Integer;
begin
  OpenDialog1.Filter := TBitmapCodecManager.GetFilterString;
  if OpenDialog1.Execute then
  begin
    // create item and save file name in the tag
    for I := 0 to OpenDialog1.Files.Count - 1 do
    begin
      Item := TListBoxItem.Create(nil);
      Item.Parent := ListBox1;
      Item.TagString := OpenDialog1.Files[I];
      Item.StyleLookup := 'CustomItem';
      Item.Text := OpenDialog1.Files[i]; // set filename
      Item.StylesData['icon'] := OpenDialog1.Files[i];
      Item.StylesData['resolution'] := '1024x768 px'; // set size
      Item.StylesData['depth'] := '32 bit';
      Item.StylesData['visible'] := true; // set Checkbox value
      Item.StylesData['visible.OnChange'] := TValue.From(DoVisibleChange); // set OnChange value
      Item.StylesData['info.OnClick'] := TValue.From(DoInfoClick); // set OnClick value
    end;
    Caption := IntToStr(ListBox1.Count) + ' items';
  end;
end;

procedure TfrmCustomList.Button2Click(Sender: TObject);
var
  Item: TListBoxItem;
begin
  // create custom item
  Item := TListBoxItem.Create(nil);
  Item.Parent := ListBox1;
  Item.StyleLookup := 'CustomItem';
  Item.Text := 'item ' + IntToStr(Item.Index); // set filename
  if Odd(Item.Index) then
    Item.ItemData.Bitmap := Image1.Bitmap // set thumbnail
  else
    Item.ItemData.Bitmap := Image2.Bitmap; // set thumbnail
  Item.StylesData['resolution'] := '1024x768 px'; // set size
  Item.StylesData['depth'] := '32 bit';
  Item.StylesData['visible'] := true; // set Checkbox value
  Item.StylesData['visible.OnChange'] := TValue.From(DoVisibleChange); // set OnChange value
  Item.StylesData['info.OnClick'] := TValue.From(DoInfoClick); // set OnClick value
end;

procedure TfrmCustomList.DoInfoClick(Sender: TObject);
begin
  InfoLabel.Text := 'Info Button click on ' + IntToStr(ListBox1.ItemIndex) + ' listbox item';
end;

procedure TfrmCustomList.DoVisibleChange(Sender: TObject);
begin
  InfoLabel.Text := 'Checkbox changed ' + IntToStr(ListBox1.ItemIndex) + ' listbox item to ' + BoolToStr(Listbox1.Selected.StylesData['visible'].AsBoolean, true);
end;

procedure TfrmCustomList.Button3Click(Sender: TObject);
var
  i: integer;
begin
  ListBox1.BeginUpdate;
  for i := 1 to 1000 do
    Button2Click(Sender);
  ListBox1.EndUpdate;

  Caption := IntToStr(ListBox1.Count) + ' items';
end;

procedure TfrmCustomList.CheckBox1Change(Sender: TObject);
begin
  ListBox1.AllowDrag := CheckBox1.IsChecked;
end;

end.

TAlphacolor 色に関するメモ


  function valueToColor(aValue: double): TAlphaColor;
  var
    tmpSingle: Single;
    tmpAlphaColor: TAlphaColor;
  begin
    // 割合を0.15 なら1とするように切り上げる
    tmpSingle := aValue * (1/0.15);
    if tmpSingle > 1 then tmpSingle := 1;
    // 最大値 160(青) 最小値 0(赤)に補正
    tmpSingle := tmpSingle * 220 / 360;
    tmpAlphaColor := HSLtoRGB(tmpSingle, 0.75,0.5);

    tmpAlphaColorRec.Color := tmpAlphaColor;

    result := MakeColor(tmpAlphaColorRec.R,
                        tmpAlphaColorRec.G,
                        tmpAlphaColorRec.B,
                        $80);
  end;

TcomboBox コンボボックス TCombobox コンボボックスのまとめ

ボックスアイテムのフォントサイズを設定

  for i := 0 to frmConfig.cmbDesignFontName.Count -1 do
  begin
    frmConfig.cmbDesignFontName.ListItems[i].StyledSettings := [];
    frmConfig.cmbDesignFontName.ListItems[i].Font.Size := 11;
  end;

フォントと列挙


procedure TfrmMain.initFontCombo;
var
  tmpFileList: TstringList;
  i: Integer;
  DC:HDC;

  function EnumFamToLines(lplf: PLOGFONT; lpntm: PNEWTEXTMETRIC;
                            FontType: DWORD; Lines: LPARAM): Integer; stdcall;
  begin
    with lplf^ do
//      if    (lfCharSet = SHIFTJIS_CHARSET) and (lfPitchAndFamily and $0F = FIXED_PITCH) then
      // シフトJIS文字セット
      if    (lfCharSet = SHIFTJIS_CHARSET) then
        TStrings(Lines).Add(lplf.lfFaceName);
    Result := 1;
  end;

begin
  tmpFileList := TstringList.Create();
  DC := GetDC(0);
  tmpFileList.Clear;

  frmConfig.cmbDesignFontName.Items.Add(DEFAULT_DesignFontName);

  EnumFontFamilies(DC, nil, @EnumFamToLines, LongInt(tmpFileList));
  for i := 0 to tmpFileList.Count - 1 do
    if pos('@', tmpFileList[i]) = 0 then
      frmConfig.cmbDesignFontName.Items.Add(tmpFileList[i]);
  tmpFileList.Free;

  for i := 0 to frmConfig.cmbDesignFontName.Count -1 do
  begin
    frmConfig.cmbDesignFontName.ListItems[i].StyledSettings := [];
    frmConfig.cmbDesignFontName.ListItems[i].Font.Size := 11;
  end;

end;

OnChange のタイミング

iOS では clear で OnChange イベントが発生する
iOS では BeginUpdate、EndUpdate が無いとエラーが起こる可能性がある?

  frmMain.cbxValueStep.BeginUpdate;
  frmMain.cbxValueStep.Items.Clear;
  for i := 0 to TValueStep.count - 1 do
  begin
    tmpValueStep.serial := i;
    ListBoxItem      := TListBoxItem.Create(frmMain.cbxValueStep);
    ListBoxItem.Tag  := tmpValueStep.serial;
    ListBoxItem.Text :=tmpWatchPair.pipToPriceStr(tmpValueStep.pip);
    frmMain.cbxValueStep.AddObject(ListBoxItem);
  end;

  frmMain.cbxValueStep.EndUpdate;