mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Improved keyboard missing handling, implemented keyboard select
This commit is contained in:
parent
af2b99b1a7
commit
d6ff4a0551
@ -3,6 +3,7 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Artemis.Utilities;
|
||||
using CUE.NET;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Keyboard;
|
||||
using CUE.NET.Exceptions;
|
||||
|
||||
@ -25,8 +26,9 @@ namespace Artemis.KeyboardProviders.Corsair
|
||||
}
|
||||
catch (CUEException e)
|
||||
{
|
||||
if (e.Message.Contains("not found"))
|
||||
if (e.Error == CorsairError.ServerNotFound)
|
||||
return false;
|
||||
throw;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -82,27 +84,5 @@ namespace Artemis.KeyboardProviders.Corsair
|
||||
}
|
||||
_keyboard.Update(true);
|
||||
}
|
||||
|
||||
/*
|
||||
RectangleF[,] ledRectangles = new RectangleF[bitmap.Width, bitmap.Height];
|
||||
RectangleKeyGroup[,] ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height];
|
||||
//_keyboard.Brush = new SolidColorBrush(Color.Black);
|
||||
for (var x = 0 ; x < bitmap.Width; x++)
|
||||
{
|
||||
for (var y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x*(_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y*(y*(_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height);
|
||||
ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) };
|
||||
}
|
||||
}
|
||||
_keyboard.Update();
|
||||
for (var x = 0; x < bitmap.Width; x++)
|
||||
{
|
||||
for (var y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
_keyboard.DetachKeyGroup(ledGroups[x, y]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -84,27 +84,5 @@ namespace Artemis.KeyboardProviders.Corsair
|
||||
}
|
||||
_keyboard.Update(true);
|
||||
}
|
||||
|
||||
/*
|
||||
RectangleF[,] ledRectangles = new RectangleF[bitmap.Width, bitmap.Height];
|
||||
RectangleKeyGroup[,] ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height];
|
||||
//_keyboard.Brush = new SolidColorBrush(Color.Black);
|
||||
for (var x = 0 ; x < bitmap.Width; x++)
|
||||
{
|
||||
for (var y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x*(_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y*(y*(_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height);
|
||||
ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) };
|
||||
}
|
||||
}
|
||||
_keyboard.Update();
|
||||
for (var x = 0; x < bitmap.Width; x++)
|
||||
{
|
||||
for (var y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
_keyboard.DetachKeyGroup(ledGroups[x, y]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
using System.Drawing;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Artemis.KeyboardProviders.Razer.Utilities;
|
||||
using Corale.Colore.Core;
|
||||
using Corale.Colore.Razer.Keyboard;
|
||||
using Color = Corale.Colore.Core.Color;
|
||||
|
||||
namespace Artemis.KeyboardProviders.Razer
|
||||
{
|
||||
@ -14,7 +16,23 @@ namespace Artemis.KeyboardProviders.Razer
|
||||
|
||||
public override bool CanEnable()
|
||||
{
|
||||
return Chroma.IsSdkAvailable();
|
||||
if (!Chroma.IsSdkAvailable())
|
||||
return false;
|
||||
|
||||
// Some people have Synapse installed, but not a Chroma keyboard, deal with this
|
||||
try
|
||||
{
|
||||
// Create a bitmap to send as a test
|
||||
var b = new Bitmap(22, 6);
|
||||
var razerArray = RazerUtilities.BitmapColorArray(b, 6, 22);
|
||||
Chroma.Instance.Keyboard.SetGrid(razerArray);
|
||||
Chroma.Instance.Keyboard.Clear();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -88,7 +88,7 @@ namespace Artemis.Models
|
||||
ChangeKeyboard(keyboard ?? KeyboardProviders.First(k => k.Name == "Logitech G910 Orion Spark RGB"));
|
||||
}
|
||||
|
||||
private void ChangeKeyboard(KeyboardProvider keyboardProvider)
|
||||
public void ChangeKeyboard(KeyboardProvider keyboardProvider)
|
||||
{
|
||||
if (ActiveKeyboard != null && keyboardProvider.Name == ActiveKeyboard.Name)
|
||||
return;
|
||||
|
||||
@ -33,6 +33,7 @@ namespace Artemis.ViewModels
|
||||
return;
|
||||
|
||||
_isOpen = value;
|
||||
HandleOpen();
|
||||
NotifyOfPropertyChange(() => IsOpen);
|
||||
}
|
||||
}
|
||||
@ -50,5 +51,7 @@ namespace Artemis.ViewModels
|
||||
NotifyOfPropertyChange(() => Position);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void HandleOpen();
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,48 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Artemis.Models;
|
||||
using Caliburn.Micro;
|
||||
using MahApps.Metro.Controls;
|
||||
|
||||
namespace Artemis.ViewModels.Flyouts
|
||||
{
|
||||
public class FlyoutSettingsViewModel : FlyoutBaseViewModel
|
||||
{
|
||||
public FlyoutSettingsViewModel()
|
||||
private string _selectedKeyboardProvider;
|
||||
public MainModel MainModel { get; set; }
|
||||
|
||||
public FlyoutSettingsViewModel(MainModel mainModel)
|
||||
{
|
||||
MainModel = mainModel;
|
||||
Header = "settings";
|
||||
Position = Position.Right;
|
||||
}
|
||||
|
||||
public BindableCollection<string> KeyboardProviders
|
||||
=> new BindableCollection<string>(MainModel.KeyboardProviders.Select(k => k.Name));
|
||||
|
||||
public string SelectedKeyboardProvider
|
||||
{
|
||||
get { return _selectedKeyboardProvider; }
|
||||
set
|
||||
{
|
||||
if (value == _selectedKeyboardProvider) return;
|
||||
_selectedKeyboardProvider = value;
|
||||
NotifyOfPropertyChange(() => SelectedKeyboardProvider);
|
||||
|
||||
MainModel.ChangeKeyboard(MainModel.KeyboardProviders.First(k => k.Name == _selectedKeyboardProvider));
|
||||
}
|
||||
}
|
||||
|
||||
public void NavigateTo(string url)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(url));
|
||||
}
|
||||
|
||||
protected override void HandleOpen()
|
||||
{
|
||||
SelectedKeyboardProvider = MainModel.ActiveKeyboard?.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace Artemis.ViewModels
|
||||
_gamesVm = new GamesViewModel(MainModel) {DisplayName = "Games"};
|
||||
_overlaysVm = new OverlaysViewModel(MainModel) {DisplayName = "Overlays"};
|
||||
|
||||
Flyouts.Add(new FlyoutSettingsViewModel());
|
||||
Flyouts.Add(new FlyoutSettingsViewModel(MainModel));
|
||||
|
||||
// By now Effects are added to the MainModel so we can savely start one
|
||||
ToggleEffects();
|
||||
|
||||
@ -42,8 +42,9 @@
|
||||
<!-- Keyboard selection -->
|
||||
<Label Grid.Row="2" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
|
||||
Content="Keyboard:" />
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Right"
|
||||
<ComboBox Grid.Row="2" Grid.Column="1" x:Name="KeyboardProviders" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Right"
|
||||
Width="120" />
|
||||
<!-- TODO: Ugly -->
|
||||
|
||||
<!-- Gamestate port -->
|
||||
<Label Grid.Row="3" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user