Made the terminal store all the content and scroll and be able to save.
This commit is contained in:
parent
686d660876
commit
8f2a99e63e
7 changed files with 152 additions and 258 deletions
|
|
@ -97,12 +97,6 @@ namespace MatterHackers.MatterControl
|
|||
OnHasChanged(eventArgs);
|
||||
}
|
||||
|
||||
public void HookupPrinterOutput()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
PrinterLines.Clear();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace MatterHackers.MatterControl
|
|||
Button sendCommand;
|
||||
CheckBox autoUppercase;
|
||||
MHTextEditWidget manualCommandTextEdit;
|
||||
TextScrollWidget outputScrollWidget;
|
||||
TextScrollWidget textScrollWidget;
|
||||
RGBA_Bytes backgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
RGBA_Bytes textColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
TextImageButtonFactory controlButtonFactory = new TextImageButtonFactory();
|
||||
|
|
@ -81,22 +81,19 @@ namespace MatterHackers.MatterControl
|
|||
FlowLayoutWidget leftToRight = new FlowLayoutWidget();
|
||||
leftToRight.AnchorAll();
|
||||
|
||||
outputScrollWidget = new TextScrollWidget(PrinterOutputCache.Instance.PrinterLines);
|
||||
textScrollWidget = new TextScrollWidget(PrinterOutputCache.Instance.PrinterLines);
|
||||
//outputScrollWidget.Height = 100;
|
||||
outputScrollWidget.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
outputScrollWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
outputScrollWidget.HAnchor = HAnchor.ParentLeftRight;
|
||||
outputScrollWidget.VAnchor = VAnchor.ParentBottomTop;
|
||||
outputScrollWidget.Margin = new BorderDouble(0, 5);
|
||||
outputScrollWidget.Padding = new BorderDouble(3, 0);
|
||||
textScrollWidget.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
textScrollWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textScrollWidget.HAnchor = HAnchor.ParentLeftRight;
|
||||
textScrollWidget.VAnchor = VAnchor.ParentBottomTop;
|
||||
textScrollWidget.Margin = new BorderDouble(0, 5);
|
||||
textScrollWidget.Padding = new BorderDouble(3, 0);
|
||||
|
||||
leftToRight.AddChild(textScrollWidget);
|
||||
|
||||
leftToRight.AddChild(outputScrollWidget);
|
||||
|
||||
GuiWidget fakeScrollBar = new GuiWidget(10, 10);
|
||||
fakeScrollBar.VAnchor = Agg.UI.VAnchor.ParentBottomTop;
|
||||
fakeScrollBar.BackgroundColor = RGBA_Bytes.Blue;
|
||||
leftToRight.AddChild(fakeScrollBar);
|
||||
TextScrollBar textScrollBar = new TextScrollBar(textScrollWidget, 15);
|
||||
leftToRight.AddChild(textScrollBar);
|
||||
|
||||
manualEntryTopToBottomLayout.AddChild(leftToRight);
|
||||
}
|
||||
|
|
@ -182,7 +179,7 @@ namespace MatterHackers.MatterControl
|
|||
string filePathToSave = saveParams.FileName;
|
||||
if (filePathToSave != null && filePathToSave != "")
|
||||
{
|
||||
outputScrollWidget.WriteToFile(filePathToSave);
|
||||
textScrollWidget.WriteToFile(filePathToSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
83
PrinterControls/TerminalWindow/TextScrolBar.cs
Normal file
83
PrinterControls/TerminalWindow/TextScrolBar.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (c) 2014, Lars Brubaker
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Font;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class TextScrollBar : GuiWidget
|
||||
{
|
||||
TextScrollWidget textScrollWidget;
|
||||
bool downOnBar = false;
|
||||
|
||||
public TextScrollBar(TextScrollWidget textScrollWidget, int width)
|
||||
: base(width, 10)
|
||||
{
|
||||
this.textScrollWidget = textScrollWidget;
|
||||
Margin = new BorderDouble(0, 5);
|
||||
VAnchor = Agg.UI.VAnchor.ParentBottomTop;
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
int thumbHeight = 2;
|
||||
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Black);
|
||||
double bottom = textScrollWidget.Position0To1 * (Height - thumbHeight - 1);// the 2 is the border
|
||||
RectangleDouble thumb = new RectangleDouble(0, bottom + 1, Width, bottom + 1 + thumbHeight);// the 1 is the border
|
||||
graphics2D.FillRectangle(thumb, RGBA_Bytes.Black);
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
public override void OnMouseDown(MouseEventArgs mouseEvent)
|
||||
{
|
||||
downOnBar = true;
|
||||
textScrollWidget.Position0To1 = mouseEvent.Y / Height;
|
||||
base.OnMouseDown(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseMove(MouseEventArgs mouseEvent)
|
||||
{
|
||||
if (downOnBar)
|
||||
{
|
||||
textScrollWidget.Position0To1 = mouseEvent.Y / Height;
|
||||
}
|
||||
base.OnMouseMove(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnMouseUp(MouseEventArgs mouseEvent)
|
||||
{
|
||||
downOnBar = false;
|
||||
base.OnMouseUp(mouseEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,10 +41,47 @@ namespace MatterHackers.MatterControl
|
|||
event EventHandler unregisterEvents;
|
||||
List<string> sourceLines;
|
||||
|
||||
TypeFacePrinter printer = new TypeFacePrinter();
|
||||
public RGBA_Bytes TextColor = new RGBA_Bytes(102, 102, 102);
|
||||
int forceStartLine = -1;
|
||||
public double Position0To1
|
||||
{
|
||||
get
|
||||
{
|
||||
if (forceStartLine == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((sourceLines.Count - (double)forceStartLine) / sourceLines.Count);
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
forceStartLine = (int)(sourceLines.Count * (1 - value)) - 1;
|
||||
forceStartLine = Math.Max(0, forceStartLine);
|
||||
forceStartLine = Math.Min(sourceLines.Count - 1, forceStartLine);
|
||||
|
||||
// If the start would be less than one screen worth of content, allow
|
||||
// the whole screen to have content and scroll with new material.
|
||||
if(forceStartLine > sourceLines.Count - NumVisibleLines)
|
||||
{
|
||||
forceStartLine = -1;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int NumVisibleLines
|
||||
{
|
||||
get { return (int)Math.Ceiling(Height / printer.TypeFaceStyle.EmSizeInPixels); }
|
||||
}
|
||||
|
||||
public TextScrollWidget(List<string> sourceLines)
|
||||
{
|
||||
printer.DrawFromHintedCache = true;
|
||||
this.sourceLines = sourceLines;
|
||||
PrinterOutputCache.Instance.HasChanged.RegisterEvent((sender, e) => { Invalidate(); }, ref unregisterEvents);
|
||||
}
|
||||
|
|
@ -65,15 +102,26 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
TypeFacePrinter printer = new TypeFacePrinter();
|
||||
printer.DrawFromHintedCache = true;
|
||||
|
||||
RectangleDouble Bounds = LocalBounds;
|
||||
|
||||
int numLinesToDraw = (int)Math.Ceiling(Height / printer.TypeFaceStyle.EmSizeInPixels);
|
||||
int numLinesToDraw = NumVisibleLines;
|
||||
|
||||
double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * numLinesToDraw;
|
||||
int startLineIndex = sourceLines.Count - numLinesToDraw;
|
||||
if (forceStartLine != -1)
|
||||
{
|
||||
y = LocalBounds.Top;
|
||||
|
||||
if (forceStartLine > sourceLines.Count - numLinesToDraw)
|
||||
{
|
||||
forceStartLine = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make sure we show all the lines we can
|
||||
startLineIndex = Math.Min(forceStartLine, startLineIndex);
|
||||
}
|
||||
}
|
||||
int endLineIndex = sourceLines.Count;
|
||||
for (int lineIndex = startLineIndex; lineIndex < endLineIndex; lineIndex++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue