mirror of https://github.com/stella-emu/stella.git
parent
5d0bc45a09
commit
1a7dff416a
|
@ -0,0 +1,191 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony
|
||||
// and the Stella Team
|
||||
//
|
||||
// See the file "License.txt" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//============================================================================
|
||||
|
||||
#include "FBSurface.hxx"
|
||||
#include "Font.hxx"
|
||||
#include "Dialog.hxx"
|
||||
#include "RadioButtonWidget.hxx"
|
||||
|
||||
/* Radiobutton bitmaps */
|
||||
static uInt32 radio_img_outercircle[14] =
|
||||
{
|
||||
0b00001111110000,
|
||||
0b00111111111100,
|
||||
0b01110000001110,
|
||||
0b01100000000110,
|
||||
0b11000000000011,
|
||||
0b11000000000011,
|
||||
0b11000000000011,
|
||||
0b11000000000011,
|
||||
0b11000000000011,
|
||||
0b11000000000011,
|
||||
0b01100000000110,
|
||||
0b01110000001110,
|
||||
0b00111111111100,
|
||||
0b00001111110000
|
||||
};
|
||||
|
||||
static uInt32 radio_img_innercircle[10] =
|
||||
{
|
||||
0b0011111100,
|
||||
0b0111111110,
|
||||
0b1111111111,
|
||||
0b1111111111,
|
||||
0b1111111111,
|
||||
0b1111111111,
|
||||
0b1111111111,
|
||||
0b1111111111,
|
||||
0b0111111110,
|
||||
0b0011111100
|
||||
};
|
||||
|
||||
static uInt32 radio_img_active[8] =
|
||||
{
|
||||
0b00111100,
|
||||
0b01111110,
|
||||
0b11111111,
|
||||
0b11111111,
|
||||
0b11111111,
|
||||
0b11111111,
|
||||
0b01111110,
|
||||
0b00111100
|
||||
};
|
||||
|
||||
static uInt32 radio_img_inactive[8] =
|
||||
{
|
||||
0b00111100,
|
||||
0b01111110,
|
||||
0b11100111,
|
||||
0b11000011,
|
||||
0b11000011,
|
||||
0b11100111,
|
||||
0b01111110,
|
||||
0b00111100
|
||||
};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
RadioButtonWidget::RadioButtonWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int x, int y, const string& label,
|
||||
RadioButtonGroup* group,
|
||||
int cmd)
|
||||
: CheckboxWidget(boss, font, x, y, label, cmd),
|
||||
myGroup(group)
|
||||
{
|
||||
_flags = WIDGET_ENABLED;
|
||||
_bgcolor = _bgcolorhi = kWidColor;
|
||||
|
||||
_editable = true;
|
||||
|
||||
if(label == "")
|
||||
_w = 14;
|
||||
else
|
||||
_w = font.getStringWidth(label) + 20;
|
||||
_h = font.getFontHeight() < 14 ? 14 : font.getFontHeight();
|
||||
|
||||
|
||||
// Depending on font size, either the font or box will need to be
|
||||
// centered vertically
|
||||
if(_h > 14) // center box
|
||||
_boxY = (_h - 14) / 2;
|
||||
else // center text
|
||||
_textY = (14 - _font.getFontHeight()) / 2;
|
||||
|
||||
setFill(CheckboxWidget::Normal);
|
||||
myGroup->addWidget(this);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
|
||||
{
|
||||
if(isEnabled() && _editable && x >= 0 && x < _w && y >= 0 && y < _h)
|
||||
{
|
||||
if(!_state)
|
||||
{
|
||||
setState(true);
|
||||
|
||||
// We only send a command when the widget has been changed interactively
|
||||
sendCommand(_cmd, _state, _id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonWidget::setState(bool state, bool send)
|
||||
{
|
||||
if(_state != state)
|
||||
{
|
||||
_state = state;
|
||||
setDirty();
|
||||
if(send)
|
||||
sendCommand(_cmd, _state, _id);
|
||||
if (state)
|
||||
myGroup->select(this);
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonWidget::setFill(FillType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case CheckboxWidget::Normal:
|
||||
_img = radio_img_active;
|
||||
break;
|
||||
case CheckboxWidget::Inactive:
|
||||
_img = radio_img_inactive;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonWidget::drawWidget(bool hilite)
|
||||
{
|
||||
FBSurface& s = _boss->dialog().surface();
|
||||
|
||||
// Draw the outer bounding circle
|
||||
s.drawBitmap(radio_img_outercircle, _x, _y + _boxY, kShadowColor, 14, 14);
|
||||
|
||||
// Draw the inner bounding circle with enabled color
|
||||
s.drawBitmap(radio_img_innercircle, _x + 2, _y + _boxY + 2, isEnabled() ? _bgcolor : kColor, 10, 10);
|
||||
|
||||
// draw state
|
||||
if(_state)
|
||||
s.drawBitmap(_img, _x + 3, _y + _boxY + 3, isEnabled() ? kCheckColor : kShadowColor);
|
||||
|
||||
// Finally draw the label
|
||||
s.drawString(_font, _label, _x + 20, _y + _textY, _w,
|
||||
isEnabled() ? kTextColor : kColor);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonGroup::addWidget(RadioButtonWidget* widget)
|
||||
{
|
||||
myWidgets.push_back(widget);
|
||||
// set first button as default
|
||||
widget->setState(myWidgets.size() == 1, false);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void RadioButtonGroup::select(RadioButtonWidget* widget)
|
||||
{
|
||||
for(const auto& w : myWidgets)
|
||||
if(w != widget)
|
||||
((RadioButtonWidget*)w)->setState(false);
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony
|
||||
// and the Stella Team
|
||||
//
|
||||
// See the file "License.txt" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
//============================================================================
|
||||
|
||||
#ifndef RADIOBUTTON_WIDGET_HXX
|
||||
#define RADIOBUTTON_WIDGET_HXX
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "Widget.hxx"
|
||||
|
||||
class Dialog;
|
||||
class RadioButtonGroup;
|
||||
|
||||
class RadioButtonWidget : public CheckboxWidget
|
||||
{
|
||||
public:
|
||||
RadioButtonWidget(GuiObject* boss, const GUI::Font& font, int x, int y,
|
||||
const string& label, RadioButtonGroup* group,
|
||||
int cmd = 0);
|
||||
|
||||
void handleMouseUp(int x, int y, int button, int clickCount) override;
|
||||
void setState(bool state, bool send = true);
|
||||
|
||||
protected:
|
||||
void setFill(FillType type);
|
||||
void drawWidget(bool hilite) override;
|
||||
|
||||
private:
|
||||
RadioButtonGroup* myGroup;
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
RadioButtonWidget() = delete;
|
||||
RadioButtonWidget(const RadioButtonWidget&) = delete;
|
||||
RadioButtonWidget(RadioButtonWidget&&) = delete;
|
||||
RadioButtonWidget& operator=(const RadioButtonWidget&) = delete;
|
||||
RadioButtonWidget& operator=(RadioButtonWidget&&) = delete;
|
||||
};
|
||||
|
||||
class RadioButtonGroup
|
||||
{
|
||||
public:
|
||||
RadioButtonGroup() {};
|
||||
|
||||
// add widget to group
|
||||
void addWidget(RadioButtonWidget* widget);
|
||||
// tell the group which widget was selected
|
||||
void select(RadioButtonWidget* widget);
|
||||
|
||||
private:
|
||||
WidgetArray myWidgets;
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
RadioButtonGroup(const RadioButtonGroup&) = delete;
|
||||
RadioButtonGroup(RadioButtonGroup&&) = delete;
|
||||
RadioButtonGroup& operator=(const RadioButtonGroup&) = delete;
|
||||
RadioButtonGroup& operator=(RadioButtonGroup&&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue