黑莓自定义幻灯片式位图字段管理器

发布于 2024-08-30 16:17:09 字数 297 浏览 8 评论 0原文

现在,我正在尝试弄清楚如何实现以下内容:

假设我有一个自定义管理器,其中大约有 10 个左右的 BitmapFields 以水平方式布局(类似于 HFM 中包含的幻灯片)。我想要实现的是能够通过 touchEvent 水平移动图像 HFM,其中 BitmapField 将聚焦在自定义管理器的左侧。换句话说,我是否必须为 setHorizo​​ntalScroll 提供一个值,如果是的话,是否只需在用户进行左或右触摸事件时增加该值即可。另外,当 HFM 通过 touchEvent 横向滚动时,如何获得屏幕上给定位置内的字段(即 HFM 上最左侧的字段)的焦点?

Right now, I'm trying to figure out how to implement the following:

Suppose I have a custom Manager that has about 10 or so BitmapFields layed out in a horizontal manner (similar to a slideshow contained in a HFM ) . What I want to achieve is to be able to move the image HFM via touchEvent horizontally, where a BitmapField would take focus on the left-hand side of the custom Manager. In other words, will I have to give a value to setHorizontalScroll and if so, is it a matter of just incrementing that value when the user makes a left or right touch event. Also, how can I get the focus of a Field within a given position on the screen (i.e. the left-most Field on the HFM) when the HFM is scrolling sideways via touchEvent?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-09-06 16:17:09

1 - 是的,setHorizo​​ntalScroll应该可以工作,不要忘记使用 HORIZONTAL_SCROLL 在管理器构造函数

2 中 - 尝试测试每个字段 getContentRect() 用于 EventTouch getX(int)getY(int)

更新

要简化全局字段位置计算,请使用

    public XYPoint getGlobalXY(Field field) {
        XYPoint result = new XYPoint(field.getLeft(), field.getTop());
        if (field.getManager() != null) {
            result.translate(getGlobalXY(field.getManager()));
        }
        return result;
    }

线程安全消息对话框:

    public void showMessage(final String message) {
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                Dialog.inform(message);
            }
        });

    }

示例代码:

class Scr extends MainScreen {
    HorizontalFieldManager hfm;    
    public Scr() {
        add(new LabelField("asdfsad"));
        hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL);
        for (int i = 0; i < 5; i++) {
            Bitmap bmp = new Bitmap(100, 100);
            Graphics g = Graphics.create(bmp);
            g.setFont(g.getFont().derive(100));
            String txt = String.valueOf(i);
            int x = g.getFont().getAdvance(txt);
            g.drawText(txt, x, 0);
            BitmapField bf = new BitmapField(bmp);
            hfm.add(bf);
        }
        add(hfm);
    }        

    protected boolean touchEvent(TouchEvent message) {
        if (message.getEvent() == TouchEvent.CLICK) {
            int x = message.getX(1);
            int y = message.getY(1);
            XYRect r = hfm.getExtent();
            r.setLocation(getGlobalXY(hfm));    
            if (r.contains(x, y)) {
                XYRect rf = hfm.getField(2).getExtent();
                rf.setLocation(getGlobalXY(hfm.getField(2)));    
                if (x < rf.x) {
                    showMessage("left side");
                } else if (x > rf.X2()) {
                    showMessage("right side");
                } else {
                    showMessage("field");
                }
            }
        }
        return super.touchEvent(message);
    }
}

1 - yes, setHorizontalScroll should work, don't forget to use HORIZONTAL_SCROLL in manager constructor

2 - try to test each Field getContentRect() for EventTouch getX(int) and getY(int)

UPDATE

To simplify global field position calculation use

    public XYPoint getGlobalXY(Field field) {
        XYPoint result = new XYPoint(field.getLeft(), field.getTop());
        if (field.getManager() != null) {
            result.translate(getGlobalXY(field.getManager()));
        }
        return result;
    }

Thread safe message dialog:

    public void showMessage(final String message) {
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                Dialog.inform(message);
            }
        });

    }

Sample code:

class Scr extends MainScreen {
    HorizontalFieldManager hfm;    
    public Scr() {
        add(new LabelField("asdfsad"));
        hfm = new HorizontalFieldManager(HORIZONTAL_SCROLL);
        for (int i = 0; i < 5; i++) {
            Bitmap bmp = new Bitmap(100, 100);
            Graphics g = Graphics.create(bmp);
            g.setFont(g.getFont().derive(100));
            String txt = String.valueOf(i);
            int x = g.getFont().getAdvance(txt);
            g.drawText(txt, x, 0);
            BitmapField bf = new BitmapField(bmp);
            hfm.add(bf);
        }
        add(hfm);
    }        

    protected boolean touchEvent(TouchEvent message) {
        if (message.getEvent() == TouchEvent.CLICK) {
            int x = message.getX(1);
            int y = message.getY(1);
            XYRect r = hfm.getExtent();
            r.setLocation(getGlobalXY(hfm));    
            if (r.contains(x, y)) {
                XYRect rf = hfm.getField(2).getExtent();
                rf.setLocation(getGlobalXY(hfm.getField(2)));    
                if (x < rf.x) {
                    showMessage("left side");
                } else if (x > rf.X2()) {
                    showMessage("right side");
                } else {
                    showMessage("field");
                }
            }
        }
        return super.touchEvent(message);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文