小编Nik*_*pol的帖子

为类型列表创建别名并将其作为模板参数传递

我使用可变参数模板来实现访问者模式:

template<typename... Types>
class Visitor;

template<typename Type>
class Visitor<Type> {
    public:
        virtual void visit(Type &visitable) = 0;
};

template<typename Type, typename... Types>
class Visitor<Type, Types...>: public Visitor<Types...> {
    public:
        using Visitor<Types...>::visit;

        virtual void visit(Type &visitable) = 0;
};


template<typename... Types>
class VisitableInterface {
    public:
        virtual void accept(Visitor<Types...> &visitor) = 0;
};

template<typename Derived, typename... Types>
class Visitable : public VisitableInterface<Types...> {
    public:
        virtual void accept(Visitor<Types...> &visitor) {
            visitor.visit(static_cast<Derived&>(*this));
        }
};

class IntegerElement;
class StringElement;
class BoxElement;
class ImageElement;

class IntegerElement: …
Run Code Online (Sandbox Code Playgroud)

c++ crtp variadic-templates c++11 c++14

7
推荐指数
1
解决办法
418
查看次数

如何强制 Java FX 场景刷新?

我有一个 Java FX 场景,带有一个开始按钮和几个代表地图图块的矩形。我还绘制了一个代表我的探险家的球体(它必须探索地图),但我在运行动画时遇到了困难。

在开始按钮的 OnMouseClicked 处理程序中,我启动了一个用于探索地图的算法,该算法改变了球体的位置和已访问过的图块的颜色。问题是在算法运行时场景不会自行更新,所以我只能看到最终场景的样子(在算法停止运行之后)。如何强制场景更新以便我可以按顺序查看所有颜色更改?

后期编辑:

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Test extends Application {

private static final double boxOuterSize = 50;
private static final double boxInnerSize = 48;
private static final double boxCornerRadius = 20;

private Stage applicationStage;
private Scene applicationScene;

private static double   sceneWidth  = 1024;
private static double   sceneHeight = 800;
private …
Run Code Online (Sandbox Code Playgroud)

java animation javafx

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

animation ×1

c++ ×1

c++11 ×1

c++14 ×1

crtp ×1

java ×1

javafx ×1

variadic-templates ×1