how to drag and drop button to target button in flash - actionscript-2

I want to create a button which can be dragged and dropped toward another button so that the button location (x, y) is dragged into the location of the destination button.
My code:
sejarah.onPress = function(){
startDrag(this);}
sejarah.onRelease = function(){
if(this.hitTest (atarget)){
this._x = _root.atarget._x;
this._y = _root.atarget._y;}
else{stopDrag();}
}
I want to achieve this: http://www.thibaud.be/#

on(press) {
startDrag(this);
}
on(release) {
stopDrag();
_x = Math.round(_x/_width)*_width + 0;
_y = Math.round(_y/_height)*_height + 0;
}
This is one of the most simple code that can do a job like this. You put this code inside a button and when you stop dragging this button it's position will snap to the grid.
Your button's clip center must be at top-left corner of button else it can get weird. Also, you can change beginning of grid by changing zeros to position you need.
You can draw a grid to see attachment.

Related

SDL2 window resize mouse position

How do i make so that positions adapts to the new window position when i resize my window in SDL2 and with SDL_RenderSetLogicalSize?
I want to be able to hover a text and make it change color but whenever i resize the window its still in the same window cords. Is there a way to adapt the mouse?
void MainMenu::CheckHover()
{
for (std::list<MenuItem>::iterator it = menuItems.begin(); it != menuItems.end(); it++)
{
Text* text = (*it).text;
float Left = text->GetX();
float Right = text->GetX() + text->GetWidth();
float Top = text->GetY();
float Bottom = text->GetY() + text->GetHeight();
if (mouseX < Left ||
mouseX > Right ||
mouseY < Top ||
mouseY > Bottom)
{
//hover = false
text->SetTextColor(255, 255, 255);
}
else
{
//hover = true
text->SetTextColor(100, 100, 100);
}
}
}
I had a similar problem some time ago, and it was due to multiple updates of my mouse position in one SDL eventloop. I wanted to move a SDL_Texture around by dragging with the mouse but it failed after resizing, because somehow the mouse coordinates were messed up.
What I did was rearrange my code to have only one event handling the mouse position update. Also I'm not using any calls to SDL_SetWindowSize(). When the user resizes the window the renderer is resized appropriately due to SDL_RenderSetLogicalSize().
The relevant code parts look like this - some stuff is adapted to your case. I would also suggest to use a SDL_Rect to detect if the mouse is inside your text area, because the SDL_Rects will be resized internally if the the window/renderer changes size.
//Declarations
//...
SDL_Point mousePosRunning;
// Picture in picture texture I wanted to move
SDL_Rect pipRect;
// Init resizable sdl window
window = SDL_CreateWindow(
"Window",
SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex),
SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex),
defaultW, defaultH,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // This one is optional
SDL_RenderSetLogicalSize(renderer, defaultW, defaultH);
// SDL main loop
while(SDL_PollEvent(&event) && running)
{
switch (event.type)
{
// Some event handling here
// ...
// Handle mouse motion event
case SDL_MOUSEMOTION:
// Update mouse pos
mousePosRunning.x = event.button.x;
mousePosRunning.y = event.button.y;
// Check if mouse is inside the pip region
if (SDL_EnclosePoints(&mousePosRunning, 1, &pipRect, NULL))
{
// Mouse is inside the pipRect
// do some stuff... i.e. change color
}
else
{
// Mouse left rectangle
}
break;
}
}

Not able to set the width of alert box

I have this simple alert box that shows a simple message but when the text is too long then it gets cut off.. Is there any way that I can set the width of the alert box..
I tried Ext.Msg.MinWidth=300;
But that didn't work
onForgotPwdTap: function(button, e, eOpts) {
Ext.Msg.alert('Forgot Password?', 'Please contact your administrator for password assistance.', Ext.emptyFn);
}
You could try getting the screen dimensions like this:
Display display = getWindowManager().getDefaultDisplay();
int mwidth = display.getWidth();
int mheight = display.getHeight();
And then alter the Dialog like this:
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
d.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = mwidth;
lp.height = myheight;
//change position of window on screen
lp.x = mwidth/2; //set these values to what work for you; probably like I have here at
lp.y = mheight/2; //half the screen width and height so it is in center
//set the dim level of the background
lp.dimAmount=0.1f; //change this value for more or less dimming
d.getWindow().setAttributes(lp);
//add a blur/dim flags
d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND | WindowManager.LayoutParams.FLAG_DIM_BEHIND);

ILNumerics Mouse Event

I have a problem with the Mouse events!
I have subscribed to the event MouseEnter and MouseLeave.
If my mouse cursor example is in the exact center of the panel, the MouseEnter and MouseLeave event triggered, why?
My goal would be to sense, starting from when the mouse cursor is on the 3D PlotCube and when not.
Code:
scene.MouseEnter += ILSurface_MouseEnter;
scene.MouseLeave += ILSurface_MouseLeave;
A plot cube catches events for the whole area of its ScreenRect rectangle. In a standard setup, this rectangle is set to (0,0,1,1) which fills the whole panel. So, unless you have multiple plot cubes / cameras on your panel, the mouse will basically always be on the plot cube.
In order to show the functioning of the MouseEnter and MouseLeave events nevertheless, I'll post an example which acts on a plot within the plot cube instead. It writes "On Plot" in the title bar of the form when the mouse enteres the plot. "Off Plot" is written as soon as the mouse leaves the plot.
Start with a fresh panel and setup ILNumerics as shown here: http://ilnumerics.net/visualization-api-quick-start-guide.html
Drag an ILPanel onto form1 and double click on it in order to switch to the code of the auto generated ilPanel1_Load event handler. Replace the handler with the following code:
private void ilPanel1_Load(object sender, EventArgs e) {
var surfPlot = new ILSurface(ILMath.tosingle(ILSpecialData.sincf(50, 40))) {
Colormap = Colormaps.Prism
};
var pc = ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
surfPlot
});
surfPlot.MouseEnter += (_s, _a) => {
if (!_a.DirectionUp)
Text = "On Plot - Target: " + _a.Target.ToString();
};
surfPlot.MouseLeave += (_s, _a) => {
if (!_a.DirectionUp)
Text = "Off Plot - Target: " + _a.Target.ToString();
};
}
This would produce a result similar to the following image:
The title of the form now reflects, if the mouse is on the plot or not. Note, that this is working regardless of the rotation / shape of the plot. The full documentation of the mouse event handling in ILNumerics is found here: http://ilnumerics.net/mouse-events.html

programatically duplicate xaml control in WP

I'm not getting how I could duplicate a XAML element pgrogramatically. For example if I define on XAML a rectangle om the middle of the screen, the user presses a button and I would like to duplicate this rectangle with all properties of it and then put it to the right of the first one, should this be possible?
Sure - just do a deep copy of the properties you want inserted and then add it to the panel. Assuming your controls are in a StackPanel with horizontal orientation:
Rectangle newRect = new Rectangle()
{
Width = oldRect.Width,
Height = oldrect.Height,
Stroke = oldRect.Stroke,
// repeat for other values you want the same
};
myStackPanel.Children.Add(newRect);

How do I determine the page number for the tab I just clicked on in gtk#?

I have a GTK notebook with multiple tabs. Each tab label is a composite container containing, among other things, a button I want to use to close the tab. The button has a handler for the "clicked" signal.
When the signal is called, I get the button widget and "EventArgs" as a parameter.
I need to determine the page number based on the button widget, but myNotebook.PageNum(buttonWidget) always returns -1. I've even tried buttonWidget.Parent which is the HBox which contains the widget.
Any ideas on what I can do or what I am doing wrong?
One easy work around is to pass the page number to your button's Clicked event as you construct the buttons.
for (int page = 0; page < n; page++){
int the_page = page;
NotebookPage p = new NotebookPage ();
...
Button b = new Button ("Close page {0}", the_page);
b.Clicked += delegate {
Console.WriteLine ("Page={0}", the_page);
};
}
The "the_page" is important, as it is a new variable that will be captured by the delegate.