#include "KWindow.hpp" ➔ class KWindow

KWindow

KWindow is a class that represent a window. You can display things on it.

#include "KRect.hpp"
#include "KColor.hpp"
#include "KSurface.hpp"
#include "KEvent.hpp"

class KWindow : KRect {
    KEvent event;
};

Constructor

KWindow(std::string name, int width, int height);

Open a window with the specified name, dimensions, icon and flags.

Member

KEvent event;

KEvent class holding events occurring on the window.

Method

bool open(std::string name, int width, int height);
void close();

void show();
void hide();
void resize(int w, int h);

bool is_opened();
bool is_closed();

Methods to manage the window.

void fill(KColor color);
void fill(KRect rect, KColor color);

void draw_rect(KRect rect, KColor color);
void draw_line(int x1, int y1, int x2, int y2, KColor color);

void print(KSurface src);
void print(KSurface src, int x, int y);
void print(KSurface src, int x, int y, int w, int h);

Methods to draw on the window.

void display();

This must be call to display new drawing.
No new drawing will be displayed until display() is called.

Example

KWindow window("example", 520, 380);
KTimer timer(1000/30);

while (not window.event.quit && not window.event.close) {
    window.fill(KColor::Black);
    window.fill(KRect<>(0, 100, 520, 10), KColor::White);
    window.display();

    window.event.update();
    timer.wait();
}