added support for colour cursors

This commit is contained in:
Dave White 2004-03-31 20:47:45 +00:00
parent efa115b0a9
commit 7aecbbb498
13 changed files with 141 additions and 9 deletions

View file

@ -235,7 +235,8 @@ skip_button="Skip"
turn_dialog_button="Turn Dialog"
turn_bell_button="Turn Bell"
show_side_colours="Show Team Colours"
show_side_colours="Show Team Colors"
show_colour_cursors="Show Color Cursors"
lawful=Lawful
neutral=Neutral

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 200 B

BIN
images/cursors/attack.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

BIN
images/cursors/move.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

BIN
images/cursors/normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B

BIN
images/cursors/wait.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

View file

@ -6,6 +6,7 @@
#include "SDL.h"
#include <iostream>
#include <vector>
namespace
@ -58,6 +59,9 @@ const std::string images[cursor::NUM_CURSORS] = { "normal.png", "wait.png", "mov
cursor::CURSOR_TYPE current_cursor = cursor::NUM_CURSORS;
int cursor_x = -1, cursor_y = -1;
SDL_Surface* cursor_buf = NULL;
SDL_Cursor* get_cursor(cursor::CURSOR_TYPE type)
{
if(cache[type] == NULL) {
@ -77,6 +81,11 @@ void clear_cache()
cache[n] = NULL;
}
}
if(cursor_buf != NULL) {
SDL_FreeSurface(cursor_buf);
cursor_buf = NULL;
}
}
}
@ -86,11 +95,18 @@ namespace cursor
manager::manager()
{
use_colour(preferences::use_colour_cursors());
}
manager::~manager()
{
clear_cache();
SDL_ShowCursor(SDL_ENABLE);
}
void use_colour(bool value)
{
SDL_ShowCursor(value ? SDL_DISABLE : SDL_ENABLE);
}
void set(CURSOR_TYPE type)
@ -117,4 +133,67 @@ setter::~setter()
set(old_);
}
void draw(SDL_Surface* screen)
{
if(preferences::use_colour_cursors() == false) {
return;
}
if(current_cursor == NUM_CURSORS) {
return;
}
int new_cursor_x, new_cursor_y;
SDL_GetMouseState(&new_cursor_x,&new_cursor_y);
const bool must_update = new_cursor_x != cursor_x || new_cursor_y != cursor_y;
cursor_x = new_cursor_x;
cursor_y = new_cursor_y;
const scoped_sdl_surface surf(image::get_image("cursors/" + images[current_cursor],image::UNSCALED));
if(surf == NULL) {
return;
}
if(cursor_buf != NULL && (cursor_buf->w != surf->w || cursor_buf->h != surf->h)) {
SDL_FreeSurface(cursor_buf);
cursor_buf = NULL;
}
if(cursor_buf == NULL) {
cursor_buf = SDL_CreateRGBSurface(SDL_SWSURFACE,surf->w,surf->h,surf->format->BitsPerPixel,
surf->format->Rmask,surf->format->Gmask,surf->format->Bmask,surf->format->Amask);
if(cursor_buf == NULL) {
std::cerr << "Could not allocate surface for mouse cursor\n";
return;
}
}
//save the screen area where the cursor is being drawn onto the back buffer
SDL_Rect area = {cursor_x,cursor_y,surf->w,surf->h};
SDL_BlitSurface(screen,&area,cursor_buf,NULL);
//blit the surface
SDL_BlitSurface(surf,NULL,screen,&area);
if(must_update) {
update_rect(area);
}
}
void undraw(SDL_Surface* screen)
{
if(preferences::use_colour_cursors() == false) {
return;
}
if(cursor_buf == NULL) {
return;
}
SDL_Rect area = {cursor_x,cursor_y,cursor_buf->w,cursor_buf->h};
SDL_BlitSurface(cursor_buf,NULL,screen,&area);
update_rect(area);
}
}

View file

@ -1,6 +1,8 @@
#ifndef CURSOR_HPP_INCLUDED
#define CURSOR_HPP_INCLUDED
#include "SDL.h"
namespace cursor
{
@ -12,8 +14,13 @@ struct manager
enum CURSOR_TYPE { NORMAL, WAIT, MOVE, ATTACK, NUM_CURSORS };
void use_colour(bool value);
void set(CURSOR_TYPE type);
void draw(SDL_Surface* screen);
void undraw(SDL_Surface* screen);
struct setter
{
setter(CURSOR_TYPE type);

View file

@ -211,7 +211,6 @@ int play_game(int argc, char** argv)
const preferences::manager prefs_manager;
const image::manager image_manager;
const events::event_context main_event_context;
const cursor::manager cursor_manager;
std::cerr << "initialized managers\n";
@ -344,6 +343,8 @@ int play_game(int argc, char** argv)
video.make_fake();
}
const cursor::manager cursor_manager;
std::cerr << "initialized gui\n";
//load in the game's configuration files

View file

@ -11,6 +11,7 @@
See the COPYING file for more details.
*/
#include "cursor.hpp"
#include "events.hpp"
#include "filesystem.hpp"
#include "font.hpp"
@ -36,6 +37,7 @@ config prefs;
display* disp = NULL;
bool muted_ = false;
bool colour_cursors = true;
}
@ -47,6 +49,8 @@ manager::manager()
set_music_volume(music_volume());
set_sound_volume(sound_volume());
set_colour_cursors(prefs["colour_cursors"] != "no");
}
manager::~manager()
@ -396,7 +400,15 @@ void set_theme(const std::string& theme)
bool use_colour_cursors()
{
return false;
return colour_cursors;
}
void set_colour_cursors(bool value)
{
prefs["colour_cursors"] = value ? "yes" : "no";
colour_cursors = value;
cursor::use_colour(value);
}
void show_preferences_dialog(display& disp)
@ -407,7 +419,7 @@ void show_preferences_dialog(display& disp)
log_scope("show_preferences_dialog");
const int width = 600;
const int height = 400;
const int height = 440;
const int xpos = disp.x()/2 - width/2;
const int ypos = disp.y()/2 - height/2;
@ -506,7 +518,7 @@ void show_preferences_dialog(display& disp)
gui::button resolution_button(disp,string_table["video_mode"]);
resolution_button.set_x(slider_left);
resolution_button.set_y(sound_pos + 80 + 150);
resolution_button.set_y(sound_pos + 80 + 200);
gui::button turn_dialog_button(disp,string_table["turn_dialog_button"],
gui::button::TYPE_CHECK);
@ -526,9 +538,15 @@ void show_preferences_dialog(display& disp)
side_colours_button.set_x(slider_left + fullscreen_button.width() + 100);
side_colours_button.set_y(sound_pos + 80 + 100);
gui::button colour_cursors_button(disp,string_table["show_colour_cursors"],
gui::button::TYPE_CHECK);
colour_cursors_button.set_check(use_colour_cursors());
colour_cursors_button.set_x(slider_left + fullscreen_button.width() + 100);
colour_cursors_button.set_y(sound_pos + 80 + 150);
gui::button hotkeys_button (disp,string_table["hotkeys_button"]);
hotkeys_button.set_x(slider_left + fullscreen_button.width() + 100);
hotkeys_button.set_y(sound_pos + 80 + 150);
hotkeys_button.set_y(sound_pos + 80 + 200);
bool redraw_all = true;
@ -560,6 +578,7 @@ void show_preferences_dialog(display& disp)
turn_dialog_button.draw();
turn_bell_button.draw();
side_colours_button.draw();
colour_cursors_button.draw();
hotkeys_button.draw();
font::draw_text(&disp,clip_rect,14,font::NORMAL_COLOUR,music_label,
@ -610,11 +629,15 @@ void show_preferences_dialog(display& disp)
set_show_side_colours(side_colours_button.checked());
}
if(hotkeys_button.process (mousex, mousey, left_button)) {
if(hotkeys_button.process(mousex,mousey,left_button)) {
show_hotkeys_dialog (disp);
break;
}
if(colour_cursors_button.process(mousex,mousey,left_button)) {
set_colour_cursors(colour_cursors_button.checked());
}
music_slider.process();
sound_slider.process();
scroll_slider.process();
@ -625,7 +648,7 @@ void show_preferences_dialog(display& disp)
disp.update_display();
SDL_Delay(50);
SDL_Delay(20);
events::pump();
}
}

View file

@ -83,6 +83,7 @@ namespace preferences {
bool ask_delete_saves();
bool use_colour_cursors();
void set_colour_cursors(bool value);
std::string client_type();

View file

@ -762,15 +762,25 @@ void fade_logo(display& screen, int xpos, int ypos)
std::cerr << "fading logo in....\n";
std::cerr << "logo size: " << logo->w << "," << logo->h << "\n";
for(int x = 0; x != logo->w; ++x) {
SDL_Rect srcrect = {x,0,1,logo->h};
SDL_Rect dstrect = {xpos+x,ypos,1,logo->h};
std::cerr << "iteration " << x << " blitting " << srcrect.x << "," << srcrect.y << "," << srcrect.w << "," << srcrect.h
<< " -> " << dstrect.x << "," << dstrect.y << "," << dstrect.w << "," << dstrect.h << "\n";
SDL_BlitSurface(logo,&srcrect,fb,&dstrect);
std::cerr << "updating rect " << dstrect.x << "," << dstrect.y << "," << dstrect.w << "," << dstrect.h << "\n";
update_rect(dstrect);
if(!faded_in && (x%5) == 0) {
std::cerr << "checking keys...\n";
const bool new_button = key[SDLK_ESCAPE] || key[SDLK_SPACE];
if(new_button && !last_button) {
faded_in = true;
@ -778,11 +788,17 @@ void fade_logo(display& screen, int xpos, int ypos)
last_button = new_button;
std::cerr << "updating display...\n";
screen.update_display();
std::cerr << "delaying...\n";
SDL_Delay(10);
std::cerr << "pumping events...\n";
events::pump();
}
std::cerr << "end iteration...\n";
}
std::cerr << "logo faded in\n";
@ -885,7 +901,7 @@ TITLE_RESULT show_title(display& screen)
events::pump();
SDL_Delay(50);
SDL_Delay(20);
}
return QUIT_GAME;

View file

@ -14,6 +14,7 @@
#include <iostream>
#include <vector>
#include "cursor.hpp"
#include "image.hpp"
#include "mouse.hpp"
#include "preferences.hpp"
@ -276,6 +277,7 @@ void CVideo::flip()
if(fake_screen)
return;
cursor::draw(frameBuffer);
if(update_all) {
::SDL_Flip(frameBuffer);
} else if(update_rects.empty() == false) {
@ -283,6 +285,8 @@ void CVideo::flip()
}
clear_updates();
cursor::undraw(frameBuffer);
}
void CVideo::lock()