Commit 7b479563 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Plot a more credible rendition of TextArea and ScrollList

Both the TextArea gadget and ScrollList were outputting an unhelpful white rectangle and mysterious black rectangle when asked to plot the gadget prototype (eg. in the gadget palette in ResEd). The black rectangle turned out to represent a scroll bar, though it was the wrong width.
Changed to plot a 2D scrollbar (ala RISC OS 2) then overlay a virtual icon with the name of the gadget type.
main.c:
Relocate helper functions into glib.
Return 'Bad SWI' for unknown subreasons.
glib.c/glib3.c:
Remove various unused functions.
Added new function to plot a grey scrollbar from nested rectangles.
TextArea.c:
Add a vertical, or horixontal, or both, scrollbar plus the label "TextArea".
ScrollList.c:
Add a vertical scrollbar plus the label "ScrollList".

Requires Common-0_25 for the colour defines. Tested in !ResEd in various eigenfactor modes.

Version 0.40. Tagged as 'Gadgets-0_40'
parent 57071f9e
......@@ -13,4 +13,4 @@
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine standalone
amu_machine standalone THROWBACK=-throwback
/* (0.39)
/* (0.40)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.39
#define Module_MajorVersion_CMHG 0.40
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 12 Oct 2015
#define Module_Date_CMHG 28 Nov 2015
#define Module_MajorVersion "0.39"
#define Module_Version 39
#define Module_MajorVersion "0.40"
#define Module_Version 40
#define Module_MinorVersion ""
#define Module_Date "12 Oct 2015"
#define Module_Date "28 Nov 2015"
#define Module_ApplicationDate "12-Oct-15"
#define Module_ApplicationDate "28-Nov-15"
#define Module_ComponentName "Gadgets"
#define Module_ComponentPath "castle/RiscOS/Sources/Toolbox/Gadgets"
#define Module_FullVersion "0.39"
#define Module_HelpVersion "0.39 (12 Oct 2015)"
#define Module_LibraryVersionInfo "0:39"
#define Module_FullVersion "0.40"
#define Module_HelpVersion "0.40 (28 Nov 2015)"
#define Module_LibraryVersionInfo "0:40"
......@@ -60,7 +60,7 @@
#include "TextGadget.h"
#include "ScrollLisP.h"
#include "Sizes.h"
#include "utils.h"
#include "Utils.h"
#ifdef MemCheck_MEMCHECK
#include "MemCheck:MemCheck.h"
......@@ -68,7 +68,7 @@
static int my_icons[2] = {0, -1};
static unsigned int vscroll_width = SCROLLBAR_SIZE;
static unsigned int vscroll_width = SIZES_TOOL_DEFAULT;
static PrivateScrollList **scrolllist_list = NULL;
......@@ -1247,7 +1247,7 @@ _kernel_oserror *scrolllist_plot(ScrollList *sdata)
_kernel_oserror *e;
wimp_GetWindowState state;
wimp_Bbox box;
int x;
wimp_Icon label;
if (redrawing_window == 0)
return NULL;
......@@ -1264,6 +1264,7 @@ _kernel_oserror *scrolllist_plot(ScrollList *sdata)
box.xmax = sdata->hdr.xmax;
box.ymin = sdata->hdr.ymin;
box.ymax = sdata->hdr.ymax;
label.bbox = box;
work_to_screen(&box, &state);
// Plot background
......@@ -1278,11 +1279,17 @@ _kernel_oserror *scrolllist_plot(ScrollList *sdata)
os_plot(PLOT_DRAW, box.xmax, box.ymin);
os_plot(PLOT_DRAW, box.xmax, box.ymax);
// Plot fake scrollbar (black)
colourtrans_set_gcol(0 /* black */, 1<<7, 0);
x = MAX(box.xmax - vscroll_width, box.xmin);
os_plot(PLOT_MOVE, x, box.ymin);
os_plot(PLOT_RECTANGLE_FILL | PLOT_BACK, box.xmax, box.ymax);
box.xmin = MAX(box.xmax - SIZES_TOOL_DEFAULT, box.xmin);
label.bbox.xmax = label.bbox.xmax - (box.xmax - box.xmin);
plot_2d_scrollbar(&box, sdata->foreground, TRUE);
// Overlay a virtual label in the non scrollbar bit
label.flags = wimp_ICONFLAGS_TEXT |
wimp_ICONFLAGS_VCENTRE | wimp_ICONFLAGS_HCENTRE |
(wimp_ICONFLAGS_FORECOL * wimp_BLACK) |
(wimp_ICONFLAGS_BACKCOL * wimp_WHITE);
strcpy(label.data.text, "ScrollList");
wimp_plot_icon(&label);
#ifdef MemCheck_MEMCHECK
MemCheck_UnRegisterMiscBlock(sdata);
......
......@@ -56,7 +56,7 @@
#include "TextAreaP.h"
#include "Font.h"
#include "Sizes.h"
#include "utils.h"
#include "Utils.h"
extern void print_info(FILE *);
......@@ -74,8 +74,8 @@ static PrivateTextArea *dragging = NULL;
static int my_icons[] = {-1};
static unsigned int vscroll_width = SCROLLBAR_SIZE;
static unsigned int hscroll_height = SCROLLBAR_SIZE;
static unsigned int vscroll_width = SIZES_TOOL_DEFAULT;
static unsigned int hscroll_height = SIZES_TOOL_DEFAULT;
static PrivateTextArea **text_area_list = NULL;
......@@ -451,7 +451,8 @@ _kernel_oserror *textarea_plot(TextArea *tdata)
{
wimp_GetWindowState state;
_kernel_oserror *e;
wimp_Bbox box;
wimp_Bbox box, bar;
wimp_Icon label;
state.open.window_handle = redrawing_window;
if ((e = wimp_get_window_state(&state)) != NULL)
......@@ -465,12 +466,16 @@ _kernel_oserror *textarea_plot(TextArea *tdata)
box.ymin = tdata->hdr.ymin;
box.xmax = tdata->hdr.xmax;
box.ymax = tdata->hdr.ymax;
label.bbox = box;
work_to_screen(&box, &state);
colourtrans_set_gcol(tdata->background, 1<<7, 0);
// Plot background
colourtrans_set_gcol(tdata->background, 1<<7, 0);
os_plot(PLOT_MOVE, box.xmin, box.ymin);
os_plot(PLOT_RECTANGLE_FILL | PLOT_BACK,
box.xmax, box.ymax);
// Plot foreground
colourtrans_set_gcol(tdata->foreground, 0, 0);
os_plot(PLOT_DRAW, box.xmin, box.ymax);
os_plot(PLOT_DRAW, box.xmin, box.ymin);
......@@ -480,29 +485,33 @@ _kernel_oserror *textarea_plot(TextArea *tdata)
if (tdata->hdr.flags & TextArea_Scrollbar_Vertical)
{
// Has vertical scrollbar
int x, y;
colourtrans_set_gcol(0 /* black */, 1<<7, 0);
x = MAX(box.xmax - vscroll_width, box.xmin);
y = (tdata->hdr.flags & TextArea_Scrollbar_Horizontal) ?
MIN(box.ymin + hscroll_height, box.ymax) : box.ymin;
os_plot(PLOT_MOVE, x, y);
os_plot(PLOT_RECTANGLE_FILL | PLOT_BACK, box.xmax, box.ymax);
bar = box;
bar.xmin = MAX(bar.xmax - SIZES_TOOL_DEFAULT, bar.xmin);
label.bbox.xmax = label.bbox.xmax - (bar.xmax - bar.xmin);
if (tdata->hdr.flags & TextArea_Scrollbar_Horizontal)
bar.ymin = MIN(bar.ymin + SIZES_TOOL_DEFAULT, bar.ymax);
plot_2d_scrollbar(&bar, tdata->foreground, TRUE);
}
if (tdata->hdr.flags & TextArea_Scrollbar_Horizontal)
{
// Has horizontal scrollbar
int x, y;
colourtrans_set_gcol(0 /* black */, 1<<7, 0);
x = (tdata->hdr.flags & TextArea_Scrollbar_Vertical) ?
MAX(box.xmax - vscroll_width, box.xmin) : box.xmax;
y = MIN(box.ymin + hscroll_height, box.ymax);
os_plot(PLOT_MOVE, box.xmin, box.ymin);
os_plot(PLOT_RECTANGLE_FILL | PLOT_BACK, x, y);
bar = box;
bar.ymax = MIN(bar.ymin + SIZES_TOOL_DEFAULT, bar.ymax);
label.bbox.ymin = label.bbox.ymin + (bar.ymax - bar.ymin);
if (tdata->hdr.flags & TextArea_Scrollbar_Vertical)
bar.xmax = MAX(bar.xmax - SIZES_TOOL_DEFAULT, bar.xmin);
plot_2d_scrollbar(&bar, tdata->foreground, FALSE);
}
// Overlay a virtual label in the non scrollbar bit
label.flags = wimp_ICONFLAGS_TEXT |
wimp_ICONFLAGS_VCENTRE | wimp_ICONFLAGS_HCENTRE |
(wimp_ICONFLAGS_FORECOL * wimp_BLACK) |
(wimp_ICONFLAGS_BACKCOL * wimp_WHITE);
strcpy(label.data.text, "TextArea");
wimp_plot_icon(&label);
#ifdef MemCheck_MEMCHECK
MemCheck_UnRegisterMiscBlock(tdata);
#endif
......
......@@ -19,9 +19,12 @@
#include "swis.h"
#include "twimp.h"
#include "macros.h"
#include "objects/toolbox.h"
#include "objects/window.h"
#include "Sizes.h"
#include "riscos_uti.h"
#include "glib.h"
extern _kernel_oserror *register_gadget_types(unsigned int flags, GadgetExtensionRecord *rec,int SWIno)
......@@ -63,51 +66,6 @@ void mem_free(void *tag)
_swix(Window_SupportExternal, _INR(0,2), 0, 5, tag);
}
int glib_create_icon(wimp_IconCreate *i)
{
_kernel_swi_regs regs;
regs.r[0] = 0;
regs.r[1] = 0;
regs.r[2] = (int) i;
_kernel_swi(Window_SupportExternal,&regs,&regs);
return regs.r[0];
}
int glib_create_gadget(ObjectID o,Gadget *i,int f)
{
_kernel_swi_regs regs;
regs.r[1] = 3;
regs.r[2] = (int) o;
regs.r[3] = (int) i;
regs.r[4] = f;
_kernel_swi(Window_SupportExternal,&regs,&regs);
return regs.r[0];
}
void glib_move_gadget(int type,ObjectID obj,ComponentID id,wimp_Bbox *box)
{
_kernel_swi_regs regs;
FeatureMask features;
features.mask = 0;
features.bits.method = DEFAULT_HANDLER;
features.bits.move = DEFAULT_HANDLER;
register_gadget_type(0, type,0, features.mask,0);
regs.r[0] = 0;
regs.r[1] = (int) obj;
regs.r[2] = Gadget_MoveGadget;
regs.r[3] = (int) id;
regs.r[4] = (int) box;
_kernel_swi(Toolbox_ObjectMiscOp,&regs,&regs);
deregister_gadget_type(0, type ,0);
}
void graphics_window(wimp_Bbox *area)
{
_swix(OS_WriteI+5,0);
......@@ -123,18 +81,91 @@ void graphics_window(wimp_Bbox *area)
}
static wimp_Bbox intersect;
/* convert work area coords to screen coords */
void work_to_screen(wimp_Bbox *wa, wimp_GetWindowState *state)
{
wa->xmin += state->open.visible_area.xmin - state->open.scx;
wa->xmax += state->open.visible_area.xmin - state->open.scx;
wa->ymin += state->open.visible_area.ymax - state->open.scy;
wa->ymax += state->open.visible_area.ymax - state->open.scy;
}
#define min(a,b) ((a>b) ? b:a)
#define max(a,b) ((a>b) ? a:b)
/* convert screen coords to work area */
wimp_Bbox *intersection(wimp_Bbox *a, wimp_Bbox *b)
void screen_to_work(wimp_Bbox *wa, wimp_GetWindowState *state)
{
if ((a->xmin >= b->xmax) || (a->xmax <= b->xmin) || (a->ymin >= b->ymax) || (a->ymax <= b->ymin)) return 0;
intersect.xmin = max(a->xmin,b->xmin);
intersect.xmax = min(a->xmax,b->xmax);
intersect.ymin = max(a->ymin,b->ymin);
intersect.ymax = min(a->ymax,b->ymax);
wa->xmin -= state->open.visible_area.xmin - state->open.scx;
wa->xmax -= state->open.visible_area.xmin - state->open.scx;
return &intersect;
wa->ymin -= state->open.visible_area.ymax - state->open.scy;
wa->ymax -= state->open.visible_area.ymax - state->open.scy;
}
/* modify a box and then colour it in */
static void plot_2d_rect(const wimp_Bbox *bound, wimp_Bbox *rect, int fillcol, int adjx, int adjy)
{
int scalex, scaley;
scalex = sizes_x_scale();
scaley = sizes_y_scale();
// New size
rect->xmin = MIN(rect->xmin + adjx, bound->xmax);
rect->xmax = MAX(rect->xmax - adjx, bound->xmin);
rect->ymin = MIN(rect->ymin + adjy, bound->ymax);
rect->ymax = MAX(rect->ymax - adjy, bound->ymin);
// Plot if it's at least 1 OSU wide and high
if (((rect->ymax - rect->ymin) >= scaley) &&
((rect->xmax - rect->xmin) >= scalex))
{
colourtrans_set_gcol(fillcol, 1<<7, 0);
os_plot(PLOT_MOVE, rect->xmin, rect->ymin);
os_plot(PLOT_RECTANGLE_FILL | PLOT_BACK, rect->xmax, rect->ymax);
}
}
/* plot a fake flat scroll bar */
void plot_2d_scrollbar(const wimp_Bbox *bound, int bordercol, BOOL vertical)
{
int scalex, scaley, insetx, insety;
wimp_Bbox box;
scalex = sizes_x_scale();
scaley = sizes_y_scale();
box = *bound;
// Plot scrollbar inner border 'L' or ''
colourtrans_set_gcol(bordercol, 0, 0);
if (vertical)
{
box.xmin += scalex;
os_plot(PLOT_MOVE, box.xmin, box.ymax);
os_plot(PLOT_DRAW, box.xmin, box.ymin);
os_plot(PLOT_DRAW, box.xmax, box.ymin);
insetx = scalex * (SIZES_SCROLL_WELL_LR / scalex);
insety = scaley * SIZES_SCROLL_WELL_TB;
}
else
{
box.ymax -= scaley;
os_plot(PLOT_MOVE, box.xmin, box.ymax);
os_plot(PLOT_DRAW, box.xmax, box.ymax);
os_plot(PLOT_DRAW, box.xmax, box.ymin);
insetx = scalex * SIZES_SCROLL_WELL_TB;
insety = scaley * (SIZES_SCROLL_WELL_LR / scaley);
}
// Plot scrollbar background (MidLightGrey), 1 pixel in
plot_2d_rect(bound, &box, 0x99999900, scalex, scaley);
// Plot scrollbar border, inset by the well size
plot_2d_rect(bound, &box, bordercol, insetx, insety);
// Plot scrollbar inner (VeryLightGrey), 1 pixel in
plot_2d_rect(bound, &box, 0xDDDDDD00, scalex, scaley);
}
......@@ -18,6 +18,7 @@
#include "kernel.h"
#include "swis.h"
#include "macros.h"
#include "twimp.h"
#include "objects/toolbox.h"
#include "objects/window.h"
......
......@@ -77,28 +77,6 @@ int filter_wimp_events[] =
extern int Resources(void);
#endif
/* convert work area coords to screen coords */
void work_to_screen(wimp_Bbox *wa, wimp_GetWindowState *state)
{
wa->xmin += state->open.visible_area.xmin - state->open.scx;
wa->xmax += state->open.visible_area.xmin - state->open.scx;
wa->ymin += state->open.visible_area.ymax - state->open.scy;
wa->ymax += state->open.visible_area.ymax - state->open.scy;
}
/* convert screen coords to work area */
void screen_to_work(wimp_Bbox *wa, wimp_GetWindowState *state)
{
wa->xmin -= state->open.visible_area.xmin - state->open.scx;
wa->xmax -= state->open.visible_area.xmin - state->open.scx;
wa->ymin -= state->open.visible_area.ymax - state->open.scy;
wa->ymax -= state->open.visible_area.ymax - state->open.scy;
}
static void register_gadgets(void)
{
FeatureMask features;
......@@ -326,7 +304,7 @@ _kernel_oserror *TextGadgets_SWI_handler(int swi_no, _kernel_swi_regs *r,
e = scrolllist_move((int) r->r[1],
(PrivateScrollList *) r->r[3],
(wimp_Bbox *) r->r[5]);
break;
break;
default:
break;
......@@ -380,6 +358,7 @@ _kernel_oserror *TextGadgets_SWI_handler(int swi_no, _kernel_swi_regs *r,
break;
default:
e = error_BAD_SWI;
break;
}
......
......@@ -15,7 +15,10 @@
/* Sizes.h
*/
#define SIZES_TOOL_DEFAULT 44
#define SIZES_TOOL_DEFAULT 42 /* OSU, inc border */
#define SIZES_SCROLL_WELL_LR 7 /* OSU */
#define SIZES_SCROLL_WELL_TB 1 /* Pixel */
#define SIZES_SCROLL_BAR 23 /* OSU */
unsigned int sizes_x_scale (void);
unsigned int sizes_y_scale (void);
......
......@@ -22,24 +22,10 @@
#ifndef _TEXTGADGETS_H
#define _TEXTGADGETS_H
#include "kernel.h"
extern _kernel_oserror *TextGadgets_init(const char *cmd_tail, int podule_base, void *pw);
extern _kernel_oserror *TextGadgets_final(int fatal, int podule, void *pw);
extern void TextGadgets_services(int service_number, _kernel_swi_regs *r, void *pw);
extern _kernel_oserror *TextGadgets_SWI_handler(int swi_offset, _kernel_swi_regs *r, void *pw);
// Horrible. Need to work this out properly and change on mode changes.
#define SCROLLBAR_SIZE 44
extern unsigned int redrawing_window;
extern int filter_toolbox_events[];
extern int filter_wimp_events[];
extern void work_to_screen(wimp_Bbox *box, wimp_GetWindowState *state);
extern void screen_to_work(wimp_Bbox *box, wimp_GetWindowState *state);
extern _kernel_oserror *redraw_gadget(int window_handle, GadgetHeader *hdr);
#ifndef Service_RedrawingWindow
#define Service_RedrawingWindow 0x44ec6
#endif
......
......@@ -83,20 +83,15 @@ void *mem_allocate(int amount);
void mem_free(void *tag);
int glib_create_icon(wimp_IconCreate *i);
int glib_create_gadget(ObjectID,Gadget *i,int f);
void glib_move_gadget(int type, ObjectID obj,ComponentID id,wimp_Bbox *box);
void graphics_window(wimp_Bbox *area);
wimp_Bbox *intersection(wimp_Bbox *a, wimp_Bbox *b);
_kernel_oserror *add_task_interest(FilterTypes type, int *list, int SWI);
_kernel_oserror *remove_task_interest(FilterTypes type,int *list);
_kernel_oserror *glib_plot_gadget(int flags,Gadget *g);
extern void work_to_screen(wimp_Bbox *box, wimp_GetWindowState *state);
extern void screen_to_work(wimp_Bbox *box, wimp_GetWindowState *state);
extern void plot_2d_scrollbar(const wimp_Bbox *, int, BOOL);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment