Commit 83811440 authored by Steve Revill's avatar Steve Revill
Browse files

Changes to SpriteFile window to allow selections and sprite edit window...

Changes to SpriteFile window to allow selections and sprite edit window changed to improve positioning accuracy.

Detail:
  * Wimp_EScroll event added to make wheelmouse work.
  * Tool rubber banding now snaps to pixel centres making location easier.
  * flickering of box stopped in move (hand) tool.
  * Bottom left of sprites used in painting aligned with grid and sprite plotted
    directly under moving version.
  * Text painting now plots under the moving version of the text.
  * copy, move and hand tools cancel dragging with Adjust.
  * SpriteFile window changed to allow selections using Select,Adjust or Drag.
  * Alt-Select/Adjust on name allows renaming of sprite.
  * TAB moves rename icon to next sprite.
  * Shift TAB moves rename icon to previous sprite
  * Ctrl-Return renames sprite and moves the rename icon to the
    next sprite.
 V2 changes
  * Rubber band rectangular boxes with 0 width or height drawn as a
   line so they don't disappear.
  * Parallelogram rubber band where all the points are in line drawn
    as a line so they don't disappear.
Admin:
  Tested on Iyonix RO5.10
  Programmer tested only.
Changed by:
  Colin Granville

Version 1.98. Tagged as 'Paint-1_98'
parent 0e1361c6
......@@ -15,3 +15,4 @@
Dir <Obey$Dir>
Echo Cleaning <Obey$Dir> ...
AMU_machine INSTDIR=!Paint clean_all
StripDepnd Makefile
......@@ -107,11 +107,12 @@ DFILES = \
debug.${APP}.Templates
OBJS = o.colours o.main o.menus o.psprite o.sprwindow o.tools o.toolwindow \
o.jpeg o.writepixel
o.jpeg o.writepixel o.AltRename o.PaintLib
OBJSZ = oz.colours oz.main oz.menus oz.psprite oz.sprwindow\
oz.tools oz.toolwindow o.jpeg o.writepixel
oz.tools oz.toolwindow o.jpeg o.writepixel o.AltRename o.PaintLib
OBJSD = od.colours od.ftrace od.guard od.main od.menus\
od.psprite od.sprwindow od.tools od.toolwindow o.jpeg o.m o.writepixel
od.psprite od.sprwindow od.tools od.toolwindow o.jpeg o.m o.writepixel\
o.AltRename o.PaintLib
ASMS = s.colours s.main s.menus s.psprite s.sprwindow s.tools s.toolwindow
INCS = i.colours i.main i.menus i.psprite i.sprwindow i.tools i.toolwindow
......
No preview for this file type
No preview for this file type
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.97"
Module_Version SETA 197
Module_MajorVersion SETS "1.98"
Module_Version SETA 198
Module_MinorVersion SETS ""
Module_Date SETS "22 Jan 2007"
Module_ApplicationDate SETS "22-Jan-07"
Module_Date SETS "27 Jul 2007"
Module_ApplicationDate SETS "27-Jul-07"
Module_ComponentName SETS "Paint"
Module_ComponentPath SETS "RiscOS/Sources/Apps/Paint"
Module_FullVersion SETS "1.97"
Module_HelpVersion SETS "1.97 (22 Jan 2007)"
Module_ComponentPath SETS "castle/RiscOS/Sources/Apps/Paint"
Module_FullVersion SETS "1.98"
Module_HelpVersion SETS "1.98 (27 Jul 2007)"
END
/* (1.97)
/* (1.98)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.2.
*
*/
#define Module_MajorVersion_CMHG 1.97
#define Module_MajorVersion_CMHG 1.98
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 22 Jan 2007
#define Module_Date_CMHG 27 Jul 2007
#define Module_MajorVersion "1.97"
#define Module_Version 197
#define Module_MajorVersion "1.98"
#define Module_Version 198
#define Module_MinorVersion ""
#define Module_Date "22 Jan 2007"
#define Module_Date "27 Jul 2007"
#define Module_ApplicationDate "22-Jan-07"
#define Module_ApplicationDate "27-Jul-07"
#define Module_ComponentName "Paint"
#define Module_ComponentPath "RiscOS/Sources/Apps/Paint"
#define Module_ComponentPath "castle/RiscOS/Sources/Apps/Paint"
#define Module_FullVersion "1.97"
#define Module_HelpVersion "1.97 (22 Jan 2007)"
#define Module_LibraryVersionInfo "1:97"
#define Module_FullVersion "1.98"
#define Module_HelpVersion "1.98 (27 Jul 2007)"
#define Module_LibraryVersionInfo "1:98"
/* Copyright 2007 Castle Technology Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AltRename.h"
#include "bbc.h"
#include "wimpt.h"
#include "werr.h"
#include "string.h"
#include "psprite.h"
#include "PaintLib.h"
#include "os.h"
#include "main.h"
#include "sprite.h"
#include "sprwindow.h"
#include "swis.h"
#include "akbd.h"
static wimp_i rename_icon=-1;
static char rename_buffer[16];
static main_window* rename_window;
static main_sprite* rename_sprite;
static wimp_box rename_bbox;
static int rename_sprites_per_row;
static void AltRename_renamesprite(main_sprite* sprite,char* newname)
{
sprite_id sid;
char name[NAME_LIMIT+1];
sid.tag = sprite_id_name; /*doesn't flex*/
sid.s.name = newname;
if (*newname==0) return;
/* check if new name exists */
if (!sprite_select (sprite->file->spritearea,&sid)) return ;
strncpy(name,psprite_address(sprite)->name,NAME_LIMIT);
name[NAME_LIMIT]=0;
sid.s.name=name;
if (wimpt_complain (sprite_rename
(sprite->file->spritearea, &sid, newname)) !=
NULL) return;
main_set_modified(sprite->file);
sprwindow_set_window_titles (sprite);
/* rename must reset the titles of all the windows open on
the sprite */
if (sprite->colourdialogue != NULL)
{ char new_title [80];
colourpicker_dialogue dialogue;
dialogue.title = new_title;
sprintf (new_title, msgs_lookup ("PntW7"), newname);
ftracef0 ("ColourPicker_UpdateDialogue: setting new title");
wimpt_complain (os_swix3 (ColourPicker_UpdateDialogue,
colourpicker_UPDATE_TITLE, sprite->colourdialogue,
&dialogue));
}
else if (sprite->colourhandle != NULL)
{ wimp_winfo winfo;
wimp_redrawstr redraw_str;
wimp_wstate wstate;
winfo.w = sprite->colourhandle;
wimpt_noerr (PaintLib_get_wind_info (&winfo));
sprintf (winfo.info.title.indirecttext.buffer,
msgs_lookup ("PntW7"), newname);
/*Force redraw of the title bar.*/
wimpt_noerr (wimp_get_wind_state
(sprite->colourhandle, &wstate));
redraw_str.w = sprite->colourhandle;
wimpt_noerr (wimp_getwindowoutline (&redraw_str));
redraw_str.w = -1;
redraw_str.box.y0 = wstate.o.box.y1;
wimpt_noerr (wimp_force_redraw (&redraw_str));
}
}
void AltRename_delete(void)
{
wimp_redrawstr ds;
if (!rename_window) return;
wimp_delete_icon(rename_window->handle,rename_icon);
ds.w=rename_window->handle;
ds.box=rename_bbox;
wimp_force_redraw(&ds);
rename_window=0;
}
static int AltRename_sprites_per_row(int* toggled)
{
wimp_wstate ws;
int width;
if (!rename_window) return 0;
if (rename_window->data->file.fullinfo)
width = main_FILER_FullInfoWidth;
else
width = main_FILER_TotalWidth;
wimp_get_wind_state(rename_window->handle,&ws);
if (toggled) *toggled=(ws.flags & wimp_WCLICK_TOGGLE);
width=(ws.o.box.x1-ws.o.box.x0)/width;
return width?width:1;
}
void AltRename_start(main_window* window, main_sprite* sprite)
{
wimp_box bbox;
psprite_info sinfo;
wimp_icreate icon;
wimp_wstate ws;
int y,scy;
if (!window || ! sprite) return;
if (window==rename_window && sprite==rename_sprite) return;
AltRename_delete();
if (!main_get_all_sprite_bboxes (window,sprite,&bbox,0,&icon.i.box))
return;
if (window->data->file.fullinfo)
icon.i.box.x1=icon.i.box.x0+12*main_FILER_TextWidth;
else
{
icon.i.box.x0=bbox.x0;
icon.i.box.x1=bbox.x1;
}
icon.w=window->handle;
icon.i.flags=(wimp_iconflags)(wimp_ITEXT | wimp_INDIRECT | wimp_IHCENTRE |
wimp_IFILLED | wimp_IBORDER |
(7*wimp_IFORECOL) | (0*wimp_IBACKCOL) |
(wimp_BWRITABLE*wimp_IBTYPE));
icon.i.data.indirecttext.buffer=rename_buffer;
icon.i.data.indirecttext.validstring="";
icon.i.data.indirecttext.bufflen=NAME_LIMIT+1;
psprite_read_full_info (sprite, &sinfo);
strcpy(rename_buffer,sinfo.name);
if (wimpt_complain(wimp_create_icon(&icon,&rename_icon))) return;
wimp_redrawstr ds;
wimp_caretstr caret;
rename_window=window;
rename_sprite=sprite;
ds.w=icon.w;
ds.box=icon.i.box;
rename_bbox=ds.box;
rename_sprites_per_row=AltRename_sprites_per_row(0);
caret.w=window->handle;
caret.i=rename_icon;
caret.x=caret.y=0;
caret.height=-1;
caret.index=strlen(sinfo.name);
wimp_set_caret_pos(&caret);
wimp_force_redraw(&ds);
wimp_get_wind_state(window->handle,&ws);
scy=ws.o.y;
y=WORKAREA_TO_SCREEN_Y(&ws,bbox.y1);
if (y>ws.o.box.y1)
ws.o.y+=(y-ws.o.box.y1);
y=WORKAREA_TO_SCREEN_Y(&ws,bbox.y0);
if (y<ws.o.box.y0)
ws.o.y+=(y-ws.o.box.y0);
if (scy != ws.o.y) wimp_open_wind(&ws.o);
}
BOOL AltRename_claim_event(wimp_eventstr *e,main_window* window)
{
if (!rename_window) return 0;
switch (e->e)
{
case wimp_EBUT:
if (window->handle!=rename_window->handle ||
(e->data.but.m.bbits & 2))
{
AltRename_delete();
break;
}
if ( e->data.but.m.i==rename_icon &&
window->handle==rename_window->handle) return 1;
if (e->data.but.m.bbits & (wimp_BCLICKLEFT | wimp_BCLICKRIGHT))
{
AltRename_delete();
break;
}
return 1;
case wimp_EOPEN:
{
int wid;
if (window->handle==rename_window->handle)
{
int toggled;
wid = AltRename_sprites_per_row(&toggled);
if (wid != rename_sprites_per_row || toggled)
AltRename_delete();
}
break;
}
case wimp_EKEY:
if (window->handle!=rename_window->handle) break;
switch (e->data.key.chcode)
{
case 13:
AltRename_renamesprite(rename_sprite,rename_buffer);
if (!akbd_pollctl())
{
AltRename_delete();
break;
}
// fall through
case 0x18A: /* TAB - next sprite */
{
main_sprite* sprite=rename_sprite->link;
if (sprite==0) sprite=rename_window->data->file.sprites;
AltRename_start(rename_window,sprite);
}
break;
case 0x19A: /* Shift TAB - previous sprite */
{
main_sprite* sprite=rename_sprite;
for (sprite=rename_window->data->file.sprites;
!(sprite->link==0 || sprite->link==rename_sprite);
sprite=sprite->link);
AltRename_start(rename_window,sprite);
}
break;
}
}
return 0;
}
......@@ -84,6 +84,8 @@
#include "colours.h"
#include "MenuD.h"
#include "trace.h"
#include "PaintLib.h"
#include "AltRename.h"
#undef ColourPicker_UpdateDialogue
#define ColourPicker_UpdateDialogue 0x47704
......@@ -111,6 +113,7 @@ static menu
spritefile_misc_menu,
filedisplay_menu,
sprite_colour_menu,
sprite_selection_menu,
sprite_misc_menu;
static char Spritename [22];
......@@ -731,13 +734,35 @@ static BOOL buffer_sprite_palette (void *shandle, int *max)
return mysendbuf (&pp, len, max, 0);
}
static void menus_save_selection (main_window* window)
{
ftracef0 ("menus_save_selection\n");
if (window->selection.count==1)
{
main_sprite* sprite;
for (sprite=window->data->file.sprites;sprite;sprite=sprite->link)
{
if (sprite->flags & MSF_SELECTED) break;
}
if (sprite) menus_save_sprite(sprite);
return;
}
ftracef1 ("sprite called \"%s\"\n", name);
myxfersend (SPRITE_FILE,"Selection",main_selection_file_size(window),main_save_selection,0,0,window);
}
void menus_save_sprite (main_sprite *sprite)
{ char name [NAME_LIMIT + 1];
ftracef0 ("menus_save_sprite\n");
(void) COPY_N (name, psprite_address (sprite)->name, NAME_LIMIT);
ftracef1 ("sprite called \"%s\"\n", name);
myxfersend (SPRITE_FILE, name,
psprite_address (sprite)->next + sizeof (sprite_area),
&save_sprite, &buffer_sprite,
......@@ -904,7 +929,7 @@ static void insdel_EOR (void)
wimp_winfo curr;
curr.w = sprw->window->handle;
wimpt_noerr (wimp_get_wind_info (&curr));
wimpt_noerr (PaintLib_get_wind_info (&curr));
rds.w = sprw->window->handle;
rds.box = main_big_extent;
wimpt_noerr (wimp_update_wind (&rds, &more));
......@@ -922,14 +947,18 @@ static void insdel_EOR (void)
if (insdel_rowfield != -1)
{ ftracef0 ("insdel_EOR row\n");
bbc_rectanglefill (MAX (x0, 0), y0 + Row*ymul/ydiv,
0x1FFF, (insdel_row - Row)*ymul/ydiv);
int top=MAX(insdel_row,Row)+1;
int bottom=MIN(insdel_row,Row);
bbc_rectanglefill (MAX (x0, 0), y0 + bottom*ymul/ydiv,
0x1FFF, (top - bottom)*ymul/ydiv);
}
if (insdel_colfield != -1)
{ ftracef0 ("insdel_EOR column\n");
bbc_rectanglefill (x0 + Column*xmul/xdiv, MAX (y0, 0),
(insdel_col - Column)*xmul/xdiv, 0x1FFF);
int left=MIN(insdel_col,Column);
int right=MAX(insdel_col,Column)+1;
bbc_rectanglefill (x0 + left*xmul/xdiv, MAX (y0, 0),
(right-left)*xmul/xdiv, 0x1FFF);
}
wimpt_noerr (wimp_get_rectangle (&rds, &more));
......@@ -966,29 +995,21 @@ static void insdeltool_null (main_window *window, wimp_mousestr *mpos)
{ ftracef0 ("insdeltool_null\n");
if (mpos->w == window->handle)
{ int x, y, tempx, tempy;
main_scaling_block *ms = &window->data->sprite.sprite->mode;
tools_mouse_to_extent_coords (window, mpos, &x, &y);
tempx = x / ms->scale_xmul;
/* Do integer ceil() in case the xmul is a non integer multiple */
x = tempx + (((tempx * ms->scale_xmul) < x ) ? 1 : 0);
tempy = y / ms->scale_ymul;
/* Do integer ceil() in case the ymul is a non integer multiple */
y = tempy + (((tempy * ms->scale_ymul) < y ) ? 1 : 0);
ftracef2 ("extent coords are (%d, %d)\n", x, y);
{
int x, y;
tools_mouse_to_pixel (window, mpos, &x, &y);
if (x == Column) x = Column + 1;
if (y == Row) y = Row + 1;
ftracef2 ("extent coords are (%d, %d)\n", x, y);
if (x != insdel_col || y != insdel_row)
{ insdel_EOR (); /* remove old data */
insdel_col = x; insdel_row = y;
if (insdel_rowfield != -1)
dbox_setnumeric (insdel_d, 0, abs (insdel_row - Row));
dbox_setnumeric (insdel_d, 0, abs (insdel_row - Row)+1);
if (insdel_colfield != -1)
dbox_setnumeric (insdel_d, 0, abs (insdel_col - Column));
dbox_setnumeric (insdel_d, 0, abs (insdel_col - Column)+1);
insdel_EOR (); /* EOR on the new */
}
......@@ -1015,15 +1036,19 @@ static void insdeltool_redraw (main_window *window, int x0, int y0)
#endif
if (insdel_rowfield != -1)
{ ftracef0 ("insdeltool_redraw: row\n");
bbc_rectanglefill (MAX (x0, 0), y0 + Row*ymul/ydiv,
0x1FFF, (insdel_row - Row)*ymul/ydiv);
{ ftracef0 ("insdel_EOR row\n");
int top=MAX(insdel_row,Row)+1;
int bottom=MIN(insdel_row,Row);
bbc_rectanglefill (MAX (x0, 0), y0 + bottom*ymul/ydiv,
0x1FFF, (top - bottom)*ymul/ydiv);
}
if (insdel_colfield != -1)
{ ftracef0 ("insdeltool_redraw: column\n");
bbc_rectanglefill (x0 + Column*xmul/xdiv, MAX (y0, 0),
(insdel_col - Column)*xmul/xdiv, 0x1FFF);
{ ftracef0 ("insdel_EOR column\n");
int left=MIN(insdel_col,Column);
int right=MAX(insdel_col,Column)+1;
bbc_rectanglefill (x0 + left*xmul/xdiv, MAX (y0, 0),
(right-left)*xmul/xdiv, 0x1FFF);
}
}
}
......@@ -1059,7 +1084,7 @@ static void start_insdel_graphics (main_sprite *sprite, int rowfield,
insdel_tool = toolwindow_current_tool;
spencer (else ftracef0 ("!"))
insdel_row = Row + 1; insdel_col = Column + 1;
insdel_row = Row; insdel_col = Column;
/* stop the tool in all sprite windows */
for (window = main_windows; window != NULL; window = window->link)
......@@ -2394,37 +2419,62 @@ void menus_file_handler (void *handle, char *hit)
break;
case m_Sprite:
if (hit_sprite != NULL)
switch (hit [1])
{ case m_Sprite_Delete:
{ sprite_area *sarea = hit_sprite->file->spritearea;
{
case m_Sprite_SelectAll:
main_select_all(window);
break;
case m_Sprite_ClearAll:
main_clear_all(window);
break;
case m_Sprite_Delete:
{
main_sprite* sprite;
main_sprite* next;
int count;
int total=window->selection.count;
if (window->selection.count==0) break;
visdelay_begin();
for (count=1,sprite=window->data->file.sprites;sprite;sprite=next,count++)
{
visdelay_percent(count*100/total);
next=sprite->link;
if (sprite->flags & MSF_SELECTED)
{
sprite_area *sarea = sprite->file->spritearea;
#if FIXDELSPR
main_file *spritefile = hit_sprite->file;
main_file *spritefile = sprite->file;
#endif
sprite_id sid;
char name [NAME_LIMIT + 1];
sprite_id sid;
char name [NAME_LIMIT + 1];
sid.tag = sprite_id_name; /*doesn't flex*/
sid.s.name = COPY_N (name, psprite_address (hit_sprite)->name,
NAME_LIMIT);
sid.tag = sprite_id_name; /*doesn't flex*/
sid.s.name = COPY_N (name, psprite_address (sprite)->name,
NAME_LIMIT);
ftracef0 ("Edit delete\n");
ftracef0 ("Edit delete\n");
/*The next two lines used to be reversed, but it could give a
fatal error. So do it this way*/
wimpt_complain (sprite_delete (sarea, &sid));
/*The next two lines used to be reversed, but it could give a
fatal error. So do it this way*/
wimpt_complain (sprite_delete (sarea, &sid));
#if FIXDELSPR
menus_ensure_size(&spritefile->spritearea,0);
menus_ensure_size(&spritefile->spritearea,0);
#endif
psprite_delete (hit_sprite);
ftracef0("do menus_file_has_changed\n");
menus_file_has_changed (window);
ftracef0("do menus_ensure_size(,0)\n");
psprite_delete (window,sprite);
ftracef0("do menus_file_has_changed\n");
menus_file_has_changed (window);
ftracef0("do menus_ensure_size(,0)\n");
#if !FIXDELSPR
menus_ensure_size (&hit_sprite->file->spritearea, 0);
menus_ensure_size (&sprite->file->spritearea, 0);
#endif
}
}
visdelay_end();
}
break;
break;
case m_Sprite_Copy:
case m_Sprite_Rename:
......@@ -2479,7 +2529,6 @@ void menus_file_handler (void *handle, char *hit)
(hit_sprite->file->spritearea, &sid, spritenamebuffer)) !=
NULL)
break;
menus_file_has_changed (window);
sprwindow_set_window_titles (hit_sprite);
......@@ -2502,7 +2551,7 @@ void menus_file_handler (void *handle, char *hit)
wimp_wstate wstate;
winfo.w = hit_sprite->colourhandle;
wimpt_noerr (wimp_get_wind_info (&winfo));
wimpt_noerr (PaintLib_get_wind_info (&winfo));
sprintf (winfo.info.title.indirecttext.buffer,
msgs_lookup ("PntW7"), spritenamebuffer);
......@@ -2523,7 +2572,7 @@ void menus_file_handler (void *handle, char *hit)
case m_Sprite_Save:
ftracef1 ("File sprite save %x\n", hit_sprite);
if (hit [2])
menus_save_sprite (hit_sprite);
menus_save_selection (window);
break;
case m_Sprite_Info:
......@@ -2560,7 +2609,7 @@ void menus_file_handler (void *handle, char *hit)
/*Change window width to allow one full item, if it is less.*/
curr.w = window->handle;
wimpt_noerr (wimp_get_wind_info (&curr));
wimpt_noerr (PaintLib_get_wind_info (&curr));
ftracef2 ("current width is %d; need %d\n",
curr.info.box.x1 - curr.info.box.x0,
......@@ -2700,16 +2749,19 @@ static void hack_entry (menu menyoo, int entryno, char *name)
menu menus_file_maker (void *handle)
{ main_file *file = &((main_window *) handle)->data->file;
{
main_window* window =(main_window *) handle;
main_file *file = &window->data->file;