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 WIDTH 720
|
||||||
#define HEIGHT 420
|
#define HEIGHT 420
|
||||||
|
|
||||||
int graph(uint32_t *img, bool &needUpdate);
|
int graph(uint32_t *img);
|
||||||
int graph2(uint32_t *img, bool &needUpdate);
|
int graph2(uint32_t *img);
|
||||||
int mountain(uint32_t *img, bool &needUpdate);
|
int mountain(uint32_t *img);
|
||||||
int cloud(uint32_t *img, bool &needUpdate);
|
int cloud(uint32_t *img);
|
||||||
int marble(uint32_t *img, bool &needUpdate);
|
int marble(uint32_t *img);
|
||||||
int random(uint32_t *img, bool &needUpdate);
|
int random(uint32_t *img);
|
||||||
int wood(uint32_t *img, bool &needUpdate);
|
int wood(uint32_t *img);
|
||||||
|
int test(uint32_t *img);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -10,20 +10,20 @@
|
||||||
|
|
||||||
class WindowManager {
|
class WindowManager {
|
||||||
public:
|
public:
|
||||||
WindowManager(int width, int height, int (*)(u_int32_t *img, bool &needUpdate));
|
WindowManager(int width, int height, int (*)(u_int32_t *img));
|
||||||
~WindowManager();
|
~WindowManager();
|
||||||
|
|
||||||
u_int32_t *get_image_addr() { return img; }
|
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();
|
void loop();
|
||||||
private:
|
private:
|
||||||
void update_image(int (*)(u_int32_t *img, bool &needUpdate));
|
void update_image(int (*)(u_int32_t *img));
|
||||||
void display_image();
|
void display_image();
|
||||||
void handle_events(XEvent &GeneralEvent);
|
void handle_events(XEvent &GeneralEvent);
|
||||||
|
|
||||||
int (*render)(u_int32_t *img, bool &needUpdate);
|
int (*render)(u_int32_t *img);
|
||||||
std::vector<int (*)(u_int32_t *img, bool &needUpdate)> renderFunctions;
|
std::vector<int (*)(u_int32_t *img)> renderFunctions;
|
||||||
uint8_t ptrTabIndex;
|
uint8_t ptrTabIndex;
|
||||||
u_int32_t *img;
|
u_int32_t *img;
|
||||||
int WindowX;
|
int WindowX;
|
||||||
|
|
@ -42,7 +42,7 @@ private:
|
||||||
Atom wmDelete;
|
Atom wmDelete;
|
||||||
bool isWindowOpen;
|
bool isWindowOpen;
|
||||||
bool isDisplayReady;
|
bool isDisplayReady;
|
||||||
bool needUpdate;
|
Pixmap Pixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP
|
#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,13 @@ WindowManager::WindowManager(int width, int height, int (*render)(u_int32_t *img
|
||||||
XMapWindow(MainDisplay, MainWindow);
|
XMapWindow(MainDisplay, MainWindow);
|
||||||
wmDelete = XInternAtom(MainDisplay, "WM_DELETE_WINDOW", false);
|
wmDelete = XInternAtom(MainDisplay, "WM_DELETE_WINDOW", false);
|
||||||
XSetWMProtocols(MainDisplay, MainWindow, &wmDelete, 1);
|
XSetWMProtocols(MainDisplay, MainWindow, &wmDelete, 1);
|
||||||
|
Pixmap = XCreatePixmap(MainDisplay, MainWindow, WindowWidth, WindowHeight, 24);
|
||||||
load_render(render);
|
load_render(render);
|
||||||
isWindowOpen = true;
|
isWindowOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowManager::~WindowManager() {
|
WindowManager::~WindowManager() {
|
||||||
|
XFreePixmap(MainDisplay, Pixmap);
|
||||||
XUnmapWindow(this->MainDisplay, this->MainWindow);
|
XUnmapWindow(this->MainDisplay, this->MainWindow);
|
||||||
XDestroyWindow(this->MainDisplay, this->MainWindow);
|
XDestroyWindow(this->MainDisplay, this->MainWindow);
|
||||||
XCloseDisplay(this->MainDisplay);
|
XCloseDisplay(this->MainDisplay);
|
||||||
|
|
@ -82,7 +84,6 @@ void WindowManager::loop() {
|
||||||
if (isDisplayReady) {
|
if (isDisplayReady) {
|
||||||
update_image(this->render);
|
update_image(this->render);
|
||||||
display_image();
|
display_image();
|
||||||
// XSync(this->MainDisplay, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,10 +103,8 @@ void WindowManager::display_image() {
|
||||||
image.bytes_per_line = this->WindowWidth * 4;
|
image.bytes_per_line = this->WindowWidth * 4;
|
||||||
image.bits_per_pixel = 32;
|
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);
|
||||||
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);
|
||||||
XCopyArea(MainDisplay, pixmap, MainWindow, DefaultGC(MainDisplay, 0), 0, 0, WindowWidth, WindowHeight, 0, 0);
|
|
||||||
XFreePixmap(MainDisplay, pixmap);
|
|
||||||
XFlush(MainDisplay);
|
XFlush(MainDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue