我正在做一个简单的程序,支持图形用户界面在DOS上使用Allegro4。为了实现鼠标操作,我创建了一个shape对象来表示鼠标的当前信息。Allegro提供了许多有用的全局变量,如mouse_x、mouse_y、mouse_b等。只有在通过以下代码安装鼠标驱动程序后,才能使用这些变量。

代码语言:javascript复制install_mouse();这是我的MousePointerObjectClass。

代码语言:javascript复制class MousePointerObject : public GameObject {

public:

MousePointerObject(Scene *scene, std::shared_ptr parent = nullptr, std::string res = "");

virtual void preupdate();

virtual void collides(GameObject &other);

void notCollides(GameObject &other);

private:

int pressed_;

int released_;

friend class Scene;

};

MousePointerObject::MousePointerObject(Scene *scene, std::shared_ptr parent, std::string res)

: GameObject (scene, parent)

{

setRenderer(new MousePointerRenderer(res + "/renderer"));

setCollider(new PointCollider({0, 0}));

}

void MousePointerObject::preupdate()

{

place(Vector(mouse_x, mouse_y));

static int held_buttons = 0;

int changed = mouse_b ^ held_buttons;

pressed_ = changed & mouse_b;

released_ = changed & ~mouse_b;

held_buttons = mouse_b;

}

void MousePointerObject::collides(GameObject &other)

{

if (pressed_ > 0)

other.mouseDown(pressed_);

if (released_ > 0)

other.mouseUp(released_, true);

other.mouse_inside_ = true;

}

void MousePointerObject::notCollides(GameObject &other)

{

other.mouse_inside_ = false;

if (released_ > 0)

other.mouseUp(released_, false);

}我用DJGPP在Ubuntu上交叉编译了这个程序,它在Ubuntu和Real Dos上运行得很好,没有任何冲突。但是当它要在Dosbox或Dosbox-x上运行时,它会导致段故障。无论鼠标指针是否显示在屏幕上,一旦调用install_mouse(),当我移动鼠标指针时,DOSBOX会意外退出。我费了很大力气来解决这个问题,但它们根本不起作用。

任何建议都将不胜感激。

德国中英文地名对照表
【科普知识】冬天手机为啥耗电快?这几招让手机电量更耐用