Is a single pass dropshadow pixel shader possible? - c#

I've been working on a project, in WPF/C#, at work which uses quite a few animations. As a whole the project is going very well, and we've managed to make the animations efficient and impressive.
The problem is, we had to remove drop shadows to make that a reality. This has been met with a bit of resistance, as drop shadows on our title text generally look nicer. Now that we are getting close to the wrap-up stage I was asked to take another look at drop shadows and see if I can't make a workable solution. I tried the standard drop shadow effect, which is notoriously bad, and the Windows.Themes.x.DropShadowChrome effect which is more lightweight but still not great.
I am currently approaching the issue by trying to make a custom control which is using a template selector to basically remove the drop shadows during animation, and things are going well enough but I was curious about making my own pixel shader. Once upon a time I learned HLSL, and I have made a few shaders before but try as I might I cannot seem to make a single pass (a requirement of wpf) drop shadow.
I'm honestly not even sure such a shader is possible and I couldn't find a definitive yes or no online. Anyone have any insight to the possibility/method of doing something like this?

Related

Change marker's type after it's creation

I'm using Gmap.NET in winforms and I'm trying to figure out proper way to change marker's type (pin style) after marker is created. I'm making application with quite a lot of different overlays and eventually they will run out unique markers.
I tried looking through library, but couldn't find possibility of that. So far my best solution seems to backup markers positions, clear markers and remake them again. But this solution feels far from ideal. Maybe you guys have any better ideas.
Thanks.
The best approach here imo is to derive a CustomMarker and let this type be aware of all the (graphical) states it needs to display. All the marker types provided mostly only differ in the image they display. That way you avoid the hassle of recreating markers over and over again.

Slow drawing when using many controls in C#

I've been trying to create a roll-playing game for a little over a year now, and I thought a good way to test it and flesh it out a bit would be to turn it into a Dungeons and Dragons variant. However, the inherent problem with using a DnD setup is that there's a lot to keep track of, to the point where it becomes impossible for a single person to do by themselves. As such, I thought of writing a C# program to help.
I ran into this problem when I tried using a series of PictureBox objects to represent the spaces on the map where characters can move. I wanted to use PictureBoxes because that would allow me to use images to represent terrain and characters occupying the given space. However, the map I am using is roughly 46 x 75 1-inch squares, totaling 3450 PictureBoxes. This, understandably, slows the application down so much that it actually freezes for minutes at a time while it redraws the map every so often.
I tried two solutions. First, I tried using a Panel object for its free scrolling capabilities in the hopes that the application wouldn't have to redraw the whole map, but rather only the subset of PictureBoxes visible at that time. This helped only a little, and not enough to make the application usable. Second, I looked online, including this forum, and found people having similar problems. However, the problems they were having were entirely unrelated to mine (aside from the whole slow redraw thing) and thus the solutions didn't really apply to me. I did see a few recurring lines that I tried:
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
I'm not really sure what they do, but they did help a bit. I am still seeing way too much lag, though.
I'm out of ideas at the moment. Is there a better control I could use or a different way of drawing? Thanks in advance for your help!
I would try to develop a solution that only renders the images that are visible on the screen at any given time. Images should only be rendered when you scroll them into focus.
This is a common technique since rendering UI is usually the slowest operation by far. I would bind a view model object to the visible objects, which means you only have to render a subset of the images instead of the entire screen.
Grids with endless scroll sometimes use this approach.

How to draw animations on top of winforms controls?

I'd like to create some animations to make my (old) winforms app look a little nicer. The basic premise would be something like this:
I have a button I can press, and when I do, a random letter appears on top of the button and "flies" over to a textbox. Once the letter arrives at its destination, the letter vanishes and is appended to the text in the textbox.
This should be async, meaning there can be multiple letters on the way at the same time.
My problem is that I do not really know how to accomplish this. I know I can draw things on top of my controls by creating a graphics -object and drawing with it, but unless I force a redraw (Invalidate, or something else), the previous drawing is not cleared. However, if I do force the redraw, things tend to go all flickery (with or without DoubleBuffered set to true).
So I'm a bit at a loss in here, and despite my best efforts at googling, I wasn't able to find a suitable solution. Probably because drawing animations on winforms isn't all that popular (wpf would probably suit this ten times better), but I'd still like to at least learn if it is possible to accomplish.
What if you first draw it on a bitmap, then bitblt it to the screen/form. Look at the accepted answer in: Simple Game in C# with only native libraries

Resize and move image control with transparency

Either I'm not searching on quite the correct terms, or strangely no-one has asked about quite what I am looking for.
Put simply I'd like to have an image loaded into a user resizeable and moveable control (within the panel it belongs to). The image would need to have its opacity set. It should be resized via stretching if necessary no matter how the parent form or panel is resized. It should all be achievable fairly smoothly and on winforms.
I don't really want to re-invent the wheel here, and feel sure that something like this must have been done openly.
Strangely it seems difficult just to create a UserControl that's user resizeable and moveable at run time!?
I have a degree of understanding of drawing the image using ImageAttributes to reduce the opacity to the background, I am just wondering if there are useful resources for attempting the rest?
Thanks
I decided to take the plunge and make the effort to learn WPF. It was worth it, it makes all of this much easier to do when you get your head around it. It's so much more powerful, I think I'm converted.
I used this nice example too for how I can have resizeable and movable controls.
http://denismorozov.blogspot.co.uk/2008/01/how-to-resize-wpf-controls-at-runtime.html
I realise this isn't an answer quite for the original question on Winforms, but since no-one else was supporting and it seems Winforms is getting left behind, I thought I'd close the issue

How to select, display and save regions of a graphic?

So here's the situation: I need to take a (user-specified) graphic, and allow the user to define and label regions within that graphic. For example, if you uploaded a picture of a face, you might want to define "right eye", "left eye", "nose" etc. Also, having defined the regions, if I select a previously defined region, it should be highlighted on the image somehow. These regions are (obviously) not necessarily rectangular, and they cannot overlap. And if you click within a defined region in the graphic, I would be able to identify which region was clicked on.
There are a couple ways I can think of for doing this, none of which are quite satisfactory. Another developer before me tried doing it with a transparent grid overlaid on the original graphic, fiddling with the background alpha/color for highlighting regions, but I think they rather kludged it. I could either get my hands really dirty trying to clean up their code, or try a completely new approach.
What would you suggest for maximum speed and user-friendliness?
Bounty added: for the best solution that will get me up and running in the minimum time.
The GraphicsPath class is made to do this. Keep a list of them along with the image. Draw the image first, then Graphics.DrawPath() to draw the regions on top of the image.
Hit testing is simple with GraphicsPath.IsVisible(). Iterate the list in reverse order so overlaps work.
Assuming you haven't decided yet on the technology you'll use, I'd suggest WPF; I find most graphics-related tasks easier with WPF (at least in version 4) and it's specifically geared for interactivity, so creating non-rectangular regions using mouse clicks and hit-testing clicks to select shapes would be pretty easy. Loading images is also easy.
However, if you haven't used WPF or Silverlight until now, there is some overhead in learning the basic concepts and APIs; so I'm afraid there's no real way I can recommend it as a maximum speed solution without knowing your (or whoever's will be working on it) competencies. That said, using MVVM and WPF would be definitely the maximum speed solution for me. Also the maximum user-friendliness since WPF enables quite interesting interaction models out-of-the-box, like multi-touch support (that's the trendy one that should be mentioned, right?) and easy non-standard layout and placement of controls.
You need polygons, saved as list of points. And you need hit testing for them. See the link:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/40ebadc1-6154-4c7c-9cb1-d608a426b29c

Categories

Resources