diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-17 15:11:19 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-17 15:11:19 +0000 |
commit | d0c97b98e477cfdf46ed7f36fd16c64f7943d551 (patch) | |
tree | 156acefaae842888432f923257b76bad12a16672 /src | |
parent | d9593657605b2e286b478718c89bcbe7cd341c43 (diff) | |
download | mana-d0c97b98e477cfdf46ed7f36fd16c64f7943d551.tar.gz mana-d0c97b98e477cfdf46ed7f36fd16c64f7943d551.tar.bz2 mana-d0c97b98e477cfdf46ed7f36fd16c64f7943d551.tar.xz mana-d0c97b98e477cfdf46ed7f36fd16c64f7943d551.zip |
Committing Allegro -> SDL switch, hugely breaking the game.
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/being.cpp | 2 | ||||
-rw-r--r-- | src/game.cpp | 135 | ||||
-rw-r--r-- | src/game.h | 6 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 85 | ||||
-rw-r--r-- | src/graphic/graphic.h | 8 | ||||
-rw-r--r-- | src/graphic/spriteset.h | 1 | ||||
-rw-r--r-- | src/gui/allegroinput.cpp | 70 | ||||
-rw-r--r-- | src/gui/allegroinput.h | 49 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 21 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 19 | ||||
-rw-r--r-- | src/gui/chat.cpp | 10 | ||||
-rw-r--r-- | src/gui/checkbox.cpp | 2 | ||||
-rw-r--r-- | src/gui/gui.cpp | 15 | ||||
-rw-r--r-- | src/gui/gui.h | 19 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 4 | ||||
-rw-r--r-- | src/gui/login.cpp | 25 | ||||
-rw-r--r-- | src/gui/playerbox.cpp | 4 | ||||
-rw-r--r-- | src/gui/progressbar.cpp | 4 | ||||
-rw-r--r-- | src/gui/radiobutton.cpp | 2 | ||||
-rw-r--r-- | src/gui/setup.cpp | 11 | ||||
-rw-r--r-- | src/gui/setup.h | 1 | ||||
-rw-r--r-- | src/gui/slider.cpp | 8 | ||||
-rw-r--r-- | src/gui/window.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 84 | ||||
-rw-r--r-- | src/main.h | 7 | ||||
-rw-r--r-- | src/resources/image.cpp | 111 | ||||
-rw-r--r-- | src/resources/image.h | 44 |
28 files changed, 330 insertions, 420 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 3d5a5c5e..e8dfee8c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,6 @@ bin_PROGRAMS = tmw tmw_SOURCES = sound/sound.cpp \ graphic/graphic.cpp \ graphic/spriteset.cpp \ - gui/allegroinput.cpp \ gui/button.cpp \ gui/buy.cpp \ gui/buysell.cpp \ diff --git a/src/being.cpp b/src/being.cpp index 365ece88..095a48ca 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -141,7 +141,7 @@ Being::Being() { hair_style = 1; hair_color = 1; weapon = 0; x = 0; y = 0; direction = 0; - speech_color = makecol(0, 0, 0); + speech_color = 0;//makecol(0, 0, 0); } Being::~Being() { diff --git a/src/game.cpp b/src/game.cpp index 84e642dd..a3b5b5a5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -35,6 +35,7 @@ #include "./gui/ok_dialog.h" #include "./graphic/graphic.h" #include "./sound/sound.h" +#include <SDL.h> char map_path[480]; @@ -78,38 +79,24 @@ class DeatchNoticeListener : public gcn::ActionListener { char walk_status = 0; -// SDL callbacks -/* Uint32 refresh_time(Uint32 interval, void *param) { tick_time++; if (tick_time == MAX_TIME) tick_time = 0; + return interval; } -Uint32 second(Uint32 interval, void *param) -{ - action_time = true; - fps = frame; - frame = 0; -} -*/ - -void refresh_time(void) { - tick_time++; - if (tick_time == MAX_TIME) tick_time = 0; -} -END_OF_FUNCTION(refresh_frame); - /** * Lets u only trigger an action every other second * tmp. counts fps */ -void second(void) { +Uint32 second(Uint32 interval, void *param) +{ action_time = true; fps = frame; frame = 0; + return interval; } -END_OF_FUNCTION(second); short get_elapsed_time(short start_time) { if (start_time <= tick_time) { @@ -124,19 +111,20 @@ void game() { do_init(); Engine *engine = new Engine(); - //SDL_Event event; - //SDL_EnableUNICODE(1); - - while (state != EXIT) { + SDL_Event event; + while (state != EXIT) + { // Handle SDL events - //while (SDL_PollEvent(&event)) { - // switch (event.type) { - // case SDL_QUIT: - // state = EXIT; - // break; - // } - //} + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + state = EXIT; + break; + } + + guiInput->pushInput(event); + } do_input(); engine->draw(); @@ -163,13 +151,8 @@ void do_init() { tick_time = 0; // The SDL way - //SDL_AddTimer(10, refresh_time, NULL); - //SDL_AddTimer(1000, second, NULL); - - // The Allegro way - LOCK_VARIABLE(tick_time); - install_int_ex(refresh_time, MSEC_TO_TIMER(1)); - install_int_ex(second, BPS_TO_TIMER(1)); + SDL_AddTimer(10, refresh_time, NULL); + SDL_AddTimer(1000, second, NULL); // Initialize beings empty(); @@ -193,6 +176,7 @@ void do_exit() { } void do_input() { + /* if (walk_status == 0 && player_node->action != DEAD) { int x = player_node->x; int y = player_node->y; @@ -209,7 +193,7 @@ void do_input() { player_node->direction = NORTH; } else player_node->direction = NORTH; } else if (key[KEY_2_PAD] || key[KEY_DOWN]) { - if(get_walk(x, y + 1) != 0) { + if (get_walk(x, y + 1) != 0) { walk(x, y + 1, SOUTH); walk_status = 1; src_x = x; @@ -298,10 +282,12 @@ void do_input() { WFIFOSET(7); } } + */ } bool handle_key(int unicode, int scancode) { + /* switch (scancode) { case KEY_ESC: state = EXIT; @@ -309,25 +295,23 @@ bool handle_key(int unicode, int scancode) case KEY_F1: save_bitmap("./data/graphic/screenshot.bmp", buffer, NULL); return true; -#ifndef WIN32 case KEY_F12: sound.adjustVolume(1); return true; case KEY_F11: sound.adjustVolume(-1); return true; -#endif /* not WIN32 */ case KEY_F9: setup = Setup::create_setup(); return true; case KEY_F10: // was 3 goes to 0 // was 0 goes to 3 - screen_mode = 3 - screen_mode; - if (set_gfx_mode(screen_mode, 800, 600, 0, 0) != 0) { + //screen_mode = 3 - screen_mode; + //if (set_gfx_mode(screen_mode, 800, 600, 0, 0) != 0) { // less than: to add support for other hardware platforms - error(allegro_error); - } + //error(allegro_error); + //} return true; } @@ -344,6 +328,7 @@ bool handle_key(int unicode, int scancode) return true; } } + */ return false; } @@ -394,15 +379,15 @@ void do_parse() { memset(temp, '\0', RFIFOW(2)-7); memcpy(temp, RFIFOP(8), RFIFOW(2)-8); being = find_node(RFIFOL(4)); - if(being!=NULL) { - if(being->speech!=NULL) { + if (being != NULL) { + if (being->speech != NULL) { free(being->speech); being->speech = NULL; being->speech_time = 0; } being->speech = temp; being->speech_time = SPEECH_TIME; - being->speech_color = makecol(255, 255, 255); + being->speech_color = 0;//makecol(255, 255, 255); chatBox->chat_log(being->speech, BY_OTHER); } break; @@ -419,7 +404,7 @@ void do_parse() { memcpy(player_node->speech, RFIFOP(4), RFIFOW(2)-4); // receive 1 byte less than expected, server might be sending garbage instead of '\0' /-kth5 player_node->speech_time = SPEECH_TIME; - player_node->speech_color = makecol(255, 255, 255); + player_node->speech_color = 0;//makecol(255, 255, 255); if(id==0x008e) { chatBox->chat_log(player_node->speech, BY_PLAYER); @@ -522,17 +507,21 @@ void do_parse() { being->path = calculate_path(get_src_x(RFIFOP(50)), get_src_y(RFIFOP(50)),get_dest_x(RFIFOP(50)), get_dest_y(RFIFOP(50))); - if(being->path!=NULL) { + if (being->path!=NULL) { direction = 0; - if(being->path->next) { - if(being->path->next->x>being->path->x && being->path->next->y>being->path->y)direction = SE; - else if(being->path->next->x<being->path->x && being->path->next->y>being->path->y)direction = SW; - else if(being->path->next->x>being->path->x && being->path->next->y<being->path->y)direction = NE; - else if(being->path->next->x<being->path->x && being->path->next->y<being->path->y)direction = NW; - else if(being->path->next->x>being->path->x)direction = EAST; - else if(being->path->next->x<being->path->x)direction = WEST; - else if(being->path->next->y>being->path->y)direction = SOUTH; - else if(being->path->next->y<being->path->y)direction = NORTH; + if (being->path->next) { + if (being->path->next->x>being->path->x && being->path->next->y>being->path->y) direction = SE; + else if (being->path->next->x < being->path->x && being->path->next->y>being->path->y) direction = SW; + else if (being->path->next->x > being->path->x && being->path->next->y<being->path->y) direction = NE; + else if (being->path->next->x < being->path->x && being->path->next->y<being->path->y) direction = NW; + else if (being->path->next->x > being->path->x) + direction = EAST; + else if (being->path->next->x < being->path->x) + direction = WEST; + else if (being->path->next->y > being->path->y) + direction = SOUTH; + else if (being->path->next->y < being->path->y) + direction = NORTH; } pn = being->path; being->path = being->path->next; @@ -548,7 +537,7 @@ void do_parse() { // Being moving case 0x01da: being = find_node(RFIFOL(2)); - if(being==NULL) { + if (being == NULL) { being = new Being(); being->id = RFIFOL(2); being->job = RFIFOW(14); @@ -556,15 +545,20 @@ void do_parse() { being->y = get_src_y(RFIFOP(50)); add_node(being); } - if(being->action!=WALK) { + if (being->action != WALK) { direction = being->direction; being->action = WALK; - if(get_dest_x(RFIFOP(50))>being->x)direction = EAST; - else if(get_dest_x(RFIFOP(50))<being->x)direction = WEST; - else if(get_dest_y(RFIFOP(50))>being->y)direction = SOUTH; - else if(get_dest_y(RFIFOP(50))<being->y)direction = NORTH; + if (get_dest_x(RFIFOP(50)) > being->x) + direction = EAST; + else if (get_dest_x(RFIFOP(50)) < being->x) + direction = WEST; + else if (get_dest_y(RFIFOP(50)) > being->y) + direction = SOUTH; + else if (get_dest_y(RFIFOP(50)) < being->y) + direction = NORTH; else being->action = STAND; - if(being->action==WALK)being->tick_time = tick_time; + if (being->action == WALK) + being->tick_time = tick_time; being->x = get_dest_x(RFIFOP(50)); being->y = get_dest_y(RFIFOP(50)); being->direction = direction; @@ -593,7 +587,8 @@ void do_parse() { // Warp case 0x0091: memset(map_path, '\0', 480); - append_filename(map_path, "./data/map/", RFIFOP(2), 480); + strcat(map_path, "./data/map/"); + strncat(map_path, RFIFOP(2), 497 - strlen(map_path)); if (load_map(map_path)) { Being *temp; temp = new Being(); @@ -615,7 +610,7 @@ void do_parse() { // Send "map loaded" WFIFOW(0) = net_w_value(0x007d); WFIFOSET(2); - while(out_size>0)flush(); + while (out_size > 0) flush(); } else { error("Could not find map file"); @@ -711,14 +706,14 @@ void do_parse() { memset(being->speech, '\0', 5); if (RFIFOW(22) == 0) { sprintf(being->speech, "miss"); - being->speech_color = makecol(255, 255, 0); + being->speech_color = 0;//makecol(255, 255, 0); } else { sprintf(being->speech, "%i", RFIFOW(22)); if (being->id != player_node->id) { - being->speech_color = makecol(0,0,255); + being->speech_color = 0;//makecol(0,0,255); } else { - being->speech_color = makecol(255,0,0); + being->speech_color = 0;//makecol(255,0,0); } } being->speech_time = SPEECH_TIME; @@ -754,7 +749,7 @@ void do_parse() { break; // Status change case 0x00b1: - switch(RFIFOW(2)) { + switch (RFIFOW(2)) { case 1: char_info->xp = RFIFOL(4); break; @@ -24,15 +24,10 @@ #ifndef _TMW_GAME_H #define _TMW_GAME_H -#ifdef WIN32 - #pragma warning (disable:4312) -#endif - #include "main.h" #include "./gui/gui.h" #include "./gui/skill.h" #include <stdio.h> -#include <allegro.h> #define SPEECH_TIME 80 #define EMOTION_TIME 40 @@ -62,7 +57,6 @@ #define SE 7 extern char map_path[480]; -extern DIALOG skill_dialog[]; extern int fps, frame, current_npc; extern char walk_status; extern unsigned short src_x, src_y, x, y; diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index bc982b6c..5ee5df87 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -27,7 +27,7 @@ #include "../gui/status.h" #include "../main.h" -BITMAP *buffer; +SDL_Surface *screen; char itemCurrenyQ[10] = "0"; int map_x, map_y, camera_x, camera_y; @@ -146,18 +146,10 @@ int get_y_offset(Being *being) { Graphics::Graphics() { - // Create drawing buffer - // SDL probably doesn't need this buffer, it'll buffer for us. - buffer = create_bitmap(SCREEN_W, SCREEN_H); - if (!buffer) { - error("Not enough memory to create buffer"); - } - - setTarget(buffer); + setTarget(SDL_GetVideoSurface()); } Graphics::~Graphics() { - destroy_bitmap(buffer); } void Graphics::drawImageRect( @@ -169,33 +161,33 @@ void Graphics::drawImageRect( Image *center) { // Draw the center area - center->drawPattern(buffer, + center->drawPattern(screen, x + topLeft->getWidth(), y + topLeft->getHeight(), w - topLeft->getWidth() - topRight->getWidth(), h - topLeft->getHeight() - bottomLeft->getHeight()); // Draw the sides - top->drawPattern(buffer, + top->drawPattern(screen, x + topLeft->getWidth(), y, w - topLeft->getWidth() - topRight->getWidth(), top->getHeight()); - bottom->drawPattern(buffer, + bottom->drawPattern(screen, x + bottomLeft->getWidth(), y + h - bottom->getHeight(), w - bottomLeft->getWidth() - bottomRight->getWidth(), bottom->getHeight()); - left->drawPattern(buffer, + left->drawPattern(screen, x, y + topLeft->getHeight(), left->getWidth(), h - topLeft->getHeight() - bottomLeft->getHeight()); - right->drawPattern(buffer, + right->drawPattern(screen, x + w - right->getWidth(), y + topRight->getHeight(), right->getWidth(), h - topRight->getHeight() - bottomRight->getHeight()); // Draw the corners - topLeft->draw(buffer, x, y); - topRight->draw(buffer, x + w - topRight->getWidth(), y); - bottomLeft->draw(buffer, x, y + h - bottomLeft->getHeight()); - bottomRight->draw(buffer, + topLeft->draw(screen, x, y); + topRight->draw(screen, x + w - topRight->getWidth(), y); + bottomLeft->draw(screen, x, y + h - bottomLeft->getHeight()); + bottomRight->draw(screen, x + w - bottomRight->getWidth(), y + h - bottomRight->getHeight()); } @@ -212,8 +204,7 @@ void Graphics::drawImageRect( void Graphics::updateScreen() { - //SDL_Flip(); - blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); + SDL_Flip(screen); } @@ -222,7 +213,7 @@ Engine::Engine() // Initializes GUI chatInput = new TextField(); chatInput->setPosition(chatInput->getBorderSize(), - SCREEN_H - chatInput->getHeight() - chatInput->getBorderSize() -1); + screen->h - chatInput->getHeight() - chatInput->getBorderSize() -1); chatInput->setWidth(592 - 2 * chatInput->getBorderSize()); ChatListener *chatListener = new ChatListener(); @@ -243,7 +234,7 @@ Engine::Engine() // Create dialogs statusWindow = new StatusWindow(); - statusWindow->setPosition(SCREEN_W - statusWindow->getWidth() - 10, 10); + statusWindow->setPosition(screen->w - statusWindow->getWidth() - 10, 10); buyDialog = new BuyDialog(); buyDialog->setVisible(false); @@ -334,11 +325,11 @@ void Engine::draw() unsigned short tile1 = get_tile(i + camera_x, j + camera_y, 1); if (tile0 < tileset->spriteset.size()) { - tileset->spriteset[tile0]->draw(buffer, + tileset->spriteset[tile0]->draw(screen, i * 32 - offset_x, j * 32 - offset_y); } if (tile1 > 0 && tile1 < tileset->spriteset.size()) { - tileset->spriteset[tile1]->draw(buffer, + tileset->spriteset[tile1]->draw(screen, i * 32 - offset_x, j * 32 - offset_y); } @@ -357,11 +348,11 @@ void Engine::draw() int sy = y - camera_y; #ifdef DEBUG - rect(buffer, sx*32, sy*32, sx*32+32, sy*32+32, makecol(0,0,255)); + //rect(screen, sx*32, sy*32, sx*32+32, sy*32+32, makecol(0,0,255)); #endif if ((being->job >= 100) && (being->job <= 110)) { // Draw a NPC - npcset->spriteset[4 * (being->job - 100) + dir]->draw(buffer, + npcset->spriteset[4 * (being->job - 100) + dir]->draw(screen, sx * 32 - 8 - offset_x, sy * 32 - 52 - offset_y); } @@ -375,23 +366,23 @@ void Engine::draw() if (being->action == ATTACK) { int pf = being->frame + being->action + 4 * being->weapon; - playerset->spriteset[4 * pf + dir]->draw(buffer, + playerset->spriteset[4 * pf + dir]->draw(screen, being->text_x - 64, being->text_y - 80); - hairset->spriteset[hf]->draw(buffer, + hairset->spriteset[hf]->draw(screen, being->text_x - 2 + 2 * hairtable[pf][dir][0], being->text_y - 50 + 2 * hairtable[pf][dir][1]); } else { int pf = being->frame + being->action; - playerset->spriteset[4 * pf + dir]->draw(buffer, + playerset->spriteset[4 * pf + dir]->draw(screen, being->text_x - 64, being->text_y - 80); - hairset->spriteset[hf]->draw(buffer, + hairset->spriteset[hf]->draw(screen, being->text_x - 2 + 2 * hairtable[pf][dir][0], being->text_y - 50 + 2 * hairtable[pf][dir][1]); } if (being->emotion != 0) { - emotionset->spriteset[being->emotion - 1]->draw(buffer, + emotionset->spriteset[being->emotion - 1]->draw(screen, sx * 32 - 5 + get_x_offset(being) - offset_x, sy * 32 - 45 + get_y_offset(being) - offset_y); being->emotion_time--; @@ -425,11 +416,11 @@ void Engine::draw() int mf = being->frame + being->action; if (being->action == MONSTER_DEAD) { - monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(buffer, + monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(screen, being->text_x + 30, being->text_y + 40); } else { - monsterset->spriteset[sprnum + 8 * mf]->draw(buffer, + monsterset->spriteset[sprnum + 8 * mf]->draw(screen, being->text_x + 30, being->text_y + 40); } @@ -498,12 +489,12 @@ void Engine::draw() if (tile > 0 && tile < tileset->spriteset.size()) { tileset->spriteset[tile]->draw( - buffer, i * 32 - offset_x, j * 32 - offset_y); + screen, i * 32 - offset_x, j * 32 - offset_y); } #ifdef DEBUG - rect(buffer, i * 32 - offset_x, j * 32 - offset_y, - i * 32 - offset_x + 32, j * 32 - offset_y + 32, - makecol(0,0,0)); + //rect(screen, i * 32 - offset_x, j * 32 - offset_y, + // i * 32 - offset_x + 32, j * 32 - offset_y + 32, + // makecol(0,0,0)); #endif } } @@ -515,16 +506,16 @@ void Engine::draw() if (being->speech != NULL) { guiGraphics->_beginDraw(); - if (being->speech_color == makecol(255, 255, 255)) { - guiGraphics->drawText(being->speech, - being->text_x + 16, being->text_y - 60, - gcn::Graphics::CENTER); - } - else { + //if (being->speech_color == makecol(255, 255, 255)) { + // guiGraphics->drawText(being->speech, + // being->text_x + 16, being->text_y - 60, + // gcn::Graphics::CENTER); + //} + //else { guiGraphics->drawText(being->speech, being->text_x + 60, being->text_y, gcn::Graphics::CENTER); - } + //} guiGraphics->_endDraw(); being->speech_time--; @@ -547,8 +538,8 @@ void Engine::draw() gui->draw(); std::stringstream debugStream; - debugStream << "[" << fps << " fps] " << - (mouse_x / 32 + camera_x) << ", " << (mouse_y / 32 + camera_y); + debugStream << "[" << fps << " fps] ";// << + // (mouse_x / 32 + camera_x) << ", " << (mouse_y / 32 + camera_y); debugInfo->setCaption(debugStream.str()); debugInfo->adjustSize(); } diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index 1887a77b..22388fc6 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -43,12 +43,12 @@ class Graphics; #include "../gui/skill.h" #include "../resources/resourcemanager.h" #include "spriteset.h" -#include <allegro.h> -#include <guichan/allegro.hpp> +#include <SDL.h> +#include <guichan/sdl.hpp> #define TILE_SIZE 32 -extern BITMAP *buffer; +extern SDL_Surface *screen; extern char speech[255]; extern char npc_text[1000]; extern char skill_points[10]; @@ -111,7 +111,7 @@ struct ImageRect { /** * A central point of control for graphics. */ -class Graphics : public gcn::AllegroGraphics { +class Graphics : public gcn::SDLGraphics { public: /** * Constructor. diff --git a/src/graphic/spriteset.h b/src/graphic/spriteset.h index b732d4cf..d7b72a0e 100644 --- a/src/graphic/spriteset.h +++ b/src/graphic/spriteset.h @@ -24,7 +24,6 @@ #ifndef _TMW_SPRITESET_H #define _TMW_SPRITESET_H -#include <allegro.h> #include <string> #include <vector> #include <iostream> diff --git a/src/gui/allegroinput.cpp b/src/gui/allegroinput.cpp deleted file mode 100644 index 8ca077c1..00000000 --- a/src/gui/allegroinput.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#include "allegroinput.h" -#include "../game.h" -#include <allegro.h> - -AllegroInput::AllegroInput() : - gcn::AllegroInput() -{ -} - -void AllegroInput::pollKeyInput() -{ - int unicode, scancode; - - if (keyboard_needs_poll()) - { - poll_keyboard(); - } - - while (keypressed()) - { - unicode = ureadkey(&scancode); - - if (!handle_key(unicode, scancode)) - { - gcn::Key keyObj = convertToKey(scancode, unicode); - mKeyQueue.push(gcn::KeyInput(keyObj, gcn::KeyInput::PRESS)); - mPressedKeys[scancode] = keyObj; - } - } - - // Check for released keys - std::map<int, gcn::Key>::iterator iter, tempIter; - for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); ) - { - if (!key[iter->first]) - { - mKeyQueue.push(gcn::KeyInput(iter->second, gcn::KeyInput::RELEASE)); - tempIter = iter; - iter++; - mPressedKeys.erase(tempIter); - } - else - { - iter++; - } - } -} diff --git a/src/gui/allegroinput.h b/src/gui/allegroinput.h deleted file mode 100644 index ab1a1301..00000000 --- a/src/gui/allegroinput.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The Mana World - * Copyright 2004 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * The Mana World is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ - */ - -#ifndef _TMW_ALLEGRO_INPUT_H__ -#define _TMW_ALLEGRO_INPUT_H__ - -#include <guichan.hpp> -#include <guichan/allegro.hpp> - -/** - * Allegro input handler that gives us a chance to handle some shortkeys. - * - * \ingroup GUI - */ -class AllegroInput : public gcn::AllegroInput -{ - public: - /** - * Constructor. - */ - AllegroInput(); - - /** - * Polls key input. - */ - void pollKeyInput(); -}; - -#endif diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index ac644f3a..3e509727 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -222,7 +222,8 @@ void CharSelectDialog::serverCharSelect() } char_ID = RFIFOL(2); memset(map_path, '\0', 480); - append_filename(map_path, "./data/map/", RFIFOP(6), 480); + strcat(map_path, "./data/map/"); + strncat(map_path, RFIFOP(6), 479 - strlen(map_path)); map_address = RFIFOL(22); map_port = RFIFOW(26); state = GAME; @@ -430,20 +431,32 @@ void charSelect() state = CHAR_SELECT; - while (!key[KEY_ESC] && !key[KEY_ENTER] && state == CHAR_SELECT) + while (/*!key[KEY_ESC] && !key[KEY_ENTER] &&*/ state == CHAR_SELECT) { + // Handle SDL events + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + state = EXIT; + break; + } + + guiInput->pushInput(event); + } + if (n_character > 0) { sel->setPlayerInfo(char_info); } // Draw background - login_wallpaper->draw(buffer, 0, 0); + login_wallpaper->draw(screen, 0, 0); gui->logic(); gui->draw(); // Draw to screen - blit(buffer, screen, 0, 0, 0, 0, 800, 600); + guiGraphics->updateScreen(); } delete sel; diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 4178a8e5..5b3992f1 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -116,11 +116,24 @@ void char_server() { state = LOGIN; showServerList = 1; - while (showServerList) { - login_wallpaper->draw(buffer, 0, 0); + while (showServerList) + { + // Handle SDL events + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + state = EXIT; + break; + } + + guiInput->pushInput(event); + } + + login_wallpaper->draw(screen, 0, 0); gui->logic(); gui->draw(); - blit(buffer, screen, 0, 0, 0, 0, 800, 600); + guiGraphics->updateScreen(); } delete dialog; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 4d1f23ce..8c08b545 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -95,11 +95,11 @@ void ChatBox::draw(gcn::Graphics *graphics) graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); getAbsolutePosition(x, y); - set_trans_blender(0, 0, 0, 100); - drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); - rectfill(buffer, x, y, x + getWidth(), y + getHeight(), - makecol(255, 255, 255)); - drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); + //set_trans_blender(0, 0, 0, 100); + //drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); + //rectfill(buffer, x, y, x + getWidth(), y + getHeight(), + // makecol(255, 255, 255)); + //drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); for (iter = chatlog.begin(); iter != chatlog.end(); iter++) { line = *iter; diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index 25ae93b4..5eced992 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -57,6 +57,6 @@ void CheckBox::drawBox(gcn::Graphics* graphics) { x += 2; y += 2; if (box != NULL) { - box->draw(buffer, x, y); + box->draw(screen, x, y); } } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index dd4216e5..c9742b05 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -22,13 +22,13 @@ */ #include "gui.h" -#include "allegroinput.h" #include "window.h" #include "windowcontainer.h" // Guichan stuff Gui *gui; -gcn::AllegroGraphics *guiGraphics; // Graphics driver +Graphics *guiGraphics; // Graphics driver +gcn::SDLInput *guiInput; // GUI input WindowContainer *guiTop; // The top container Gui::Gui(Graphics *graphics) @@ -37,15 +37,15 @@ Gui::Gui(Graphics *graphics) guiGraphics = graphics; // Set input - guiInput = new AllegroInput(); + guiInput = new gcn::SDLInput(); // Set image loader - imageLoader = new gcn::AllegroImageLoader(); + imageLoader = new gcn::SDLImageLoader(); gcn::Image::setImageLoader(imageLoader); // Initialize top GUI widget guiTop = new WindowContainer(); - guiTop->setDimension(gcn::Rectangle(0, 0, SCREEN_W, SCREEN_H)); + guiTop->setDimension(gcn::Rectangle(0, 0, screen->w, screen->h)); guiTop->setOpaque(false); Window::setWindowContainer(guiTop); @@ -67,14 +67,11 @@ Gui::~Gui() delete guiTop; delete imageLoader; delete guiInput; - delete guiGraphics; delete focusHandler; } void Gui::logic() { - guiInput->_pollInput(); - while (!guiInput->isMouseQueueEmpty()) { gcn::MouseInput mi = guiInput->dequeueMouseInput(); @@ -157,7 +154,7 @@ void Gui::draw() guiGraphics->popClipArea(); // Draw the mouse - draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); + //draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); guiGraphics->_endDraw(); } diff --git a/src/gui/gui.h b/src/gui/gui.h index 3d42087b..cd37ae63 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -25,8 +25,7 @@ #define _TMW_GUI #include <guichan.hpp> -#include <guichan/allegro.hpp> -#include <allegro.h> +#include <guichan/sdl.hpp> #include <string.h> #include "windowcontainer.h" #include "../graphic/graphic.h" @@ -75,19 +74,19 @@ class Gui void draw(); private: - gcn::Gui* gui; /**< The GUI system */ - gcn::Input* guiInput; /**< Input driver */ - gcn::ImageLoader* imageLoader; /**< For loading images */ - gcn::ImageFont* guiFont; /**< The global GUI font */ + gcn::Gui *gui; /**< The GUI system */ + gcn::ImageLoader *imageLoader; /**< For loading images */ + gcn::ImageFont *guiFont; /**< The global GUI font */ bool topHasMouse; - gcn::FocusHandler* focusHandler; + gcn::FocusHandler *focusHandler; }; -extern Gui* gui; -extern WindowContainer* guiTop; // The top container -extern gcn::AllegroGraphics* guiGraphics; // Graphics driver +extern Gui *gui; +extern WindowContainer *guiTop; // The top container +extern Graphics *guiGraphics; // Graphics driver +extern gcn::SDLInput *guiInput; // GUI input /** Initialize gui system */ void init_gui(Graphics *graphics); diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index dcaedc6f..c7f7aec8 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -55,12 +55,10 @@ void InventoryWindow::draw(gcn::Graphics *graphics) // Draw window graphics Window::draw(graphics); - BITMAP *target = ((Graphics*)graphics)->getTarget(); - for (int i = 0; i < INVENTORY_SIZE; i++) { if (items[i].quantity > 0) { if (items[i].id >= 501 && items[i].id <= 511) { - itemset->spriteset[items[i].id - 501]->draw(target, + itemset->spriteset[items[i].id - 501]->draw(screen, x + 24 * i, y + 26); } diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 13a8c2f3..b5104204 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -130,14 +130,27 @@ void LoginDialog::action(const std::string& eventId) void login() { LoginDialog *dialog = new LoginDialog(); - while (state == LOGIN) { - login_wallpaper->draw(buffer, 0, 0); + while (state == LOGIN) + { + // Handle SDL events + SDL_Event event; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + state = EXIT; + break; + } + + guiInput->pushInput(event); + } + + login_wallpaper->draw(screen, 0, 0); gui->logic(); gui->draw(); - blit(buffer, screen, 0, 0, 0, 0, 800, 600); - if (key[KEY_ESC]) { - state = EXIT; - } + guiGraphics->updateScreen(); + //if (key[KEY_ESC]) { + // state = EXIT; + //} } delete dialog; diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index 9efb9bad..70715729 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -58,12 +58,12 @@ void PlayerBox::draw(gcn::Graphics *graphics) getAbsolutePosition(x, y); // Draw character - playerset->spriteset[0]->draw(buffer, x - 25, y - 25); + playerset->spriteset[0]->draw(screen, x - 25, y - 25); // Draw his hair int hf = hairColor + 40 * (hairStyle); if (hf >= 0 && hf < (int)hairset->spriteset.size()) { - hairset->spriteset[hf]->draw(buffer, x + 37, y + 5); + hairset->spriteset[hf]->draw(screen, x + 37, y + 5); } } } diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 55fadd60..fdaefa73 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -40,7 +40,7 @@ void ProgressBar::draw(gcn::Graphics *graphics) { int absx, absy; getAbsolutePosition(absx, absy); - + /* // outer bar int MyColor = makecol(abs(Red-70), abs(Green-70), abs(Blue-70)); hline(buffer, absx+X+7, absy+Y, absx+X+Width, MyColor); @@ -75,7 +75,7 @@ void ProgressBar::draw(gcn::Graphics *graphics) line(buffer, absx+X+7, absy+Y+1, absx+X+2, absy+Y+7-1, MyColor); //rectfill(buffer, absx+7, absy+7, absx+39, absy+9, MyColor); - + */ /* if (progress != 0) { masked_blit(gui_skin.bar.bg.grid[3], buffer, diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index 4e90cbb1..ef84bbc2 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -57,6 +57,6 @@ void RadioButton::drawBox(gcn::Graphics* graphics) x += 2; y += 2; if (box != NULL) { - box->draw(buffer, x, y); + box->draw(screen, x, y); } } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index e9675ab3..bfb619c2 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -34,6 +34,7 @@ #include "radiobutton.h" #include "ok_dialog.h" #include "../main.h" +#include <SDL.h> #ifndef WIN32 extern Sound sound; @@ -141,15 +142,17 @@ void Setup::action(const std::string& eventId) if (fsCheckBox->isMarked() && config.getValue("screen", 0) == 2) { config.setValue("screen", 1); - set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, - modes[sel].height, modes[sel].width, 0, 0); + SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); + //set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, + // modes[sel].height, modes[sel].width, 0, 0); } else if (!fsCheckBox->isMarked() && config.getValue("screen", 0) == 1) { config.setValue("screen", 2); - set_gfx_mode(GFX_AUTODETECT_WINDOWED, - modes[sel].height, modes[sel].width, 0, 0); + SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); + //set_gfx_mode(GFX_AUTODETECT_WINDOWED, + // modes[sel].height, modes[sel].width, 0, 0); } // Sound settings diff --git a/src/gui/setup.h b/src/gui/setup.h index a1b00ea1..20540aa2 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -27,7 +27,6 @@ #include "gui.h" #include "../graphic/graphic.h" #include "../sound/sound.h" -#include <allegro.h> /** * The list model for mode list. diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index ca6d547c..2d07d661 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -80,15 +80,15 @@ void Slider::draw(gcn::Graphics *graphics) y += (h - hStart->getHeight()) / 2; - hStart->draw(buffer, x, y); + hStart->draw(screen, x, y); w -= hStart->getWidth() + hEnd->getWidth(); x += hStart->getWidth(); - hMid->drawPattern(buffer, x, y, w, hMid->getHeight()); + hMid->drawPattern(screen, x, y, w, hMid->getHeight()); x += w; - hEnd->draw(buffer, x, y); + hEnd->draw(screen, x, y); drawMarker(graphics); } @@ -102,5 +102,5 @@ void Slider::drawMarker(gcn::Graphics *graphics) x += mMarkerPosition; y += (h - hGrip->getHeight()) / 2; - hGrip->draw(buffer, x, y); + hGrip->draw(screen, x, y); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 34ced06a..ca788883 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -106,8 +106,6 @@ void Window::draw(gcn::Graphics* graphics) getWidth(), getHeight() - titlebarHeight + 1)); // Skinned dialog render - Graphics *gfx = (Graphics*)graphics; - BITMAP *screen = gfx->getTarget(); int x, y; getAbsolutePosition(x, y); diff --git a/src/main.cpp b/src/main.cpp index c3dd3287..c1d64426 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,8 @@ #include "./graphic/graphic.h" #include "resources/resourcemanager.h" #include <iostream> +#include <guichan.hpp> +#include <SDL.h> #ifdef __USE_UNIX98 #include <sys/stat.h> @@ -60,7 +62,6 @@ unsigned char direction; unsigned char stretch_mode, screen_mode; char *dir; -// new sound-engine /- kth5 #ifndef WIN32 Sound sound; #endif /* not WIN32 */ @@ -99,19 +100,15 @@ void request_exit() { */ void init_engine() { // Initialize SDL - //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { - // std::cerr << "Could not initialize SDL: " << - // SDL_GetError() << std::endl; - // exit(1); - //} - //atexit(SDL_Quit); - - // Initialize Allegro - allegro_init(); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { + std::cerr << "Could not initialize SDL: " << + SDL_GetError() << std::endl; + exit(1); + } + atexit(SDL_Quit); + SDL_EnableUNICODE(1); init_log(); - // SDL will send an event for this - set_close_button_callback(request_exit); dir = new char[400]; strcpy(dir, ""); @@ -190,40 +187,24 @@ void init_engine() { config.init(dir); #ifdef MACOSX - set_color_depth(32); + //set_color_depth(32); #else - set_color_depth(16); + //set_color_depth(16); #endif - //SDL_WM_SetCaption("The Mana World", NULL); - set_window_title("The Mana World"); + SDL_WM_SetCaption("The Mana World", NULL); - //screen = SDL_SetVideoMode(800, 600, 16, SDL_SWSURFACE | SDL_ANYFORMAT); - //if (screen == NULL) { - // std::cerr << "Couldn't set 800x600x16 video mode: " << - // SDL_GetError() << std::endl; - // exit(1); - //} - - if (set_gfx_mode((unsigned char)config.getValue("screen", 0), 800, 600, - 0, 0)) { - error(allegro_error); - } - - // In SDL these three are all done in the SDL_Init call - if (install_keyboard()) { - error("Unable to install keyboard"); - } - - if (install_timer()) { - error("Unable to install timer"); + screen = SDL_SetVideoMode(800, 600, 16, SDL_SWSURFACE | SDL_ANYFORMAT); + if (screen == NULL) { + std::cerr << "Couldn't set 800x600x16 video mode: " << + SDL_GetError() << std::endl; + exit(1); } - if (install_mouse() == -1) { - error("Unable to install mouse"); - } + //if (set_gfx_mode((unsigned char)config.getValue("screen", 0), 800, 600, + // 0, 0)) { + //} - // Buffer creation shouldn't be necessary with SDL // Create the graphics context graphics = new Graphics(); @@ -253,9 +234,7 @@ void init_engine() { // initialize sound-engine and start playing intro-theme /-kth5 try { if (config.getValue("sound", 0) == 1) { - //SDL_InitSubSystem(SDL_INIT_AUDIO); - SDL_Init(SDL_INIT_AUDIO); - atexit(SDL_Quit); + SDL_InitSubSystem(SDL_INIT_AUDIO); sound.init(32, 20); } sound.setVolume(64); @@ -280,14 +259,25 @@ void exit_engine() { delete dir; gui_exit(); ResourceManager::deleteInstance(); - allegro_exit(); } /** Main */ int main() { init_engine(); - while (state != EXIT) { + SDL_Event event; + + while (state != EXIT) + { + // Handle SDL events + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + state = EXIT; + break; + } + } + switch (state) { case LOGIN: status("LOGIN"); @@ -317,11 +307,10 @@ int main() { break; case ERROR: // Redraw GUI - login_wallpaper->draw(buffer, 0, 0); - guiGraphics->setTarget(buffer); + login_wallpaper->draw(screen, 0, 0); gui->logic(); gui->draw(); - blit(buffer, screen, 0, 0, 0, 0, 800, 600); + guiGraphics->updateScreen(); break; default: state = EXIT; @@ -332,4 +321,3 @@ int main() { exit_engine(); return 0; } -END_OF_MAIN(); @@ -24,9 +24,6 @@ #ifndef _TMW_MAIN_H #define _TMW_MAIN_H -#include <guichan.hpp> -#include <guichan/allegro.hpp> - #include "configuration.h" #include "gui/login.h" #include "gui/gui.h" @@ -35,10 +32,6 @@ #include "log.h" #include "game.h" #include "net/protocol.h" -#include <allegro.h> -#ifdef WIN32 -#include <winalleg.h> -#endif #include <stdio.h> #define CORE_VERSION "0.0.8" diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 4e6b5bcb..f3af2790 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -24,8 +24,9 @@ #include "../log.h" #include "image.h" #include <iostream> +#include <SDL_image.h> -Image::Image(BITMAP *image): +Image::Image(SDL_Surface *image): image(image) { } @@ -41,13 +42,12 @@ Image* Image::load(const std::string &filePath) std::cout << "Image::load(" << filePath << ")\n"; #endif // Attempt to use SDL_Image to load the file. - //image = IMG_Load(filePath.c_str()); - BITMAP *image = load_bitmap(filePath.c_str(), NULL); + SDL_Surface *image = IMG_Load(filePath.c_str()); // Check if the file was opened and return the appropriate value. if (!image) { - //log("Error", "Image load failed : %s", IMG_GetError()); - log("Error", "Image load failed : %s", filePath.c_str()); + log("Error", "Image load failed : %s", IMG_GetError()); + //log("Error", "Image load failed : %s", filePath.c_str()); return NULL; } @@ -58,14 +58,12 @@ void Image::unload() { // Free the image surface. if (image != NULL) { - //SDL_FreeSurface(image); - destroy_bitmap(image); + SDL_FreeSurface(image); image = NULL; loaded = false; } } - int Image::getWidth() const { if (image != NULL) { @@ -82,36 +80,34 @@ int Image::getHeight() const return 0; } -Image* Image::getSubImage(int x, int y, int width, int height) +Image *Image::getSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image return new SubImage(this, image, x, y, width, height); } -Image* Image::getScaledInstance(int width, int height) +Image *Image::getScaledInstance(int width, int height) { return new ScaledImage(this, image, width, height); } -bool Image::draw(BITMAP *screen, int x, int y) +bool Image::draw(SDL_Surface *screen, int x, int y) { // Check that preconditions for blitting are met. if (screen == NULL || image == NULL) return false; - //SDL_Rect dst_rect; - //dst_rect.x = x + offset_x; - //dst_rect.y = y + offset_y; - //SDL_BlitSurface(src, NULL, dst, &dst_rect); - // Draw the image onto the screen. - draw_sprite(screen, image, x, y); - //if (SDL_BlitSurface(image, NULL, screen, &screenRect) < 0) { - // return false; - //} + SDL_Rect dstRect; + dstRect.x = x; + dstRect.y = y; + + if (SDL_BlitSurface(image, NULL, screen, &dstRect) < 0) { + return false; + } return true; } -void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h) +void Image::drawPattern(SDL_Surface *screen, int x, int y, int w, int h) { int iw = getWidth(); // Width of image int ih = getHeight(); // Height of image @@ -133,58 +129,87 @@ void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h) //============================================================================ -SubImage::SubImage(Image *parent, BITMAP *image, +SubImage::SubImage(Image *parent, SDL_Surface *image, int x, int y, int width, int height): - Image(create_sub_bitmap(image, x, y, width, height)), + Image(image), parent(parent) { - //this->image = create_sub_bitmap(image, x, y, width, height); parent->incRef(); - // Set up the clipping rectangle. - //clipRect.x = x; - //clipRect.y = y; - //clipRect.w = width; - //clipRect.h = height; + + // Set up the rectangle. + rect.x = x; + rect.y = y; + rect.w = width; + rect.h = height; } SubImage::~SubImage() { - if (image) { - destroy_bitmap(image); - image = NULL; - } + image = NULL; // TODO: Enable when no longer a problem //parent->decRef(); } -bool SubImage::draw(BITMAP *screen, int x, int y) +int SubImage::getWidth() const +{ + return rect.w; +} + +int SubImage::getHeight() const +{ + return rect.h; +} + +Image *SubImage::getSubImage(int x, int y, int w, int h) +{ + return NULL; +} + +bool SubImage::draw(SDL_Surface *screen, int x, int y) { // Check that drawing preconditions are satisfied. if (screen == NULL || image == NULL) return false; - // Draw the image onto the screen. - draw_sprite(screen, image, x, y); - //if (SDL_BlitSurface(image, &clipRect, screen, &screenRect) < 0) { - // return false; - //} + SDL_Rect dstRect; + dstRect.x = x; + dstRect.y = y; + + // Draw subimage part to given location + if (SDL_BlitSurface(image, &rect, screen, &dstRect) < 0) { + return false; + } return true; } //============================================================================ -ScaledImage::ScaledImage(Image *parent, BITMAP *bmp, int width, int height): - Image(create_bitmap(width, height)) +ScaledImage::ScaledImage( + Image *parent, SDL_Surface *bmp, int width, int height): + Image(SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + 0xff000000, + 0x00ff0000, + 0x0000ff00, + 0x000000ff +#else + 0x000000ff, + 0x0000ff00, + 0x00ff0000, + 0xff000000 +#endif + )) { if (image) { - stretch_blit(bmp, image, 0, 0, bmp->w, bmp->h, 0, 0, width, height); + // Somehow stretch the image using SDL_gfx + //stretch_blit(bmp, image, 0, 0, bmp->w, bmp->h, 0, 0, width, height); } } ScaledImage::~ScaledImage() { if (image) { - destroy_bitmap(image); + SDL_FreeSurface(image); image = NULL; } } diff --git a/src/resources/image.h b/src/resources/image.h index 0452cd4a..d5c98c5d 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -25,8 +25,7 @@ #define _TMW_IMAGE_H #include "resource.h" -//#include <SDL/SDL.h> -#include <allegro.h> +#include <SDL.h> // Forward declarations class SubImage; @@ -41,7 +40,7 @@ class Image : public Resource /** * Constructor. */ - Image(BITMAP *image); + Image(SDL_Surface *image); /** * Destructor. @@ -89,17 +88,17 @@ class Image : public Resource * @return <code>true</code> if the image was blitted properly * <code>false</code> otherwise. */ - virtual bool draw(BITMAP *screen, int x, int y); + virtual bool draw(SDL_Surface *screen, int x, int y); /** * Does a pattern fill on the given area. */ - virtual void drawPattern(BITMAP *screen, int x, int y, int w, int h); + virtual void drawPattern( + SDL_Surface *screen, int x, int y, int w, int h); protected: - //SDL_Rect screenRect; - //SDL_Surface *image; - BITMAP *image; + SDL_Surface *image; + //BITMAP *image; }; /** @@ -112,7 +111,7 @@ class SubImage : public Image * Constructor. */ //SubImage(SDL_Surface *timage, int x, int y, int width, int height); - SubImage(Image *parent, BITMAP *image, + SubImage(Image *parent, SDL_Surface *image, int x, int y, int width, int height); /** @@ -121,20 +120,33 @@ class SubImage : public Image ~SubImage(); /** + * Returns the width of the image. + */ + int getWidth() const; + + /** + * Returns the height of the image. + */ + int getHeight() const; + + /** + * Creates a new image with the desired clipping rectangle. + * @return <code>NULL</code> if creation failed and a valid + * object otherwise. + */ + Image* getSubImage(int x, int y, int width, int height); + + /** * Draws the clipped image onto the screen. * @return <code>true</code> if drawing was succesful * <code>false</code> otherwise. */ - bool draw(BITMAP *screen, int x, int y); + bool draw(SDL_Surface *screen, int x, int y); private: Image *parent; + SDL_Rect rect; //BITMAP *image; - //SDL_Rect clipRect; - //SDL_Rect screenRect; - //SDL_Surface *image; - //SDL_Surface *screen; - //unsigned int referenceCount; }; /** @@ -146,7 +158,7 @@ class ScaledImage : public Image /** * Constructor. */ - ScaledImage(Image *parent, BITMAP *image, int width, int height); + ScaledImage(Image *parent, SDL_Surface *image, int width, int height); /** * Destructor. |