PreviousUpNext

15.4.1338  src/lib/x-kit/tut/badbricks-game/brickview.pkg

## brickview.pkg

# Compiled by:
#     src/lib/x-kit/tut/badbricks-game/badbricks-game-app.lib


stipulate
    include threadkit;                                  # threadkit                     is from   src/lib/src/lib/thread-kit/src/core-thread-kit/threadkit.pkg
    #
    package xg  =  xgeometry;                           # xgeometry                     is from   src/lib/std/2d/xgeometry.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/wrapper/border.pkg
    package lbl =  label;                               # label                         is from   src/lib/x-kit/widget/leaf/label.pkg
    package sz  =  size_preference_wrapper;             # size_preference_wrapper       is from   src/lib/x-kit/widget/wrapper/size-preference-wrapper.pkg
    package wg  =  widget;                              # widget                        is from   src/lib/x-kit/widget/basic/widget.pkg
    package wt  =  widget_types;                        # widget_types                  is from   src/lib/x-kit/widget/basic/widget-types.pkg
    #
    package bu  =  brick_util;                          # brick_util                    is from   src/lib/x-kit/tut/badbricks-game/brick-util.pkg
herein

    package   brickview
    :         Brickview                                 # Brick_Util                    is from   src/lib/x-kit/tut/badbricks-game/brick-util.pkg
    {
        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: bu::Palette)
            =
            {   foo = palette.brick;

                label
                    =
                    lbl::make_label  root_window
                      {
                        label =>  "",
                        font  =>  THE bu::brick_font,
                        align =>  wt::HCENTER,
                        #
                        foreground =>  NULL,
                        background =>  THE (.brick palette)
                      };

                widget'
                    =
                    sz::make_tight_sized_preference_wrapper
                      (
                        lbl::as_widget label,

                        xg::SIZE { wide =>  bu::brick_size_wide,
                                   high =>  bu::brick_size_high
                                 }
                      );

                border
                    =
                    bdr::make_border
                      {
                        color =>  THE palette.dark_lines,
                        width =>  1,
                        child =>  widget'
                      };

                my (widget, read_mouse_mailop)
                    =
                    wg::filter_mouse (bdr::as_widget  border);

                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, ... }, _)
                        =>
                        {    give (brick_slot, bu::DOWN (mouse_button, pt));
                             TRUE;
                        };

                    do_mouse (xc::MOUSE_LAST_UP { mouse_button, ... }, TRUE)
                        =>
                        {   give (brick_slot, bu::UP (mouse_button, pt));
                            FALSE;
                        };

                    do_mouse (xc::MOUSE_LEAVE _, TRUE)
                        =>
                        {   give (brick_slot, bu::CANCEL pt);
                            FALSE;
                        };

                    do_mouse (_, me)
                        =>
                        me;
                end;


                fun main_imp ((from_mouse', _), me)
                    =
                    loop me
                    where
                        fun loop (updown, border)
                            =
                            loop (
                                #
                                select [
                                    #
                                    from_mouse'
                                        ==>
                                        (fn envelope = (do_mouse  (xc::envelope_contents  envelope,  updown), border)),

                                    take' plea_slot
                                        ==>
                                        (fn f = (updown, f border))
                                ]
                            );
                    end;

                fun init_loop ()
                    =
                    loop (FALSE, THE palette.dark_lines)
                    where
                        fun loop (me as (updown, border))
                            =
                            select [

                                read_mouse_mailop ==>
                                    (fn mouse_filter_hook =  main_imp (mouse_filter_hook, me)),

                                take' plea_slot
                                    ==>
                                    (fn f = loop (updown, f border))
                            ];
                    end;


                make_thread  "brickview"  init_loop;

                BRICKVIEW
                  {
                    widget,
                    #
                    highlight    =>  fn b  =  give (plea_slot, highlight b),
                    set_text_fn  =>  fn t  =  give (plea_slot, set_text t),
                    #
                    show_view_fn =>  fn t  =  give (plea_slot, show_view t),
                    end_view_fn  =>  fn t  =  give (plea_slot, end_view t),
                    #
                    norm_view_fn =>  fn () =  give (plea_slot, norm_view),
                    mark_view_fn =>  fn () =  give (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;



Comments and suggestions to: bugs@mythryl.org

PreviousUpNext