// Start is called before the first frame update void Start() { actions = GetData.getActions(); _cs = GetControlSequence(); _world = GameObject.Find("WorldBuilder").GetComponent <RPGWorldBuilder>(); _ani = GetComponent <ActorAnimationController>(); }
public void TestKeyBuild() { var key = new ControlSequence(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, false)).GetHashCode(); Assert.Equal(65, key); key = new ControlSequence(new ConsoleKeyInfo('A', ConsoleKey.A, false, false, true)).GetHashCode(); Assert.Equal(1024 + 65, key); key = new ControlSequence(new ConsoleKeyInfo('A', ConsoleKey.OemClear, true, false, false)).GetHashCode(); Assert.Equal(512 + 254, key); key = new ControlSequence(new ConsoleKeyInfo('A', ConsoleKey.OemClear, false, true, false)).GetHashCode(); Assert.Equal(256 + 254, key); }
public string Format(string format, object arg, IFormatProvider formatProvider) { if (arg == null) { return(String.Empty); } string[] formatPieces = format?.Split(',') ?? new[] { String.Empty }; bool hasFg = Enum.TryParse <ConsoleColor>(formatPieces.ElementAtOrDefault(1), out var fgColor); bool hasBg = Enum.TryParse <ConsoleColor>(formatPieces.ElementAtOrDefault(2), out var bgColor); if (hasFg || hasBg) { var sb = PushSgrSequence.Instance.AppendTo(new StringBuilder(), true); var parameters = new List <int>(2); if (hasFg) { parameters.Add(CaStringUtil.ForegroundColorMap[fgColor]); } if (hasBg) { parameters.Add(CaStringUtil.BackgroundColorMap[bgColor]); } ControlSequence.AppendCommand(sb, parameters, "m"); if (arg is ISupportColor asColor) { asColor.ToColorString().AppendTo(sb, true); } else { sb.Append(ArgumentToString(arg, formatPieces[0], true)); } PopSgrSequence.Instance.AppendTo(sb, true); return(sb.ToString()); } return(ArgumentToString(arg, formatPieces[0], true)); } // end Format()
ControlSequence GetControlSequence() { ControlSequence cs = new ControlSequence(); cs._controls = new Tuple <Movement, Spell> [actions.Length]; for (int i = 0; i < actions.Length; i++) { string[] s_action = System.Text.RegularExpressions.Regex.Replace(actions[i], @"\s+", ",").Split(','); string move_action = s_action[0]; string spell_action = s_action[1]; cs._controls[i] = new Tuple <Movement, Spell>(new Movement(move_action), new Spell(spell_action)); } // cs._controls = new Tuple<Movement, Spell>[] // { // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.R), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.R), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.JUMP)), // // new Tuple<Movement, Spell>(new Movement(Movement.R), new Spell(Spell.SLASH)), // // new Tuple<Movement, Spell>(new Movement(Movement.I), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.I), new Spell(Spell.DIE)), // // new Tuple<Movement, Spell>(new Movement(Movement.I), new Spell(Spell.JUMP)), // // // new Tuple<Movement, Spell>(new Movement(Movement.I), new Spell(Spell.EXIT)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.SLASH)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.R), new Spell(Spell.JUMP)), // // new Tuple<Movement, Spell>(new Movement(Movement.B), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.I)), // // new Tuple<Movement, Spell>(new Movement(Movement.F), new Spell(Spell.SLASH)), // // // }; return(cs); }
protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) { PInvoke.RECT rect; IntPtr dlg; switch (msg) { case PInvoke.WM_INITDIALOG: var dialogFont = PInvoke.SendMessage(hWnd, PInvoke.WM_GETFONT, IntPtr.Zero, IntPtr.Zero); // 全体のサイズを広げる PInvoke.GetClientRect(hWnd, out rect); OriginalClientSize.Width = rect.Right - rect.Left; OriginalClientSize.Height = rect.Bottom - rect.Top; PInvoke.GetWindowRect(hWnd, out rect); OriginalSize.Width = rect.Right - rect.Left; OriginalSize.Height = rect.Bottom - rect.Top; PInvoke.MoveWindow(hWnd, rect.Left, rect.Top, Size.Width, Size.Height, true); // 選択されている色の表示エリアの高さを半分に dlg = PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_CURRENT); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top, rect.Right - rect.Left, (rect.Bottom - rect.Top) / 2 - 2, true); // その下にテキストのサンプル dlg = PInvoke.CreateWindowEx(0, "EDIT", Properties.Resources.SAMPLE, PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_BORDER | PInvoke.WindowStyles.ES_CENTER, rect.Left, (rect.Top + rect.Bottom) / 2 + 4, rect.Right - rect.Left, (rect.Bottom - rect.Top) / 2 - 2, hWnd, new IntPtr(ID_CURRENTTEXTCOLOR), Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule), IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.EM_SETREADONLY, new IntPtr(1), IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); // OK,キャンセル,色の追加を下に移動. dlg = PInvoke.GetDlgItem(hWnd, PInvoke.IDOK); var okButton = dlg; GetControlRect(hWnd, dlg, out rect); var RadioBtnPos = new System.Drawing.Point(rect.Left, rect.Top + 5); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); dlg = PInvoke.GetDlgItem(hWnd, PInvoke.IDCANCEL); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); dlg = PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_ADD); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, OriginalClientSize.Width - 10 - rect.Left, rect.Bottom - rect.Top, true); if (ShowHelp) { dlg = PInvoke.GetDlgItem(hWnd, PInvoke.pshHelp); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); } // ラジオボタン四つ var instance = Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule); dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\color", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON | PInvoke.WindowStyles.WS_GROUP, RadioBtnPos.X, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_COLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SendMessage(dlg, PInvoke.BM_SETCHECK, new IntPtr(1), IntPtr.Zero); // タブオーダーをCOLOR_CUSTOM1の後に持ってくる. // http://stackoverflow.com/questions/50236/how-do-you-programmatically-change-the-tab-order-in-a-win32-dialog PInvoke.SetWindowPos(dlg, PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_CUSTOM1), 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); var prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\textcolor", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width / 4, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_TEXTCOLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\colorbox", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width / 2, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_COLORBOX), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\definecolor", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width * 3 / 4, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_DEFINECOLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); // 入力される命令を出すエディトボックス dlg = PInvoke.CreateWindowEx(0, "EDIT", "", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_BORDER, RadioBtnPos.X, RadioBtnPos.Y + 20, ClientSize.Width - 10 - RadioBtnPos.X, 20, hWnd, new IntPtr(ID_SAMPLETEXTBOX), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SendMessage(dlg, PInvoke.EM_SETREADONLY, new IntPtr(1), IntPtr.Zero); PInvoke.SetWindowText(dlg, GetControlSequenceString(hWnd)); // ウィンドウ広げたら出てきた.消しておく. PInvoke.ShowWindow(PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_SOLID), PInvoke.ShowWindowCommands.Hide); // 常にFullOpen = trueなので不要だから消しておく. PInvoke.ShowWindow(PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_MIX), PInvoke.ShowWindowCommands.Hide); break; case PInvoke.WM_COMMAND: //System.Diagnostics.Debug.WriteLine("WM_COMMAND: id = " + (wparam.ToInt32() & 0xFFFF).ToString()); switch (wparam.ToInt32() & 0xFFFF) { case PInvoke.COLOR_RED: case PInvoke.COLOR_BLUE: case PInvoke.COLOR_GREEN: OnSelectedColorChanged(GetCurrentColor(hWnd), GetControlSequence(hWnd)); dlg = PInvoke.GetDlgItem(hWnd, ID_CURRENTTEXTCOLOR); PInvoke.InvalidateRect(dlg, IntPtr.Zero, true); PInvoke.SetWindowText(PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX), GetControlSequenceString(hWnd)); break; case ID_CHECKBOX_COLOR: case ID_CHECKBOX_COLORBOX: case ID_CHECKBOX_DEFINECOLOR: case ID_CHECKBOX_TEXTCOLOR: PInvoke.SetWindowText(PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX), GetControlSequenceString(hWnd)); break; case PInvoke.IDOK: CheckedControlSequence = GetControlSequence(hWnd); break; default: break; } break; case PInvoke.WM_CTLCOLORSTATIC: if (lparam == PInvoke.GetDlgItem(hWnd, ID_CURRENTTEXTCOLOR)) { PInvoke.SetTextColor(wparam, ToRGB(GetCurrentColor(hWnd))); return(PInvoke.GetStockObject(PInvoke.StockObjects.WHITE_BRUSH)); } if (lparam == PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX)) { PInvoke.SetTextColor(wparam, ToRGB(Properties.Settings.Default.editorNormalColorFont)); return(brush); } break; default: break; } return(base.HookProc(hWnd, msg, wparam, lparam)); }
protected void OnSelectedColorChanged(System.Drawing.Color c, ControlSequence cs) { SelectedColorChanged(this, new SelectedColorChangedEventArgs(c, cs)); }
public SelectedColorChangedEventArgs(System.Drawing.Color c, ControlSequence cs) { Color = c; ControlSequence = cs; }
public void HandleControlSequence(ControlSequence seq) { switch (seq.Type) { case ControlSequenceType.Home: { var diff = CurrentEditor.MoveHome(); terminal.CursorBackward(diff); } break; case ControlSequenceType.End: { var diff = CurrentEditor.MoveEnd(); terminal.CursorForward(diff); } break; case ControlSequenceType.LeftArrow: if (CurrentEditor.MoveCharacterBackward()) { terminal.CursorBackward(); } break; case ControlSequenceType.RightArrow: if (CurrentEditor.MoveCharacterForward()) { terminal.CursorForward(); } break; case ControlSequenceType.UpArrow: { if (mode == Mode.UserInput) { break; } if (!history.HasMoved) { history.SetCurrentCommand(CurrentEditor.Value); } var prev = history.PreviousCommand(); if (prev != null) { var len = CurrentEditor.Position; CurrentEditor.SetValue(prev); terminal.CursorBackward(len); terminal.ClearToTheEndOfLine(); terminal.Write(CurrentEditor.Value); } } break; case ControlSequenceType.DownArrow: { if (mode == Mode.UserInput) { break; } var cmd = history.NextCommand(); if (cmd != null) { var len = CurrentEditor.Position; CurrentEditor.SetValue(cmd); terminal.CursorBackward(len); terminal.ClearToTheEndOfLine(); terminal.Write(CurrentEditor.Value); } } break; case ControlSequenceType.Backspace: if (CurrentEditor.RemovePreviousCharacter()) { terminal.CursorBackward(); if (mode == Mode.Command || mode == Mode.UserInput) { terminal.ClearToTheEndOfLine(); terminal.WriteNoMove(CurrentEditor.ToString(CurrentEditor.Position)); } else if (mode == Mode.Search) { SearchPrompt.Recreate(terminal); history.Reset(); var result = history.ReverseSearch(search.Value); terminal.WriteNoMove(result, SearchPrompt.Skip); } } break; case ControlSequenceType.Delete: if (CurrentEditor.RemoveNextCharacter()) { if (mode == Mode.Command || mode == Mode.UserInput) { terminal.ClearToTheEndOfLine(); terminal.WriteNoMove(CurrentEditor.ToString(CurrentEditor.Position)); } else if (mode == Mode.Search) { SearchPrompt.Recreate(terminal); history.Reset(); var result = history.ReverseSearch(search.Value); terminal.WriteNoMove(result, SearchPrompt.Skip); } } break; case ControlSequenceType.CtrlLeftArrow: { var diff = CurrentEditor.MoveWordBackward(); terminal.CursorBackward(diff); } break; case ControlSequenceType.CtrlRightArrow: { var diff = CurrentEditor.MoveWordForward(); terminal.CursorForward(diff); } break; case ControlSequenceType.Ctrl: switch ((char)seq.Argument) { case 'c': if (mode == Mode.Command) { terminal.CursorForward(CurrentEditor.MoveEnd()); terminal.Write("^C"); terminal.NewLine(); } else { mode = Mode.Command; terminal.ClearLine(); } search.Clear(); command.Clear(); NormalPrompt.Write(terminal); history.Reset(); break; case 'r': if (mode == Mode.UserInput) { break; } else if (mode == Mode.Command) { mode = Mode.Search; terminal.CursorBackward(command.MoveHome()); terminal.ClearLine(); search.SetValue(string.Empty); command.Clear(); CurrentPrompt.Write(terminal); } else if (mode == Mode.Search) { if (search.Value != string.Empty) { var result = history.ReverseSearch(search.Value); terminal.CursorForward(SearchPrompt.Skip); terminal.ClearToTheEndOfLine(); terminal.WriteNoMove(result); terminal.CursorBackward(SearchPrompt.Skip); } } break; case 'w': { var diff = CurrentEditor.RemoveWord(); if (diff > 0) { terminal.CursorBackward(diff); if (mode == Mode.Command || mode == Mode.UserInput) { terminal.ClearToTheEndOfLine(); terminal.WriteNoMove(CurrentEditor.ToString(CurrentEditor.Position)); } else if (mode == Mode.Search) { SearchPrompt.Recreate(terminal); history.Reset(); var result = history.ReverseSearch(search.Value); terminal.WriteNoMove(result); } } } break; case 'k': CurrentEditor.RemoveToTheEnd(); if (mode == Mode.Command || mode == Mode.UserInput) { terminal.ClearToTheEndOfLine(); } else if (mode == Mode.Search) { SearchPrompt.Recreate(terminal); history.Reset(); var result = history.ReverseSearch(search.Value); terminal.WriteNoMove(result); } break; default: break; } break; case ControlSequenceType.Esc: if (mode == Mode.Search) { search.Clear(); command.SetValue(history.CurrentCommand ?? string.Empty); mode = Mode.Command; terminal.ClearLine(); NormalPrompt.Write(terminal); terminal.Write(command.Value); } break; case ControlSequenceType.Tab: if (mode == Mode.UserInput) { break; } else if (mode == Mode.Search) { mode = Mode.Command; CurrentEditor.SetValue(history.CurrentCommand); terminal.ClearLine(); CurrentPrompt.Write(terminal); terminal.Write(CurrentEditor.Value); } else if (mode == Mode.Command) { var sugs = handler.SuggestionNeeded(CurrentEditor.Value); var preparedBaseString = PreprocessSuggestionsInput(CurrentEditor.Value); var commonPrefix = Helper.CommonPrefix(sugs, preparedBaseString); var prefix = String.IsNullOrEmpty(commonPrefix) ? CurrentEditor.Value : commonPrefix; if (sugs.Length == 0) { break; } if (!tabTabMode || sugs.Length == 1) { tabTabMode = true; terminal.CursorBackward(CurrentEditor.Position); terminal.ClearToTheEndOfLine(); CurrentEditor.SetValue(prefix); } else if (tabTabMode) { terminal.NewLine(); var splitPoint = prefix.LastIndexOf(" ", StringComparison.Ordinal); foreach (var sug in sugs) { terminal.WriteRaw(string.Format(" {0}\r\n", sug.Substring(splitPoint + 1))); } CurrentEditor.SetValue(prefix); NormalPrompt.Write(terminal); } if (sugs.Length == 1 && sugs[0][sugs[0].Length - 1] != DirectorySeparatorChar) { CurrentEditor.InsertCharacter(' '); } terminal.Write(CurrentEditor.Value); return; } break; case ControlSequenceType.Enter: var wasInSearchMode = false; if (mode == Mode.Search) { mode = Mode.Command; command.SetValue(history.CurrentCommand ?? string.Empty); search.Clear(); terminal.ClearLine(); wasInSearchMode = true; } else { terminal.CursorForward(CurrentEditor.MoveEnd()); terminal.NewLine(); } if (CurrentEditor.Value != string.Empty) { if (wasInSearchMode) { NormalPrompt.Write(terminal); terminal.Write(command.Value); terminal.NewLine(); } var cmd = CurrentEditor.Value; while (true) { var interaction = handler.HandleCommand(cmd, null); if (interaction != null && interaction.QuitEnvironment) { terminal.Stop(); return; } CurrentEditor.Clear(); if (interaction != null && interaction.CommandToExecute != null) { cmd = interaction.CommandToExecute; terminal.Write(cmd); terminal.NewLine(); (interaction as CommandInteraction).Clear(); } else { break; } } } NormalPrompt.Write(terminal); if (CurrentEditor.Length > 0) { terminal.Write(CurrentEditor.Value); } history.Reset(); break; default: break; } tabTabMode = false; }
public SymConst Visit(ControlSequence node) { throw EvalException(); }
protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) { PInvoke.RECT rect; IntPtr dlg; switch(msg) { case PInvoke.WM_INITDIALOG: var dialogFont = PInvoke.SendMessage(hWnd, PInvoke.WM_GETFONT, IntPtr.Zero, IntPtr.Zero); // 全体のサイズを広げる PInvoke.GetClientRect(hWnd, out rect); OriginalClientSize.Width = rect.Right - rect.Left; OriginalClientSize.Height = rect.Bottom - rect.Top; PInvoke.GetWindowRect(hWnd, out rect); OriginalSize.Width = rect.Right - rect.Left; OriginalSize.Height = rect.Bottom - rect.Top; PInvoke.MoveWindow(hWnd, rect.Left, rect.Top, Size.Width, Size.Height, true); // 選択されている色の表示エリアの高さを半分に dlg = PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_CURRENT); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top, rect.Right - rect.Left, (rect.Bottom - rect.Top) / 2-2, true); // その下にテキストのサンプル dlg = PInvoke.CreateWindowEx(0,"EDIT",Properties.Resources.SAMPLE, PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_BORDER | PInvoke.WindowStyles.ES_CENTER, rect.Left,(rect.Top + rect.Bottom)/2+4,rect.Right - rect.Left,(rect.Bottom - rect.Top)/2-2, hWnd,new IntPtr(ID_CURRENTTEXTCOLOR),Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule), IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.EM_SETREADONLY, new IntPtr(1), IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); // OK,キャンセル,色の追加を下に移動. dlg = PInvoke.GetDlgItem(hWnd,PInvoke.IDOK); var okButton = dlg; GetControlRect(hWnd, dlg, out rect); var RadioBtnPos = new System.Drawing.Point(rect.Left, rect.Top + 5); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); dlg = PInvoke.GetDlgItem(hWnd,PInvoke.IDCANCEL); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); dlg = PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_ADD); GetControlRect(hWnd,dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, OriginalClientSize.Width - 10 - rect.Left, rect.Bottom - rect.Top, true); if(ShowHelp) { dlg = PInvoke.GetDlgItem(hWnd, PInvoke.pshHelp); GetControlRect(hWnd, dlg, out rect); PInvoke.MoveWindow(dlg, rect.Left, rect.Top + 50, rect.Right - rect.Left, rect.Bottom - rect.Top, true); } // ラジオボタン四つ var instance = Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule); dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\color", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON | PInvoke.WindowStyles.WS_GROUP, RadioBtnPos.X, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_COLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SendMessage(dlg, PInvoke.BM_SETCHECK, new IntPtr(1), IntPtr.Zero); // タブオーダーをCOLOR_CUSTOM1の後に持ってくる. // http://stackoverflow.com/questions/50236/how-do-you-programmatically-change-the-tab-order-in-a-win32-dialog PInvoke.SetWindowPos(dlg, PInvoke.GetDlgItem(hWnd,PInvoke.COLOR_CUSTOM1), 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); var prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\textcolor", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width / 4, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_TEXTCOLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\colorbox", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width / 2, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_COLORBOX), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); prevdlg = dlg; dlg = PInvoke.CreateWindowEx(0, "BUTTON", "\\definecolor", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_TABSTOP | PInvoke.WindowStyles.BS_AUTORADIOBUTTON, RadioBtnPos.X + ClientSize.Width * 3 / 4, RadioBtnPos.Y, ClientSize.Width / 4, 15, hWnd, new IntPtr(ID_CHECKBOX_DEFINECOLOR), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SetWindowPos(dlg, prevdlg, 0, 0, 0, 0, PInvoke.SetWindowPosFlags.SWP_NOMOVE | PInvoke.SetWindowPosFlags.SWP_NOSIZE); // 入力される命令を出すエディトボックス dlg = PInvoke.CreateWindowEx(0, "EDIT", "", PInvoke.WindowStyles.WS_CHILD | PInvoke.WindowStyles.WS_VISIBLE | PInvoke.WindowStyles.WS_BORDER, RadioBtnPos.X, RadioBtnPos.Y + 20, ClientSize.Width - 10 - RadioBtnPos.X, 20, hWnd, new IntPtr(ID_SAMPLETEXTBOX), instance, IntPtr.Zero); PInvoke.SendMessage(dlg, PInvoke.WM_SETFONT, dialogFont, new IntPtr(1)); PInvoke.SendMessage(dlg, PInvoke.EM_SETREADONLY, new IntPtr(1), IntPtr.Zero); PInvoke.SetWindowText(dlg, GetControlSequenceString(hWnd)); // ウィンドウ広げたら出てきた.消しておく. PInvoke.ShowWindow(PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_SOLID), PInvoke.ShowWindowCommands.Hide); // 常にFullOpen = trueなので不要だから消しておく. PInvoke.ShowWindow(PInvoke.GetDlgItem(hWnd, PInvoke.COLOR_MIX), PInvoke.ShowWindowCommands.Hide); break; case PInvoke.WM_COMMAND: //System.Diagnostics.Debug.WriteLine("WM_COMMAND: id = " + (wparam.ToInt32() & 0xFFFF).ToString()); switch(wparam.ToInt32() & 0xFFFF) { case PInvoke.COLOR_RED: case PInvoke.COLOR_BLUE: case PInvoke.COLOR_GREEN: OnSelectedColorChanged(GetCurrentColor(hWnd),GetControlSequence(hWnd)); dlg = PInvoke.GetDlgItem(hWnd, ID_CURRENTTEXTCOLOR); PInvoke.InvalidateRect(dlg, IntPtr.Zero, true); PInvoke.SetWindowText(PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX), GetControlSequenceString(hWnd)); break; case ID_CHECKBOX_COLOR: case ID_CHECKBOX_COLORBOX: case ID_CHECKBOX_DEFINECOLOR: case ID_CHECKBOX_TEXTCOLOR: PInvoke.SetWindowText(PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX), GetControlSequenceString(hWnd)); break; case PInvoke.IDOK: CheckedControlSequence = GetControlSequence(hWnd); break; default: break; } break; case PInvoke.WM_CTLCOLORSTATIC: if(lparam == PInvoke.GetDlgItem(hWnd, ID_CURRENTTEXTCOLOR)) { PInvoke.SetTextColor(wparam, ToRGB(GetCurrentColor(hWnd))); return PInvoke.GetStockObject(PInvoke.StockObjects.WHITE_BRUSH); } if(lparam == PInvoke.GetDlgItem(hWnd, ID_SAMPLETEXTBOX)) { PInvoke.SetTextColor(wparam, ToRGB(Properties.Settings.Default.editorNormalColorFont)); return brush; } break; default: break; } return base.HookProc(hWnd, msg, wparam, lparam); }
protected void OnSelectedColorChanged(System.Drawing.Color c,ControlSequence cs) { SelectedColorChanged(this, new SelectedColorChangedEventArgs(c, cs)); }