|
Does not draw |
TeamTerradactyl
Member #7,733
September 2006
|
I am trying to teach myself how to use objects. I created a window with about 4 objects. I want it to look something like this: +--------------------------------------+ | | | +----------------------------------+ | | | MENU | | | +----------------------------------+ | | | | +-----------------------+ +--------+ | | | MAIN | | SIDE | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------------------+ +--------+ | | | | +----------------------------------+ | | | STAT | | | | | | | +----------------------------------+ | | | +--------------------------------------+ The problem I'm getting is that it looks like the attachment (image.png), which isn't really what I want at all. I'm thinking that the WindowObject.draw() function in the mapObjects.hpp is where the problem is occurring, as it's the only thing that calls blit() (other than the blit2screen() function), but if anyone could take a look at my sources (I've included them all) and let me know where I've got the error... Thanks!
|
ReyBrujo
Moderator
January 2001
|
That is possible. Check this: (gdb) n 330 blit(surface, double_buffer, 0, 0, x1, y1, objectWidth, objectHeight); (gdb) p surface->x There is no member named x. (gdb) p surface->w $23 = 27 (gdb) p surface->h $24 = 390 (gdb) p objectWidth $25 = 390 (gdb) p objectHeight $26 = 27 (gdb) Note that the width and height of the surface are exactly the opposite from the object properties. The other mistake I found is that you are positioning the object within the surface, when it is the surface the one you should move. In example: x1 = HORZ_BUFFER; // 5 y1 = VERT_BUFFER; // 5 x2 = SW - HORZ_BUFFER; // 395 y2 = SH / 8 - VERT_BUFFER; // 32 WindowObject MenuObject("Menu", x1, y1, x2, y2); The WindowObject class will call calculate size:
(Note that you twisted the height and width, the arguments should be width and then height). Here, you create a bitmap with a determine width and height. If you pass 5, 5, 10, 10, it will create a 5x5 bitmap. However, your draw method: void WindowObject::draw(void) { ASSERT (surface != NULL); clear_to_color(surface, makecol(255,0,128)); rectfill(surface, x1, y1, x2, y2, bgcolor); rectfill(surface, x1 + 5, y1 + 5, x2 - 5, y2 - 5, fgcolor); print_sfont(x1 + 3, y1 + 3, name.c_str(), surface); blit(surface, double_buffer, 0, 0, 0, 0, surface->w, surface->h); } will draw in the surface taking into account the offsets. So, mathematically:
Where is the rectangle? Nowhere, because the rectangle begins at (5,5), and your surface has coordenates (0,4) only. So, you basically need to turn the height and width arguments when creating the bitmap, then changing your draw code to draw the rectfill always at (0, 0); (x2-x1, y2-y1), and then move the surface in the bitmap. (Edited: In mapobjects.hpp, change the create_bitmap line to surface = create_bitmap(objectWidth, objectHeight);, and change your draw method to void WindowObject::draw(void) { ASSERT (surface != NULL); clear_to_color(surface, makecol(255,0,128)); rectfill(surface, 0, 0, x2-x1, y2-y1, bgcolor); // rectfill(surface, x1 + 5, y1 + 5, x2 - 5, y2 - 5, fgcolor); print_sfont(x1 + 3, y1 + 3, name.c_str(), surface); blit(surface, double_buffer, 0, 0, x1, y1, objectWidth, objectHeight); } That should do) -- |
TeamTerradactyl
Member #7,733
September 2006
|
Thank you! I love these allegro gurus; they're so sweet :-)! That works beautifully. I carried that one further and figured out why my bottom object (STAT) had disappeared, and why the names of the objects were all off-mark. It looks great now; thanks so much. Does this mean that my objects should not hold their own sizes and coordinates? If I need to do any mouse detection, I would need 0..size instead of (x1,y1)..(x2,y2), correct? I'll mull this over, but in the meantime, thank you again for the in-depth help! -TeamTerradactyl
|
|