Redesign ToggleBitmap to operate on a command
Originally committed to SVN as r5565.
This commit is contained in:
parent
3ecfd34bd3
commit
a45b971b3a
5 changed files with 37 additions and 147 deletions
|
@ -66,7 +66,6 @@
|
|||
#include "main.h"
|
||||
#include "toggle_bitmap.h"
|
||||
#include "selection_controller.h"
|
||||
#include "tooltip_manager.h"
|
||||
#include "utils.h"
|
||||
|
||||
enum AudioBoxControlIDs {
|
||||
|
@ -110,11 +109,7 @@ AudioBox::AudioBox(wxWindow *parent, agi::Context *context)
|
|||
wxSizer *VertVolArea = new wxBoxSizer(wxVERTICAL);
|
||||
VertVolArea->Add(VertVol,1,wxEXPAND,0);
|
||||
|
||||
cmd::Command *link_command = cmd::get("audio/opt/vertical_link");
|
||||
ToggleBitmap *link_btn = new ToggleBitmap(this, cmd::id("audio/opt/vertical_link"), link_command->Icon(16), wxSize(20, -1));
|
||||
ToolTipManager::Bind(link_btn, link_command->StrHelp(), "Audio", "audio/opt/vertical_link");
|
||||
link_btn->SetValue(OPT_GET("Audio/Link")->GetBool());
|
||||
link_btn->Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &AudioBox::OnVerticalLinkButton, this);
|
||||
ToggleBitmap *link_btn = new ToggleBitmap(this, context, "audio/opt/vertical_link", 16, "Audio", wxSize(20, -1));
|
||||
VertVolArea->Add(link_btn, 0, wxRIGHT | wxALIGN_CENTER | wxEXPAND, 0);
|
||||
OPT_SUB("Audio/Link", bind(&AudioBox::OnVerticalLink, this, std::tr1::placeholders::_1));
|
||||
|
||||
|
@ -186,10 +181,6 @@ BEGIN_EVENT_TABLE(AudioBox,wxPanel)
|
|||
EVT_TOGGLEBUTTON(Audio_Button_Karaoke, AudioBox::OnKaraoke)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
void AudioBox::OnVerticalLinkButton(wxCommandEvent &) {
|
||||
cmd::call("audio/opt/vertical_link", context);
|
||||
}
|
||||
|
||||
void AudioBox::OnHorizontalZoom(wxScrollEvent &event) {
|
||||
// Negate the value, we want zoom out to be on bottom and zoom in on top,
|
||||
// but the control doesn't want negative on bottom and positive on top.
|
||||
|
|
|
@ -103,7 +103,6 @@ class AudioBox : public wxPanel {
|
|||
void OnVerticalZoom(wxScrollEvent &event);
|
||||
void OnVolume(wxScrollEvent &event);
|
||||
void OnVerticalLink(agi::OptionValue const& opt);
|
||||
void OnVerticalLinkButton(wxCommandEvent&);
|
||||
|
||||
void OnKaraoke(wxCommandEvent &);
|
||||
void OnJoin(wxCommandEvent &);
|
||||
|
|
|
@ -34,9 +34,6 @@
|
|||
/// @ingroup custom_control
|
||||
///
|
||||
|
||||
|
||||
///////////
|
||||
// Headers
|
||||
#include "config.h"
|
||||
|
||||
#ifndef AGI_PRE
|
||||
|
@ -47,125 +44,48 @@
|
|||
|
||||
#include "toggle_bitmap.h"
|
||||
|
||||
#include "command/command.h"
|
||||
#include "include/aegisub/context.h"
|
||||
#include "tooltip_manager.h"
|
||||
|
||||
/// @brief Constructor
|
||||
/// @param parent
|
||||
/// @param id
|
||||
/// @param image
|
||||
/// @param size
|
||||
///
|
||||
ToggleBitmap::ToggleBitmap(wxWindow *parent,wxWindowID id,const wxBitmap &image,const wxSize &size)
|
||||
: wxControl (parent,id,wxDefaultPosition,wxDefaultSize,wxSUNKEN_BORDER)
|
||||
ToggleBitmap::ToggleBitmap(wxWindow *parent, agi::Context *context, const char *cmd_name, int icon_size, const char *ht_ctx, wxSize const& size)
|
||||
: wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
|
||||
, context(context)
|
||||
, command(cmd::get(cmd_name))
|
||||
, img(command->Icon(icon_size))
|
||||
{
|
||||
// Set variables
|
||||
img = image;
|
||||
state = false;
|
||||
|
||||
// Set size
|
||||
int w,h;
|
||||
if (size.GetWidth() != -1) w = size.GetWidth();
|
||||
else w = img.GetWidth();
|
||||
if (size.GetHeight() != -1) h = size.GetHeight();
|
||||
else h = img.GetHeight();
|
||||
int w = size.GetWidth() != -1 ? size.GetWidth() : img.GetWidth();
|
||||
int h = size.GetHeight() != -1 ? size.GetHeight() : img.GetHeight();
|
||||
SetClientSize(w, h);
|
||||
GetSize(&w, &h);
|
||||
SetSizeHints(w, h, w, h);
|
||||
|
||||
ToolTipManager::Bind(this, command->StrHelp(), ht_ctx, cmd_name);
|
||||
Bind(wxEVT_PAINT, &ToggleBitmap::OnPaint, this);
|
||||
Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Get state
|
||||
/// @return
|
||||
///
|
||||
bool ToggleBitmap::GetValue() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Set state
|
||||
/// @param _state
|
||||
///
|
||||
void ToggleBitmap::SetValue(bool _state) {
|
||||
// Set flag
|
||||
state = _state;
|
||||
|
||||
// Refresh
|
||||
void ToggleBitmap::OnMouseEvent(wxMouseEvent &) {
|
||||
(*command)(context);
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Draw image
|
||||
/// @param dc
|
||||
///
|
||||
void ToggleBitmap::DrawImage(wxDC &dc) {
|
||||
// Get size
|
||||
void ToggleBitmap::OnPaint(wxPaintEvent &) {
|
||||
wxPaintDC dc(this);
|
||||
int w,h;
|
||||
GetClientSize(&w,&h);
|
||||
|
||||
// Get background color
|
||||
wxColour bgColor;
|
||||
if (state) bgColor = wxColour(0,255,0);
|
||||
else bgColor = wxColour(255,0,0);
|
||||
wxColour bgColor = command->IsActive(context) ? wxColour(0,255,0) : wxColour(255,0,0);
|
||||
wxColor sysCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
|
||||
int r,g,b;
|
||||
r = (sysCol.Red() + bgColor.Red()) / 2;
|
||||
g = (sysCol.Green() + bgColor.Green()) / 2;
|
||||
b = (sysCol.Blue() + bgColor.Blue()) / 2;
|
||||
bgColor.Set(r,g,b);
|
||||
bgColor.Set(
|
||||
(sysCol.Red() + bgColor.Red()) / 2,
|
||||
(sysCol.Green() + bgColor.Green()) / 2,
|
||||
(sysCol.Blue() + bgColor.Blue()) / 2);
|
||||
|
||||
// Draw background
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(wxBrush(bgColor));
|
||||
dc.DrawRectangle(0, 0, w, h);
|
||||
|
||||
// Draw bitmap
|
||||
dc.DrawBitmap(img, (w - img.GetWidth()) / 2, (h - img.GetHeight()) / 2, true);
|
||||
}
|
||||
|
||||
|
||||
///////////////
|
||||
// Event table
|
||||
BEGIN_EVENT_TABLE(ToggleBitmap,wxControl)
|
||||
EVT_MOUSE_EVENTS(ToggleBitmap::OnMouseEvent)
|
||||
EVT_PAINT(ToggleBitmap::OnPaint)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
|
||||
/// @brief Mouse events
|
||||
/// @param event
|
||||
///
|
||||
void ToggleBitmap::OnMouseEvent(wxMouseEvent &event) {
|
||||
// Get mouse position
|
||||
int x = event.GetX();
|
||||
int y = event.GetY();
|
||||
int w,h;
|
||||
GetClientSize(&w,&h);
|
||||
bool inside = true;
|
||||
if (x < 0 || y < y || x >= w || y >= h) inside = false;
|
||||
|
||||
// Left click to toggle state
|
||||
if (inside && event.ButtonDown(wxMOUSE_BTN_LEFT)) {
|
||||
// Update
|
||||
state = !state;
|
||||
Refresh(false);
|
||||
|
||||
// Send event
|
||||
wxCommandEvent sendEvent(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,GetId());
|
||||
AddPendingEvent(sendEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @brief Paint event
|
||||
/// @param event
|
||||
///
|
||||
void ToggleBitmap::OnPaint(wxPaintEvent &event) {
|
||||
wxPaintDC dc(this);
|
||||
DrawImage(dc);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,16 +34,13 @@
|
|||
/// @ingroup custom_control
|
||||
///
|
||||
|
||||
|
||||
|
||||
|
||||
///////////
|
||||
// Headers
|
||||
#ifndef AGI_PRE
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/control.h>
|
||||
#endif
|
||||
|
||||
namespace agi { struct Context; }
|
||||
namespace cmd { class Command; }
|
||||
|
||||
/// DOCME
|
||||
/// @class ToggleBitmap
|
||||
|
@ -51,22 +48,13 @@
|
|||
///
|
||||
/// DOCME
|
||||
class ToggleBitmap : public wxControl {
|
||||
private:
|
||||
|
||||
/// DOCME
|
||||
agi::Context *context;
|
||||
cmd::Command *command;
|
||||
wxBitmap img;
|
||||
|
||||
/// DOCME
|
||||
bool state;
|
||||
|
||||
void OnMouseEvent(wxMouseEvent &event);
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void DrawImage(wxDC &dc);
|
||||
void OnMouseEvent(wxMouseEvent &evt);
|
||||
void OnPaint(wxPaintEvent &evt);
|
||||
|
||||
public:
|
||||
ToggleBitmap(wxWindow *parent,wxWindowID id,const wxBitmap &image,const wxSize &size=wxDefaultSize);
|
||||
bool GetValue();
|
||||
void SetValue(bool state);
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
ToggleBitmap(wxWindow *parent, agi::Context *context, const char *command, int icon_size, const char *ht_ctx, wxSize const& size = wxDefaultSize);
|
||||
};
|
||||
|
|
|
@ -70,14 +70,6 @@ static void add_button(wxWindow *parent, wxSizer *sizer, const char *command) {
|
|||
sizer->Add(btn, 0, wxTOP | wxLEFT | wxBOTTOM | wxALIGN_CENTER, 2);;
|
||||
}
|
||||
|
||||
static void add_option(wxWindow *parent, wxSizer *sizer, const char *command, const char *option) {
|
||||
cmd::Command *c = cmd::get(command);
|
||||
ToggleBitmap *btn = new ToggleBitmap(parent, cmd::id(command), c->Icon(24));
|
||||
ToolTipManager::Bind(btn, c->StrHelp(), "Video", command);
|
||||
btn->SetValue(OPT_GET(option)->GetBool());
|
||||
sizer->Add(btn, 0, wxTOP | wxLEFT | wxBOTTOM | wxALIGN_CENTER, 2);
|
||||
}
|
||||
|
||||
VideoBox::VideoBox(wxWindow *parent, bool isDetached, agi::Context *context)
|
||||
: wxPanel (parent,-1)
|
||||
, context(context)
|
||||
|
@ -90,7 +82,7 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, agi::Context *context)
|
|||
add_button(this, videoBottomSizer, "video/play");
|
||||
add_button(this, videoBottomSizer, "video/play/line");
|
||||
add_button(this, videoBottomSizer, "video/stop");
|
||||
add_option(this, videoBottomSizer, "video/opt/autoscroll", "Video/Subtitle Sync");
|
||||
videoBottomSizer->Add(new ToggleBitmap(this, context, "video/opt/autoscroll", 24, "Video"), 0, wxTOP | wxLEFT | wxBOTTOM | wxALIGN_CENTER, 2);
|
||||
|
||||
// Seek
|
||||
videoSlider = new VideoSlider(this, context);
|
||||
|
|
Loading…
Reference in a new issue