add: image manager
This commit is contained in:
parent
18c4896be4
commit
e0d23c9a82
4 changed files with 46 additions and 3 deletions
2
Makefile
2
Makefile
|
|
@ -9,7 +9,7 @@ NAME = window
|
||||||
|
|
||||||
CC = c++
|
CC = c++
|
||||||
CFLAGS = -Wall -Wextra -Werror -g3
|
CFLAGS = -Wall -Wextra -Werror -g3
|
||||||
CPPFLAGS = -std=c++98 -MMD -MP
|
CPPFLAGS = -MMD -MP
|
||||||
BUILDDIR = build/
|
BUILDDIR = build/
|
||||||
INCLUDEDIR = includes/
|
INCLUDEDIR = includes/
|
||||||
DEPENDENCIESDIR = $(BUILDDIR)dependencies/
|
DEPENDENCIESDIR = $(BUILDDIR)dependencies/
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#define NOISE_GENERATOR_WINDOWMANAGER_HPP
|
#define NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <mutex>
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
|
|
||||||
class WindowManager {
|
class WindowManager {
|
||||||
|
|
@ -10,8 +11,12 @@ public:
|
||||||
WindowManager(int width, int height);
|
WindowManager(int width, int height);
|
||||||
~WindowManager();
|
~WindowManager();
|
||||||
|
|
||||||
|
u_int32_t *get_image_addr() { return img; }
|
||||||
|
|
||||||
|
void display_image();
|
||||||
void loop();
|
void loop();
|
||||||
private:
|
private:
|
||||||
|
u_int32_t *img;
|
||||||
int WindowX;
|
int WindowX;
|
||||||
int WindowY;
|
int WindowY;
|
||||||
int WindowWidth;
|
int WindowWidth;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
#include "windowManager/WindowManager.hpp"
|
#include "windowManager/WindowManager.hpp"
|
||||||
|
|
||||||
#define WIDTH 500
|
#define WIDTH 500
|
||||||
|
|
@ -6,7 +7,16 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
WindowManager window(WIDTH, HEIGHT);
|
WindowManager window(WIDTH, HEIGHT);
|
||||||
window.loop();
|
u_int32_t *img = window.get_image_addr();
|
||||||
|
|
||||||
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
|
for (int x = 0; x < WIDTH; x++) {
|
||||||
|
img[y * WIDTH + x] = (y * 255 / HEIGHT) * 0x100 + (x * 255 / WIDTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
window.loop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <csignal>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
WindowManager::WindowManager(int width, int height) :
|
WindowManager::WindowManager(int width, int height) :
|
||||||
WindowX(0), WindowY(0),
|
WindowX(0), WindowY(0),
|
||||||
|
|
@ -13,10 +15,11 @@ WindowManager::WindowManager(int width, int height) :
|
||||||
WindowVisual(CopyFromParent),
|
WindowVisual(CopyFromParent),
|
||||||
AttributeValueMask(CWBackPixel | CWEventMask)
|
AttributeValueMask(CWBackPixel | CWEventMask)
|
||||||
{
|
{
|
||||||
|
img = new u_int32_t[width * height];
|
||||||
MainDisplay = XOpenDisplay(0);
|
MainDisplay = XOpenDisplay(0);
|
||||||
RootWindow = XDefaultRootWindow(MainDisplay);
|
RootWindow = XDefaultRootWindow(MainDisplay);
|
||||||
bzero(&WindowAttributes, sizeof(XSetWindowAttributes));
|
bzero(&WindowAttributes, sizeof(XSetWindowAttributes));
|
||||||
WindowAttributes.background_pixel = 0xffafe9af;
|
WindowAttributes.background_pixel = 0x0;
|
||||||
WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ExposureMask;
|
WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ExposureMask;
|
||||||
|
|
||||||
MainWindow = XCreateWindow(MainDisplay, RootWindow,
|
MainWindow = XCreateWindow(MainDisplay, RootWindow,
|
||||||
|
|
@ -34,6 +37,7 @@ WindowManager::~WindowManager() {
|
||||||
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);
|
||||||
|
delete[] img;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::loop() {
|
void WindowManager::loop() {
|
||||||
|
|
@ -55,6 +59,30 @@ void WindowManager::loop() {
|
||||||
this->isWindowOpen = false;
|
this->isWindowOpen = false;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case Expose:
|
||||||
|
{
|
||||||
|
std::cout << "test" << std::endl;
|
||||||
|
display_image();
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::display_image() {
|
||||||
|
XImage image;
|
||||||
|
|
||||||
|
image.width = WindowWidth;
|
||||||
|
image.height = WindowHeight;
|
||||||
|
image.format = ZPixmap;
|
||||||
|
image.data = reinterpret_cast<char *>(img);
|
||||||
|
image.byte_order = LSBFirst;
|
||||||
|
image.bitmap_unit = 32;
|
||||||
|
image.byte_order = LSBFirst;
|
||||||
|
image.bitmap_pad = 32;
|
||||||
|
image.depth = 24;
|
||||||
|
image.bytes_per_line = this->WindowWidth * 4;
|
||||||
|
image.bits_per_pixel = 32;
|
||||||
|
|
||||||
|
XPutImage(MainDisplay, MainWindow, DefaultGC(MainDisplay, 0), &image, 0, 0, 0, 0, WindowWidth, WindowHeight);
|
||||||
|
XFlush(MainDisplay);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue