aseprite/src/widgets/toolbar.cpp

126 lines
3.1 KiB
C++
Raw Normal View History

2007-11-17 02:25:45 +08:00
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2009 David Capello
2007-09-19 07:57:02 +08:00
*
* 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 <allegro/unicode.h>
#include "jinete/jaccel.h"
#include "jinete/jbox.h"
#include "jinete/jbutton.h"
#include "jinete/jhook.h"
#include "jinete/jtooltips.h"
#include "jinete/jwidget.h"
2007-09-19 07:57:02 +08:00
#include "commands/commands.h"
2007-09-19 07:57:02 +08:00
#include "modules/gfx.h"
#include "modules/gui.h"
#include "modules/tools.h"
#include "widgets/groupbut.h"
#include "widgets/toolbar.h"
static bool tools_change_hook(JWidget widget, void *data);
static void conf_command(JWidget widget);
2007-09-19 07:57:02 +08:00
JWidget toolbar_new()
2007-09-19 07:57:02 +08:00
{
JWidget box, confbutton, tools;
char buf[1024]; /* TODO warning buffer overflow */
int c;
for (c=0; c<MAX_TOOLS; c++)
if (current_tool == tools_list[c])
2007-09-19 07:57:02 +08:00
break;
box = jbox_new(JI_VERTICAL);
confbutton = jbutton_new(NULL);
2007-09-19 07:57:02 +08:00
add_gfxicon_to_button(confbutton, GFX_TOOL_CONFIGURATION,
JI_CENTER | JI_MIDDLE);
2007-09-19 07:57:02 +08:00
tools = group_button_new(1, MAX_TOOLS, c,
GFX_TOOL_MARKER,
GFX_TOOL_PENCIL,
GFX_TOOL_BRUSH,
GFX_TOOL_ERASER,
GFX_TOOL_FLOODFILL,
GFX_TOOL_SPRAY,
GFX_TOOL_LINE,
2008-09-29 04:53:42 +08:00
GFX_TOOL_CURVE,
GFX_TOOL_RECTANGLE,
GFX_TOOL_ELLIPSE,
2008-04-15 01:56:38 +08:00
GFX_TOOL_BLUR,
GFX_TOOL_JUMBLE);
for (c=0; c<MAX_TOOLS; c++) {
JWidget child;
usprintf(buf, "radio%d", c);
child = jwidget_find_name(tools, buf);
usprintf(buf, "%s", _(tools_list[c]->tips));
JAccel accel = get_accel_to_change_tool(tools_list[c]);
if (accel) {
ustrcat(buf, "\n(");
jaccel_to_string(accel, buf+ustrsize(buf));
ustrcat(buf, ")");
}
jwidget_add_tooltip_text(child, buf);
}
jwidget_expansive(box, TRUE);
2007-09-19 07:57:02 +08:00
jwidget_add_child(box, tools);
jwidget_add_child(box, confbutton);
2007-09-19 07:57:02 +08:00
HOOK(tools, SIGNAL_GROUP_BUTTON_CHANGE, tools_change_hook, 0);
jbutton_add_command(confbutton, conf_command);
2007-09-19 07:57:02 +08:00
box->user_data[0] = tools;
2007-09-19 07:57:02 +08:00
return box;
}
void toolbar_update(JWidget widget)
2007-09-19 07:57:02 +08:00
{
2008-10-01 05:01:54 +08:00
JWidget group = reinterpret_cast<JWidget>(widget->user_data[0]);
2007-09-19 07:57:02 +08:00
int c;
for (c=0; c<MAX_TOOLS; c++)
if (current_tool == tools_list[c])
2007-09-19 07:57:02 +08:00
break;
group_button_select(group, c);
2007-09-19 07:57:02 +08:00
}
static bool tools_change_hook(JWidget widget, void *data)
2007-09-19 07:57:02 +08:00
{
int c = group_button_get_selected(widget);
2007-09-19 07:57:02 +08:00
if (current_tool != tools_list[c])
select_tool(tools_list[c]);
2007-09-19 07:57:02 +08:00
return FALSE;
}
static void conf_command(JWidget widget)
2007-09-19 07:57:02 +08:00
{
command_execute(command_get_by_name(CMD_CONFIGURE_TOOLS), NULL);
2007-09-19 07:57:02 +08:00
}