Implemented UIDialog

This commit is contained in:
smallmodel 2023-12-31 23:43:22 +01:00
parent 46e7f29820
commit 72a38b0b68
No known key found for this signature in database
GPG key ID: A96F163ED4891440
2 changed files with 114 additions and 64 deletions

View file

@ -22,75 +22,127 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "ui_local.h"
CLASS_DECLARATION( UIFloatingWindow, UIDialog, NULL )
{
{ NULL, NULL }
CLASS_DECLARATION(UIFloatingWindow, UIDialog, NULL) {
{NULL, NULL}
};
UIDialog::UIDialog()
{
// FIXME: stub
m_label = NULL;
m_ok = NULL;
m_cancel = NULL;
}
void UIDialog::FrameInitialized
(
void
)
UIDialog::~UIDialog()
{
// FIXME: stub
if (m_label) {
delete m_label;
}
if (m_ok) {
delete m_ok;
}
if (m_cancel) {
delete m_cancel;
}
}
void UIDialog::LinkCvar
(
str cvarname
)
void UIDialog::FrameInitialized(void)
{
// FIXME: stub
UIRect2D rect;
UIFloatingWindow::FrameInitialized();
rect = getChildSpace()->getClientFrame();
m_label = new UILabel();
m_label->InitFrame(getChildSpace(), rect, 0);
m_cancel = new UIButton();
m_cancel->setTitle("Cancel");
m_cancel->setBackgroundAlpha(0);
m_cancel->InitFrame(getChildSpace(), rect.size.width - 60 - 48, rect.size.height - 24 - 6, 60, 24, 0);
m_cancel->Connect(this, W_Button_Pressed, UIFloatingWindow::W_ClosePressed);
m_ok = new UIButton();
m_ok->setTitle("Ok");
m_ok->setBackgroundAlpha(0);
m_ok->InitFrame(getChildSpace(), 48, rect.size.height - 24 - 6, 60, 24, 0);
m_ok->Connect(this, W_Button_Pressed, UIFloatingWindow::W_ClosePressed);
m_minimizeButton->ProcessEvent(new Event("hide"));
m_closeButton->ProcessEvent(new Event("hide"));
}
void UIDialog::SetOKCommand
(
str cvarname
)
void UIDialog::LinkCvar(str cvarname)
{
// FIXME: stub
cvar_t *cvar;
str formatted;
char *ptr;
char *nextptr;
char dialog[256];
if (!m_label) {
return;
}
cvar = UI_FindCvar(cvarname);
if (!cvar) {
return;
}
Q_strncpyz(dialog, cvar->string, sizeof(dialog));
ptr = dialog;
for (ptr = dialog; ptr; ptr = nextptr + 1) {
nextptr = strchr(ptr, '$');
if (nextptr) {
*nextptr = 0;
}
if (strlen(ptr)) {
formatted += ptr;
}
formatted += '\n';
if (!nextptr) {
break;
}
*nextptr = '$';
}
m_label->SetLabel(formatted);
}
void UIDialog::SetCancelCommand
(
str cvarname
)
void UIDialog::SetOKCommand(str cvarname)
{
// FIXME: stub
if (m_ok) {
m_ok->LinkCommand(cvarname);
}
}
void UIDialog::SetLabelMaterial
(
UIReggedMaterial *mat
)
void UIDialog::SetCancelCommand(str cvarname)
{
// FIXME: stub
if (m_cancel) {
m_cancel->LinkCommand(cvarname);
}
}
void UIDialog::SetOkMaterial
(
UIReggedMaterial *mat
)
void UIDialog::SetLabelMaterial(UIReggedMaterial *mat)
{
// FIXME: stub
m_label->setMaterial(mat);
m_label->setTitle(str());
}
void UIDialog::SetCancelMaterial
(
UIReggedMaterial *mat
)
void UIDialog::SetOkMaterial(UIReggedMaterial *mat)
{
// FIXME: stub
m_ok->setMaterial(mat);
m_ok->setTitle(str());
}
void UIDialog::SetCancelMaterial(UIReggedMaterial *mat)
{
m_cancel->setMaterial(mat);
m_cancel->setTitle(str());
}

View file

@ -20,28 +20,26 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#ifndef __UIDIALOG_H__
#define __UIDIALOG_H__
#pragma once
class UIDialog : public UIFloatingWindow {
class UIDialog : public UIFloatingWindow
{
public:
UILabel *m_label;
UIButton *m_ok;
UIButton *m_cancel;
UILabel *m_label;
UIButton *m_ok;
UIButton *m_cancel;
public:
CLASS_PROTOTYPE( UIDialog );
CLASS_PROTOTYPE(UIDialog);
UIDialog();
UIDialog();
~UIDialog();
void FrameInitialized( void ) override;
void LinkCvar( str cvarname ) override;
void SetOKCommand( str command );
void SetCancelCommand( str command );
void SetLabelMaterial( UIReggedMaterial *mat );
void SetOkMaterial( UIReggedMaterial *mat );
void SetCancelMaterial( UIReggedMaterial *mat );
void FrameInitialized(void) override;
void LinkCvar(str cvarname) override;
void SetOKCommand(str command);
void SetCancelCommand(str command);
void SetLabelMaterial(UIReggedMaterial *mat);
void SetOkMaterial(UIReggedMaterial *mat);
void SetCancelMaterial(UIReggedMaterial *mat);
};
#endif