Click here to Skip to main content
15,897,704 members
Articles / Desktop Programming / X11

Programming Xlib with Mono Develop - Part 2: Athena widgets (proof of concept)

Rate me:
Please Sign up or sign in to vote.
4.89/5 (4 votes)
14 Sep 2013CPOL12 min read 30.7K   231   5  
How to call native Xt API from Mono Develop C# ending up in a very little Athena widget application.
// ==================
// The X11 C# wrapper
// ==================

/*
 * Created by Mono Develop 2.4.1.
 * User: PloetzS
 * Date: April 2013
 * --------------------------------
 * Author: Steffen Ploetz
 * eMail:  Steffen.Ploetz@cityweb.de
 * 
 */

// //////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2013 Steffen Ploetz
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// This copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// //////////////////////////////////////////////////////////////////////

using System;

namespace X11
{
	/// <summary> The shadow type to apply a 3D look. </summary>
	public enum TShadowType
	{
		/// <summary> No shadow at all. </summary>
		None,
		
		/// <summary> Shadow for sunken 3D effect. </summary>
		Sunken,
		
		/// <summary> Shadoe for rised 3D effect. </summary>
		Raised
	}
	
	/// <summary> Platform specific integer point structure. </summary>
	public struct TPoint
	{
		/// <summary> The x-coordinate. </summary>
		public int X;
		
		/// <summary> The x-coordinate. </summary>
		public int Y;
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="x"> The x-coordinate. <see cref="System.Int32"/> </param>
		/// <param name="y"> The y-coordinate. <see cref="System.Int32"/> </param>
		public TPoint (int x, int y)
		{
			X = x;
			Y = y;
		}
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="x"> The x-coordinate. <see cref="TInt"/> </param>
		/// <param name="y"> The y-coordinate. <see cref="TInt"/> </param>
		public TPoint (TInt x, TInt y)
		{
			X = (int)x;
			Y = (int)y;
		}
		
		/// <summary> Add the indicated size. </summary>
		/// <param name="summand"> The size to add. <see cref="TSize"/> </param>
		public void Add (TSize summand)
		{
			X = X + summand.Width;
			Y = Y + summand.Height;
		}
		
		/// <summary> Substract the indicated size. </summary>
		/// <param name="subtrahend"> The size to substract. <see cref="TSize"/> </param>
		public void Substract (TSize subtrahend)
		{
			X = X - subtrahend.Width;
			Y = Y - subtrahend.Height;
		}
	}
	
	/// <summary> Platform specific integer size structure. </summary>
	public struct TSize
	{
		/// <summary> The width. </summary>
		public int Width;
		
		/// <summary> The height. </summary>
		public int Height;
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="width"> The width. <see cref="System.Int32"/> </param>
		/// <param name="height"> The height. <see cref="System.Int32"/> </param>
		public TSize (int width, int height)
		{
			Width = width;
			Height = height;
		}
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="width"> The width. <see cref="TInt"/> </param>
		/// <param name="height"> The height. <see cref="TInt"/> </param>
		public TSize (TInt width, TInt height)
		{
			Width = (int)width;
			Height = (int)height;
		}
		
		/// <summary> Add the indicated size. </summary>
		/// <param name="summand"> The size to add. <see cref="TSize"/> </param>
		public void Add (TSize summand)
		{
			Width  = Width + summand.Width;
			Height = Height + summand.Height;
		}
		
		/// <summary> Substract the indicated size. </summary>
		/// <param name="subtrahend"> The size to substract. <see cref="TSize"/> </param>
		public void Substract (TSize subtrahend)
		{
			Width  = Width - subtrahend.Width;
			Height = Height - subtrahend.Height;
		}

	}
	
	/// <summary> Platform specific integer rectangle structure. </summary>
	public struct TRectangle
	{
		/// <summary> The x-coordinate. </summary>
		public int X;
		
		/// <summary> The x-coordinate. </summary>
		public int Y;

		/// <summary> The width. </summary>
		public int Width;
		
		/// <summary> The height. </summary>
		public int Height;
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="x"> The x-coordinate. <see cref="TInt"/> </param>
		/// <param name="y"> The y-coordinate. <see cref="TInt"/> </param>
		/// <param name="width"> The width. <see cref="TInt"/> </param>
		/// <param name="height"> The height. <see cref="TInt"/> </param>
		public TRectangle(int x, int y, int width, int height)
		{
			X = x;
			Y = y;
			Width = width;
			Height = height;
		}
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="position"> The top left position. <see cref="TPoint"/> </param>
		/// <param name="width"> The width. <see cref="System.Int32"/> </param>
		/// <param name="height"> The height. <see cref="System.Int32"/> </param>
		public TRectangle(TPoint position, int width, int height)
		{
			X = position.X;
			Y = position.Y;
			Width = width;
			Height = height;
		}
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="x"> The x-coordinate. <see cref="System.Int32"/> </param>
		/// <param name="y"> The y-coordinate. <see cref="System.Int32"/> </param>
		/// <param name="size"> The size. <see cref="TSize"/> </param>
		public TRectangle(int x, int y, TSize size)
		{
			X = x;
			Y = y;
			Width = size.Width;
			Height = size.Height;
		}
		
		
		/// <summary> Initializing constructor. </summary>
		/// <param name="position"> The top left position. <see cref="TPoint"/> </param>
		/// <param name="size"> The size. <see cref="TSize"/> </param>
		public TRectangle(TPoint position, TSize size)
		{
			X = position.X;
			Y = position.Y;
			Width = size.Width;
			Height = size.Height;
		}

		/// <summary> Get the top coordinate. </summary>
		public int Top
		{
			get { return Y;	}
		}
		
		/// <summary> Get the left coordinate. </summary>
		public int Left
		{
			get { return X;	}
		}
		
		/// <summary> Get the bottom coordinate. </summary>
		public int Bottom
		{
			get { return Y + Height;	}
		}
		
		/// <summary> Get the right coordinate. </summary>
		public int Right
		{
			get { return X + Width;	}
		}
		
		/// <summary> Get the top left position. </summary>
		public TPoint Position
		{
			get { return new TPoint (X, Y);	}
		}
		
		/// <summary> Get the size. </summary>
		public TSize Size
		{
			get { return new TSize (Width, Height);	}
		}
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Celonis SA
Germany Germany
I am currently the CEO of Symbioworld GmbH and as such responsible for personnel management, information security, data protection and certifications. Furthermore, as a senior programmer, I am responsible for the automatic layout engine, the simulation (Activity Based Costing), the automatic creation of Word/RTF reports and the data transformation in complex migration projects.

The main focus of my work as a programmer is the development of Microsoft Azure Services using C# and Visual Studio.

Privately, I am interested in C++ and Linux in addition to C#. I like the approach of open source software and like to support OSS with own contributions.

Comments and Discussions