mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 21:33:12 +00:00
Remove deprecated dialogs: drawtext.cpp, playfli.cpp, repo.cpp.
This commit is contained in:
parent
f1180e7a71
commit
a27d1d3eeb
1
TODO.txt
1
TODO.txt
@ -13,7 +13,6 @@ For next release
|
||||
This button should apply a color curve to the whole sprite to remap
|
||||
old indexes to the new positions.
|
||||
+ Move launcher.cpp to base/ lib adding an extension point for "gui" lib.
|
||||
+ Remove src/dialogs/repo,playfli,drawtext.
|
||||
+ Move src/dialogs/aniedit,filesel to src/widgets (remove dialogs/ directory).
|
||||
+ Merge everything related to configuration/settings in one class
|
||||
(allow configuration per document). Use cfg.cpp and settings/ dir.
|
||||
|
@ -249,11 +249,8 @@ add_library(aseprite-library
|
||||
commands/filters/filter_window.cpp
|
||||
commands/filters/filter_worker.cpp
|
||||
dialogs/aniedit.cpp
|
||||
dialogs/drawtext.cpp
|
||||
dialogs/filesel.cpp
|
||||
dialogs/maskcol.cpp
|
||||
dialogs/playfli.cpp
|
||||
dialogs/repo.cpp
|
||||
file/ase_format.cpp
|
||||
file/bmp_format.cpp
|
||||
file/file.cpp
|
||||
|
@ -1,287 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 <allegro.h>
|
||||
|
||||
#include "gui/gui.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app/color.h"
|
||||
#include "console.h"
|
||||
#include "dialogs/filesel.h"
|
||||
#include "ini_file.h"
|
||||
#include "modules/gui.h"
|
||||
#include "modules/palettes.h"
|
||||
#include "raster/blend.h"
|
||||
#include "raster/image.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "resource_finder.h"
|
||||
#include "util/clipboard.h"
|
||||
#include "util/misc.h"
|
||||
#include "widgets/color_bar.h"
|
||||
#include "widgets/color_button.h"
|
||||
|
||||
static JWidget font_button;
|
||||
|
||||
static Image *render_text(Sprite* sprite, FONT *f, const char *text, int color);
|
||||
|
||||
static FONT *my_load_font(const char *filename);
|
||||
static void button_font_command(JWidget widget);
|
||||
static void update_button_text();
|
||||
|
||||
void dialogs_draw_text(Sprite* sprite)
|
||||
{
|
||||
#if 0
|
||||
Image *image, *dest_image;
|
||||
JWidget button_ok, color_box, color_but;
|
||||
JWidget entry_size, entry_text;
|
||||
char buf[256];
|
||||
|
||||
if (!App::instance()->isGui() || !sprite)
|
||||
return;
|
||||
|
||||
dest_image = GetImage(sprite);
|
||||
if (!dest_image)
|
||||
return;
|
||||
|
||||
JWidgetPtr window = load_widget("draw_text.xml", "drawtext_window");
|
||||
|
||||
if (!get_widgets(window,
|
||||
"font", &font_button,
|
||||
"text", &entry_text,
|
||||
"size", &entry_size,
|
||||
"color_box", &color_box,
|
||||
"ok", &button_ok, NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* font button */
|
||||
jbutton_add_command(font_button, button_font_command);
|
||||
update_button_text();
|
||||
|
||||
/* color button */
|
||||
color_but = colorbutton_new
|
||||
(get_config_color("DrawText", "Color",
|
||||
colorbar_get_fg_color(app_get_colorbar())),
|
||||
sprite->imgtype);
|
||||
|
||||
color_box->addChild(color_but);
|
||||
|
||||
/* entries */
|
||||
usprintf(buf, "%d", get_config_int("DrawText", "Size", 8));
|
||||
jwidget_set_text(entry_size, buf);
|
||||
jwidget_set_text(entry_text,
|
||||
get_config_string("DrawText", "Text", "ABCabc"));
|
||||
|
||||
/* window */
|
||||
window->remap_window();
|
||||
window->center_window();
|
||||
window->open_window_fg();
|
||||
|
||||
if (window->get_killer() == button_ok) {
|
||||
Color color_with_type = colorbutton_get_color(color_but);
|
||||
const char *text = jwidget_get_text(entry_text);
|
||||
const char *size_str = jwidget_get_text(entry_size);
|
||||
const char *font_str = get_config_string("DrawText", "Font",
|
||||
"allegro.pcx");
|
||||
int color;
|
||||
int size;
|
||||
FONT *f;
|
||||
|
||||
/* size */
|
||||
size = ustrtol(size_str, NULL, 10);
|
||||
size = MID(1, size, 256);
|
||||
|
||||
/* load the font */
|
||||
f = my_load_font(font_str);
|
||||
|
||||
/* error loading font */
|
||||
if (!f) {
|
||||
console_printf(_("Error loading font.\n"));
|
||||
}
|
||||
/* the font was loaded */
|
||||
else {
|
||||
/* set font size */
|
||||
ji_font_set_size(f, size);
|
||||
|
||||
/* setup color */
|
||||
color = color_utils::color_for_image(color_with_type, sprite->imgtype);
|
||||
|
||||
/* update configuration */
|
||||
set_config_color("DrawText", "Color", color_with_type);
|
||||
set_config_string("DrawText", "Text", text);
|
||||
set_config_int("DrawText", "Size", size);
|
||||
|
||||
/* render text */
|
||||
image = render_text(sprite, f, text, color);
|
||||
if (image) {
|
||||
clipboard::copy_image(image, sprite_get_palette(sprite, sprite->frame));
|
||||
clipboard::paste(sprite);
|
||||
}
|
||||
else
|
||||
console_printf(_("Error rendering text.\n"));
|
||||
|
||||
/* free the font */
|
||||
destroy_font(f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Image *RenderText(Sprite* sprite, const char *fontname, int size, int color, const char *text)
|
||||
{
|
||||
Image *render;
|
||||
FONT *f;
|
||||
|
||||
f = my_load_font(fontname);
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
ji_font_set_size(f, size);
|
||||
|
||||
render = render_text(sprite, f, text, color);
|
||||
|
||||
destroy_font(f);
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
static Image* render_text(Sprite* sprite, FONT *f, const char *text, int color)
|
||||
{
|
||||
/* TODO warning this uses Image->dat and not Image->line */
|
||||
#define DO(type, colfunc) \
|
||||
{ \
|
||||
register int c; \
|
||||
uint32_t* src = (uint32_t*)bmp->dat; \
|
||||
type* dst = (type*)image->dat; \
|
||||
for (i=0; i<pixels; i++) { \
|
||||
c = *src; \
|
||||
*dst = colfunc; \
|
||||
src++; \
|
||||
dst++; \
|
||||
} \
|
||||
}
|
||||
|
||||
int i, pixels, w, h;
|
||||
Image *image;
|
||||
BITMAP *bmp;
|
||||
|
||||
w = text_length(f, text);
|
||||
h = text_height(f);
|
||||
pixels = w*h;
|
||||
if (!pixels)
|
||||
return NULL;
|
||||
|
||||
bmp = create_bitmap_ex(32, w, h);
|
||||
if (!bmp)
|
||||
return NULL;
|
||||
|
||||
ji_font_set_aa_mode(f, -1);
|
||||
|
||||
clear_to_color(bmp, makecol32 (255, 0, 255));
|
||||
textout_ex(bmp, f, text, 0, 0, makecol32 (255, 255, 255), -1);
|
||||
|
||||
image = Image::create(sprite->getPixelFormat(), w, h);
|
||||
if (!image) {
|
||||
destroy_bitmap(bmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image_clear(image, 0);
|
||||
acquire_bitmap(bmp);
|
||||
|
||||
switch (image->getPixelFormat()) {
|
||||
|
||||
case IMAGE_RGB:
|
||||
DO(uint32_t, _rgba(_rgba_getr(color),
|
||||
_rgba_getg(color),
|
||||
_rgba_getb(color), getg32(c)));
|
||||
break;
|
||||
|
||||
case IMAGE_GRAYSCALE:
|
||||
DO(uint16_t, _graya(_graya_getv(color), getg32(c)));
|
||||
break;
|
||||
|
||||
case IMAGE_INDEXED:
|
||||
DO(uint8_t, c == makecol32(255, 0, 255) ? 0: color);
|
||||
break;
|
||||
}
|
||||
|
||||
release_bitmap(bmp);
|
||||
destroy_bitmap(bmp);
|
||||
return image;
|
||||
}
|
||||
|
||||
static FONT *my_load_font(const char *filename)
|
||||
{
|
||||
FONT *f = NULL;
|
||||
char buf[256];
|
||||
|
||||
// Directories to search
|
||||
ResourceFinder rf;
|
||||
|
||||
rf.addPath(filename);
|
||||
|
||||
usprintf(buf, "fonts/%s", filename);
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
usprintf(buf, "fonts/%s", get_filename(filename));
|
||||
rf.findInDataDir(buf);
|
||||
|
||||
// Search the font
|
||||
while (const char* path = rf.next()) {
|
||||
// Load the font
|
||||
f = ji_font_load(path);
|
||||
if (f)
|
||||
break;
|
||||
else {
|
||||
if (exists(path))
|
||||
PRINTF("Unknown font format \"%s\"\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
// Error loading font
|
||||
if (!f) {
|
||||
Console console;
|
||||
console.printf("Error loading font.\n");
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static void button_font_command(JWidget widget)
|
||||
{
|
||||
base::string filename =
|
||||
ase_file_selector("Open Font (TTF or Allegro bitmap format)",
|
||||
get_config_string ("DrawText", "Font", ""),
|
||||
"pcx,bmp,tga,lbm,ttf");
|
||||
|
||||
if (!filename.empty()) {
|
||||
set_config_string("DrawText", "Font", filename.c_str());
|
||||
update_button_text();
|
||||
}
|
||||
}
|
||||
|
||||
static void update_button_text()
|
||||
{
|
||||
const char *font_str = get_config_string("DrawText", "Font", "allegro.pcx");
|
||||
|
||||
font_button->setText(get_filename(font_str));
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 DIALOGS_DRAWTEXT_H_INCLUDED
|
||||
#define DIALOGS_DRAWTEXT_H_INCLUDED
|
||||
|
||||
class Image;
|
||||
class Sprite;
|
||||
|
||||
void dialogs_draw_text(Sprite* sprite);
|
||||
|
||||
Image* RenderText(Sprite* sprite, const char* fontname, int size, int color, const char* text);
|
||||
|
||||
#endif
|
@ -1,205 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 <allegro.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gui/manager.h"
|
||||
#include "gui/system.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "file/fli/fli.h"
|
||||
#include "modules/gui.h"
|
||||
|
||||
static bool my_callback();
|
||||
static void my_play_fli(const char *filename, bool loop, bool fullscreen,
|
||||
bool (*callback)());
|
||||
|
||||
void play_fli_animation(const char *filename, bool loop, bool fullscreen)
|
||||
{
|
||||
if (App::instance()->isGui()) {
|
||||
PALETTE backup;
|
||||
|
||||
jmanager_free_mouse();
|
||||
|
||||
/* hide the mouse */
|
||||
jmouse_hide();
|
||||
|
||||
/* get the current color palette */
|
||||
get_palette(backup);
|
||||
|
||||
/* clear the screen */
|
||||
clear(ji_screen);
|
||||
|
||||
/* clear the keyboard buffer */
|
||||
clear_keybuf();
|
||||
|
||||
/* play the fli */
|
||||
my_play_fli(filename, loop, fullscreen, my_callback);
|
||||
/* play_fli(filename, ji_screen, loop, my_callback); */
|
||||
|
||||
/* clear the screen */
|
||||
clear(ji_screen);
|
||||
|
||||
/* restore the color palette */
|
||||
set_palette(backup);
|
||||
|
||||
/* show the mouse cursor */
|
||||
jmouse_show();
|
||||
|
||||
/* wait while the user has pushed some mouse button */
|
||||
do {
|
||||
jmouse_poll();
|
||||
} while (jmouse_b(0));
|
||||
|
||||
/* clear again the keyboard buffer */
|
||||
clear_keybuf();
|
||||
|
||||
jmanager_refresh_screen();
|
||||
}
|
||||
}
|
||||
|
||||
static bool my_callback()
|
||||
{
|
||||
jmouse_poll();
|
||||
|
||||
return (keypressed() || jmouse_b(0));
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/* my_play_fli */
|
||||
|
||||
static int speed_timer;
|
||||
|
||||
static void speed_timer_callback()
|
||||
{
|
||||
speed_timer++;
|
||||
}
|
||||
|
||||
END_OF_STATIC_FUNCTION(speed_timer_callback);
|
||||
|
||||
static void my_play_fli(const char *filename, bool loop, bool fullscreen,
|
||||
bool (*callback)())
|
||||
{
|
||||
unsigned char cmap[768];
|
||||
unsigned char omap[768];
|
||||
s_fli_header fli_header;
|
||||
BITMAP *bmp, *old;
|
||||
int x, y, w, h;
|
||||
PALETTE pal;
|
||||
int frpos;
|
||||
int done;
|
||||
int c, i;
|
||||
FILE *f;
|
||||
|
||||
/* open the file to read in binary mode */
|
||||
f = fopen(filename, "rb");
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
/* read the header */
|
||||
fli_read_header(f, &fli_header);
|
||||
fseek(f, 128, SEEK_SET);
|
||||
|
||||
bmp = create_bitmap_ex(8, fli_header.width, fli_header.height);
|
||||
old = create_bitmap_ex(8, fli_header.width, fli_header.height);
|
||||
|
||||
/* stretch routine doesn't support bitmaps of different color depths */
|
||||
if (bitmap_color_depth(ji_screen) != 8)
|
||||
fullscreen = false;
|
||||
|
||||
w = fli_header.width;
|
||||
h = fli_header.height;
|
||||
|
||||
if (fullscreen) {
|
||||
double scale;
|
||||
|
||||
if (JI_SCREEN_W-bmp->w > JI_SCREEN_H-bmp->h)
|
||||
scale = (double)JI_SCREEN_W / (double)w;
|
||||
else
|
||||
scale = (double)JI_SCREEN_H / (double)h;
|
||||
|
||||
w = (double)w * (double)scale;
|
||||
h = (double)h * (double)scale;
|
||||
}
|
||||
|
||||
x = JI_SCREEN_W/2 - w/2;
|
||||
y = JI_SCREEN_H/2 - h/2;
|
||||
|
||||
LOCK_VARIABLE(speed_timer);
|
||||
LOCK_FUNCTION(speed_timer_callback);
|
||||
|
||||
speed_timer = 0;
|
||||
install_int_ex(speed_timer_callback, MSEC_TO_TIMER(fli_header.speed));
|
||||
|
||||
frpos = 0;
|
||||
done = false;
|
||||
|
||||
while (!done) {
|
||||
/* read the frame */
|
||||
fli_read_frame(f, &fli_header,
|
||||
(unsigned char *)old->dat, omap,
|
||||
(unsigned char *)bmp->dat, cmap);
|
||||
|
||||
if ((!frpos) || (memcmp (omap, cmap, 768) != 0)) {
|
||||
for (c=i=0; c<256; c++) {
|
||||
pal[c].r = cmap[i++]>>2;
|
||||
pal[c].g = cmap[i++]>>2;
|
||||
pal[c].b = cmap[i++]>>2;
|
||||
}
|
||||
set_palette(pal);
|
||||
memcpy(omap, cmap, 768);
|
||||
}
|
||||
|
||||
if (fullscreen)
|
||||
stretch_blit(bmp, ji_screen,
|
||||
0, 0, fli_header.width, fli_header.height, x, y, w, h);
|
||||
else
|
||||
blit(bmp, ji_screen, 0, 0, x, y, w, h);
|
||||
|
||||
jmanager_refresh_screen();
|
||||
gui_feedback();
|
||||
|
||||
do {
|
||||
if ((*callback) ()) {
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
} while (speed_timer <= 0);
|
||||
|
||||
if ((++frpos) >= fli_header.frames) {
|
||||
if (!loop)
|
||||
break;
|
||||
else {
|
||||
fseek(f, 128, SEEK_SET);
|
||||
frpos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
blit(bmp, old, 0, 0, 0, 0, fli_header.width, fli_header.height);
|
||||
speed_timer--;
|
||||
}
|
||||
|
||||
destroy_bitmap(bmp);
|
||||
destroy_bitmap(old);
|
||||
|
||||
fclose(f);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 DIALOGS_PLAYFLI_H_INCLUDED
|
||||
#define DIALOGS_PLAYFLI_H_INCLUDED
|
||||
|
||||
#include "gui/base.h"
|
||||
|
||||
void play_fli_animation(const char *filename, bool loop, bool fullscreen);
|
||||
|
||||
#endif
|
@ -1,251 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 <allegro/gfx.h>
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "gui/gui.h"
|
||||
|
||||
#include "dialogs/repo.h"
|
||||
#include "ini_file.h"
|
||||
#include "modules/gui.h"
|
||||
|
||||
static void fill_listbox(RepoDlg *repo_dlg);
|
||||
static void kill_listbox(RepoDlg *repo_dlg);
|
||||
|
||||
static int repo_listbox_type();
|
||||
static bool repo_listbox_msg_proc(JWidget widget, Message* msg);
|
||||
|
||||
static void use_command(Button* widget, RepoDlg* repo_dlg);
|
||||
static void add_command(Button* widget, RepoDlg* repo_dlg);
|
||||
static void delete_command(Button* widget, RepoDlg* repo_dlg);
|
||||
|
||||
void ji_show_repo_dlg(RepoDlg *repo_dlg)
|
||||
{
|
||||
Frame* window = new Frame(false, repo_dlg->title);
|
||||
Box* box1 = new Box(JI_HORIZONTAL);
|
||||
Box* box2 = new Box(JI_VERTICAL);
|
||||
View* view = new View();
|
||||
repo_dlg->listbox = jlistbox_new();
|
||||
repo_dlg->button_use = new Button(repo_dlg->use_text);
|
||||
repo_dlg->button_add = new Button("&Add");
|
||||
repo_dlg->button_delete = new Button("&Delete");
|
||||
Button* button_close = new Button("&Close");
|
||||
|
||||
jwidget_add_hook(repo_dlg->listbox, repo_listbox_type(),
|
||||
repo_listbox_msg_proc, repo_dlg);
|
||||
|
||||
repo_dlg->button_use->Click.connect(Bind<void>(&use_command, repo_dlg->button_use, repo_dlg));
|
||||
repo_dlg->button_add->Click.connect(Bind<void>(&add_command, repo_dlg->button_add, repo_dlg));
|
||||
repo_dlg->button_delete->Click.connect(Bind<void>(&delete_command, repo_dlg->button_delete, repo_dlg));
|
||||
button_close->Click.connect(Bind<void>(&Frame::closeWindow, window, button_close));
|
||||
|
||||
jwidget_magnetic(repo_dlg->button_use, true);
|
||||
|
||||
jwidget_expansive(view, true);
|
||||
view->attachToView(repo_dlg->listbox);
|
||||
jwidget_set_min_size(view, JI_SCREEN_W*25/100, JI_SCREEN_H*25/100);
|
||||
|
||||
/* fill the list */
|
||||
fill_listbox(repo_dlg);
|
||||
jlistbox_select_index(repo_dlg->listbox, 0);
|
||||
|
||||
/* no items? */
|
||||
if (jlistbox_get_selected_index(repo_dlg->listbox) != 0) {
|
||||
repo_dlg->button_use->setEnabled(false);
|
||||
repo_dlg->button_delete->setEnabled(false);
|
||||
}
|
||||
|
||||
/* hierarchy */
|
||||
box2->addChild(repo_dlg->button_use);
|
||||
box2->addChild(repo_dlg->button_add);
|
||||
box2->addChild(repo_dlg->button_delete);
|
||||
box2->addChild(button_close);
|
||||
box1->addChild(box2);
|
||||
box1->addChild(view);
|
||||
window->addChild(box1);
|
||||
|
||||
/* default position */
|
||||
window->remap_window();
|
||||
window->center_window();
|
||||
|
||||
/* load window configuration */
|
||||
load_window_pos(window, repo_dlg->config_section);
|
||||
|
||||
/* open window */
|
||||
window->open_window_fg();
|
||||
|
||||
/* kill the list */
|
||||
kill_listbox(repo_dlg);
|
||||
|
||||
/* save window configuration */
|
||||
save_window_pos(window, repo_dlg->config_section);
|
||||
|
||||
jwidget_free(window);
|
||||
}
|
||||
|
||||
static void fill_listbox(RepoDlg *repo_dlg)
|
||||
{
|
||||
/* no item selected (ID=0) */
|
||||
repo_dlg->listitem = 0;
|
||||
|
||||
/* load the entries */
|
||||
if (repo_dlg->load_listbox)
|
||||
(*repo_dlg->load_listbox)(repo_dlg);
|
||||
|
||||
View::getView(repo_dlg->listbox)->updateView();
|
||||
}
|
||||
|
||||
static void kill_listbox(RepoDlg *repo_dlg)
|
||||
{
|
||||
JWidget listbox = repo_dlg->listbox;
|
||||
JWidget listitem;
|
||||
JLink link, next;
|
||||
|
||||
/* save the entries */
|
||||
if (repo_dlg->save_listbox)
|
||||
(*repo_dlg->save_listbox) (repo_dlg);
|
||||
|
||||
/* remove all items */
|
||||
JI_LIST_FOR_EACH_SAFE(listbox->children, link, next) {
|
||||
listitem = reinterpret_cast<JWidget>(link->data);
|
||||
|
||||
repo_dlg->listbox->removeChild(listitem);
|
||||
|
||||
if (repo_dlg->free_listitem) {
|
||||
repo_dlg->listitem = listitem;
|
||||
(*repo_dlg->free_listitem) (repo_dlg);
|
||||
}
|
||||
|
||||
jwidget_free(listitem);
|
||||
}
|
||||
}
|
||||
|
||||
static int repo_listbox_type()
|
||||
{
|
||||
static int type = 0;
|
||||
if (!type)
|
||||
type = ji_register_widget_type();
|
||||
return type;
|
||||
}
|
||||
|
||||
static bool repo_listbox_msg_proc(JWidget widget, Message* msg)
|
||||
{
|
||||
RepoDlg* repo_dlg = reinterpret_cast<RepoDlg*>(jwidget_get_data(widget, repo_listbox_type()));
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_DESTROY:
|
||||
/* do nothing (don't free repo_dlg) */
|
||||
break;
|
||||
|
||||
case JM_SIGNAL:
|
||||
switch (msg->signal.num) {
|
||||
|
||||
case JI_SIGNAL_LISTBOX_CHANGE:
|
||||
repo_dlg->listitem = jlistbox_get_selected_child(widget);
|
||||
|
||||
repo_dlg->button_use->setEnabled(true);
|
||||
repo_dlg->button_delete->setEnabled(true);
|
||||
break;
|
||||
|
||||
case JI_SIGNAL_LISTBOX_SELECT:
|
||||
if (repo_dlg->use_listitem)
|
||||
if (!(*repo_dlg->use_listitem)(repo_dlg))
|
||||
widget->closeWindow();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void use_command(Button* widget, RepoDlg* repo_dlg)
|
||||
{
|
||||
if (repo_dlg->use_listitem) {
|
||||
if (!(*repo_dlg->use_listitem)(repo_dlg))
|
||||
widget->closeWindow();
|
||||
}
|
||||
}
|
||||
|
||||
static void add_command(Button* widget, RepoDlg* repo_dlg)
|
||||
{
|
||||
int ret, added;
|
||||
|
||||
if (repo_dlg->add_listitem) {
|
||||
added = false;
|
||||
ret = (*repo_dlg->add_listitem)(repo_dlg, &added);
|
||||
|
||||
if (added) {
|
||||
/* update the list-box */
|
||||
View::getView(repo_dlg->listbox)->updateView();
|
||||
|
||||
/* select the last item */
|
||||
jlistbox_select_index(repo_dlg->listbox,
|
||||
jlist_length(repo_dlg->listbox->children)-1);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
widget->closeWindow();
|
||||
}
|
||||
}
|
||||
|
||||
static void delete_command(Button* widget, RepoDlg* repo_dlg)
|
||||
{
|
||||
int ret, kill, index, last;
|
||||
|
||||
if (repo_dlg->delete_listitem) {
|
||||
kill = false;
|
||||
ret = (*repo_dlg->delete_listitem) (repo_dlg, &kill);
|
||||
|
||||
if (kill) {
|
||||
index = jlistbox_get_selected_index(repo_dlg->listbox);
|
||||
|
||||
/* delete "repo_dlg->listitem" */
|
||||
repo_dlg->listbox->removeChild(repo_dlg->listitem);
|
||||
|
||||
if (repo_dlg->free_listitem)
|
||||
(*repo_dlg->free_listitem) (repo_dlg);
|
||||
|
||||
jwidget_free(repo_dlg->listitem);
|
||||
|
||||
/* disable buttons */
|
||||
if (!repo_dlg->listbox->children) {
|
||||
repo_dlg->button_use->setEnabled(false);
|
||||
repo_dlg->button_delete->setEnabled(false);
|
||||
}
|
||||
/* select other item */
|
||||
else {
|
||||
last = jlist_length(repo_dlg->listbox->children)-1;
|
||||
|
||||
jlistbox_select_index(repo_dlg->listbox,
|
||||
index > last ? last: index);
|
||||
}
|
||||
|
||||
/* update the list-box */
|
||||
View::getView(repo_dlg->listbox)->updateView();
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
widget->closeWindow();
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/* ASEPRITE
|
||||
* Copyright (C) 2001-2012 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 DIALOGS_REPO_H_INCLUDED
|
||||
#define DIALOGS_REPO_H_INCLUDED
|
||||
|
||||
#include "gui/base.h"
|
||||
|
||||
class Button;
|
||||
|
||||
typedef struct RepoDlg { /* a window to shows repositories
|
||||
(used for mask/paths repositories,
|
||||
and the bookmarks) */
|
||||
|
||||
/**********************************************************************/
|
||||
/* from user */
|
||||
|
||||
const char *config_section;
|
||||
const char *title;
|
||||
const char *use_text;
|
||||
|
||||
/* fill the list box (you should add items to "repo_dlg->listbox") */
|
||||
void (*load_listbox)(struct RepoDlg *repo_dlg);
|
||||
|
||||
/* when the dialog is closed (you should save the modified entries) */
|
||||
void (*save_listbox)(struct RepoDlg *repo_dlg);
|
||||
|
||||
/* free the "user_data" of "repo_dlg->listitem", don't call
|
||||
jwidget_free(), it's called automatically */
|
||||
void (*free_listitem)(struct RepoDlg *repo_dlg);
|
||||
|
||||
/* return false if to close the window, true to continue (use the
|
||||
"repo_dlg->listitem") */
|
||||
bool (*use_listitem)(struct RepoDlg *repo_dlg);
|
||||
bool (*add_listitem)(struct RepoDlg *repo_dlg, int *added);
|
||||
bool (*delete_listitem)(struct RepoDlg *repo_dlg, int *kill);
|
||||
|
||||
void *user_data[4];
|
||||
|
||||
/**********************************************************************/
|
||||
/* for the user */
|
||||
|
||||
JWidget listbox; /* list box */
|
||||
JWidget listitem; /* selected list item */
|
||||
Button* button_use; /* button for usage the selected item */
|
||||
Button* button_add; /* "Add" button */
|
||||
Button* button_delete; /* "Delete" button */
|
||||
} RepoDlg;
|
||||
|
||||
void ji_show_repo_dlg(RepoDlg *repo_dlg);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user