粘貼箱: OmegaChart Fibonacciリトレースメント Preference.cs 追加修正ポイントには//☆Fibonacci

格式
Plain text
Post date
2017-12-27 19:57
Publication Period
Unlimited
  1. using System;
  2. using System.IO;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Text;
  6. using Travis.Storage;
  7. using Travis.Util;
  8. using Zanetti.Indicators;
  9. namespace Zanetti.UI
  10. {
  11. internal class ChartFormatSpecificValue
  12. {
  13. private int[] _data;
  14. private const int LENGTH = 4;
  15. public ChartFormatSpecificValue(int[] t)
  16. {
  17. if (t.Length == LENGTH)
  18. _data = t; //多くはこれ
  19. else
  20. {
  21. _data = new int[LENGTH];
  22. for (int i = 0; i < LENGTH; i++) _data[i] = t.Length > i ? t[i] : 0;
  23. }
  24. }
  25. public ChartFormatSpecificValue(string value)
  26. {
  27. string[] t = value.Split(',');
  28. _data = new int[LENGTH];
  29. for (int i = 0; i < LENGTH; i++)
  30. _data[i] = t.Length > i ? Int32.Parse(t[i]) : 0;
  31. }
  32. public int GetValue(ChartFormat fmt)
  33. {
  34. #if DOJIMA
  35. if(fmt==ChartFormat.HalfDaily) fmt = ChartFormat.Daily;
  36. #endif
  37. int i = (int)fmt;
  38. return i < _data.Length ? _data[i] : 0;
  39. }
  40. public void Update(int[] t)
  41. {
  42. Debug.Assert(t.Length == LENGTH);
  43. _data = t;
  44. }
  45. public override string ToString()
  46. {
  47. StringBuilder b = new StringBuilder();
  48. for (int i = 0; i < LENGTH; i++)
  49. {
  50. if (i > 0) b.Append(",");
  51. b.Append(_data[i].ToString());
  52. }
  53. return b.ToString();
  54. }
  55. }
  56. internal class OscillatorPreference
  57. {
  58. //最大3個
  59. public const int LENGTH = 3;
  60. //Groupが存在していても一時的に表示されないという形態を想定して_visibleを導入
  61. private OscillatorGroup _group;
  62. private string _id;
  63. private HeightConfig _config;
  64. private double[] _scaleValues;
  65. private Trans _trans;
  66. public OscillatorPreference(string id)
  67. {
  68. string[] t = id.Split(':');
  69. _config = Util.ParseHeightConfig(t[0], HeightConfig.None);
  70. _id = t.Length > 1 ? t[1] : "none";
  71. _scaleValues = new double[3];
  72. }
  73. public OscillatorGroup OscillatorGroup
  74. {
  75. get
  76. {
  77. if (_group == null) Bind();
  78. return _group;
  79. }
  80. set
  81. {
  82. _group = value;
  83. if (_group != null) _id = value.Name;
  84. }
  85. }
  86. public HeightConfig Config
  87. {
  88. get
  89. {
  90. if (_group == null) Bind();
  91. if (_group == null)
  92. return HeightConfig.None;
  93. else
  94. return _config; //起動直後にはGroupが存在しないこともある
  95. }
  96. set
  97. {
  98. _config = value;
  99. }
  100. }
  101. private void Bind()
  102. {
  103. _group = Env.CurrentIndicators.FindOscillatorGroup(_id);
  104. }
  105. public string Format()
  106. {
  107. return String.Format("{0}:{1}", _config.ToString(), _group == null ? "none" : _id);
  108. }
  109. public double[] ScaleValues
  110. {
  111. get
  112. {
  113. return _scaleValues;
  114. }
  115. }
  116. public void SetScaleValues(double v0, double v1, double v2)
  117. {
  118. _scaleValues[0] = v0;
  119. _scaleValues[1] = v1;
  120. _scaleValues[2] = v2;
  121. }
  122. public Trans Trans
  123. {
  124. get
  125. {
  126. return _trans;
  127. }
  128. set
  129. {
  130. _trans = value;
  131. }
  132. }
  133. //スキーマのリロードなど、読み込みなおしたときは参照を切っておく必要がある
  134. public void Refresh()
  135. {
  136. _group = null;
  137. }
  138. }
  139. [EnumDesc(typeof(MouseTrackingLineMode))]
  140. internal enum MouseTrackingLineMode
  141. {
  142. [EnumValue(Description = "なし")] None,
  143. [EnumValue(Description = "日付のみ")] Date,
  144. [EnumValue(Description = "日付と価格")] Full
  145. }
  146. //出来高とオシレータの高さ設定
  147. internal enum HeightConfig
  148. {
  149. None,
  150. Large,
  151. Middle,
  152. Small
  153. }
  154. /// <summary>
  155. /// Preferenceは、ユーザがカスタマイズ可能な表示に関する設定を収録する。Optionの一部とも言えるが、
  156. /// レイトバインディングするGDIオブジェクトなどもある
  157. /// </summary>
  158. internal class Preference
  159. {
  160. //色関係
  161. private ZBrush _defaultBrush;
  162. private ZPen _defaultPen;
  163. private ZBrush _backBrush;
  164. private ZBrush _volumeBrush;
  165. private ZCandlePen _candlePen;
  166. private ZBrush _insenBrush;
  167. private ZPen _monthDivPen;
  168. private ZPen _mouseTrackingLinePen;
  169. private MouseTrackingLineMode _mouseTrackingLineMode;
  170. private ZPen _priceScalePen;
  171. private ZPen _volumeScalePen;
  172. private ZPen _oscillatorScalePen;
  173. private Color _fushiColor;
  174. private Color _freeLineColor;
  175. private Color _fibonacciColor;//☆Fibonacci
  176. private IndicatorAppearance _creditLongAppearance;
  177. private IndicatorAppearance _creditShortAppearance;
  178. // ローソク幅
  179. private int _candleWidth;
  180. //表示設定系
  181. private bool _useCandleEffect;
  182. private bool _inverseChart; // 上下逆
  183. private bool _logScale; // 対数表示
  184. private bool _showPrice;
  185. private HeightConfig _showVolume;
  186. private bool _showAccumulativeVolume; //価格帯別出来高
  187. private bool _adjustSplit; //分割を調整するかどうか
  188. private bool _scaleLock;
  189. //font
  190. private string _fontName;
  191. private float _fontSize;
  192. private FontStyle _fontStyle;
  193. //レイトバインドする物
  194. private bool _fontDirty;
  195. private SizeF _defaultFontPitch;
  196. private SizeF _headerFontPitch;
  197. private Font _defaultFont;
  198. private Font _headerFont;
  199. private IntPtr _defaultHFont;
  200. private IntPtr _headerHFont;
  201. private ZPen _freeLinePen;
  202. private ZPen _freeLineDottedPen;
  203. private ZPen _freeLineBoldPen;
  204. private ZPen _fibonacciPen;//☆Fibonacci
  205. private ZPen _fibonacciDottedPen;//☆Fibonacci
  206. private ZPen _fibonacciBoldPen;//☆Fibonacci
  207. //何日間の高値・安値を節とするか
  208. private int _fushiRange;
  209. //価格帯別出来高
  210. private ChartFormatSpecificValue _accumulativeVolumePeriod;
  211. //オシレータ
  212. private OscillatorPreference[] _oscillatorPreferences;
  213. public Color FushiColor
  214. {
  215. get
  216. {
  217. return _fushiColor;
  218. }
  219. set
  220. {
  221. _fushiColor = value;
  222. }
  223. }
  224. public string FontName
  225. {
  226. get
  227. {
  228. return _fontName;
  229. }
  230. set
  231. {
  232. _fontName = value;
  233. _fontDirty = true;
  234. }
  235. }
  236. public float FontSize
  237. {
  238. get
  239. {
  240. return _fontSize;
  241. }
  242. set
  243. {
  244. _fontSize = value;
  245. _fontDirty = true;
  246. }
  247. }
  248. public FontStyle FontStyle
  249. {
  250. get
  251. {
  252. return _fontStyle;
  253. }
  254. set
  255. {
  256. _fontStyle = value;
  257. _fontDirty = true;
  258. }
  259. }
  260. public Color TextColor
  261. {
  262. get
  263. {
  264. return _defaultBrush.Color;
  265. }
  266. }
  267. public ZBrush DefaultBrush
  268. {
  269. get
  270. {
  271. return _defaultBrush;
  272. }
  273. }
  274. public ZPen DefaultPen
  275. {
  276. get
  277. {
  278. return _defaultPen;
  279. }
  280. }
  281. public ZBrush BackBrush
  282. {
  283. get
  284. {
  285. return _backBrush;
  286. }
  287. }
  288. public ZBrush InsenBrush
  289. {
  290. get
  291. {
  292. return _insenBrush;
  293. }
  294. }
  295. public ZCandlePen CandlePen
  296. {
  297. get
  298. {
  299. return _candlePen;
  300. }
  301. }
  302. public ZBrush VolumeBrush
  303. {
  304. get
  305. {
  306. return _volumeBrush;
  307. }
  308. }
  309. public ZPen MonthDivPen
  310. {
  311. get
  312. {
  313. return _monthDivPen;
  314. }
  315. }
  316. public ZPen MouseTrackingLinePen
  317. {
  318. get
  319. {
  320. return _mouseTrackingLinePen;
  321. }
  322. }
  323. public ZPen PriceScalePen
  324. {
  325. get
  326. {
  327. return _priceScalePen;
  328. }
  329. }
  330. public ZPen VolumeScalePen
  331. {
  332. get
  333. {
  334. return _volumeScalePen;
  335. }
  336. }
  337. public ZPen OscillatorScalePen
  338. {
  339. get
  340. {
  341. return _oscillatorScalePen;
  342. }
  343. }
  344. public int FushiRange
  345. {
  346. get
  347. {
  348. return _fushiRange;
  349. }
  350. }
  351. public IndicatorAppearance CreditLongAppearance
  352. {
  353. get
  354. {
  355. return _creditLongAppearance;
  356. }
  357. }
  358. public IndicatorAppearance CreditShortAppearance
  359. {
  360. get
  361. {
  362. return _creditShortAppearance;
  363. }
  364. }
  365. public MouseTrackingLineMode MouseTrackingLineMode
  366. {
  367. get
  368. {
  369. return _mouseTrackingLineMode;
  370. }
  371. }
  372. // ローソク足幅
  373. public bool InverseChart
  374. {
  375. get
  376. {
  377. return _inverseChart;
  378. }
  379. set
  380. {
  381. _inverseChart = value;
  382. }
  383. }
  384. public bool LogScale
  385. {
  386. get
  387. {
  388. return _logScale;
  389. }
  390. set
  391. {
  392. _logScale = value;
  393. }
  394. }
  395. public bool AdjustSplit
  396. {
  397. get
  398. {
  399. return _adjustSplit;
  400. }
  401. set
  402. {
  403. _adjustSplit = value;
  404. }
  405. }
  406. public bool ShowPrice
  407. {
  408. get
  409. {
  410. return _showPrice;
  411. }
  412. set
  413. {
  414. _showPrice = value;
  415. }
  416. }
  417. public HeightConfig ShowVolume
  418. {
  419. get
  420. {
  421. return _showVolume;
  422. }
  423. set
  424. {
  425. _showVolume = value;
  426. }
  427. }
  428. public bool ShowAccumulativeVolume
  429. {
  430. get
  431. {
  432. return _showAccumulativeVolume;
  433. }
  434. set
  435. {
  436. _showAccumulativeVolume = value;
  437. }
  438. }
  439. public bool ScaleLock
  440. {
  441. get
  442. {
  443. return _scaleLock;
  444. }
  445. set
  446. {
  447. _scaleLock = value;
  448. }
  449. }
  450. public bool UseCandleEffect
  451. {
  452. get
  453. {
  454. return _useCandleEffect;
  455. }
  456. set
  457. {
  458. _useCandleEffect = value;
  459. }
  460. }
  461. //ロウソク幅。奇数でないとだめ
  462. public int CandleWidth
  463. {
  464. get
  465. {
  466. return _candleWidth;
  467. }
  468. set
  469. {
  470. Debug.Assert((_candleWidth & 1) == 1);
  471. _candleWidth = value;
  472. }
  473. }
  474. //CandleWidthからの導出
  475. public int DatePitch
  476. {
  477. get
  478. {
  479. return _candleWidth * 5 / 3; //ロウソクの隙間を空けるためこれくらい
  480. }
  481. }
  482. public int HalfCandleWidth
  483. {
  484. get
  485. {
  486. return (_candleWidth + 1) >> 1;
  487. }
  488. }
  489. //自由直線系
  490. public Color FreeLineColor
  491. {
  492. get
  493. {
  494. return _freeLineColor;
  495. }
  496. set
  497. {
  498. _freeLineColor = value;
  499. _freeLinePen = null;
  500. _freeLineDottedPen = null;
  501. }
  502. }
  503. public ZPen FreeLinePen
  504. {
  505. get
  506. {
  507. if (_freeLinePen == null)
  508. _freeLinePen = new ZPen(_freeLineColor, ZPen.PenStyle.Bold);
  509. return _freeLinePen;
  510. }
  511. }
  512. public ZPen FreeLineDottedPen
  513. {
  514. get
  515. {
  516. if (_freeLineDottedPen == null)
  517. _freeLineDottedPen = new ZPen(_freeLineColor, ZPen.PenStyle.Dotted);
  518. return _freeLineDottedPen;
  519. }
  520. }
  521. public ZPen FreeLineBoldPen
  522. {
  523. get
  524. {
  525. if (_freeLineBoldPen == null)
  526. _freeLineBoldPen = new ZPen(_freeLineColor, ZPen.PenStyle.Bold);
  527. return _freeLineBoldPen;
  528. }
  529. }
  530. //☆Fibonacci
  531. public Color FibonacciColor
  532. {
  533. get
  534. {
  535. return _fibonacciColor;
  536. }
  537. set
  538. {
  539. _fibonacciColor = value;
  540. _fibonacciPen = null;
  541. _fibonacciDottedPen = null;
  542. }
  543. }
  544. public ZPen FibonacciPen
  545. {
  546. get
  547. {
  548. if (_fibonacciPen == null)
  549. _fibonacciPen = new ZPen(_fibonacciColor, ZPen.PenStyle.Bold);
  550. return _fibonacciPen;
  551. }
  552. }
  553. public ZPen FibonacciDottedPen
  554. {
  555. get
  556. {
  557. if (_fibonacciDottedPen == null)
  558. _fibonacciDottedPen = new ZPen(_fibonacciColor, ZPen.PenStyle.Dotted);
  559. return _freeLineDottedPen;
  560. }
  561. }
  562. public ZPen FibonacciBoldPen
  563. {
  564. get
  565. {
  566. if (_fibonacciBoldPen == null)
  567. _fibonacciBoldPen = new ZPen(_fibonacciColor, ZPen.PenStyle.Bold);
  568. return _fibonacciBoldPen;
  569. }
  570. }
  571. //☆Fibonacci 追加ここまで
  572. public ChartFormatSpecificValue AccumulativeVolumePeriod
  573. {
  574. get
  575. {
  576. return _accumulativeVolumePeriod;
  577. }
  578. set
  579. {
  580. _accumulativeVolumePeriod = value;
  581. }
  582. }
  583. public OscillatorPreference[] OscillatorPreferences
  584. {
  585. get
  586. {
  587. return _oscillatorPreferences;
  588. }
  589. }
  590. public Preference(StorageNode config)
  591. {
  592. _fontName = LoadString(config, "font-name", "MS 明朝");
  593. _fontSize = LoadFloat(config, "font-size", 9);
  594. _fontStyle = LoadFontStyle(config, "font-style", FontStyle.Regular);
  595. _defaultBrush = new ZBrush(LoadColor(config, "text-color", Color.White));
  596. _backBrush = new ZBrush(LoadColor(config, "back-color", Color.Black));
  597. _insenBrush = new ZBrush(LoadColor(config, "insen-color", Color.White));
  598. _fushiColor = LoadColor(config, "fushi-color", Color.DarkGray);
  599. _freeLineColor = LoadColor(config, "free-line-color", Color.Pink);
  600. _fibonacciColor = LoadColor(config, "fibonacci-color", Color.Red);//☆Fibonacci
  601. _defaultPen = new ZPen(_defaultBrush.Color, ZPen.PenStyle.Normal);
  602. _useCandleEffect = LoadBool(config, "candle-effect", true);
  603. _logScale = LoadBool(config, "log-scale", false);
  604. _inverseChart = LoadBool(config, "inverse-chart", false);
  605. _adjustSplit = LoadBool(config, "adjust-split", true);
  606. _candleWidth = LoadInt(config, "candle-width", 9);
  607. _candleWidth |= 1; //奇数にする
  608. if (_candleWidth < Env.Constants.MIN_CANDLE_WIDTH) _candleWidth = Env.Constants.MIN_CANDLE_WIDTH; //min
  609. if (_candleWidth > Env.Constants.MAX_CANDLE_WIDTH) _candleWidth = Env.Constants.MAX_CANDLE_WIDTH;
  610. _showPrice = LoadBool(config, "show-price", true);
  611. _showVolume = Util.ParseHeightConfig(LoadString(config, "show-volume", "Large"), HeightConfig.Large);
  612. _showAccumulativeVolume = LoadBool(config, "show-accumulative-volume", true);
  613. _candlePen = new ZCandlePen(LoadColor(config, "candle-color", Color.White), _backBrush.Color);
  614. _monthDivPen = new ZPen(LoadColor(config, "month-div-color", Color.OliveDrab), LoadStyle(config, "month-div-style", ZPen.PenStyle.Normal));
  615. _priceScalePen = new ZPen(LoadColor(config, "price-scale-color", Color.MediumSeaGreen), LoadStyle(config, "price-scale-style", ZPen.PenStyle.Dotted));
  616. _volumeScalePen = new ZPen(LoadColor(config, "volume-scale-color", Color.WhiteSmoke), LoadStyle(config, "volume-scale-style", ZPen.PenStyle.Dotted));
  617. _oscillatorScalePen = new ZPen(LoadColor(config, "oscillator-scale-color", Color.DarkRed), LoadStyle(config, "oscillator-scale-style", ZPen.PenStyle.Dotted));
  618. _volumeBrush = new ZBrush(LoadColor(config, "volume-color", Color.RoyalBlue));
  619. _mouseTrackingLineMode = (MouseTrackingLineMode)Enum.Parse(typeof(MouseTrackingLineMode), LoadString(config, "mouse-tracking-mode", "Full"));
  620. _mouseTrackingLinePen = new ZPen(LoadColor(config, "mouse-tracking-color", Color.LightGray), LoadStyle(config, "mouse-tracking-style", ZPen.PenStyle.Dotted));
  621. _creditLongAppearance = new IndicatorAppearance(LoadStyle(config, "creditlong-style", IndicatorStyle.Line), LoadColor(config, "creditlong-color", Color.Blue));
  622. _creditShortAppearance = new IndicatorAppearance(LoadStyle(config, "creditshort-style", IndicatorStyle.Line), LoadColor(config, "creditshort-color", Color.Red));
  623. _fushiRange = LoadInt(config, "fushi-range", 5);
  624. _fontDirty = true;
  625. _accumulativeVolumePeriod = new ChartFormatSpecificValue(LoadString(config, "accumulative-volume-period", "60,52,24,10"));
  626. _oscillatorPreferences = new OscillatorPreference[OscillatorPreference.LENGTH];
  627. for (int i = 0; i < _oscillatorPreferences.Length; i++)
  628. _oscillatorPreferences[i] = new OscillatorPreference(LoadString(config, "oscillator-" + i, "none"));
  629. }
  630. private string LoadString(StorageNode config, string name, string def)
  631. {
  632. if (config == null) return def;
  633. return config.GetValue(name, def);
  634. }
  635. private Color LoadColor(StorageNode config, string name, Color def)
  636. {
  637. if (config == null) return def;
  638. string cn = config.GetValue(name);
  639. if (cn == null)
  640. return def;
  641. else
  642. return Util.ParseColor(cn, def);
  643. }
  644. private FontStyle LoadFontStyle(StorageNode config, string name, FontStyle def)
  645. {
  646. if (config == null) return def;
  647. string cn = config.GetValue(name);
  648. if (cn == null)
  649. return def;
  650. else
  651. return (FontStyle)Enum.Parse(typeof(FontStyle), cn);
  652. }
  653. private int LoadInt(StorageNode config, string name, int def)
  654. {
  655. if (config == null) return def;
  656. return Util.ParseInt(config.GetValue(name, ""), def);
  657. }
  658. private bool LoadBool(StorageNode config, string name, bool def)
  659. {
  660. if (config == null) return def;
  661. return Util.ParseBool(config.GetValue(name, ""), def);
  662. }
  663. private float LoadFloat(StorageNode config, string name, float def)
  664. {
  665. if (config == null) return def;
  666. return Util.ParseFloat(config.GetValue(name, ""), def);
  667. }
  668. private IndicatorStyle LoadStyle(StorageNode config, string name, IndicatorStyle def)
  669. {
  670. if (config == null) return def;
  671. return IndicatorAppearance.ParseStyle(config.GetValue(name, ""), def);
  672. }
  673. private ZPen.PenStyle LoadStyle(StorageNode config, string name, ZPen.PenStyle def)
  674. {
  675. if (config == null) return def;
  676. string t = config.GetValue(name, "");
  677. if (t == "Normal")
  678. return ZPen.PenStyle.Normal;
  679. else if (t == "Dotted")
  680. return ZPen.PenStyle.Dotted;
  681. else if (t == "Bold")
  682. return ZPen.PenStyle.Bold;
  683. else
  684. return def;
  685. }
  686. public void SaveTo(StorageNode parent)
  687. {
  688. StorageNode node = new StorageNode();
  689. node.Name = "preference";
  690. node["font-name"] = _fontName;
  691. node["font-size"] = _fontSize.ToString();
  692. node["font-style"] = _fontStyle.ToString();
  693. node["text-color"] = Util.FormatColor(_defaultBrush.Color);
  694. node["back-color"] = Util.FormatColor(_backBrush.Color);
  695. node["insen-color"] = Util.FormatColor(_insenBrush.Color);
  696. node["fushi-color"] = Util.FormatColor(_fushiColor);
  697. node["free-line-color"] = Util.FormatColor(_freeLineColor);
  698. node["fibonacci-color"] = Util.FormatColor(_fibonacciColor);//☆Fibonacci
  699. node["candle-color"] = Util.FormatColor(_candlePen.Color);
  700. node["month-div-color"] = Util.FormatColor(_monthDivPen.Color);
  701. node["month-div-style"] = _monthDivPen.Style.ToString();
  702. node["price-scale-color"] = Util.FormatColor(_priceScalePen.Color);
  703. node["price-scale-style"] = _priceScalePen.Style.ToString();
  704. node["volume-scale-color"] = Util.FormatColor(_volumeScalePen.Color);
  705. node["volume-scale-style"] = _volumeScalePen.Style.ToString();
  706. node["oscillator-scale-color"] = Util.FormatColor(_oscillatorScalePen.Color);
  707. node["oscillator-scale-style"] = _oscillatorScalePen.Style.ToString();
  708. node["volume-color"] = Util.FormatColor(_volumeBrush.Color);
  709. node["mouse-tracking-color"] = Util.FormatColor(_mouseTrackingLinePen.Color);
  710. node["mouse-tracking-style"] = _mouseTrackingLinePen.Style.ToString();
  711. node["mouse-tracking-mode"] = _mouseTrackingLineMode.ToString();
  712. node["fushi-range"] = _fushiRange.ToString();
  713. node["creditlong-style"] = _creditLongAppearance.Pen.Style.ToString();
  714. node["creditlong-color"] = Util.FormatColor(_creditLongAppearance.Pen.Color);
  715. node["creditshort-style"] = _creditShortAppearance.Pen.Style.ToString();
  716. node["creditshort-color"] = Util.FormatColor(_creditShortAppearance.Pen.Color);
  717. node["candle-width"] = _candleWidth.ToString();
  718. node["candle-effect"] = _useCandleEffect.ToString();
  719. node["log-scale"] = _logScale.ToString();
  720. node["inverse-chart"] = _inverseChart.ToString();
  721. node["adjust-split"] = _adjustSplit.ToString();
  722. node["show-price"] = _showPrice.ToString();
  723. node["show-volume"] = _showVolume.ToString();
  724. node["show-accumulative-volume"] = _showAccumulativeVolume.ToString();
  725. node["accumulative-volume-period"] = _accumulativeVolumePeriod.ToString();
  726. for (int i = 0; i < _oscillatorPreferences.Length; i++)
  727. node["oscillator-" + i] = _oscillatorPreferences[i].Format();
  728. parent.AddChild(node);
  729. }
  730. public void Refresh()
  731. {
  732. for (int i = 0; i < _oscillatorPreferences.Length; i++)
  733. _oscillatorPreferences[i].Refresh();
  734. }
  735. /*
  736. #define PS_SOLID 0
  737. #define PS_DASH 1 /* -------
  738. #define PS_DOT 2 /* .......
  739. #define PS_DASHDOT 3 /* _._._._
  740. */
  741. public IntPtr DefaultHFont
  742. {
  743. get
  744. {
  745. if (_fontDirty) CreateFont();
  746. return _defaultHFont;
  747. }
  748. }
  749. public Font DefaultFont
  750. {
  751. get
  752. {
  753. if (_fontDirty) CreateFont();
  754. return _defaultFont;
  755. }
  756. }
  757. public IntPtr HeaderHFont
  758. {
  759. get
  760. {
  761. if (_fontDirty) CreateFont();
  762. return _headerHFont;
  763. }
  764. }
  765. public Font HeaderFont
  766. {
  767. get
  768. {
  769. if (_fontDirty) CreateFont();
  770. return _headerFont;
  771. }
  772. }
  773. public SizeF DefaultCharPitch
  774. {
  775. get
  776. {
  777. if (_fontDirty) CreateFont();
  778. return _defaultFontPitch;
  779. }
  780. }
  781. public SizeF HeaderCharPitch
  782. {
  783. get
  784. {
  785. if (_fontDirty) CreateFont();
  786. return _headerFontPitch;
  787. }
  788. }
  789. private void CreateFont()
  790. {
  791. _defaultFont = new Font(_fontName, _fontSize, _fontStyle);
  792. _headerFont = new Font(_fontName, _fontSize, _fontStyle);
  793. Graphics g = Env.Frame.CreateGraphics();
  794. SizeF t1 = g.MeasureString("A", _defaultFont);
  795. SizeF t2 = g.MeasureString("AA", _defaultFont);
  796. _defaultFontPitch = new SizeF(t2.Width - t1.Width, t1.Height);
  797. t1 = g.MeasureString("A", _headerFont);
  798. t2 = g.MeasureString("AA", _headerFont);
  799. _headerFontPitch = new SizeF(t2.Width - t1.Width, t1.Height);
  800. g.Dispose();
  801. _defaultHFont = _defaultFont.ToHfont();
  802. _headerHFont = _headerFont.ToHfont();
  803. _fontDirty = false;
  804. }
  805. }
  806. /// <summary>
  807. /// LayoutInfoは、Preferenceオブジェクトと現在のウィンドウサイズなどを元に計算するレイアウト情報を収録
  808. /// </summary>
  809. internal class LayoutInfo
  810. {
  811. //画面構成
  812. private int _volumePaneHeight; //出来高系統を表示する高さ
  813. private int[] _oscillatorPaneHeights; //オシレータの高さ
  814. private int _oscillatorPaneHeightTotal; //その合計
  815. private int _headerHeight; //上部の銘柄名などを表示する領域の高さ
  816. private int _footerHeight; //下部の日付などを表示する領域の高さ
  817. private int _scaleAreaWidth; //目盛りの数値を表示する領域の幅
  818. private int _accumulativeVolumeWidth; //価格帯出来高用の幅
  819. private int _remarkAreaWidth; //現在値と注釈
  820. private int _defaultTextWidth;
  821. private int _defaultTextHeight;
  822. private int _brandInfoHeight;
  823. public void Init()
  824. {
  825. //一部はPreferenceから取得
  826. Preference pref = Env.Preference;
  827. _volumePaneHeight = CalcHeight(pref.ShowVolume, 100);
  828. _oscillatorPaneHeightTotal = 0;
  829. _oscillatorPaneHeights = new int[OscillatorPreference.LENGTH];
  830. for (int i = 0; i < _oscillatorPaneHeights.Length; i++)
  831. {
  832. int h = CalcHeight(pref.OscillatorPreferences[i].Config, 100);
  833. _oscillatorPaneHeights[i] = h;
  834. _oscillatorPaneHeightTotal += h;
  835. }
  836. _headerHeight = 28; //(int)pref.HeaderCharPitch.Height+2;
  837. _footerHeight = (int)pref.DefaultCharPitch.Height + 2;
  838. _brandInfoHeight = Math.Min(40, _footerHeight);
  839. _scaleAreaWidth = (int)(pref.DefaultCharPitch.Width * 7);
  840. _accumulativeVolumeWidth = pref.ShowAccumulativeVolume ? (int)(pref.DefaultCharPitch.Width * 20) : 0;
  841. _remarkAreaWidth = pref.ShowPrice ? (int)(pref.DefaultCharPitch.Width * 23) : 0;
  842. _defaultTextWidth = (int)Math.Ceiling(pref.DefaultCharPitch.Width);
  843. _defaultTextHeight = (int)Math.Ceiling(pref.DefaultCharPitch.Height);
  844. }
  845. public int OscillatorPaneHeightTotal
  846. {
  847. get
  848. {
  849. return _oscillatorPaneHeightTotal;
  850. }
  851. }
  852. public int VolumePaneHeight
  853. {
  854. get
  855. {
  856. return _volumePaneHeight;
  857. }
  858. }
  859. public int[] OscillatorPaneHeights
  860. {
  861. get
  862. {
  863. return _oscillatorPaneHeights;
  864. }
  865. }
  866. public int HeaderHeight
  867. {
  868. get
  869. {
  870. return _headerHeight;
  871. }
  872. }
  873. public int FooterHeight
  874. {
  875. get
  876. {
  877. return _footerHeight;
  878. }
  879. }
  880. public int ScaleAreaWidth
  881. {
  882. get
  883. {
  884. return _scaleAreaWidth;
  885. }
  886. }
  887. public int AccumulativeVolumeWidth
  888. {
  889. get
  890. {
  891. return _accumulativeVolumeWidth;
  892. }
  893. }
  894. public int RemarkAreaWidth
  895. {
  896. get
  897. {
  898. return _remarkAreaWidth;
  899. }
  900. }
  901. public int DefaultTextHeight
  902. {
  903. get
  904. {
  905. return _defaultTextHeight;
  906. }
  907. }
  908. public int DefaultTextWidth
  909. {
  910. get
  911. {
  912. return _defaultTextWidth;
  913. }
  914. }
  915. //レイアウトがらみ
  916. public Rectangle ChartBodyRect
  917. {
  918. get
  919. {
  920. return new Rectangle(0, 0, Env.Frame.ChartCanvas.Width - _remarkAreaWidth - _accumulativeVolumeWidth - _scaleAreaWidth, Env.Frame.ChartCanvas.BodyHeight);
  921. }
  922. }
  923. public Rectangle BrandInformationRect
  924. {
  925. get
  926. {
  927. return new Rectangle(0, _headerHeight, Env.Frame.ChartCanvas.Width - _remarkAreaWidth - _accumulativeVolumeWidth, _brandInfoHeight);
  928. }
  929. }
  930. public Rectangle CurrentValueRect
  931. {
  932. get
  933. {
  934. return new Rectangle(Env.Frame.ChartCanvas.Width - _remarkAreaWidth, _headerHeight, _remarkAreaWidth, _defaultTextHeight * (GetDrawingEngine().MaximumValueWindowItemCount + 1));
  935. }
  936. }
  937. public Rectangle ExplanationRect
  938. {
  939. get
  940. {
  941. Rectangle r = this.CurrentValueRect;
  942. r.Y = r.Bottom;
  943. r.Height = Env.Frame.ChartCanvas.BodyHeight - r.Y;
  944. return r;
  945. }
  946. }
  947. public Rectangle AccumulativeVolumeRect
  948. {
  949. get
  950. {
  951. return new Rectangle(Env.Frame.ChartCanvas.Width - _remarkAreaWidth - _accumulativeVolumeWidth, _headerHeight, _accumulativeVolumeWidth, Env.Frame.ChartCanvas.BodyHeight - _oscillatorPaneHeightTotal - _volumePaneHeight - _footerHeight);
  952. }
  953. }
  954. public int ChartAreaHeight
  955. {
  956. get
  957. {
  958. return Env.Frame.ChartCanvas.BodyHeight - _headerHeight - _footerHeight;
  959. }
  960. }
  961. public int ChartAreaWidth
  962. {
  963. get
  964. {
  965. return Env.Frame.ChartCanvas.Width - _remarkAreaWidth - _accumulativeVolumeWidth - _scaleAreaWidth;
  966. }
  967. }
  968. public int ChartAreaBottom
  969. {
  970. get
  971. {
  972. return Env.Frame.ChartCanvas.BodyHeight - _footerHeight;
  973. }
  974. }
  975. public int DisplayColumnCount
  976. {
  977. get
  978. {
  979. int n = this.ChartAreaWidth / Env.Preference.DatePitch;
  980. #if DOJIMA
  981. if(Env.CurrentIndicators.Format==ChartFormat.HalfDaily) n /= 2;
  982. #endif
  983. if (n <= 1) n = 1;
  984. return n;
  985. }
  986. }
  987. //PreferenceのDatePitchと異なり、ChartFormatを考慮した値になる
  988. public int DatePitch
  989. {
  990. get
  991. {
  992. int n = Env.Preference.DatePitch;
  993. #if DOJIMA
  994. if(Env.CurrentIndicators.Format==ChartFormat.HalfDaily) n *= 2;
  995. #endif
  996. return n;
  997. }
  998. }
  999. public int CandleMiddleOffset
  1000. {
  1001. get
  1002. {
  1003. return DatePitch / 2;
  1004. }
  1005. }
  1006. private ChartDrawing GetDrawingEngine()
  1007. {
  1008. return Env.Frame.ChartCanvas.DrawingEngine;
  1009. }
  1010. private static int CalcHeight(HeightConfig value, int max)
  1011. {
  1012. switch (value)
  1013. {
  1014. case HeightConfig.None:
  1015. return 0;
  1016. case HeightConfig.Large:
  1017. return max;
  1018. case HeightConfig.Middle:
  1019. return max * 3 / 4;
  1020. default: //Small
  1021. return max / 2;
  1022. }
  1023. }
  1024. }
  1025. }
下載 Printable view

網址

Embed with JavaScript

Embed with iframe

Raw text