GTK: Get pointer position on scroll-event AFTER scrolled_window has scrolled - c

I've got a drawing area inside a scrolled window (with convenience viewport),
and this drawing area updates itself according to incoming motion-notify-events.
When I scroll the area though obviously no motion events are emitted,
but I wanted to work around this, and so tried to connect the drawing area's
"scroll-event" signal to the same motion-notify callback.
The problem I'm facing here is that this signal is emitted before the scrolled window
has update its viewport, so in the callback, I end up with pointer coordinates that were true just before scrolling, making it look like the drawing area is always "lagging a step behind" the actual pointer when scrolling while not moving the pointer itself.
I thought I could compensate for this by manually extracting the coordinates with gdk_window_get_pointer, but then I realized this cannot work as the pointer is technically still at its old position when the callback is commencing.
I also tried using g_signal_connect_after in hopes it would have the callback get called after the viewport was scrolled, but it didn't help.
My last hope would be to start a timer on scroll-events, and have the callback fire after a minimal amount of time, but this sounds realllly ugly, and I'd like to avoid that at any cost.
Any ideas as to how this could be realized?
Thanks in advance!

A solution would be to connect to the "value-changed" signal of the GtkScrolledWindow
adjustments.
Source: https://mail.gnome.org/archives/gtk-app-devel-list/2011-September/msg00014.html

Related

Content lost when window is repainted

I am currently messing around with the windows API in C. I thought it would be funny to make a simple chalkboard. Everything is working fine. It's drawing etc, etc.
The problem is that the contents are lost when the window is repainted/updated/resized...
I thought maybe I should save the HDC or something, but then I don't know how to put it back.
How do I solve this? I figured it shouldn't be a very difficult question to answer, yet I can't really find anything on google somehow.
You need to handle the WM_PAINT event and repaint the invalidated region in its entirety. That's what WM_PAINT is -- a request from the system to redraw a dirty region.
For your specific application it sounds like you should create an off-screen device context (CreateCompatibleDC), a corresponding bitmap (CreateBitmap) of the size of your canvas, do all the drawing operations there and call InvalidateRect on your window. When WM_PAINT fires call BitBlt to transfer the relevant portion of that bitmap to the screen.

Xlib - Two issues with call to XMoveResizeWindow

I am new to Xlib (in C) and am having two issues when calling the XMoveResizeWindow function.
ex.
XMoveResizeWindow(display, window_id, move_x, move_y, resize_x, resize_y);
1) After the call, the window I move will reposition itself correctly, however, if I select the window with the pointer after the move, it will instantly revert back to the position it held prior to the move. I assume I have to somehow 'update' the X11 server after it's moved with the windows new position?
2) Secondly, in regards to the resize of the window. My window is essentially being truncated by the x and y values entered, instead of resized. In other words, instead of the entire window shrinking down, the right and bottom sides of the window are cut off from view. Is there a way to instead resize the entire window?
--I am sorry I am unable to submit my complete code, however, I believe my issues are due solely to my lack of understanding of Xlib and this particular function's operations. As such, I am not neccessarily looking for specific code as a solution, merely an explination or suggestion on how I should go about implementing a solution.
Thank you.
I believe there is something wrong with your code, since that code is not available i'll point to an example.
Examples are given at readme itself.

MVVM Get Control Position

I am a bit stuck in my current project.
I'm using a terrible API that needs to be told where and when to draw at any give time. This API does not expose any controls, and I need a control in order to place the drawn object properly.
What I have done is I've put a canvas in my grid in my view. This canvas takes up the space that my drawn API element needs to take up. So, by getting the canvas actualwidth and actualheight, I can draw my API element at the proper size. The issue i'm having is the position of the API element. The Canvas is in the proper place at all times, but when the program first starts, Canvas.TranslatePoint(new System.Windows.Point(0, 0), App.Current.MainWindow); returns 0,0. As soon as I manipulate the UI and cause the Canvas to Resize, the location function returns the real location and my API element draws in the proper spot. My question is why is the initial location 0? How can I remedy this? I call the initial draw function from the UserControl_Loaded event.
Thanks
P.S. Would I be wrong in thinking that the initial 0,0 is a relative coordinate, and not an absolute coordinate?
I figured out my issue - my control wasn't part of the PresentationSource. Long story short, you can't get the location of a control that isn't shown on the screen yet. My fix was this:
private void WaveformCanvas_Loaded(object sender, RoutedEventArgs e){
if((sender as Canvas).IsVisible)
{
(this.DataContext as StudioControlViewModel).MoveWaveform();
}
}
For me, the MoveWaveform() function calls WaveformCanvas.TranslatePoint(new System.Windows.Point(0, 0), App.Current.MainWindow);
So now the function only gets called when the control is visible, which has solved all of my issues.

Canvas - dynamic drawing and managing shapes

I'm trying to make an application which allows the user to draw shapes to the canvas. Once drawn, I would like for the user to be able to select, move, resize, basically manipulate the shapes in any which way.
I have done something similar in XNA and that was quite easy due to the fact that there was a draw loop. In Silverlight there is no such thing as far as I understand and I am having trouble figuring out how to manage the objects on the canvas. As in what is the best way to manage the canvas' children collection to ensure appropriate response of the UI to what the user does.
Most examples out there are pretty basic and do not go anywhere near this kind of thing. I would be grateful if somebody who has done this before could tell me how they approached the problem.
Thinking about it for a while I think I figured out how it works.
There is a draw loop for the canvas, which is the draw loop of the top level parent container which it lives on.
The difference with XNA I guess is that the collection of items to draw on the canvas doesn't need to be explicitly drawn, since the canvas takes care of drawing its children automatically.
So, what I need is some way to hold on to any object I add to the canvas' children... I can then update the objects drawing properties and the changes will be reflected in the canvas next time it refreshes.
I guess a dictionary of some sort in which to store the items I put in the list might be best...?
Not a finished answer yet, but I guess I understand half of it now.

Reversing an animation in Silverlight on button press or any other event

How would I reverse a double animation in Silverlight on an event? For example, lets say I have an ellipse as a path and I am moving a shape along this path in an infinite loop. If I press a button, I want to reverse the direction of the spin (clockwise <-> counterclockwise).
To be more specific, I am using the PathListBox object that is new in SL4. It has a start property from 0 to 100% (double 0 - 1) that will place the first item at the specified location along the path. By animating this property from 0 to 1 and 1 to 0, I can make an object spin clockwise and counter clockwise.
Lets say I have a button and on the button press, I want to reverse the direction. How do I go about doing it? I've tried pausing the animation and swapping the To and From values of the animation and resuming it, but this causes the animation to jump. So if its at "3 o'clock" on the ellipse, it jumps to "9 o'clock" and goes backwards from there. I tried doing something like setting the storyboard's CurrentTime property to "Duration - CurrentTime", but that property doesn't seem to be settable.
So, in conclusion, any ideas about how to reverse an animation on demand?
PS: I know there is a PathListBoxUtils that provides scroll behaviors for PathListBox, but that doesn't quite implement what I want. Or to put it another way, I am looking to modify the PathListBoxUtils to have an infinitely rotating, reversible carousel rather than scrolling one item at a time.
Ok, the way I got it working was by pausing the animation, swapping the To and From values, and using the Seek method to move the animation forward by a set amount. The amount I needed it to move forward is "Duration.TimeSpan() - GetCurrentTime()", but accessing Duration seems to throw an exception (Operation not valid for the current state of the object).
For now, I just hard coded the Duration value for a test and seems to be working fine. I guess for a real implementation the Duration can be bound to some value and the calculation can use that value too.

Resources