Invalidate() command is not repainting the control - controls

I am trying to develop a custom control which needs to have some rectangles to be drawn. Now, 1 rectangle needs to be moved so I used overrided mousemove method to get the new location and change the location part of that rectangle and then used Invalidate() command. But problem is, that whole control is painted instead of that rectangle. It is disaapearing. If someone can point out where I am doing wrong, that would be a great help. Thanks.

You can use partial invalidate using Invallidate() overloads. pass a rectangle as a parameter to Invalidate() or you can pass 4 number to do it.
Invalidate(new Rectangle(left, top, width, height));
of course you must invalidate rectangle's old place and new place.

Related

Drag and Drop functionality using testcomplete

I want to simulate a drag and drop functionality from one DevXtraGridcell to another DevXtraGridcell without using the coordinate system.
Can someone give me an idea how can I do it without the default record and play and without the source and destination cordinates.
The Drag action always uses coordinates, but you can calculate the coordinates on the fly instead of using hard-coded coordinates:
Explore your grid in TestComplete's Object Browser and find a method or property that returns cell coordinates.
According to this old blog post, it should be something like:
gridObj.MainView.ViewInfo.RowsInfo.GetInfoByHandle(Row).Cells.Item_2(Column).Bounds
Calculate the coordinates of the first and second cell. (Make sure that both cells are visible on the screen.)
Do the Drag from one first cell's coordiantes to the second cell's coordinates.
in my case i had to user the obj.MainView.get_ViewInfo property worked for one gridcontrol , the other is of card layout the link given doesnt work in my case though

Positioning a UIView between two other views. Autolayout

I'm using Autolayout to set up quite a lot of labels and buttons in a view. One button needs to be exactly betwwen 2 UILabels and I don't know how to accomplish that. I try to get the position on one label, the position of the other, do the math, etc. But since it's using autolayout, it turns out that the frame.origin.x property is always 0.
So any clues on how to do that?
thanks in advance,
One possible way to do this using the designer is to place a container that will fill the space between the two labels. Just drag a View onto the design surface and make sure that you have the following constraints: Top Space to the top label with default value and Bottom Space to the bottom label with default value.
Once you have this container simply place the button as a child of this container and centre the button horizontally and vertically in the container. That should do it.
This could also be done with code. Let me know if sample code is needed.

Drawing on an image which is inside a QScrollArea?

If I subclass QLabel and I add a QLabel directly to my QDialog, it works fine. If I add this label inside a ScrollArea, the thing I’m drawing doesn’t show unless I resize the dialog itself. Yes, weird.
I’ve setup compilable example code that indicates what the problem is. What I am trying to do is to select an area of an image with my mouse, by drawing a rectangle on the corresponding area. The images my program is designed to work with can be very large, and thus, I need to have a scroll area so as the dialog to stay at a logical dimension, and not to fill the entire screen (or even multiple workspaces, if we are talking about a linux machine with multiple desktops).
Everything works fine, except that the drawing (selection-rectangle) isn’t visible unless the dialog is resized – manually. I think I have to update something while drawing, but I’m not sure what. Well, here’s the example code: http://paste.ubuntu.com/1151553/
Another issues that I don’t know how to solve (and I want your suggestions there) are (1) when the user is selecting an area, how to set it to automatically scroll when the user actually selects an area by pushing against to a wall of the scroll area (I guess I am understandable here). (2) is there a way to let the user select a rectangle and then, when he left-clicks on a position with holding down the [Shift] button, the bottom right edge of his previous selection to actually go through the point he clicks at?
The documentation indicates that you have to set a Layout somehow somewhere, but I'm not sure how to do this to my occassion.
Thanks in advance for any help.
about problem (1):
just use of Event. i think mouse Enter Event or Leave Event is good for that.
and to do that i think you can use a hidden rectangular that fill the whole of the screen.
and over write the mouse leave Event for that rectangular and tell in that function , to scroll the page.

How to move an image

I am creating an app where bombs come into the screen and blow up this thing that you have to move. How do I make these bombs fly into the screen and move in random directions automatically ? Kind of like fruit ninja where the fruits fly out at you. How do I code that ? What do I need to do ? Please also provide some code. Thank you !
Create a class, called Bomb or something and it needs to have an instance variable and property of CGRect on iOS or NSRect on Mac OS.
Then create a method that can draw the bomb on the screen, like - drawOnScreen or just - draw which knows how to draw the object. Which would contain code like [[UIImage imageNamed:#"bomb1"] drawInRect:self.frame]
Then in your game loop you simple change the coordinates of the frame of such a bomb object to make it move, of course you will need to do that before calling the draw method as it would draw the previous frame then..
There also is another way of adding a subview to the gameview every time you need a new bomb. However a view has more overhead than using the object I described above and would most likely cause your game to run slow if you have like 50/60+ ( wild guess ) bombs.
For controls on the screen like a pause button I would definitely use a view and add it as a subview.

Changing selection state of IKImageBrowserView

Hey guys, I've just migrated my image selector from NSCollectionView to IKImageBrowserView. I've got almost everything set up the way I want it, except for the selection ring. I don't like the greyed out background that IKImageBrowserView defaults to, and I wanted to do a yellow stroke around the edge of my selected image to indicate it's selection (like in iPhoto). Is is possible to override the draw state of IKImageBrowserCell? I haven't been able to find any way to do it yet. It doesn't have the simple drawRect methods that I'm used to. Any help would be appreciated. I'm assuming I have to use CALayers?
I overrode - (CALayer *)layerForType:(NSString *)type and tried just as a test, setting the layer corner radius to 0, but it didn't seem to change anything. The method is being called because if I throw a breakpoint in it, it stops there. However, even if I return nil from that method, it still draws the images like usual.
Thanks!
That is the right method for customizing the IKImageBrowserCell.
Using CALayers and configuring different attributes, you can control many facets of how the images are presented.,
A layer of type = IKImageBrowserCellSelectionLayer is what you will want to change to have the display behave and present as you wish.
Here's a link to Apple's sample code project that will get you started

Resources