Getting mouse coordinates in Haskell FLTK - haskell

I'm trying to load an image into a fltkhs box widget and do some image processing on it and I'd like to get the coordinates when the mouse click on a point on the image.
I couldn't find any part of fltkhs that can handle mouse events.
Anyone could give any suggestions?

Glancing through the documentation yielded this page:
https://hackage.haskell.org/package/fltkhs-0.5.4.1/docs/Graphics-UI-FLTK-LowLevel-FL.html
It has a function with the following signature:
getMouse :: IO Position
I suppose it's FLTKHS's analogue for get_mouse

Related

Making a drawing game using phaser

I am developing a game using Phaser where a user is rendered a triangular canvas. User can crop this canvas to any possible shape by drawing any crop pattern on the canvas. Besides this, i need to get this cropped canvas in suitable data format to be used as an image to render and also trace changes made on this canvas for undoing puspose.
Any help to get this through will be appreciated.
Thanks in advance.
Initial canvas
Canvas after crop
Cropped canvas used to create new canvas
So it's like folding a piece of paper and then cutting it so it looks like a snowflake? Interesting idea.
I think you could either use BitmapData to draw the initial cut out, then copy that bitmap 6 (or 12?) times and rotate and flip x-axis to construct the rest. Though maybe there will be seems, so like small lines, between the parts idk.
Another appproach would be to keep track of the initial cutlines like vectors. Then use math/trigonometry to calculate the result. No idea how to do this though, sorry.

Pygame Shooting Bullets

Recently ive been trying to create a small game using Pygame, Ive managed to display an image which can move side to side, the trouble ive been having is enabling it to fire bullets using the space bar.
Heres my code so far:
http://pastebin.com/24xDYwY7
Ive now got the bullet to display however it doesnt come out from the "turret.png", and just sits in the top left of the screen.
Is anyone able to help me with this? I am extremely new to python and would appreciate the help
It looks like you're using a technique I like employing in PyGame - using different sprite Groups for separating good guys, bad guys, bullets, blocks, etc… with a single unified 'all the things' Group.
What I don't see is the all_sprites.update() call that makes the whole thing work, though I do see player.update(). PyGame groups are designed to let you call group.update() in place of a for x in y call such as:
for sprite in my_sprites:
sprite.update()
EDIT: Not seeing your images in the right place? If they're being set to the upper-left corner, this is usually because nothing is setting the surface of the drawn image to appear where you want it to.
One thing I've found handy about PyGame's get_rect() call is that it allows you to pass arguments to set attributes of the rect you get back. For example, my sprite.draw(self) methods tend to look something like this:
def draw(self):
"""Sets the image's Rect to the middle of the sprite,
then blits to the screen.
"""
draw_rect = self.drawn_image.get_rect(center=self.rect.center)
SCREEN.blit(self.drawn_image, draw_rect)
This assumes that the sprite object's self.x and self.y are being updated correctly as well, but it's essentially the right thing to do; get the rect for the object you're drawing, set it to the right coordinates just as you do the actual sprite, then pass the image and the rect to SCREEN.blit().

How to drag a polygon in MFC?

I'm new to MFC. I know how to draw a line and how to scribble in MFC. I use CDC and some functions such as LineTo() and MoveTo() to do this. Moreover, I've got FillRect() and Rectangle().Now I want to drag my rectangle or any polygon in the view.It's like you drag a icon on your desktop.
I think the first step is to get the region.Then erase the old polygon and when the mouse move draw a same polygon which depends on the point where the mouse go.
So I search region in MSDN and I got Region class and CRgn class.But before I look into these two class I want to know whether I'm in the right direction.
I need more suggestions on how to learn MFC. Actually,all I need is to finish my homework which is mainly about draw polygons and drag them and link them by line. And I hope I can finish this homework all by myself and MSDN. Can MSDN help me do that?
The CDC::Polyline function will draw a polygon much faster than using LineTo and MoveTo.
You do not need region and do not need to erase the old polygon. Instead, you need to draw everything in the view OnDraw. Any change you want to make with the mouse should change the array of coordinates that represent the polygon and then call Invalidate. In other words, do not draw in the mouse message handlers. Calling Invalidate in the mouse message handlers will cause OnDraw to be called later and it should repaint the entire view.

Clearing a drawArea in haskell GTK

I'm making a game using gtk/cairo in haskell, and I'm looking for a way to completely clear the drawing area (a widget of type drawingArea). When a widget resizes for instance, the drawing area is cleared automatically. I'm looking for a way to clear it manually.
Any suggestions?
First get the DrawWindow of the DrawingArea using the function widgetGetDrawWindow, then call drawWindowClear with the DrawWindow as the argument.

How does drawImage work?

I've been trying to draw a "game over" image but for some reason the game crashes when the image is supposed to be drawn.
I've read the API for Java ME but I don't really understand what anchors are.
I want the image to be drawn over the whole screen.
if(mGameStatus==STATUS_GAME_OVER)
{
mGraphics.drawImage(mImgMgr.getGameOver(),0, 0, Graphics.TOP | Graphics.LEFT);
}
In order to help you, it would be useful if you write the Exception thrown that causes your application to crash.
Anchors
The anchors in images refer to the point of the bounding box of the image to be placed at x, y.
For example, I want to set an image in position x=10 and y=20. If I use anchors TOP and LEFT, the upper left corner of the image will be placed at 10,20. With TOP and RIGHT the upper right corner of the image will be placed at 10,20.
This can be read in JavaME API, where they do a similar comparison with strings. The same apply for images except for BASELINE as Images doesn't have one.
http://download.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Graphics.html#anchor

Resources