mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Add DropDownButton widget.
This commit is contained in:
parent
7260fa20f9
commit
bda7f6c31d
Binary file not shown.
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.8 KiB |
@ -61,9 +61,9 @@
|
||||
<part id="radio_normal" x="32" y="32" w="8" h="8" />
|
||||
<part id="radio_selected" x="32" y="48" w="8" h="8" />
|
||||
<part id="radio_disabled" x="32" y="32" w="8" h="8" />
|
||||
<part id="check_normal" x="48" y="32" w="8" h="8" />
|
||||
<part id="check_selected" x="48" y="48" w="8" h="8" />
|
||||
<part id="check_disabled" x="48" y="32" w="8" h="8" />
|
||||
<part id="check_normal" x="48" y="64" w="8" h="8" />
|
||||
<part id="check_selected" x="48" y="80" w="8" h="8" />
|
||||
<part id="check_disabled" x="48" y="64" w="8" h="8" />
|
||||
<part id="check_focus" x="32" y="64" w1="2" w2="6" w3="2" h1="2" h2="6" h3="2" />
|
||||
<part id="radio_focus" x="32" y="64" w1="2" w2="6" w3="2" h1="2" h2="6" h3="2" />
|
||||
<part id="button_normal" x="48" y="0" w1="4" w2="6" w3="4" h1="4" h2="6" h3="6" />
|
||||
@ -170,6 +170,14 @@
|
||||
<part id="layer_locked_selected" x="160" y="184" w="8" h="8" />
|
||||
<part id="unpinned" x="192" y="144" w="8" h="8" />
|
||||
<part id="pinned" x="200" y="144" w="8" h="8" />
|
||||
<part id="drop_down_button_left_normal" x="48" y="32" w1="3" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_left_hot" x="64" y="32" w1="3" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_left_focused" x="48" y="48" w1="3" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_left_selected" x="64" y="48" w1="3" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_right_normal" x="56" y="32" w1="2" w2="1" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_right_hot" x="72" y="32" w1="2" w2="1" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_right_focused" x="55" y="48" w1="2" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
<part id="drop_down_button_right_selected" x="71" y="48" w1="2" w2="2" w3="3" h1="4" h2="6" h3="6" />
|
||||
</parts>
|
||||
|
||||
</skin>
|
||||
|
@ -283,6 +283,7 @@ add_library(aseprite-library
|
||||
widgets/color_button.cpp
|
||||
widgets/color_selector.cpp
|
||||
widgets/color_sliders.cpp
|
||||
widgets/drop_down_button.cpp
|
||||
widgets/editor/click.cpp
|
||||
widgets/editor/cursor.cpp
|
||||
widgets/editor/drawing_state.cpp
|
||||
|
@ -468,6 +468,78 @@ enum {
|
||||
PART_UNPINNED,
|
||||
PART_PINNED,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_N,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_E,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_SE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_S,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_SW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_NORMAL_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_NW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_N,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_NE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_E,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_SE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_S,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_SW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_HOT_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_N,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_E,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_SE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_S,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_SW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_N,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_E,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_SE,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_S,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_SW,
|
||||
PART_DROP_DOWN_BUTTON_LEFT_SELECTED_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_N,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_E,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_SE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_S,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_SW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_NW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_N,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_NE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_E,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_SE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_S,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_SW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_HOT_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_N,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_E,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_SE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_S,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_SW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_W,
|
||||
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_N,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_E,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_SE,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_S,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_SW,
|
||||
PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_W,
|
||||
|
||||
PARTS
|
||||
};
|
||||
|
||||
|
@ -25,6 +25,8 @@ enum LookType {
|
||||
NormalLook,
|
||||
MiniLook,
|
||||
WithoutBordersLook,
|
||||
LeftButtonLook,
|
||||
RightButtonLook,
|
||||
};
|
||||
|
||||
// Property to show widgets with a special look (e.g.: buttons or sliders with mini-borders)
|
||||
|
@ -201,6 +201,14 @@ SkinTheme::SkinTheme()
|
||||
sheet_mapping["layer_locked_selected"] = PART_LAYER_LOCKED_SELECTED;
|
||||
sheet_mapping["unpinned"] = PART_UNPINNED;
|
||||
sheet_mapping["pinned"] = PART_PINNED;
|
||||
sheet_mapping["drop_down_button_left_normal"] = PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NW;
|
||||
sheet_mapping["drop_down_button_left_hot"] = PART_DROP_DOWN_BUTTON_LEFT_HOT_NW;
|
||||
sheet_mapping["drop_down_button_left_focused"] = PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NW;
|
||||
sheet_mapping["drop_down_button_left_selected"] = PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NW;
|
||||
sheet_mapping["drop_down_button_right_normal"] = PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NW;
|
||||
sheet_mapping["drop_down_button_right_hot"] = PART_DROP_DOWN_BUTTON_RIGHT_HOT_NW;
|
||||
sheet_mapping["drop_down_button_right_focused"] = PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NW;
|
||||
sheet_mapping["drop_down_button_right_selected"] = PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NW;
|
||||
|
||||
reload_skin();
|
||||
}
|
||||
@ -738,31 +746,39 @@ void SkinTheme::paintButton(PaintEvent& ev)
|
||||
if (skinPropery != NULL)
|
||||
look = skinPropery->getLook();
|
||||
|
||||
// selected
|
||||
// Selected
|
||||
if (widget->isSelected()) {
|
||||
fg = get_button_selected_text_color();
|
||||
bg = get_button_selected_face_color();
|
||||
part_nw = (look == MiniLook ? PART_TOOLBUTTON_NORMAL_NW:
|
||||
PART_BUTTON_SELECTED_NW);
|
||||
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NW:
|
||||
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NW:
|
||||
PART_BUTTON_SELECTED_NW);
|
||||
}
|
||||
// with mouse
|
||||
// With mouse
|
||||
else if (widget->isEnabled() && widget->hasMouseOver()) {
|
||||
fg = get_button_hot_text_color();
|
||||
bg = get_button_hot_face_color();
|
||||
part_nw = (look == MiniLook ? PART_TOOLBUTTON_HOT_NW:
|
||||
PART_BUTTON_HOT_NW);
|
||||
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_HOT_NW:
|
||||
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_HOT_NW:
|
||||
PART_BUTTON_HOT_NW);
|
||||
}
|
||||
// without mouse
|
||||
// Without mouse
|
||||
else {
|
||||
fg = get_button_normal_text_color();
|
||||
bg = get_button_normal_face_color();
|
||||
|
||||
if (widget->hasFocus())
|
||||
part_nw = (look == MiniLook ? PART_TOOLBUTTON_HOT_NW:
|
||||
PART_BUTTON_FOCUSED_NW);
|
||||
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NW:
|
||||
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NW:
|
||||
PART_BUTTON_FOCUSED_NW);
|
||||
else
|
||||
part_nw = (look == MiniLook ? PART_TOOLBUTTON_NORMAL_NW:
|
||||
PART_BUTTON_NORMAL_NW);
|
||||
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NW:
|
||||
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NW:
|
||||
PART_BUTTON_NORMAL_NW);
|
||||
}
|
||||
|
||||
// widget position
|
||||
|
62
src/widgets/drop_down_button.cpp
Normal file
62
src/widgets/drop_down_button.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "widgets/drop_down_button.h"
|
||||
|
||||
#include "gui/theme.h"
|
||||
#include "modules/gui.h"
|
||||
#include "skin/button_icon_impl.h"
|
||||
#include "skin/skin_property.h"
|
||||
#include "skin/skin_theme.h"
|
||||
|
||||
DropDownButton::DropDownButton(const char* text)
|
||||
: HBox()
|
||||
, m_button(new Button(text))
|
||||
, m_dropDown(new Button(""))
|
||||
{
|
||||
setup_look(m_button, LeftButtonLook);
|
||||
setup_look(m_dropDown, RightButtonLook);
|
||||
|
||||
m_button->Click.connect(&DropDownButton::onButtonClick, this);
|
||||
m_dropDown->Click.connect(&DropDownButton::onDropDownButtonClick, this);
|
||||
|
||||
addChild(m_button);
|
||||
addChild(m_dropDown);
|
||||
|
||||
child_spacing = 0;
|
||||
|
||||
m_dropDown->setIconInterface
|
||||
(new ButtonIconImpl(static_cast<SkinTheme*>(m_dropDown->getTheme()),
|
||||
PART_COMBOBOX_ARROW_DOWN,
|
||||
PART_COMBOBOX_ARROW_DOWN_SELECTED,
|
||||
PART_COMBOBOX_ARROW_DOWN_DISABLED,
|
||||
JI_CENTER | JI_MIDDLE));
|
||||
}
|
||||
|
||||
void DropDownButton::onButtonClick(Event& ev)
|
||||
{
|
||||
// Fire "Click" signal.
|
||||
Click();
|
||||
}
|
||||
|
||||
void DropDownButton::onDropDownButtonClick(Event& ev)
|
||||
{
|
||||
DropDownClick();
|
||||
}
|
45
src/widgets/drop_down_button.h
Normal file
45
src/widgets/drop_down_button.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef WIDGETS_DROP_DOWN_BUTTON_H_INCLUDED
|
||||
#define WIDGETS_DROP_DOWN_BUTTON_H_INCLUDED
|
||||
|
||||
#include "base/signal.h"
|
||||
#include "gui/box.h"
|
||||
|
||||
class Button;
|
||||
class Event;
|
||||
|
||||
class DropDownButton : public HBox
|
||||
{
|
||||
public:
|
||||
DropDownButton(const char* text);
|
||||
|
||||
Signal0<void> Click;
|
||||
Signal0<void> DropDownClick;
|
||||
|
||||
protected:
|
||||
void onButtonClick(Event& ev);
|
||||
void onDropDownButtonClick(Event& ev);
|
||||
|
||||
private:
|
||||
Button* m_button;
|
||||
Button* m_dropDown;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user