sl@49: using System;
sl@49: using System.Collections;
sl@49: using System.Collections.Generic;
sl@49: using System.Text;
sl@49: using System.Configuration;
sl@49: using System.Xml;
sl@49: using System.ComponentModel;
sl@49: using System.Runtime.Serialization;
sl@49: using System.Runtime.Serialization.Json;
sl@49: using System.IO;
sl@49: using System.Drawing;
sl@49:
sl@49: namespace SharpDisplayManager
sl@49: {
sl@49: ///
sl@50: /// Display settings for the specified hardware type
sl@49: ///
sl@49: [DataContract]
sl@50: public class DisplaySettings
sl@49: {
sl@50: public DisplaySettings()
sl@49: {
sl@49: Brightness = 1;
sl@49: DisplayType = 0;
sl@49: TimerInterval = 150;
sl@49: ReverseScreen = false;
sl@57: InverseColors = true;
sl@49: ShowBorders = false;
StephaneLenclud@115: ShowVolumeLabel = false;
sl@49: FontName = "Microsoft Sans Serif, 9.75pt";
sl@100: ScaleToFit = true;
sl@100: MinFontSize = 15.0f;
StephaneLenclud@106: Separator = " ";
StephaneLenclud@106: ScrollingSpeedInPixelsPerSecond = 64;
sl@49: }
sl@49:
StephaneLenclud@115:
StephaneLenclud@115: [DataMember]
StephaneLenclud@115: public bool ShowVolumeLabel { get; set; }
StephaneLenclud@115:
sl@49: [DataMember]
sl@49: public int Brightness { get; set; }
sl@49:
sl@50: ///
sl@50: /// See Display.TMiniDisplayType
sl@50: ///
sl@49: [DataMember]
sl@49: public int DisplayType { get; set; }
sl@49:
sl@49: [DataMember]
sl@49: public int TimerInterval { get; set; }
sl@49:
StephaneLenclud@106: [DataMember]
StephaneLenclud@106: public int ScrollingSpeedInPixelsPerSecond { get; set; }
StephaneLenclud@106:
sl@49: [DataMember]
sl@49: public bool ReverseScreen { get; set; }
sl@49:
sl@49: [DataMember]
sl@57: public bool InverseColors { get; set; }
sl@57:
sl@57: [DataMember]
sl@49: public bool ShowBorders { get; set; }
sl@49:
sl@49: [DataMember]
sl@100: public bool ScaleToFit { get; set; }
sl@100:
sl@100: [DataMember]
sl@100: public float MinFontSize { get; set; }
sl@100:
sl@100: [DataMember]
sl@100: public string Separator { get; set; }
sl@100:
sl@100: [DataMember]
sl@49: public string FontName { get; set; }
sl@49:
sl@49: public Font Font
sl@49: {
sl@49: get
sl@49: {
sl@49: FontConverter cvt = new FontConverter();
sl@49: Font font = cvt.ConvertFromInvariantString(FontName) as Font;
sl@49: return font;
sl@49: }
sl@49:
sl@49: set
sl@49: {
sl@49: FontConverter cvt = new FontConverter();
sl@49: FontName = cvt.ConvertToInvariantString(value);
sl@49: }
sl@49: }
sl@49: };
sl@49:
sl@49:
sl@50: ///
sl@100: /// Contain settings for each of our display type.
sl@50: ///
sl@49: [TypeConverter(typeof(DisplaySettingsConverter))]
sl@49: [DataContract]
sl@50: public class DisplaysSettings
sl@49: {
sl@50: public DisplaysSettings()
sl@49: {
sl@49: Init();
sl@49: }
sl@49:
sl@49: public void Init()
sl@49: {
sl@49: if (Displays == null)
sl@49: {
sl@50: Displays = new List();
sl@49: }
sl@49: }
sl@49:
sl@49: //[DataMember]
sl@49: //public int CurrentSettingsIndex { get; set; }
sl@49:
sl@49: [DataMember]
sl@50: public List Displays { get; set; }
sl@49:
sl@49: public override string ToString()
sl@49: {
sl@49: //Save settings into JSON string
sl@49: MemoryStream stream = new MemoryStream();
sl@50: DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DisplaysSettings));
sl@49: ser.WriteObject(stream, this);
sl@49: // convert stream to string
sl@49: stream.Position = 0;
sl@49: StreamReader reader = new StreamReader(stream);
sl@49: string text = reader.ReadToEnd();
sl@49: return text;
sl@49: }
sl@49: }
sl@49:
sl@49: public class DisplaySettingsConverter : TypeConverter
sl@49: {
sl@49: public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
sl@49: {
sl@49: if (sourceType == typeof(string))
sl@49: return true;
sl@49: else
sl@49: return base.CanConvertFrom(context, sourceType);
sl@49: }
sl@49:
sl@49: public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
sl@49: {
sl@49: string stringValue = value as string;
sl@49: if (stringValue != null)
sl@100: {
sl@49: //Load settings form JSON string
sl@49: byte[] byteArray = Encoding.UTF8.GetBytes(stringValue);
sl@49: MemoryStream stream = new MemoryStream(byteArray);
sl@50: DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DisplaysSettings));
sl@50: DisplaysSettings settings = (DisplaysSettings)ser.ReadObject(stream);
sl@49: settings.Init();
sl@49: return settings;
sl@49: }
sl@49: else
sl@49: return base.ConvertFrom(context, culture, value);
sl@49: }
sl@49: };
sl@49:
sl@49:
sl@49: }
sl@49: