• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

joeG

[java] Component Images

14 posts in this topic

Ok, is there any possible way to get a graphical representation of a component''s context into an Image. What I am doing is creating a stretch rectangle (you know the kind where the user clicks their mouse and stretches a rectangle to make a selection) class. I have available to me repaint(x,y,width,height), but that has proved very laborious, as there are many different cases to cover. What is the best way to do this minus flicker. I''m kind of stuck here on this part, and it would be nice to get going on some of the cooler stuff yet to do. Thanks, JoeG
0

Share this post


Link to post
Share on other sites
what are you trying to do exactly, get a picture of a component? I''ve never actually done this but i would try component.getImage() or component.getGraphics() and see what i got from those.
0

Share this post


Link to post
Share on other sites
Say, you had a panel (or component in my case) that the user could drag a selection rectangle on. The class responsible for the selection rectangle responds to the mouseDrag event, and for each mouseDrag event I update the rectangle. To make this look good I can't leave the previous rectangle on the component. I originally wanted the ability to grab a picture of the component in its original state, and paste it on and then draw the new rectangle (in response to the mouseDrag event like I said above). But what I then realized I could do (and at this moment appears to be my only option) was use the component's repaint(x,y,width,height) to restore the component to its original appearance and then paint the new rectangle. But then I realized that you had to account for when the delta x was negative and the delta y was positive, and all the combinations that arise from that. That solution is reallyl not an elegant one, so, in short, I'm searching for a better solution.

Here's a pic of what's going on (don't know about the use of pics here yet, but from what I've seen this one is innocent enough )



JoeG


Edited by - joeG on 2/22/00 10:36:26 AM
0

Share this post


Link to post
Share on other sites
You shouldn''t need to copy the background at all, if you do the selection rectangle correctly. (Assuming I understand what you''re trying to do)

A good way to do the drawing of the rectangle is to use the built-in DrawDragRect() function. It automatically erases the previous drawn rectangle before drawing a new one. You do have to keep track of the last position, but this should be easy to do. YOu also have to check for which quadrant your selection is in; you get some weird effects if you don''t. Its simple to use.. just play around with it and see if its what you want. The default behavior draws a selection rectangle seen throughout the windows interface.

Also, if you draw the lines yourself, you might want to look at using XOR operations in drawing. that way, you just draw over the last rectangle you drew with XOR, and it magically disappears. You''ll have to research this method though, haven''t done it that way in years.

good luck, and hope this was some help.



*oof*
0

Share this post


Link to post
Share on other sites
Argh. I just realized you''re using Java (my fault for following the discussion link in the index page and not checking to see where it is)... I''m not sure how well the previous reccomendations work there... but you might want to see if Java provides similar functionality somewhere.

sorry if I confused ya.


*oof*
0

Share this post


Link to post
Share on other sites
This shouldn''t be too difficult. You''ll just have to store the previous rectangle (propably at the end of the mouseDragged() method) and draw it away using this XOR method. Something like this:

int beginX;
int beginY;
int endX;
int endY;
boolean fIsSelectingArea = false;

public void mouseDragged(MouseEvent event)
{
if ((beginX != endX) && (beginY != endY))
{
paintSelectionRect(beginX, beginY, endX, endY);
}

endX = event.getX();
endY = event.getY();

// Paint the selection
paintSelectionRect(beginX, beginY, endX, endY);
}

public void paintSelectionRect
(int left, int top, int right, int bottom)
{
// Order the coordinates
if (right < left)
{
int temp = left;
left = right;
right = temp;
}

if (bottom < top)
{
int temp = top;
top = bottom;
bottom = temp;
}

Graphics g = getGraphics();
g.setColor(Color.green);
g.setXORMode(Color.red);
g.drawRect(left, top, right-left, bottom-top);
g.setPaintMode();
}


And that''s it. I''ve used this code in one bitmap editor I made and it worked beautifully.
0

Share this post


Link to post
Share on other sites
I see what you''re saying, you can''t just keep painting rectangles because there would be a ton of rectangles. Here''s something i thought of immediatley but have never implemented myself. Glass panes. Here''s a line from the tutorial "The glass pane is useful when you want to be able to catch events or paint over an area that already contains one or more components." Just catch the mouse drag events, clear out the glass pane, then paint over it. And you can set it''s visibility to false when you''re done using it. Basically glass panes are just components that are layered on top of everything.
0

Share this post


Link to post
Share on other sites
Jim, Have any idea on how to do that in JDK 1.1?

Javanerd, that''s what I eventually want to end up with, a selection rectangle over an image (but not for editing though ), but I don''t see any code to undo the last rectangle drawn, so I''m thinking that there wouldn''t be any change between what you see in the pic above.
0

Share this post


Link to post
Share on other sites
very doable under 1.1. Just make a class
MyGlassPane extends Component { 

....

paint (Graphics g) {
g.setColor(Color.OPAQUE);
g.drawRect(dimensions, of , entire, MyGlassPane);
g.setColor(Color.black);
g.drawRect(dimensions, sent, from ,dragEvent);
}
}

Now, you might have to do something fancy with the event listeners, like onmousedown, set the glasspane's visibility to true, then give the glass pane a listener for mouse drags. See I don't know if the mouse drags will still get passed to the underlying component on wich the mouse was originally clicked or not. Just include printlns in your event listener to print out the event's source.

Edited by - Jim_Ross on 2/23/00 1:36:32 PM
0

Share this post


Link to post
Share on other sites
quote:
Original post by joeG

Jim, Have any idea on how to do that in JDK 1.1?

Javanerd, that''s what I eventually want to end up with, a selection rectangle over an image (but not for editing though ), but I don''t see any code to undo the last rectangle drawn, so I''m thinking that there wouldn''t be any change between what you see in the pic above.


Ah, but there you are wrong my friend...

The XOR painting mode takes care of the painting AND the removing. The idea is that if you paint a rectangle first time using XOR mode it''ll alter the colors so that the rectangle is allways visible no matter what the background color is. Then when you paint the rectangle the second time using XOR mode it''ll erase whatever was painted the last time (assuming of course that you draw the exact same rectangle).

Try it!

0

Share this post


Link to post
Share on other sites
But, when will the rectangle ever be drawn twice over itself? As you can see in the above pic, there are rectangles all over. Trying XOR, I would get the same lines, but with weird colors. Do you have tha old app(let) with you still. I'd like to see the source to see what your talking about.

Thanks though

JoeG

And one thing more, these rectangles are not solid rectangles

Edited by - joeG on 2/25/00 8:25:54 AM
0

Share this post


Link to post
Share on other sites
quote:
Original post by javanerd

[quote] Original post by joeG

Jim, Have any idea on how to do that in JDK 1.1?

Javanerd, that's what I eventually want to end up with, a selection rectangle over an image (but not for editing though ), but I don't see any code to undo the last rectangle drawn, so I'm thinking that there wouldn't be any change between what you see in the pic above.


Ah, but there you are wrong my friend...

The XOR painting mode takes care of the painting AND the removing. The idea is that if you paint a rectangle first time using XOR mode it'll alter the colors so that the rectangle is allways visible no matter what the background color is. Then when you paint the rectangle the second time using XOR mode it'll erase whatever was painted the last time (assuming of course that you draw the exact same rectangle).

Try it!




Will that work even with the color black? I guess i don't fully understand the internals of a XOR color mode (model?)


Edited by - Jim_Ross on 2/25/00 1:00:23 PM
0

Share this post


Link to post
Share on other sites
I imagine Java, if working in palette mode, would ''dereference'' both color''s indices and then peform the bitwise XOR. False (XOR) Anything = ThatAnything. Translation: 000 000 000 (XOR) 111 000 000 (red for example) = 111 000 000. I think it looks pretty cool. But it doesn''t solve my problem either
0

Share this post


Link to post
Share on other sites