Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds zoom buttons to graph controls #637

Merged
merged 8 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Calculator/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,18 @@
<value>^</value>
<comment>{Locked}This is the character that should trigger this button. Note that it is a character and not a key, so it does not come from the Windows::System::VirtualKey enum.</comment>
</data>
<data name="zoomResetButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKeyControlChord" xml:space="preserve">
<value>Home</value>
<comment>{Locked}This is the shortcut for the zoom reset button.</comment>
</data>
<data name="zoomInButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKeyControlChord" xml:space="preserve">
<value>Add</value>
<comment>{Locked}This is the shortcut for the zoom in button.</comment>
</data>
<data name="zoomOutButton.[using:CalculatorApp.Common]KeyboardShortcutManager.VirtualKeyControlChord" xml:space="preserve">
<value>Subtract</value>
<comment>{Locked}This is the shortcut for the zoom out button.</comment>
</data>
<data name="EquationInputButtonPlaceholderText" xml:space="preserve">
<value>Add Equation</value>
<comment>Placeholder text for the equation input button</comment>
Expand Down
77 changes: 76 additions & 1 deletion src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@
mc:Ignorable="d">

<UserControl.Resources>
<Style x:Key="ZoomRepeatButtonStyle" TargetType="RepeatButton">
<Setter Property="Width" Value="36"/>
<Setter Property="Height" Value="36"/>
<Setter Property="CornerRadius" Value="18"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Delay" Value="500"/>
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
<Setter Property="Interval" Value="40"/>
</Style>
<Style x:Key="ZoomButtonStyle" TargetType="Button">
<Setter Property="Width" Value="36"/>
<Setter Property="Height" Value="36"/>
<Setter Property="CornerRadius" Value="18"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
<converters:BooleanToVisibilityConverter x:Name="BooleanToVisibilityConverter"/>
<converters:BooleanToVisibilityNegationConverter x:Name="BooleanToVisibilityNegationConverter"/>
</UserControl.Resources>
Expand All @@ -30,6 +52,30 @@
<Grid x:Name="LeftGrid"
Grid.Row="1"
Grid.Column="0">
<Grid.Resources>
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
<SolidColorBrush x:Key="RepeatButtonBackgroundPointerOver" Color="White"/>
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
<SolidColorBrush x:Key="RepeatButtonBackgroundPressed" Color="White"/>
<SolidColorBrush x:Key="RepeatButtonBackgroundDisabled" Color="White"/>
<SolidColorBrush x:Key="RepeatButtonBorderBrush" Color="Black" Opacity="0.6"/>
<SolidColorBrush x:Key="RepeatButtonBorderBrushPointerOver" Color="{ThemeResource SystemAccentColor}" Opacity="0.8"/>
<SolidColorBrush x:Key="RepeatButtonBorderBrushPressed" Color="{ThemeResource SystemAccentColor}" Opacity="1.0"/>
<SolidColorBrush x:Key="RepeatButtonBorderBrushDisabled" Color="Black" Opacity="0.2"/>
<SolidColorBrush x:Key="RepeatButtonForeground" Color="Black" Opacity="0.6"/>
<SolidColorBrush x:Key="RepeatButtonForegroundPointerOver" Color="{ThemeResource SystemAccentColor}" Opacity="0.8"/>
<SolidColorBrush x:Key="RepeatButtonForegroundPressed" Color="{ThemeResource SystemAccentColor}" Opacity="1.0"/>
<SolidColorBrush x:Key="RepeatButtonForegroundDisabled" Color="Black" Opacity="0.2"/>
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="White"/>
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="White"/>
<SolidColorBrush x:Key="ButtonBackgroundDisabled" Color="White"/>
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Black" Opacity="0.6"/>
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="{ThemeResource SystemAccentColor}" Opacity="0.8"/>
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="{ThemeResource SystemAccentColor}" Opacity="1.0"/>
<SolidColorBrush x:Key="ButtonBorderBrushDisabled" Color="Black" Opacity="0.2"/>
<SolidColorBrush x:Key="ButtonForeground" Color="Black" Opacity="0.6"/>
<SolidColorBrush x:Key="ButtonForegroundPointerOver" Color="{ThemeResource SystemAccentColor}" Opacity="0.8"/>
<SolidColorBrush x:Key="ButtonForegroundPressed" Color="{ThemeResource SystemAccentColor}" Opacity="1.0"/>
<SolidColorBrush x:Key="ButtonForegroundDisabled" Color="Black" Opacity="0.2"/>
</Grid.Resources>

<graphControl:Grapher Name="GraphingControl"
Margin="4,7,4,4"
Expand All @@ -53,7 +99,8 @@
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="18"
Content="&#xE70F;"
RequestedTheme="Light">
RequestedTheme="Light"
Background="White">
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
<Button.Flyout>
<Flyout Placement="TopEdgeAlignedRight">
<Flyout.FlyoutPresenterStyle>
Expand Down Expand Up @@ -215,6 +262,34 @@
</Flyout>
</Button.Flyout>
</Button>

<RepeatButton Margin="0,0,12,12"
x:Uid="zoomOutButton"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Content="&#xE738;"
RequestedTheme="Light"
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
Command="{x:Bind ZoomOutButtonPressed, Mode=OneTime}"
Style="{ThemeResource ZoomRepeatButtonStyle}">
</RepeatButton>

<RepeatButton Margin="0,0,12,60"
x:Uid="zoomInButton"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Content="&#xE710;"
RequestedTheme="Light"
Command="{x:Bind ZoomInButtonPressed, Mode=OneTime}"
Style="{ThemeResource ZoomRepeatButtonStyle}">
</RepeatButton>

<Button Margin="0,0,12,108"
x:Uid="zoomResetButton"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Content="&#xE895;"
RequestedTheme="Light"
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
Command="{x:Bind ZoomResetButtonPressed, Mode=OneTime}"
Style="{ThemeResource ZoomButtonStyle}">
</Button>

</Grid>

<!-- Right portion of the screen -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,25 @@ void GraphingCalculator::TextBoxGotFocus(TextBox^ sender, RoutedEventArgs^ e)
{
sender->SelectAll();
}

void GraphingCalculator::ZoomInButtonClick(Object ^ /* parameter */)
{
constexpr double scrollDamper = 0.15;
double scale = 1.0 + (abs(zoomButtonDelta) / WHEEL_DELTA) * scrollDamper;
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
scale = 1.0 / scale;

GraphingControl->ScaleRange(0, 0, scale);
}

void GraphingCalculator::ZoomOutButtonClick(Object ^ /* parameter */)
{
constexpr double scrollDamper = 0.15;
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
double scale = 1.0 + (abs(zoomButtonDelta) / WHEEL_DELTA) * scrollDamper;

GraphingControl->ScaleRange(0, 0, scale);
}

void GraphingCalculator::ZoomResetButtonClick(Object ^ /* parameter */)
{
GraphingControl->ResetGrid();
}
15 changes: 15 additions & 0 deletions src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ namespace CalculatorApp
GraphingCalculator();

OBSERVABLE_OBJECT();
COMMAND_FOR_METHOD(ZoomOutButtonPressed, GraphingCalculator::ZoomOutButtonClick);
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
COMMAND_FOR_METHOD(ZoomInButtonPressed, GraphingCalculator::ZoomInButtonClick);
COMMAND_FOR_METHOD(ZoomResetButtonPressed, GraphingCalculator::ZoomResetButtonClick);

property CalculatorApp::ViewModel::GraphingCalculatorViewModel^ ViewModel
{
CalculatorApp::ViewModel::GraphingCalculatorViewModel^ get();
void set(CalculatorApp::ViewModel::GraphingCalculatorViewModel^ vm);
}

static property double zoomButtonDelta
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
{
double get()
{
return 50;
}
}

private:
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args);

Expand All @@ -29,6 +40,10 @@ namespace CalculatorApp
void TextBoxKeyDown(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void SubmitTextbox(Windows::UI::Xaml::Controls::TextBox^ textbox);

void ZoomInButtonClick(Object ^ parameter);
greedyAI marked this conversation as resolved.
Show resolved Hide resolved
void ZoomOutButtonClick(Object ^ parameter);
void ZoomResetButtonClick(Object ^ parameter);

double validateDouble(Platform::String^ value, double defaultValue);

CalculatorApp::ViewModel::GraphingCalculatorViewModel^ m_viewModel;
Expand Down
14 changes: 14 additions & 0 deletions src/GraphControl/Control/Grapher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ namespace GraphControl
}
}

void Grapher::ResetGrid()
{
if (m_graph != nullptr && m_renderMain != nullptr)
{
if (auto renderer = m_graph->GetRenderer())
{
if (SUCCEEDED(renderer->ResetRange()))
{
m_renderMain->RunRenderPass();
}
}
}
}

void Grapher::OnApplyTemplate()
{
auto swapChainPanel = dynamic_cast<SwapChainPanel^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel)));
Expand Down
4 changes: 2 additions & 2 deletions src/GraphControl/Control/Grapher.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ namespace GraphControl
event Windows::Foundation::EventHandler<Windows::Foundation::Collections::IMap<Platform::String^, double>^>^ VariablesUpdated;

void SetVariable(Platform::String^ variableName, double newValue);
void ScaleRange(double centerX, double centerY, double scale);
void ResetGrid();

protected:
#pragma region Control Overrides
Expand Down Expand Up @@ -172,8 +174,6 @@ namespace GraphControl
void OnItemsAdded(int index, int count);
void OnItemsRemoved(int index, int count);

void ScaleRange(double centerX, double centerY, double scale);

private:
DX::RenderMain^ m_renderMain = nullptr;

Expand Down