riCOM_cpp
This repository contains the C++ implementation of the riCOM (Real Time Centre Of Mass) algorithm for 4D Scanning electron microscopy.
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
SdlImageWindow Class Reference

#include <SdlImageWindow.h>

Public Member Functions

 SdlImageWindow (const char *title)
 
 SdlImageWindow (const char *title, SDL_Surface *srf, int nx, int ny, float scale)
 
void create_window (SDL_Surface *srf, int nx, int ny, float scale)
 
void update_image ()
 

Public Attributes

const char * title
 

Detailed Description

Definition at line 22 of file SdlImageWindow.h.

Constructor & Destructor Documentation

◆ SdlImageWindow() [1/2]

SdlImageWindow::SdlImageWindow ( const char *  title)
explicit

Definition at line 22 of file SdlImageWindow.cpp.

23{
24 this->title = title;
25 this->window = NULL; // Pointer for the window
26 this->renderer = NULL; // Pointer for the renderer
27 this->tex = NULL; // Texture for the window
28 this->srf = NULL; // Surface (data source)
29};
const char * title

◆ SdlImageWindow() [2/2]

SdlImageWindow::SdlImageWindow ( const char *  title,
SDL_Surface *  srf,
int  nx,
int  ny,
float  scale 
)
explicit

Definition at line 16 of file SdlImageWindow.cpp.

17{
18 this->title = title;
19 create_window(srf, nx, ny, scale);
20};
void create_window(SDL_Surface *srf, int nx, int ny, float scale)

Member Function Documentation

◆ create_window()

void SdlImageWindow::create_window ( SDL_Surface *  srf,
int  nx,
int  ny,
float  scale 
)

Definition at line 31 of file SdlImageWindow.cpp.

32{
33 // Creating window
34 window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, scale * nx, scale * ny, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
35 if (window == NULL)
36 {
37 std::cout << "Window could not be created! SDL Error: " << SDL_GetError() << std::endl;
38 }
39 // Creating Renderer
40 renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
41 if (renderer == NULL)
42 {
43 std::cout << "Renderer could not be created! SDL Error: " << SDL_GetError() << std::endl;
44 }
45 // Creating texture for hardware rendering
46 tex = SDL_CreateTexture(renderer, SDL_GetWindowPixelFormat(window), SDL_TEXTUREACCESS_STATIC, nx, ny);
47 if (tex == NULL)
48 {
49 std::cout << "Texture could not be created! SDL Error: " << SDL_GetError() << std::endl;
50 }
51 // Maintain Pixel aspect ratio on resizing
52 if (SDL_RenderSetLogicalSize(renderer, scale * nx, scale * ny) < 0)
53 {
54 std::cout << "Logical size could not be set! SDL Error: " << SDL_GetError() << std::endl;
55 }
56 this->srf = srf;
57}

◆ update_image()

void SdlImageWindow::update_image ( )

Definition at line 59 of file SdlImageWindow.cpp.

60{
61 if (srf != NULL)
62 {
63 if (SDL_UpdateTexture(tex, NULL, srf->pixels, srf->pitch) == -1)
64 {
65 std::cout << "SDL_UpdateTexture failed: " << SDL_GetError() << std::endl;
66 }
67 if (SDL_RenderCopy(renderer, tex, NULL, NULL) == -1)
68 {
69 std::cout << "SDL_RenderCopy failed: " << SDL_GetError() << std::endl;
70 }
71 SDL_RenderPresent(renderer);
72 }
73}

Member Data Documentation

◆ title

const char* SdlImageWindow::title

Definition at line 25 of file SdlImageWindow.h.


The documentation for this class was generated from the following files: