source: abuse/branches/lol/src/ui/volumewindow.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 8 years ago

build: SDL2 compilation fixes.

File size: 2.7 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "volumewindow.h" // class VolumeWindow
18#include "property.h"     // class APropertyManager
19#include "gui.h"          // class AIconButton
20
21VolumeWindow::VolumeWindow()
22  : AWindow("Volume")
23{
24    char const *ff = "art/frame.spe";
25    u_u = cache.reg(ff, "u_u", SPEC_IMAGE, 1),
26    u_d = cache.reg(ff, "u_u", SPEC_IMAGE, 1),
27    u_ua = cache.reg(ff, "u_ua", SPEC_IMAGE, 1),
28    u_da = cache.reg(ff, "u_da", SPEC_IMAGE, 1),
29    d_u = cache.reg(ff, "d_u", SPEC_IMAGE, 1),
30    d_d = cache.reg(ff, "d_u", SPEC_IMAGE, 1),
31    d_ua = cache.reg(ff, "d_ua", SPEC_IMAGE, 1),
32    d_da = cache.reg(ff, "d_da", SPEC_IMAGE, 1),
33    slider = cache.reg(ff, "volume_slide", SPEC_IMAGE, 1);
34    m_pos.x = g_prop->getd("volume_x", xres / 2 - 20);
35    m_pos.y = g_prop->getd("volume_y", yres / 2 - 50);
36
37    AWidgetList widgets;
38    widgets << new AIconButton(ivec2(10, 27), ID_SFX_DOWN, d_u, d_d, d_ua, d_da);
39    widgets << new AIconButton(ivec2(21, 27), ID_SFX_UP, u_u, u_d, u_ua, u_da);
40    widgets << new AInfoField(ivec2(15, 42), 0, symbol_str("SFXv"));
41    widgets << new AIconButton(ivec2(10, 72), ID_MUSIC_DOWN, d_u, d_d, d_ua, d_da);
42    widgets << new AIconButton(ivec2(21, 72), ID_MUSIC_UP, u_u, u_d, u_ua, u_da);
43    widgets << new AInfoField(ivec2(10, 86), 0, symbol_str("MUSICv"));
44    inm->Add(widgets);
45
46    //reconfigure();
47    bg = cache.reg(ff, "vcontrol", SPEC_IMAGE, 1);
48    m_size = cache.img(bg)->Size();
49    m_surf = new AImage(m_size, 2);
50    redraw();
51}
52
53void VolumeWindow::redraw()
54{
55    m_surf->PutImage(cache.img(bg), ivec2(0, 0));
56    draw_music_vol();
57    draw_sfx_vol();
58    inm->redraw();
59}
60
61void VolumeWindow::draw_vol(int x1, int y1, int x2, int y2, int t,
62                            int max, int c1, int c2)
63{
64    int dx = x1 + t * (x2 - x1) / max;
65    if(t != 0)
66    {
67        m_surf->PutImage(cache.img(slider), ivec2(x1, y1));
68//      m_surf->bar(x1,y1,dx,y2,c1);
69    }
70    else
71        dx--;
72
73    if(dx < x2)
74        m_surf->Bar(ivec2(dx + 1, y1), ivec2(x2, y2), c2);
75}
76
77void VolumeWindow::draw_sfx_vol()
78{
79    draw_vol(6, 16, 34, 22, sfx_volume, 127,
80             g_palette->FindClosest(u8vec3(200, 75, 19)),
81             g_palette->FindClosest(u8vec3(40, 0, 0)));
82}
83
84void VolumeWindow::draw_music_vol()
85{
86    draw_vol(6, 61, 34, 67, music_volume, 127,
87             g_palette->FindClosest(u8vec3(255, 0, 0)),
88             g_palette->FindClosest(u8vec3(40, 0, 0)));
89}
90
Note: See TracBrowser for help on using the repository browser.