Exemplo n.º 1
0
        /// <summary>
        /// Ctor.
        /// </summary>
        public LookupControl(ZenControlBase owner, ICedictEngineFactory dictFact, ITextProvider tprov)
            : base(owner)
        {
            this.dictFact = dictFact;
            this.tprov    = tprov;
            padding       = (int)Math.Round(5.0F * Scale);

            // Init search language and script from user settings
            searchLang   = AppSettings.SearchLang;
            searchScript = AppSettings.SearchScript;

            // Init HanziLookup
            fsStrokes   = new FileStream(Magic.StrokesFileName, FileMode.Open, FileAccess.Read);
            brStrokes   = new BinaryReader(fsStrokes);
            strokesData = new StrokesDataSource(brStrokes);

            // Writing pad
            writingPad                 = new WritingPad(this, tprov);
            writingPad.RelLocation     = new Point(padding, padding);
            writingPad.LogicalSize     = new Size(200, 200);
            writingPad.StrokesChanged += writingPad_StrokesChanged;

            // Images for buttons under writing pad; will get owned by buttons, not that it matters.
            Assembly a = Assembly.GetExecutingAssembly();
            var      imgStrokesClear = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-clear.png"));
            var      imgStrokesUndo  = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-undo.png"));

            // Clear and undo buttons under writing pad.
            float leftBtnWidth = writingPad.Width / 2 + 1;
            float btnHeight    = 22.0F * Scale;

            // --
            btnClearWritingPad             = new ZenGradientButton(this);
            btnClearWritingPad.RelLocation = new Point(writingPad.RelLeft, writingPad.RelBottom - 1);
            btnClearWritingPad.Size        = new Size((int)leftBtnWidth, (int)btnHeight);
            btnClearWritingPad.Text        = tprov.GetString("WritingPadClear");
            btnClearWritingPad.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F));
            btnClearWritingPad.Padding           = (int)(3.0F * Scale);
            btnClearWritingPad.ImageExtraPadding = (int)(3.0F * Scale);
            btnClearWritingPad.Image             = imgStrokesClear;
            btnClearWritingPad.Enabled           = false;
            btnClearWritingPad.MouseClick       += onClearWritingPad;
            // --
            btnUndoStroke             = new ZenGradientButton(this);
            btnUndoStroke.RelLocation = new Point(btnClearWritingPad.RelRight - 1, writingPad.RelBottom - 1);
            btnUndoStroke.Size        = new Size(writingPad.RelRight - btnUndoStroke.RelLeft, (int)btnHeight);
            btnUndoStroke.Text        = tprov.GetString("WritingPadUndo");
            btnUndoStroke.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F));
            btnUndoStroke.Padding           = (int)(3.0F * Scale);
            btnUndoStroke.ImageExtraPadding = (int)(1.5F * Scale);
            btnUndoStroke.Image             = imgStrokesUndo;
            btnUndoStroke.Enabled           = false;
            btnUndoStroke.MouseClick       += onUndoStroke;
            // --
            btnClearWritingPad.Tooltip = new ClearUndoTooltips(btnClearWritingPad, true, tprov, padding);
            btnUndoStroke.Tooltip      = new ClearUndoTooltips(btnUndoStroke, false, tprov, padding);
            // --

            // Character picker control under writing pad.
            ctrlCharPicker             = new CharPicker(this, tprov);
            ctrlCharPicker.FontFam     = Magic.ZhoContentFontFamily;
            ctrlCharPicker.FontScript  = searchScript == SearchScript.Traditional ? IdeoScript.Trad : IdeoScript.Simp;
            ctrlCharPicker.RelLocation = new Point(padding, btnClearWritingPad.RelBottom + padding);
            ctrlCharPicker.LogicalSize = new Size(200, 80);
            ctrlCharPicker.CharPicked += onCharPicked;

            // Search input control at top
            ctrlSearchInput              = new SearchInputControl(this, tprov);
            ctrlSearchInput.RelLocation  = new Point(writingPad.RelRight + padding, padding);
            ctrlSearchInput.StartSearch += onStartSearch;

            // Tweaks for Chinese text on UI buttons
            // This is specific to Segoe UI and Noto Sans S Chinese fonts.
            float ofsZho = 0;

            //if (!(SystemFontProvider.Instance as ZydeoSystemFontProvider).SegoeExists)
            //    ofsZho = Magic.ZhoButtonFontSize * Scale / 3.7F;

            // Script selector button to the right of search input control
            btnSimpTrad        = new ZenGradientButton(this);
            btnSimpTrad.RelTop = padding;
            btnSimpTrad.Height = ctrlSearchInput.Height;
            btnSimpTrad.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont(
                                    FontStyle.Regular, Magic.ZhoButtonFontSize));
            btnSimpTrad.Width             = getSimpTradWidth();
            btnSimpTrad.ForcedCharVertOfs = ofsZho;
            btnSimpTrad.RelLeft           = Width - padding - btnSimpTrad.Width;
            btnSimpTrad.Height            = ctrlSearchInput.Height;
            btnSimpTrad.MouseClick       += onSimpTrad;

            // Search language selector to the right of search input control
            btnSearchLang        = new ZenGradientButton(this);
            btnSearchLang.RelTop = padding;
            btnSearchLang.Height = ctrlSearchInput.Height;
            btnSearchLang.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont(
                                      FontStyle.Regular, Magic.ZhoButtonFontSize));
            btnSearchLang.Width             = getSearchLangWidth();
            btnSearchLang.ForcedCharVertOfs = ofsZho;
            btnSearchLang.RelLeft           = btnSimpTrad.RelLeft - padding - btnSearchLang.Width;
            btnSearchLang.Height            = ctrlSearchInput.Height;
            btnSearchLang.MouseClick       += onSearchLang;

            // Update button texts; do it here so tooltip locations will be correct.
            simpTradChanged();
            searchLangChanged();

            // Lookup results control.
            ctrlResults             = new ResultsControl(this, tprov, onLookupThroughLink, onGetEntry);
            ctrlResults.RelLocation = new Point(writingPad.RelRight + padding, ctrlSearchInput.RelBottom + padding);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ctor.
        /// </summary>
        public LookupControl(ZenControlBase owner, ICedictEngineFactory dictFact, ITextProvider tprov)
            : base(owner)
        {
            this.dictFact = dictFact;
            this.tprov = tprov;
            padding = (int)Math.Round(5.0F * Scale);

            // Init search language and script from user settings
            searchLang = AppSettings.SearchLang;
            searchScript = AppSettings.SearchScript;

            // Init HanziLookup
            fsStrokes = new FileStream(Magic.StrokesFileName, FileMode.Open, FileAccess.Read);
            brStrokes = new BinaryReader(fsStrokes);
            strokesData = new StrokesDataSource(brStrokes);

            // Writing pad
            writingPad = new WritingPad(this, tprov);
            writingPad.RelLocation = new Point(padding, padding);
            writingPad.LogicalSize = new Size(200, 200);
            writingPad.StrokesChanged += writingPad_StrokesChanged;

            // Images for buttons under writing pad; will get owned by buttons, not that it matters.
            Assembly a = Assembly.GetExecutingAssembly();
            var imgStrokesClear = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-clear.png"));
            var imgStrokesUndo = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-undo.png"));

            // Clear and undo buttons under writing pad.
            float leftBtnWidth = writingPad.Width / 2 + 1;
            float btnHeight = 22.0F * Scale;
            // --
            btnClearWritingPad = new ZenGradientButton(this);
            btnClearWritingPad.RelLocation = new Point(writingPad.RelLeft, writingPad.RelBottom - 1);
            btnClearWritingPad.Size = new Size((int)leftBtnWidth, (int)btnHeight);
            btnClearWritingPad.Text = tprov.GetString("WritingPadClear");
            btnClearWritingPad.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F));
            btnClearWritingPad.Padding = (int)(3.0F * Scale);
            btnClearWritingPad.ImageExtraPadding = (int)(3.0F * Scale);
            btnClearWritingPad.Image = imgStrokesClear;
            btnClearWritingPad.Enabled = false;
            btnClearWritingPad.MouseClick += onClearWritingPad;
            // --
            btnUndoStroke = new ZenGradientButton(this);
            btnUndoStroke.RelLocation = new Point(btnClearWritingPad.RelRight - 1, writingPad.RelBottom - 1);
            btnUndoStroke.Size = new Size(writingPad.RelRight - btnUndoStroke.RelLeft, (int)btnHeight);
            btnUndoStroke.Text = tprov.GetString("WritingPadUndo");
            btnUndoStroke.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F));
            btnUndoStroke.Padding = (int)(3.0F * Scale);
            btnUndoStroke.ImageExtraPadding = (int)(1.5F * Scale);
            btnUndoStroke.Image = imgStrokesUndo;
            btnUndoStroke.Enabled = false;
            btnUndoStroke.MouseClick += onUndoStroke;
            // --
            btnClearWritingPad.Tooltip = new ClearUndoTooltips(btnClearWritingPad, true, tprov, padding);
            btnUndoStroke.Tooltip = new ClearUndoTooltips(btnUndoStroke, false, tprov, padding);
            // --

            // Character picker control under writing pad.
            ctrlCharPicker = new CharPicker(this, tprov);
            ctrlCharPicker.FontFam = Magic.ZhoContentFontFamily;
            ctrlCharPicker.FontScript = searchScript == SearchScript.Traditional ? IdeoScript.Trad : IdeoScript.Simp;
            ctrlCharPicker.RelLocation = new Point(padding, btnClearWritingPad.RelBottom + padding);
            ctrlCharPicker.LogicalSize = new Size(200, 80);
            ctrlCharPicker.CharPicked += onCharPicked;

            // Search input control at top
            ctrlSearchInput = new SearchInputControl(this, tprov);
            ctrlSearchInput.RelLocation = new Point(writingPad.RelRight + padding, padding);
            ctrlSearchInput.StartSearch += onStartSearch;

            // Tweaks for Chinese text on UI buttons
            // This is specific to Segoe UI and Noto Sans S Chinese fonts.
            float ofsZho = 0;
            //if (!(SystemFontProvider.Instance as ZydeoSystemFontProvider).SegoeExists)
            //    ofsZho = Magic.ZhoButtonFontSize * Scale / 3.7F;

            // Script selector button to the right of search input control
            btnSimpTrad = new ZenGradientButton(this);
            btnSimpTrad.RelTop = padding;
            btnSimpTrad.Height = ctrlSearchInput.Height;
            btnSimpTrad.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont(
                FontStyle.Regular, Magic.ZhoButtonFontSize));
            btnSimpTrad.Width = getSimpTradWidth();
            btnSimpTrad.ForcedCharVertOfs = ofsZho;
            btnSimpTrad.RelLeft = Width - padding - btnSimpTrad.Width;
            btnSimpTrad.Height = ctrlSearchInput.Height;
            btnSimpTrad.MouseClick += onSimpTrad;

            // Search language selector to the right of search input control
            btnSearchLang = new ZenGradientButton(this);
            btnSearchLang.RelTop = padding;
            btnSearchLang.Height = ctrlSearchInput.Height;
            btnSearchLang.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont(
                FontStyle.Regular, Magic.ZhoButtonFontSize));
            btnSearchLang.Width = getSearchLangWidth();
            btnSearchLang.ForcedCharVertOfs = ofsZho;
            btnSearchLang.RelLeft = btnSimpTrad.RelLeft - padding - btnSearchLang.Width;
            btnSearchLang.Height = ctrlSearchInput.Height;
            btnSearchLang.MouseClick += onSearchLang;

            // Update button texts; do it here so tooltip locations will be correct.
            simpTradChanged();
            searchLangChanged();

            // Lookup results control.
            ctrlResults = new ResultsControl(this, tprov, onLookupThroughLink, onGetEntry);
            ctrlResults.RelLocation = new Point(writingPad.RelRight + padding, ctrlSearchInput.RelBottom + padding);
        }