예제 #1
0
파일: skills.c 프로젝트: liwcezar/atrinik
/** @copydoc widgetdata::draw_func */
static void widget_draw(widgetdata *widget)
{
    SDL_Rect box;
    size_t i;

    /* Create the skill list. */
    if (!list_skills) {
        list_skills = list_create(5, 4, 8);
        list_skills->post_column_func = list_post_column;
        list_skills->row_color_func = list_row_color;
        list_skills->row_selected_func = NULL;
        list_skills->row_highlight_func = NULL;
        list_skills->surface = widget->surface;
        list_skills->row_height_adjust = INVENTORY_ICON_SIZE;
        list_set_font(list_skills, NULL);
        list_scrollbar_enable(list_skills);
        list_set_column(list_skills, 0, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 1, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 2, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 3, INVENTORY_ICON_SIZE, 0, NULL, -1);
        skill_list_reload();

        for (i = 0; i < BUTTON_NUM; i++) {
            button_create(&buttons[i]);
            buttons[i].texture = texture_get(TEXTURE_TYPE_CLIENT, "button_round");
            buttons[i].texture_pressed = texture_get(TEXTURE_TYPE_CLIENT, "button_round_down");
            buttons[i].texture_over = texture_get(TEXTURE_TYPE_CLIENT, "button_round_over");
        }
    }

    if (widget->redraw) {
        box.h = 0;
        box.w = widget->w;
        text_show(widget->surface, FONT_SERIF12, "Skills", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);
        list_set_parent(list_skills, widget->x, widget->y);
        list_show(list_skills, 10, 2);

        for (i = 0; i < BUTTON_NUM; i++) {
            buttons[i].surface = widget->surface;
            button_set_parent(&buttons[i], widget->x, widget->y);
        }

        buttons[BUTTON_CLOSE].x = widget->w - texture_surface(buttons[BUTTON_CLOSE].texture)->w - 4;
        buttons[BUTTON_CLOSE].y = 4;
        button_show(&buttons[BUTTON_CLOSE], "X");

        buttons[BUTTON_HELP].x = widget->w - texture_surface(buttons[BUTTON_HELP].texture)->w * 2 - 4;
        buttons[BUTTON_HELP].y = 4;
        button_show(&buttons[BUTTON_HELP], "?");
    }
}
예제 #2
0
파일: button.c 프로젝트: atrinik/atrinik
int button_need_redraw(button_struct *button)
{
    int ret;

    ret = 0;

    if (button->mouse_over || button->pressed) {
        int state, mx, my, mover;

        state = SDL_GetMouseState(&mx, &my);
        mover = BUTTON_MOUSE_OVER(button, mx, my, texture_surface(button->texture));

        if (button->mouse_over && !mover) {
            button->mouse_over = 0;
            ret = 1;
        }

        if (button->pressed && !button->pressed_forced &&
                (!mover || state != SDL_BUTTON_LEFT)) {
            button->pressed = 0;
            ret = 1;
        }
    }

    return ret;
}
예제 #3
0
파일: book.c 프로젝트: liwcezar/atrinik
/** @copydoc popup_struct::draw_func */
static int popup_draw_func(popup_struct *popup)
{
    if (popup->redraw) {
        SDL_Rect box;

        surface_show(popup->surface, 0, 0, NULL, texture_surface(popup->texture));

        /* Draw the book name. */
        box.w = BOOK_TITLE_WIDTH;
        box.h = BOOK_TITLE_HEIGHT;
        text_show(popup->surface, FONT_SERIF16, book_name, BOOK_TITLE_STARTX, BOOK_TITLE_STARTY, COLOR_HGOLD, TEXT_WORD_WRAP | TEXT_MARKUP | TEXT_ALIGN_CENTER, &box);

        /* Draw the content. */
        box.w = BOOK_TEXT_WIDTH;
        box.h = BOOK_TEXT_HEIGHT;
        box.y = book_scroll;
        text_color_set(0, 0, 255);
        text_set_selection(&popup->selection_start, &popup->selection_end, &popup->selection_started);
        text_show(popup->surface, FONT_ARIAL11, book_content, BOOK_TEXT_STARTX, BOOK_TEXT_STARTY, COLOR_BLACK, TEXT_WORD_WRAP | TEXT_MARKUP | TEXT_LINES_SKIP, &box);
        text_set_selection(NULL, NULL, NULL);

        popup->redraw = 0;
    }

    return 1;
}
예제 #4
0
파일: button.c 프로젝트: atrinik/atrinik
/**
 * Handle SDL event for a button.
 * @param button
 * Button to handle.
 * @param event
 * The event.
 * @return
 * 1 if the event makes the button pressed, 0 otherwise.
 */
int button_event(button_struct *button, SDL_Event *event)
{
    SDL_Surface *texture;
    int old_mouse_over;

    if (event->type != SDL_MOUSEBUTTONUP && event->type != SDL_MOUSEBUTTONDOWN && event->type != SDL_MOUSEMOTION) {
        return 0;
    }

    /* Mouse button is released, the button is no longer being pressed. */
    if (event->type == SDL_MOUSEBUTTONUP) {
        button->pressed = 0;
        button->redraw = 1;
        return 0;
    }

    old_mouse_over = button->mouse_over;
    /* Always reset this. */
    button->mouse_over = 0;

    /* The button is disabled, we don't care about the mouse. */
    if (button->disabled) {
        return 0;
    }

    texture = texture_surface(button_determine_texture(button));

    if (BUTTON_MOUSE_OVER(button, event->motion.x, event->motion.y, texture)) {
        if (event->type == SDL_MOUSEMOTION) {
            cursor_texture = texture_get(TEXTURE_TYPE_CLIENT, "cursor_pointer");
        }

        /* Left mouse click, the button has been pressed. */
        if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_LEFT) {
            button->pressed = 1;
            button->pressed_ticks = SDL_GetTicks();
            button->pressed_repeat_ticks = 750;
            button->redraw = 1;
            return 1;
        } else {
            button->mouse_over = 1;

            /* Do not reset hover ticks if the previous state was already
             * in highlight mode. */
            if (!old_mouse_over) {
                button->hover_ticks = SDL_GetTicks();
            }
        }
    }

    if (old_mouse_over != button->mouse_over) {
        button->redraw = 1;
    }

    return 0;
}
예제 #5
0
파일: button.c 프로젝트: atrinik/atrinik
/**
 * Render a button.
 * @param button
 * Button to render.
 * @param text
 * Optional text to render.
 */
void button_show(button_struct *button, const char *text)
{
    SDL_Surface *texture;

    (void) button_need_redraw(button);

    if (button->pressed_forced) {
        button->pressed = 1;
    }

    texture = texture_surface(button_determine_texture(button));
    surface_show(button->surface, button->x, button->y, NULL, texture);

    if (text) {
        const char *color, *color_shadow;
        int x, y;

        if (button->disabled) {
            color = COLOR_GRAY;
            color_shadow = COLOR_BLACK;
        } else if (button->mouse_over) {
            color = button->color_over;
            color_shadow = button->color_over_shadow;
        } else {
            color = button->color;
            color_shadow = button->color_shadow;
        }

        x = button->x;
        y = button->y;

        if (button->center) {
            x += texture->w / 2 - text_get_width(button->font, text, button->flags) / 2;
            y += texture->h / 2 - FONT_HEIGHT(button->font) / 2;
        }

        if (!color_shadow) {
            text_show(button->surface, button->font, text, x, y, color, button->flags, NULL);
        } else {
            text_show_shadow(button->surface, button->font, text, x, y - 2, color, color_shadow, button->flags, NULL);
        }
    }

    if (button->repeat_func && button->pressed && SDL_GetTicks() - button->pressed_ticks > button->pressed_repeat_ticks) {
        button->repeat_func(button);
        button->pressed_ticks = SDL_GetTicks();
        button->pressed_repeat_ticks = 150;
    }

    button->redraw = 0;
}
예제 #6
0
파일: texture.cpp 프로젝트: mutnig/vdrift
bool TEXTURE::Load(const std::string & path, const TEXTUREINFO & info, std::ostream & error)
{
	if (id)
	{
		error << "Tried to double load texture " << path << std::endl;
		return false;
	}

	if (path.empty() && !info.surface)
	{
		error << "Tried to load a texture with an empty name" << std::endl;
		return false;
	}

	id = 0;
	if (info.cube)
	{
		cube = true;
		return LoadCube(path, info, error);
	}

	SDL_Surface * orig_surface = info.surface;
	if (!orig_surface)
	{
		orig_surface = IMG_Load(path.c_str());
		if (!orig_surface)
		{
			error << "Error loading texture file: " << path << std::endl;
			return false;
		}
	}

	SDL_Surface * texture_surface(orig_surface);
	if (orig_surface)
	{
	    origw = texture_surface->w;
        origh = texture_surface->h;

		//scale to power of two if necessary
		bool norescale = (IsPowerOfTwo(orig_surface->w) && IsPowerOfTwo(orig_surface->h)) ||
					(info.npot && (GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two));
		if (!norescale)
	    {
	        int newx = orig_surface->w;
	        int maxsize = 2048;
	        if (!IsPowerOfTwo(orig_surface->w))
	        {
	            for (newx = 1; newx <= maxsize && newx <= orig_surface->w; newx = newx * 2)
	            {
	            }
	        }

	        int newy = orig_surface->h;
	        if (!IsPowerOfTwo(orig_surface->h))
	        {
	            for (newy = 1; newy <= maxsize && newy <= orig_surface->h; newy = newy * 2)
	            {
	            }
	        }

	        float scalew = ((float)newx+0.5) / orig_surface->w;
	        float scaleh = ((float)newy+0.5) / orig_surface->h;

	        SDL_Surface * pot_surface = zoomSurface (orig_surface, scalew, scaleh, SMOOTHING_ON);

	        assert(IsPowerOfTwo(pot_surface->w));
	        assert(IsPowerOfTwo(pot_surface->h));

	        SDL_FreeSurface(orig_surface);
	        orig_surface = pot_surface;
	        texture_surface = orig_surface;
	    }

		//scale texture down if necessary
		scale = Scale(info.size, orig_surface->w, orig_surface->h);
		if (scale < 1.0)
		{
			texture_surface = zoomSurface (orig_surface, scale, scale, SMOOTHING_ON);
		}

		//store dimensions
		w = texture_surface->w;
		h = texture_surface->h;

		GenTexture(texture_surface, info, id, alpha, error);
	}

	//free the texture surface separately if it's a scaled copy of the original
	if (texture_surface != orig_surface && texture_surface)
	{
		SDL_FreeSurface(texture_surface);
	}

	//free the original surface if it's not a custom surface (used for the track map)
	if (!info.surface && orig_surface)
	{
		SDL_FreeSurface(orig_surface);
	}

	return true;
}