## brickview.pkg
# Compiled by:
#
src/lib/x-kit/tut/badbricks-game/badbricks-game-app.libstipulate
include package threadkit; # threadkit is from
src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg #
package mps = microthread_preemptive_scheduler; # microthread_preemptive_scheduler is from
src/lib/src/lib/thread-kit/src/core-thread-kit/microthread-preemptive-scheduler.pkg package g2d = geometry2d; # geometry2d is from
src/lib/std/2d/geometry2d.pkg #
package xc = xclient; # xclient is from
src/lib/x-kit/xclient/xclient.pkg #
package bdr = border; # border is from
src/lib/x-kit/widget/old/wrapper/border.pkg package lbl = label; # label is from
src/lib/x-kit/widget/old/leaf/label.pkg package sz = size_preference_wrapper; # size_preference_wrapper is from
src/lib/x-kit/widget/old/wrapper/size-preference-wrapper.pkg package wg = widget; # widget is from
src/lib/x-kit/widget/old/basic/widget.pkg package wt = widget_types; # widget_types is from
src/lib/x-kit/widget/old/basic/widget-types.pkg #
package bj = brick_junk; # brick_junk is from
src/lib/x-kit/tut/badbricks-game/brick-junk.pkgherein
package brickview
: Brickview # Brickview is from
src/lib/x-kit/tut/badbricks-game/brickview.api {
Brickview = BRICKVIEW
{
widget: wg::Widget,
#
highlight: Bool -> Void,
#
set_text_fn: String -> Void,
show_view_fn: String -> Void,
end_view_fn: String -> Void,
#
mark_view_fn: Void -> Void,
norm_view_fn: Void -> Void
};
fun make_brickview
root_window
(pt, brick_slot, palette: bj::Palette)
=
{ foo = palette.brick;
label = lbl::make_label root_window
{
label => "",
font => THE bj::brick_font,
align => wt::HCENTER,
#
foreground => NULL,
background => THE (.brick palette)
};
widget' = sz::make_tight_sized_preference_wrapper
(
lbl::as_widget label,
{ wide => bj::brick_size_wide,
high => bj::brick_size_high
}
);
border = bdr::make_border
{
color => THE palette.dark_lines,
width => 1,
child => widget'
};
(wg::filter_mouse (bdr::as_widget border))
->
(widget, read_mouse_mailop);
plea_slot = make_mailslot ();
fun set_text text me
=
{ lbl::set_label label (lbl::TEXT text);
me;
};
fun show_text (backc, borderc) text _
=
{
lbl::set_background label backc;
#
lbl::set_label label (lbl::TEXT text);
bdr::set_color border borderc;
borderc;
};
show_view = show_text (palette.concrete, THE palette.light_lines);
end_view = show_text (palette.brick, THE palette.light_lines);
mark_view = show_text (palette.mark, THE palette.dark_lines) "ok";
norm_view = show_text (palette.brick, THE palette.dark_lines) "";
hilite = THE palette.highlight_lines;
fun highlight TRUE me => { bdr::set_color border hilite; me; };
highlight FALSE me => { bdr::set_color border me; me; };
end;
fun do_mouse (xc::MOUSE_FIRST_DOWN { mouse_button, ... }, _)
=>
{
put_in_mailslot (brick_slot, bj::DOWN (mouse_button, pt));
TRUE;
};
do_mouse (xc::MOUSE_LAST_UP { mouse_button, ... }, TRUE)
=>
{
put_in_mailslot (brick_slot, bj::UP (mouse_button, pt));
FALSE;
};
do_mouse (xc::MOUSE_LEAVE _, TRUE)
=>
{
put_in_mailslot (brick_slot, bj::CANCEL pt);
FALSE;
};
do_mouse (_, me)
=>
{
me;
};
end;
fun main_imp ((from_mouse', _), me)
=
loop me
where
fun loop (updown, border)
=
loop (
#
do_one_mailop [
#
from_mouse'
==>
(\\ envelope = (do_mouse (xc::get_contents_of_envelope envelope, updown), border)),
take_from_mailslot' plea_slot
==>
(\\ f = (updown, f border))
]
);
end;
fun init_loop ()
=
loop (FALSE, THE palette.dark_lines)
where
fun loop (me as (updown, border))
=
do_one_mailop [
read_mouse_mailop ==>
(\\ mouse_filter_hook = main_imp (mouse_filter_hook, me)),
take_from_mailslot' plea_slot
==>
(\\ f = loop (updown, f border))
];
end;
make_thread "brickview" init_loop;
BRICKVIEW
{
widget,
#
highlight => \\ b = put_in_mailslot (plea_slot, highlight b),
set_text_fn => \\ t = put_in_mailslot (plea_slot, set_text t),
#
show_view_fn => \\ t = put_in_mailslot (plea_slot, show_view t),
end_view_fn => \\ t = put_in_mailslot (plea_slot, end_view t),
#
norm_view_fn => \\ () = put_in_mailslot (plea_slot, norm_view),
mark_view_fn => \\ () = put_in_mailslot (plea_slot, mark_view)
};
};
fun as_widget (BRICKVIEW { widget, ... } )
=
widget;
fun show_view (BRICKVIEW { show_view_fn, ... } ) text = show_view_fn text;
fun end_view (BRICKVIEW { end_view_fn, ... } ) text = end_view_fn text;
fun mark_view (BRICKVIEW { mark_view_fn, ... } ) = mark_view_fn ();
fun norm_view (BRICKVIEW { norm_view_fn, ... } ) = norm_view_fn ();
fun set_text
(BRICKVIEW { set_text_fn, ... } )
text
=
set_text_fn text;
fun highlight_on (BRICKVIEW { highlight, ... } ) = highlight TRUE;
fun highlight_off (BRICKVIEW { highlight, ... } ) = highlight FALSE;
};
end;