c++ - 同步 : Display a transparent screen over another screen

标签 c++ mobile-phones

我正在使用 Mosync API C++ 进行跨平台移动开发。我正在尝试让一个透明屏幕(里面确实有一个不透明的标签)在另一个屏幕上显示自己,这样我就可以同时看到两个屏幕。

但是屏幕不是透明的,它是黑色的,会发生什么?为什么会这样?我知道这样做是可能的,因为菜单的 Sams CookBook 示例是一个透明屏幕(其中有一个列表框)并且它显示在另一个屏幕的顶部。

为什么你认为我下面的代码没有显示透明屏幕而是黑屏?附上我的小项目示例(包括它的透明.png文件):

#include <MAUtil/Moblet.h>
#include <MAUI/Screen.h>
#include <MAUI/Label.h>
#include <MAUI/Image.h>

using namespace MAUtil;
using namespace MAUI;

#define RES_BLANK 1

class ClearScreen : public Screen
{
    public:
        ClearScreen() : Screen()
        {
            Image *cell = new Image( 0, 0, 400, 800, NULL, true, true, RES_BLANK );
            Label *item = new Label( 10, 300, 200, 200, cell );

            // What SHOULD happen: have the whole screen transparent by having a
            // transparent Image as the background & have a pink label on this screen,
            // Then I should be able to also see parts of MyScreen behind this screen
            // because parts of this are transparent
            // What ACTUALLY happens:
            // This creates an Image that is black (that covers the whole screen)
            // & a pink label on it
            this -> setMain( cell );
        }

    private:
};

class MyScreen : public Screen
{
    public:
        MyScreen() : Screen()
        {
            Label *cell = new Label( 0, 0, 400, 800, NULL );
            Label *item = new Label( 0, 0, 200, 200, cell );
            cell -> setDrawBackground( true );
            cell -> setBackgroundColor( 20000 );
            item -> setDrawBackground( true );
            item -> setBackgroundColor( 90000 );

            this -> setMain( cell );
        }

    private:
};


class MyMoblet : public Moblet
{
    public:
        MyMoblet()
        {
            MyScreen *m = new MyScreen();
            m -> show();
            ClearScreen *c = new ClearScreen();
            c -> show();
        }

        void keyPressEvent(int keyCode, int nativeCode)
        {

        }

        void keyReleaseEvent(int keyCode, int nativeCode)
        {

        }
};

extern "C" int MAMain()
{
    Moblet::run(new MyMoblet());
    return 0;
};

最佳答案

当您调用 show() 方法时,它会隐藏当前屏幕。这是 Screen.cpp 源文件中的部分:

void Screen::show() {
            ...
            if(sCurrentScreen) sCurrentScreen->hide();
            sCurrentScreen = this;
            Engine::getSingleton().setMain(mMain);
            mMain->setEnabled(true);
            mMain->requestRepaint();
            ...
    }

只需使用具有透明颜色的布局和标签。

关于c++ - 同步 : Display a transparent screen over another screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5534649/

相关文章:

android - 在关机状态下为Android手机充电

android - Android 操作系统是否支持 OTA 配置?

css - 如何使用媒体查询定位 3 英寸或更小的小型手机

flash - html5 视频是否支持手机(symbian、android、iphone)开箱即用的 flv?

c++ - 用 C++ 编写的高质量开源文本转语音 (TTS) 引擎

c++ - C1083 : Cannot open include file: 'GL/gl.h' : No such file or directory

c++ - 保留没有文件支持的共享内存 (Linux/Windows) (boost::interprocess)

c++ - boost::date_time (boost-145) 使用带有微秒计算的 64 位 uint,没有截断

c++ - C++ 中传递的参数不完整

android - Google Cardboard 可以在哪些手机/Android 版本上使用?