public void DrawBlock(string text) { int y = 0; int x = 0; // This actually removes all new lines string[] lines = text.Split('\n'); foreach (string line in lines) { foreach (char c in line.ToCharArray()) { if (x >= 80) { continue; } if (y >= 24) { break; } try { Stdscr.Add(y, x, c); } catch { } x++; } x = 0; y++; } }
public void ClearToEnd(int ccol) { for (int c = ccol; c < w; c++) { Stdscr.Add(' '); } }
public static void Draw() { // Loop through each column, then nestedly loop through each element in the column. // This will draw the "map". for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Entity ent = grid[y][x]; if (ent != null) { ent.Draw(); } } } // Now for everything that moves. They will draw over the map. foreach (Entity ent in dyna) { ent.Draw(); } // Status bar :v string status = "HP: Alive\tGun: " + GetPlayer().gun; int printPos = 0; foreach (char character in status.ToCharArray()) { Stdscr.Add(23, printPos, character); printPos++; } printPos = 0; }
public static void DrawBlock(int x, int y, string text) { string[] lines = text.Split('\n'); int width = text.IndexOf('\n'); int height = lines.Length; x -= width / 2; y -= width / 2; int rx = x; foreach (string line in lines) { foreach (char c in line.ToCharArray()) { if (x >= 80 || x < 0) { continue; } if (y >= 24 || y < 0) { continue; } try { Stdscr.Add(y, x, c); } catch { } x++; } x = rx; y++; } }
public void DrawItem (int nth, bool isSelected) { char ch; if (nth >= listing.Count) throw new Exception ("overflow"); isSelected = HasFocus && isSelected; Move (y + (nth - top) + 1, x + 1); Listing.FileNode node = listing [nth]; uint color; if (node == null) throw new Exception (String.Format ("Problem fetching item {0}", nth)); if (node.Info.IsDirectory) { color = isSelected ? ColorFocus : ColorDir; ch = '/'; } else { color = isSelected ? ColorFocus : ColorNormal; ch = ' '; } if (node.Marked) color = isSelected ? ColorHotFocus : ColorHotNormal; Stdscr.Attr = color; for (int i = 0; i < node.Nested; i++) Stdscr.Add (" "); Stdscr.Add (ch); Stdscr.Add (node.Name); }
private static void AddStr(int y, int x, string str) { if (x >= 0 && x < Curses.Cols && y >= 0 && y < Curses.Lines) { Stdscr.Add(y, x, str); } }
// public override void Redraw () // { // //int x = 0; // int y = Terminal.Lines - 1; // Move (y, 0); // // for (int i = 0; i < labels.Length; i++) { // Stdscr.Attr = Terminal.ColorBasic; // Stdscr.Add (i == 0 ? "1" : String.Format (" {0}", i + 1)); // Stdscr.Attr = ColorFocus; // try { // Stdscr.Add ("{0,-6}", labels [i]); // } catch { // Console.WriteLine ("{0}:{1}", Curses.Lines, Curses.Cols); // } // } // } public override void Redraw() { #if DEBUG Debug.Print("Button redraw - start"); #endif int y = Terminal.Lines - 1; Move(y, 0); for (int i = 0; i < labels.Length; i++) { #if DEBUG int curX; int curY; Curses.StdScr.GetCursorYX(out curX, out curY); Debug.Print("Button redraw - x:{0} y:{1} - {2}", curX, curY, labels [i]); #endif Stdscr.Attr = Terminal.ColorBasic; Stdscr.Add(i == 0 ? "1" : String.Format(" {0}", i + 1)); Stdscr.Attr = ColorFocus; try { Stdscr.Add("{0,-6}", labels [i]); } catch { #if DEBUG Debug.Print("Exception: Button Redraw - Stdscr.Add {0,-6}", labels [i]); #endif } } #if DEBUG Debug.Print("Button redraw - end"); #endif }
/// <summary> /// Runs the main loop on the given container. /// </summary> /// <remarks> /// This method is used to start processing events /// for the main application, but it is also used to /// run modal dialog boxes. /// </remarks> static public void Run(Container container) { var runToken = Begin(container); RunLoop(runToken); Stdscr.Clear(); End(runToken); // inited = false; }
public override bool ProcessKey (int key) { var result = true; switch (key) { case (int) '>' + Curses.KeyAlt: MoveBottom (); break; case (int) '<' + Curses.KeyAlt: MoveTop (); break; case Keys.UP: case 16: // Control-p result = MoveUp (); break; case Keys.DOWN: case 14: // Control-n result = MoveDown (); break; case 22: // Control-v case Keys.NPAGE: PageDown (); break; case (int) '\n': Action (); break; case Keys.PPAGE: case (int)'v' + Curses.KeyAlt: PageUp (); break; case Keys.INSERTKEY: //Curses.KeyInsertChar: case 20: // Control-t if (listing [selected].Name == "..") return true; listing [selected].Marked = !listing [selected].Marked; if (listing [selected].Marked) marked++; else marked--; MoveDown (); break; default: result = false; break; } if (result) Stdscr.Refresh (); return result; }
void DrawStatus() { Move(y, x); Stdscr.Attr = Container.ContainerColorFocus; for (int i = 0; i < w; i++) { Stdscr.Add(' '); } Move(y, x); Stdscr.Add("File: FOOBAR"); }
// Fills with blanks from the current column/row // until the end of the widget area public void ClearToEnd(int ccol, int crow) { for (int r = crow; r < h; r++) { Move(r + y, ccol + x); for (int c = ccol; c < w; c++) { Stdscr.Add(' '); } ccol = 0; } }
private static void Main2() { Stdscr.Blocking = false; Curses.Echo = false; if (Curses.HasColors) { Curses.StartColor(); for (short i = 1; i < 8; ++i) { Curses.InitPair(i, color_table[i], Colors.BLACK); } } rng = new Random(); int flag = 0; while (Stdscr.GetChar() == -1) { int start, end, row, diff, direction; do { start = rng.Next(Curses.Cols - 3); end = rng.Next(Curses.Cols - 3); start = (start < 2) ? 2 : start; end = (end < 2) ? 2 : end; direction = (start > end) ? -1 : 1; diff = Math.Abs(start - end); } while (diff < 2 || diff >= Curses.Lines - 2); Stdscr.Attr = Attrs.NORMAL; for (row = 1; row < diff; ++row) { Stdscr.Add(Curses.Lines - row, row * direction + start, (direction < 0) ? "\\" : "/"); if (flag++ > 0) { MyRefresh(); Stdscr.Erase(); flag = 0; } } if (flag++ > 0) { MyRefresh(); flag = 0; } Explode(Curses.Lines - row, diff * direction + start); Stdscr.Erase(); MyRefresh(); } }
void SetWrap(bool wrap) { if (view.Wrap) { view.Wrap = false; bar_labels [1] = "Wrap"; } else { view.Wrap = true; bar_labels [1] = "Unwrap"; } Stdscr.Refresh(); }
void GoBottom() { long last = source.Length; SetPosition(last); var newtop = Scan(last > 0 ? last - 1 : 0, -h + 1); if (newtop == -1) { return; } SetTopByte(newtop); Redraw(); Stdscr.Refresh(); }
private void Run() { Initialize(); while (true) { Stdscr.Erase(); for (int i = 0; i < lines.Length; ++i) { if (offsets[i] <= 0) { lines[i] = null; offsets[i] = 0; } if (lines[i] == null) { lines[i] = TEXT_LINES[rng.Next(TEXT_LINES.Length)]; offsets[i] = colcount + lines[i].Length; } int of = colcount - offsets[i]; string str = lines[i]; if (of < 0) { int ln = Math.Min(str.Length + of, colcount); str = str.Substring(-of, ln); of = 0; } else { int ln = Math.Min(Math.Min(offsets[i], str.Length), colcount); str = str.Substring(0, ln); } Stdscr.Add(i, of, str); offsets[i]--; } Stdscr.Refresh(); switch (Stdscr.GetChar()) { case 'q': case 'Q': Curses.CursorVisibility = 1; return; default: break; } Curses.NapMs(100); } }
private static void Explode(int row, int col) { Stdscr.Erase(); AddStr(row, col, "-"); MyRefresh(); col--; GetColor(); AddStr(row - 1, col, " - "); AddStr(row, col, "-+-"); AddStr(row + 1, col, " - "); MyRefresh(); col--; GetColor(); AddStr(row - 2, col, " --- "); AddStr(row - 1, col, "-+++-"); AddStr(row, col, "-+#+-"); AddStr(row + 1, col, "-+++-"); AddStr(row + 2, col, " --- "); MyRefresh(); GetColor(); AddStr(row - 2, col, " +++ "); AddStr(row - 1, col, "++#++"); AddStr(row, col, "+# #+"); AddStr(row + 1, col, "++#++"); AddStr(row + 2, col, " +++ "); MyRefresh(); GetColor(); AddStr(row - 2, col, " # "); AddStr(row - 1, col, "## ##"); AddStr(row, col, "# #"); AddStr(row + 1, col, "## ##"); AddStr(row + 2, col, " # "); MyRefresh(); GetColor(); AddStr(row - 2, col, " # # "); AddStr(row - 1, col, "# #"); AddStr(row, col, " "); AddStr(row + 1, col, "# #"); AddStr(row + 2, col, " # # "); MyRefresh(); }
/// <summary> /// Forces a repaint of the screen. /// </summary> /// <remarks> /// </remarks> public static void Refresh() { Container last = null; main_window.Redraw(); foreach (Container c in toplevels) { c.Redraw(); last = c; } Stdscr.Refresh(); if (last != null) { last.PositionCursor(); } }
public static void Main(string[] args) { // C style from http://www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html // initscr(); /* Start curses mode */ // printw("Hello World !!!"); /* Print Hello World */ // refresh(); /* Print it on to the real screen */ // getch(); /* Wait for user input */ // endwin(); /* End curses mode */ Curses.InitScr(); Stdscr.Add("Hello World !!!"); Stdscr.Refresh(); Stdscr.GetChar(); Curses.Beep(); Curses.EndWin(); }
// Invoke this method instead of Redraw+refresh, as this takes care of updating while // scrolling fast. void UpdateView() { if (Terminal.MainLoop.EventsPending()) { if (dirty < 10 && (DateTime.UtcNow - dirtystart) < TimeSpan.FromMilliseconds(500)) { Log("Skipped update, dirty={0} time={1}", dirty, DateTime.UtcNow - dirtystart); return; } } // to test the dirty system: // System.Threading.Thread.Sleep (500); Redraw(); Stdscr.Refresh(); dirty = 0; }
static void Main(string[] args) { // Init Curses Curses.InitScr(); Stdscr.Blocking = false; Curses.Echo = false; Keyboard.Init(); Stdscr.Keypad = true; if (Curses.HasColors) { Curses.StartColor(); for (short i = 1; i < 8; ++i) { Curses.InitPair(i, color_table[i], Colors.BLACK); } } // Init world. StateMachine.Switch(new IntroState()); bool running = true; Stopwatch time = new Stopwatch(); time.Start(); long spillover = 0; while (running) { if (time.ElapsedMilliseconds + spillover > 100) { Keyboard.UpdateKeys(); if (Keyboard.KeyDown(27)) { running = false; } StateMachine.Update(100); Keyboard.Reset(); // Game render StateMachine.Draw(); Stdscr.Move(Curses.Lines - 1, Curses.Cols - 1); Stdscr.Refresh(); spillover = (time.ElapsedMilliseconds + spillover) - 100; time.Restart(); } } // Game end! Curses.EndWin(); }
public static void UpdateKeys() { int c = Stdscr.GetChar(); while (c != -1) { //Console.WriteLine( "Key " + c + " pressed!" ); if (c == Keys.MOUSE && mouse) { try { MouseEvent e = Curses.GetMouse(); // We want to toggle the mouse so... if (e.State == MouseState.BUTTON1_CLICKED) { mousedown = !mousedown; } mousepos = new Vector2(e.X, e.Y); } catch { } } keys.Add(c); c = Stdscr.GetChar(); } }
/// <summary> /// Starts running a new container or dialog box. /// </summary> /// <remarks> /// Use this method if you want to start the dialog, but /// you want to control the main loop execution manually /// by calling the RunLoop method (for example, to start /// the dialog, but continuing to process events). /// /// Use the returned value as the argument to RunLoop /// and later to the End method to remove the container /// from the screen. /// </remarks> static public RunState Begin(Container container) { if (container == null) { throw new ArgumentNullException("container"); } var rs = new RunState(container); Init(); Stdscr.ReadTimeout = -1; toplevels.Add(container); container.Prepare(); container.SizeChanged(); container.FocusFirst(); Redraw(container); container.PositionCursor(); Stdscr.Refresh(); return(rs); }
public override void TearDown() { Stdscr.Clear(); }
private static void MyRefresh() { Curses.NapMs(DELAYSIZE); Stdscr.Move(Curses.Lines - 1, Curses.Cols - 1); Stdscr.Refresh(); }
static void ProcessChar(Container container) { int ch = Stdscr.GetChar(); if ((ch == -1) || (ch == Keys.RESET)) { // TODO: Fixme // if (Curses.CheckWinChange ()){ // EmptyContainer.Clear (); // foreach (Container c in toplevels) // c.SizeChanged (); // Refresh (); // } return; } // Control-c, quit the current operation. if (ch == Keys.CTRLC || ch == Keys.ESC) { container.Running = false; return; } if (ch == Keys.MOUSE) { MouseEvent ev = Curses.GetMouse(); container.ProcessMouse(ev); return; } if (ch == Keys.ESC) { Stdscr.ReadTimeout = 100; int k = Stdscr.GetChar(); if (k != Curses.ERR && k != Keys.ESC) { ch = Curses.KeyAlt | k; } Stdscr.ReadTimeout = -1; } if (container.ProcessHotKey(ch)) { return; } if (container.ProcessKey(ch)) { return; } if (container.ProcessColdKey(ch)) { return; } // Control-z, suspend execution, then repaint. if (ch == Keys.CTRLZ) { Curses.SendSignalToStop(); // TODO: Fixme ;-) This is broken on return container.Redraw(); Stdscr.Refresh(); return; } // // Focus handling // if (ch == 9 || ch == Keys.DOWN || ch == Keys.RIGHT) { if (!container.FocusNext()) { container.FocusNext(); } Stdscr.Refresh(); } else if (ch == Keys.UP || ch == Keys.LEFT) { if (!container.FocusPrev()) { container.FocusPrev(); } Stdscr.Refresh(); } }
void DrawView() { int col = 0; bool skip_until_newline = false; Stdscr.Attr = Container.ContainerColorNormal; Move(y + 1, x); SetPosition(top_byte); for (int row = 0; row < h;) { int c = GetChar(); switch (c) { /* End of file */ case -1: ClearToEnd(col, row); row = h; continue; case 10: ClearToEnd(col); col = 0; row++; skip_until_newline = false; Move(y + row, x + col); continue; case 9: for (int nc = (col / 8 + 1) * 8; col < nc; col++) { Stdscr.Add(' '); } continue; case 13: continue; } // Control chars or unicode > 0xffff if (c < 32 || c > 0xffff) { c = '.'; } if (skip_until_newline) { continue; } Stdscr.Add((char)c); col++; if (col > w) { if (Wrap) { col = 0; row++; } else { skip_until_newline = true; } } } }
static void Redraw(Container container) { container.Redraw(); Stdscr.Refresh(); }
void GoTop() { SetTopByte(first_file_byte); Redraw(); Stdscr.Refresh(); }
public override void TearDown() { Stdscr.Clear(); DogSong.Stop(); }
private static void Main2() { rng = new Random(); if (Curses.HasColors) { Curses.StartColor(); short bg = Colors.BLACK; try { Curses.UseDefaultColors(); bg = -1; } catch (CursesException) { } Curses.InitPair(1, Colors.BLUE, bg); Curses.InitPair(2, Colors.CYAN, bg); } Curses.Newlines = true; Curses.Echo = false; Curses.CursorVisibility = 0; Stdscr.ReadTimeout = 0; Stdscr.Keypad = true; int r = Curses.Lines - 4, c = Curses.Cols - 4; int[] xpos = new int[5]; int[] ypos = new int[5]; for (int j = 0; j < 5; ++j) { xpos[j] = rng.Next(c) + 2; ypos[j] = rng.Next(r) + 2; } for (int j = 0; ;) { int x = rng.Next(c) + 2; int y = rng.Next(r) + 2; Stdscr.Add(y, x, '.'); Stdscr.Add(ypos[j], xpos[j], 'o'); j = NextJ(j); Stdscr.Add(ypos[j], xpos[j], 'O'); j = NextJ(j); Stdscr.Add(ypos[j] - 1, xpos[j], '-'); Stdscr.Add(ypos[j], xpos[j] - 1, "|.|"); Stdscr.Add(ypos[j] + 1, xpos[j], '-'); j = NextJ(j); Stdscr.Add(ypos[j] - 2, xpos[j], '-'); Stdscr.Add(ypos[j] - 1, xpos[j] - 1, "/ \\"); Stdscr.Add(ypos[j], xpos[j] - 2, "| O |"); Stdscr.Add(ypos[j] + 1, xpos[j] - 1, "\\ /"); Stdscr.Add(ypos[j] + 2, xpos[j], '-'); j = NextJ(j); Stdscr.Add(ypos[j] - 2, xpos[j], ' '); Stdscr.Add(ypos[j] - 1, xpos[j] - 1, " "); Stdscr.Add(ypos[j], xpos[j] - 2, " "); Stdscr.Add(ypos[j] + 1, xpos[j] - 1, " "); Stdscr.Add(ypos[j] + 2, xpos[j], ' '); xpos[j] = x; ypos[j] = y; switch (Stdscr.GetChar()) { case 'q': case 'Q': Curses.CursorVisibility = 1; return; case 's': Stdscr.Blocking = true; break; case ' ': Stdscr.Blocking = false; break; default: break; } Curses.NapMs(50); } }