我有一个不同宽度的圆圈。我创建了一个由 Screen1ViewBase 类继承的子类,以访问 WidthChange.cpp 中的“circlewidth”。我可以访问“圆角”。但我无法在 Screen1View.cpp 中调用 Change 函数,因为它不是静态的。我将更改函数设为静态,但这次我无法访问“circlewidth”和 Screen1View 的其他成员。
#ifndef SCREEN1VIEWBASE_HPP
#define SCREEN1VIEWBASE_HPP
#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/canvas/Circle.hpp>
#include <touchgfx/widgets/canvas/PainterRGB565.hpp>
class Screen1ViewBase : public touchgfx::View<Screen1Presenter>
{
public:
Screen1ViewBase();
virtual ~Screen1ViewBase() {}
virtual void setupScreen();
protected:
FrontendApplication& application() {
return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
}
/*
* Member Declarations
*/
touchgfx::Box __background;
touchgfx::Box box1;
touchgfx::Circle circlewidth;
touchgfx::PainterRGB565 circlewidthPainter;
private:
/*
* Canvas Buffer Size
*/
static const uint16_t CANVAS_BUFFER_SIZE = 7200;
uint8_t canvasBuffer[CANVAS_BUFFER_SIZE];
};
#endif // SCREEN1VIEWBASE_HPP
#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void handleTickEvent();
protected:
int lineWidthLimit;
float circleWidthChangeFactor;
};
#endif // SCREEN1VIEW_HPP
#include <gui/screen1_screen/Screen1View.hpp>
#include <gui/WidthChange.hpp>
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::handleTickEvent()
{
WidthChange::Change();
}
这是我的班级声明
#ifndef WIDTHCHANGE_HPP
#define WIDTHCHANGE_HPP
#include <gui/screen1_screen/Screen1View.hpp>
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
class WidthChange : public Screen1View
{
public:
static void Change();
};
#endif
这是声明 Change() 函数的地方
#include <gui/WidthChange.hpp>
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
void WidthChange::Change()
{
float currentRad;
float lineWidth;
circlewidth.invalidate();
circlewidth.getRadius(currentRad);
if (currentRad >= lineWidthLimit)
{
circleWidthChangeFactor = -0.25;
}
else if (currentRad<= 15)
{
circleWidthChangeFactor = 0.25;
}
currentRad = currentRad + circleWidthChangeFactor;
circlewidth.setRadius(currentRad);
circlewidth.getLineWidth(lineWidth);
circlewidth.setLineWidth(lineWidth + 2 * (circleWidthChangeFactor * (-1)));
circlewidth.invalidate();
}
我知道有很多关于它的事情,但我想知道是否有办法在调用 Change 函数时访问整个 Screen1View 成员和 Screen1ViewBase 成员。