Inyectando TypeEditors dinámicamente
Muchas aplicaciones de edición todavía utilizan Windows Forms. Y muchas de ellas (sobre todo si son prototipos rápidos o herramientas internas) utilizan el PropertyGrid como método rápido y eficiente para editar propiedades de objetos.
Una de las funcionalidades más utiles de los PropertyGrids, es la posibilidad de definir TypeEditors para las propiedades de un objeto, de forma que el sistema escogerá automáticamente un interfaz de usuario específico para editar su valor. .Net incluye por defecto algunos de ellos, como el ColorPicker o el DateTimePicker:
Cuando los TypeEditors por defecto no son suficiente, es una gran idea desarrollar tus propios editores, para hacer tus editores lo más eficientes posible. Por ejemplo, el selector de colores por defecto de .Net no permite escoger valores para el canal Alpha (transparencia). La solución es sencilla y fácil: podemos implementar nuestro propio editor que sí lo permita.
Ahora bien, ¿qué ocurre si queremos aplicar ese TypeEditor a todas las propiedades de un tipo definido en otra DLL?
Es un caso bastante frecuente. En mi entorno, por ejemplo, tengo mi propia clase para almacenar colores, llamada Color4, pero está definida en una DLL específica para operaciones matemáticas. Es una DLL muy básica que quiero mantener con el menor número de referencias posible, para evitar dependencias todo lo que pueda. Por este motivo, es imposible definir el TypeEditor en dicha DLL, ya que eso implicaría referenciar System.Windows.Forms, System.Drawing, y unas cuantas cosas más que no tienen que estar ahí. A fin de cuentas, es mi editor visual el que debe depender de Windows Forms, y no mi DLL de operaciones matemáticas. ¿La solución?
Inyección dinámica de editores de tipo
La solución es asignar el TypeEditor dinámicamente, programaticamente, o como queráis decirlo. En lugar de incluirlo en tiempo de compilación, con clásico código…
[EditorAttribute("Color4Editor", typeof(System.Drawing.Design.UITypeEditor))]
…lo añadiremos en tiempo de ejecución, algo posible gracias a la clase TypeDescriptor y su método AddAttributes.
Basta con invocar algo como lo siguiente el el inicio del programa:
TypeDescriptor.AddAttributes(typeof(Color4), new EditorAttribute(typeof(Color4Editor), typeof(UITypeEditor)));
De esta forma, mantenemos las DLLs limpias de referencias innecesarias, y solo dependeremos de Windows Forms y similares donde realmente se necesita: en el editor.
Listo !
NSU / Nokia Software Updater for Retail doesn’t detect the device
Today, I was updating my phone to Lumia Cyan, and for a while I had an issue: the NSU For Retail didn’t detect my device. No matter how many times I tried to connect in different USB ports and using different cables, the NSU was always like this:
If it’s your case, go to Control Panel->Device Manager, and under “Universal Serial Bus Devices”, you’ll find two entries:
To fix the issue, just:
- 1 - Unplug your phone
- 2 – Right-click on both devices and select “Uninstall”.
- 3 – Replug your device again
NSU should detect the device again.
Hope it helps !!
Mesa redonda–Intrograph II (Jornadas Nacionales de Informática Gráfica)
Se acaba de publicar un vídeo grabado por uno de los asistentes a Intrograph II, las Jornadas Nacionales de Informática Gráfica celebradas en Mayo en la Universidad Rey Juan Carlos.
Participé como ponente y también en la mesa redonda que clausuraba el evento. El vídeo se corresponde con ésta última sesión:
Un pequeño índice dentro del vídeo, con los temas sobre los que los ponentes respondíamos preguntas o debatíamos:
2:16 ¿Indie o triple A?
20:31 ¿PC o Consola?
49:00 Videojuegos ¿Son mas fáciles ahora?
59:55 Fecha optima del lanzamiento de videojuegos
1:13:39 Desarrollo de videjuegos ¿Por donde ir?
Massive hard drive activity when opening the Visual Studio 2013 XAML designer
I have a pretty big C# Visual Studio solution, with references to native DLLs. Part of the UI is WPF, so it involves using XAML user controls. Now, when I open one of those XAML files and the designer kicks in (you can see a new process in the task manager called XDesProc.exe), my PC almost freezes.
After checking for a while, I realized that the VStudio's designer is filling the Shadow Cache folder like crazy (in my PC it's C:\Users\XXX\AppData\Local\Microsoft\VisualStudio\12.0\Designer\ShadowCache). And when I say "crazy", believe me... I mean it... It filled like 8 GB of data in a few moments...
There are many people out there with similar problems (some say to have cleaned from that folder more than 50 GB of data). You can find more examples here, here and here.
If any of you have any clue about why this is happening, please let me know. By now, I managed to workaround it by completely disabling the XAML visual editor by:
1.- In Visual Studio solution explorer, right-click in a xaml file and select "Open With"...
2.- Choose XML (Text) Editor
3.- Click on "Set as default".
4.- Click Ok.
Please note: I found several websites suggesting a similar change, but saying the the Source Code (Text) Editor would work as well. It didn't work in my case. The designer didn't open, but the disk activity was surprisingly the same. The only choice that worked for me was XML (Text) Editor.
Next time you open an xaml file, the visual editor won't kick in, and you won't have the problem. However, it'd good to find the cause for this... Maybe I´ll try to re-install VStudio 2013 when I have a minute...
Hope it helps !! :)
Evolution of visuals in racing games 1992-2014
I still remember when I first saw Geoff Crammond - MicroProse's Formula One Grand Prix. It was mindblowing!! 3D graphics, amazing gameplay... Best racing experience I had so far...
One of my best friends had a 386 PC that met the ultra-high-end requirements the game needed (DOS, 1 MB of Ram and VGA Graphics Card). Every time I had the chance to drop by his house, first thing we did was to play this game.
But things have changed quite a lot in this time. Comparing the Monaco environment from that game with the one from CodeMasters F1 2013 makes a hell of a difference...
And things still keep moving forward. This year, we will have a new F1 2014 game, and some others that keep pushing the limits of visual realism in videogames: [All videos best viewed in FullHD 1080p]
Diveclub:
Project Cars Trailer:
Project Cars vs Real Life:
Awesome !!!
Cómo tomar una muestra de color en cualquier cosa mostrada en tu pantalla, con Photoshop
How to install Windows Phone 8.1, even with no developer account
As you might have read, all you need to do is search in the Store for the application: Preview for Developers, install and open it. It opens the door to the set of updates that will trigger the installation of Windows Phone 8.1.
The thing is that one of the steps when opening it require you to enter your Live Account credentials, and in theory you must be registered as a Developer in the Windows Phone Dev Center.
Sincerely, you should consider register as so if you plan to do any development... It's only $14 yearly... But if you don't want to pay, there is a way:
1.- Go to http://appstudio.windowsphone.com
2.- Log in with your non-developer Live Account ID, and accept all the terms and conditions
3.- Click in "Start New Project"
4.- Select whichever project template you prefer (empty app will do the trick), and complete the process.
Now, you should be able to run the Preview for Developers thing, and it should accept your credentials as a registered developer.
Ta dá !!!
Disclaimer: Do this at your own risk. Windows Phone 8.1 is currently a developer preview and might contain bugs. I take no responsibility for any damage done to your phone or to your data, so better know what you are doing... :)
Fast casting of C# Structs with no unsafe code (but still kind of "unsafe")
C# however doesn't allow to do this out of the box, unless you go into using unsafe code and perform the pointer conversion yourself, pretty much like in C++.
Problem is that unsafe code is not supported in all platforms, and generally it's a good idea to avoid using it as long as you can.
So, imagine we have two structs like this:
Obviously, if you try to simply assign them, it just won't work:
As we mentioned, in unsafe C# code this can be simply achieved by casting pointers, just like in C++. But if you mark your C# code as unsafe, it can be rejected in some platforms. Is there a way to do that without using unsafe code? Yes, there is.
C# StructLayout to the rescue
Perfectly safe C# code allows you to explicitly define the offset of struct members, using attributes from System.Runtime.InteropServices, just like this:This allows you to do tricky things like settings two different members of the struct at the same offset, creating something similar to C++ Unions:
Note that both StructA and StructB are at the same field offset, and therefore will occupy the exact same location in memory. As both share the same memory layout, the result is that you have ONE single object in memory, and two different references (kind of pointers) to them, each one using a different type.
Now, we can do the following:
As you can see, no new STA has been created in memory, and we have saved all the process of copying data from one struct to another.
However, please be aware that this is kind of cheating... You are fooling the compiler to accept that, but in practice you are performing a classical pointer conversion, even if you are using purely safe code.
PLEASE BE AWARE that this approach doesn't take into account endianness. Different platforms, with different byte endianness, may store bytes in the opposite way. For example, if STA comes from a big-endian platform, and STB works in a little-endian platform (or just the opposite), bytes will be reversed when doing this operation. It doesn't take into account differences in data types either, so you must be very careful to ensure that all types have the same size in one struct and the other.
So, remember:
Functional improvements
Memory footprint improvements
HLSL code editing in Notepad ++
You just need to download the HLSL.xml file from his GoogleDrive account, and in Notepad ++ click Language->Define Your Language->Import and then select the downloaded file. After restarting notepad++, you´ll find a new entry in the Language menu item like this:
By clicking in that new item when you load an HLSL file, you´ll get the following result:
According to him, it supports even SM 5.0 profiles.
Great job Matt !!! :)