alloc pixmap in constructor
This commit is contained in:
parent
212a30dd74
commit
fdc24916cd
3 changed files with 36 additions and 36 deletions
|
|
@ -4,12 +4,13 @@
|
|||
#define WIDTH 720
|
||||
#define HEIGHT 420
|
||||
|
||||
int graph(uint32_t *img, bool &needUpdate);
|
||||
int graph2(uint32_t *img, bool &needUpdate);
|
||||
int mountain(uint32_t *img, bool &needUpdate);
|
||||
int cloud(uint32_t *img, bool &needUpdate);
|
||||
int marble(uint32_t *img, bool &needUpdate);
|
||||
int random(uint32_t *img, bool &needUpdate);
|
||||
int wood(uint32_t *img, bool &needUpdate);
|
||||
int graph(uint32_t *img);
|
||||
int graph2(uint32_t *img);
|
||||
int mountain(uint32_t *img);
|
||||
int cloud(uint32_t *img);
|
||||
int marble(uint32_t *img);
|
||||
int random(uint32_t *img);
|
||||
int wood(uint32_t *img);
|
||||
int test(uint32_t *img);
|
||||
|
||||
#endif
|
||||
|
|
@ -10,39 +10,39 @@
|
|||
|
||||
class WindowManager {
|
||||
public:
|
||||
WindowManager(int width, int height, int (*)(u_int32_t *img, bool &needUpdate));
|
||||
WindowManager(int width, int height, int (*)(u_int32_t *img));
|
||||
~WindowManager();
|
||||
|
||||
u_int32_t *get_image_addr() { return img; }
|
||||
|
||||
void load_render(int (*)(u_int32_t *img, bool &needUpdate));
|
||||
void load_render(int (*)(u_int32_t *img));
|
||||
void loop();
|
||||
private:
|
||||
void update_image(int (*)(u_int32_t *img, bool &needUpdate));
|
||||
void update_image(int (*)(u_int32_t *img));
|
||||
void display_image();
|
||||
void handle_events(XEvent &GeneralEvent);
|
||||
|
||||
int (*render)(u_int32_t *img, bool &needUpdate);
|
||||
std::vector<int (*)(u_int32_t *img, bool &needUpdate)> renderFunctions;
|
||||
uint8_t ptrTabIndex;
|
||||
u_int32_t *img;
|
||||
int WindowX;
|
||||
int WindowY;
|
||||
int WindowWidth;
|
||||
int WindowHeight;
|
||||
int BorderWidth;
|
||||
int WindowDepth;
|
||||
int WindowClass;
|
||||
Visual *WindowVisual;
|
||||
int AttributeValueMask;
|
||||
XSetWindowAttributes WindowAttributes;
|
||||
Window MainWindow;
|
||||
Display *MainDisplay;
|
||||
Window RootWindow;
|
||||
Atom wmDelete;
|
||||
bool isWindowOpen;
|
||||
bool isDisplayReady;
|
||||
bool needUpdate;
|
||||
int (*render)(u_int32_t *img);
|
||||
std::vector<int (*)(u_int32_t *img)> renderFunctions;
|
||||
uint8_t ptrTabIndex;
|
||||
u_int32_t *img;
|
||||
int WindowX;
|
||||
int WindowY;
|
||||
int WindowWidth;
|
||||
int WindowHeight;
|
||||
int BorderWidth;
|
||||
int WindowDepth;
|
||||
int WindowClass;
|
||||
Visual *WindowVisual;
|
||||
int AttributeValueMask;
|
||||
XSetWindowAttributes WindowAttributes;
|
||||
Window MainWindow;
|
||||
Display *MainDisplay;
|
||||
Window RootWindow;
|
||||
Atom wmDelete;
|
||||
bool isWindowOpen;
|
||||
bool isDisplayReady;
|
||||
Pixmap Pixmap;
|
||||
};
|
||||
|
||||
#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||
|
|
|
|||
|
|
@ -31,11 +31,13 @@ WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img
|
|||
XMapWindow(MainDisplay, MainWindow);
|
||||
wmDelete = XInternAtom(MainDisplay, "WM_DELETE_WINDOW", false);
|
||||
XSetWMProtocols(MainDisplay, MainWindow, &wmDelete, 1);
|
||||
Pixmap = XCreatePixmap(MainDisplay, MainWindow, WindowWidth, WindowHeight, 24);
|
||||
load_render(render);
|
||||
isWindowOpen = true;
|
||||
}
|
||||
|
||||
WindowManager::~WindowManager() {
|
||||
XFreePixmap(MainDisplay, Pixmap);
|
||||
XUnmapWindow(this->MainDisplay, this->MainWindow);
|
||||
XDestroyWindow(this->MainDisplay, this->MainWindow);
|
||||
XCloseDisplay(this->MainDisplay);
|
||||
|
|
@ -82,7 +84,6 @@ void WindowManager::loop() {
|
|||
if (isDisplayReady) {
|
||||
update_image(this->render);
|
||||
display_image();
|
||||
// XSync(this->MainDisplay, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -102,10 +103,8 @@ void WindowManager::display_image() {
|
|||
image.bytes_per_line = this->WindowWidth * 4;
|
||||
image.bits_per_pixel = 32;
|
||||
|
||||
const Pixmap pixmap = XCreatePixmap(MainDisplay, MainWindow, WindowWidth, WindowHeight, image.depth);
|
||||
XPutImage(MainDisplay, pixmap, DefaultGC(MainDisplay, 0), &image, 0, 0, 0, 0, WindowWidth, WindowHeight);
|
||||
XCopyArea(MainDisplay, pixmap, MainWindow, DefaultGC(MainDisplay, 0), 0, 0, WindowWidth, WindowHeight, 0, 0);
|
||||
XFreePixmap(MainDisplay, pixmap);
|
||||
XPutImage(MainDisplay, Pixmap, DefaultGC(MainDisplay, 0), &image, 0, 0, 0, 0, WindowWidth, WindowHeight);
|
||||
XCopyArea(MainDisplay, Pixmap, MainWindow, DefaultGC(MainDisplay, 0), 0, 0, WindowWidth, WindowHeight, 0, 0);
|
||||
XFlush(MainDisplay);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue