Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Diego Pérez Peña
/
PAG_p1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5493a422
authored
Sep 19, 2025
by
Diego Pérez Peña
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Ventana de color terminada y de mensajes creada
parent
42284a54
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
34 deletions
BackgroundWindow.cpp
GUI.cpp
GUI.h
LogWindow.cpp
LogWindow.h
Renderer.cpp
Renderer.h
main.cpp
BackgroundWindow.cpp
View file @
5493a422
...
...
@@ -4,6 +4,7 @@
#include "BackgroundWindow.h"
#include <imgui.h>
#include <glm/vec3.hpp>
BackgroundWindow
::
BackgroundWindow
()
{
...
...
@@ -19,5 +20,15 @@ void BackgroundWindow::warnListeners() {
}
void
BackgroundWindow
::
render
()
{
// TODO: Implementar
ImGui
::
SetNextWindowPos
(
ImVec2
(
10
,
10
),
ImGuiCond_Once
);
if
(
ImGui
::
Begin
(
"Color de fondo"
)
)
{
// La ventana está desplegada
ImGui
::
SetWindowFontScale
(
1.0
f
);
// Escalamos el texto si fuera necesario
// Pintamos los controles
ImGui
::
ColorPicker3
(
"Selector de color"
,
(
float
*
)
&
color_fondo
,
ImGuiColorEditFlags_PickerHueWheel
|
ImGuiColorEditFlags_NoAlpha
);
warnListeners
();
}
// Si la ventana no está desplegada, Begin devuelve false
ImGui
::
End
();
}
GUI.cpp
View file @
5493a422
...
...
@@ -11,10 +11,15 @@
#include <imgui.h>
#include <imgui_impl_opengl3.h>
#include "Renderer.h"
PAG
::
GUI
*
PAG
::
GUI
::
instancia
=
nullptr
;
ImVec4
PAG
::
GUI
::
color_fondo
=
ImVec4
(
0.6
f
,
0.6
f
,
0.6
f
,
1.0
f
);
BackgroundWindow
PAG
::
GUI
::
background
=
BackgroundWindow
();
LogWindow
PAG
::
GUI
::
log
=
LogWindow
();
PAG
::
GUI
::
GUI
()
{
}
PAG
::
GUI
::
GUI
()
{
background
.
addListener
(
&
PAG
::
Renderer
::
getInstancia
());
}
PAG
::
GUI
::~
GUI
()
{
}
...
...
@@ -58,16 +63,8 @@ void PAG::GUI::prepararNuevoFrame() {
ImGui
::
NewFrame
();
// Aquí van las instrucciones de dibujado de ventanas
ImGui
::
SetNextWindowPos
(
ImVec2
(
10
,
10
),
ImGuiCond_Once
);
if
(
ImGui
::
Begin
(
"Selector de color"
)
)
{
// La ventana está desplegada
ImGui
::
SetWindowFontScale
(
1.0
f
);
// Escalamos el texto si fuera necesario
// Pintamos los controles
ImGui
::
ColorPicker3
(
"Selector de color"
,
(
float
*
)
&
color_fondo
,
ImGuiColorEditFlags_PickerHueWheel
);
}
// Si la ventana no está desplegada, Begin devuelve false
ImGui
::
End
();
background
.
render
();
log
.
render
();
}
/**
...
...
GUI.h
View file @
5493a422
...
...
@@ -12,6 +12,9 @@
#include <imgui_impl_glfw.h>
#include "BackgroundWindow.h"
#include "LogWindow.h"
namespace
PAG
{
/**
* @brief Clase encargada de encapsular la gestión de la interfaz de
...
...
@@ -23,7 +26,8 @@ namespace PAG {
*/
class
GUI
{
static
GUI
*
instancia
;
static
ImVec4
color_fondo
;
static
BackgroundWindow
background
;
static
LogWindow
log
;
GUI
();
public
:
...
...
LogWindow.cpp
0 → 100644
View file @
5493a422
//
// Created by pete on 19/09/25.
//
#include "LogWindow.h"
#include <imgui.h>
LogWindow
::
LogWindow
()
{
log
=
std
::
string
();
}
void
LogWindow
::
warnListeners
()
{
}
void
LogWindow
::
render
()
{
ImGui
::
SetNextWindowPos
(
ImVec2
(
200
,
10
),
ImGuiCond_Once
);
ImGui
::
SetNextWindowSize
(
ImVec2
(
300
,
200
),
ImGuiCond_Once
);
if
(
ImGui
::
Begin
(
"Mensajes"
))
{
ImGui
::
SetWindowFontScale
(
1.0
f
);
// Escalamos el texto si fuera necesario
// Pintamos los controles
ImGui
::
TextWrapped
(
log
.
c_str
());
}
ImGui
::
End
();
}
LogWindow.h
0 → 100644
View file @
5493a422
//
// Created by pete on 19/09/25.
//
#ifndef LOGWINDOW_H
#define LOGWINDOW_H
#include <string>
#include "GuiElement.h"
class
LogWindow
:
public
GuiElement
{
std
::
string
log
;
public
:
LogWindow
();
virtual
~
LogWindow
()
=
default
;
void
warnListeners
()
override
;
void
render
()
override
;
};
#endif //LOGWINDOW_H
Renderer.cpp
View file @
5493a422
...
...
@@ -10,9 +10,10 @@
#include <GL/gl.h>
#include "Renderer.h"
#include <cstdarg>
#include <GLFW/glfw3.h>
PAG
::
Renderer
*
PAG
::
Renderer
::
instancia
=
nullptr
;
double
PAG
::
Renderer
::
yPos
=
0.6
;
glm
::
vec3
PAG
::
Renderer
::
color_fondo
=
glm
::
vec3
(
0.6
f
,
0.6
,
0.6
f
)
;
PAG
::
Renderer
::
Renderer
()
{
}
...
...
@@ -37,7 +38,7 @@ PAG::Renderer& PAG::Renderer::getInstancia() {
void
PAG
::
Renderer
::
inicializar
()
{
// - Establecemos un gris medio como color con el que se borrará el frame buffer.
// No tiene por qué ejecutarse en cada paso por el ciclo de eventos.
glClearColor
(
yPos
,
yPos
,
yPos
,
1.0
);
glClearColor
(
color_fondo
.
r
,
color_fondo
.
g
,
color_fondo
.
b
,
1.0
);
// - Le decimos a OpenGL que tenga en cuenta la profundidad a la hora de dibujar.
// No tiene por qué ejecutarse en cada paso por el ciclo de eventos.
...
...
@@ -52,7 +53,6 @@ void PAG::Renderer::inicializar() {
*/
void
PAG
::
Renderer
::
refrescar
()
{
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
}
/**
...
...
@@ -64,21 +64,6 @@ void PAG::Renderer::refrescar_tamanio_framebuffer(int width, int height) {
glViewport
(
0
,
0
,
width
,
height
);
}
/**
* @brief Función a llamar cuando se realiza scroll con la rueda del ratón.
*
* Modifica el color de fondo. NO REFRESCA LA PANTALLA.
*
* @param yoffset
*/
void
PAG
::
Renderer
::
scroll_callback
(
double
yoffset
)
{
yPos
+=
yoffset
*
0.1
;
if
(
yPos
>
1
)
yPos
=
1
;
else
if
(
yPos
<
0
)
yPos
=
0
;
glClearColor
(
yPos
,
yPos
,
yPos
,
1.0
);
}
void
PAG
::
Renderer
::
wakeUp
(
WindowType
t
,
...)
{
switch
(
t
)
{
case
Background
:
{
...
...
@@ -86,6 +71,7 @@ void PAG::Renderer::wakeUp(WindowType t, ...) {
va_start
(
args
,
t
);
color_fondo
=
*
(
va_arg
(
args
,
glm
::
vec3
*
));
va_end
(
args
);
glClearColor
(
color_fondo
.
r
,
color_fondo
.
g
,
color_fondo
.
b
,
1.0
);
break
;
}
}
...
...
Renderer.h
View file @
5493a422
...
...
@@ -37,7 +37,6 @@ namespace PAG {
void
refrescar
();
void
refrescar_tamanio_framebuffer
(
int
width
,
int
height
);
void
scroll_callback
(
double
yoffset
);
void
wakeUp
(
WindowType
t
,
...)
override
;
};
...
...
main.cpp
View file @
5493a422
...
...
@@ -47,12 +47,12 @@ void mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
std
::
cout
<<
"Soltado el botón "
<<
button
<<
std
::
endl
;
PAG
::
GUI
::
getInstancia
().
callback_raton
(
button
,
false
);
}
refresh_window_callback
(
window
);
}
// - Esta función callback será llamada cada vez que se mueva la rueda
// del ratón sobre el área de dibujo OpenGL.
void
scroll_callback
(
GLFWwindow
*
window
,
double
xoffset
,
double
yoffset
)
{
PAG
::
Renderer
::
getInstancia
().
scroll_callback
(
yoffset
);
refresh_window_callback
(
window
);
std
::
cout
<<
"Movida la rueda del ratón "
<<
xoffset
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment