Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Current Values option from Custom Palette #169

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/include/xmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef char *(*tokenfunc)(struct uih_context *c);
{ \
question, DIALOG_COORD, 0, NULL, default1, default2 \
}
#define DIALOGPALSLIDER(question, default) \
#define DIALOGPALSLIDER(question, default) \
{ \
question, DIALOG_SLIDER, default \
}
Expand Down
14 changes: 4 additions & 10 deletions src/ui-hlp/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ void uih_registermenudialogs_i18n(void)
NULL_I();

Register(palettedialog);
DIALOGINT_I(TR("Dialog", "Current Algorithm:"), 0);
DIALOGINT_I(TR("Dialog", "Current Seed:"), 0);
DIALOGINT_I(TR("Dialog", "Current Shift:"), 0);
DIALOGPALSLIDER_I(TR("Dialog", "Visualiser:"), 0);
NULL_I();

Expand Down Expand Up @@ -555,10 +552,7 @@ static menudialog *uih_getsffeinitdialog(struct uih_context *c)
static menudialog *uih_getpalettedialog(struct uih_context *uih)
{
if (uih != NULL) {
palettedialog[0].defint = uih->palettetype;
palettedialog[1].defint = uih->paletteseed;
palettedialog[2].defint = uih->paletteshift + uih->manualpaletteshift;
palettedialog[3].defint = 0;
palettedialog[0].defint = 0;
}
return (palettedialog);
}
Expand Down Expand Up @@ -589,9 +583,9 @@ static void uih_setspeed(uih_context *c, number_t p)

static void uih_palette(struct uih_context *uih, dialogparam *p)
{
int n1 = p[0].dint;
int n2 = p[1].dint;
int shift = p[2].dint;
int n1 = uih->palettetype;
int n2 = uih->paletteseed;
int shift = uih->paletteshift;

if (!n1) {
uih_playdefpalette(uih, shift);
Expand Down
40 changes: 15 additions & 25 deletions src/ui/customdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <quadmath.h>
#endif

struct palette *gradientpal;

QString format(number_t number)
{
char buf[256];
Expand Down Expand Up @@ -110,32 +108,26 @@ CustomDialog::CustomDialog(struct uih_context *uih, const menuitem *item,
} else if(dialog[i].type == DIALOG_PALSLIDER) {

gradientpal = clonepalette(uih->image->palette);
//Separator Line
QFrame *line = new QFrame(this);
line->setGeometry(QRect(320, 150, 118, 3));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
line->setContentsMargins(0,5,0,5);
formLayout->addRow(line);

palcontext = uih;
// 3 inputs decide color, Algorithm Number, Seed and shift
// For Algorithm number
algono = new QSpinBox(this);
algono->setObjectName(label + "algono");
algono->setValue(m_dialog[0].defint);
algono->setValue(palcontext->palettetype);
algono->setRange(1, 3);

// Algo Slider
algoslider = new QSlider(Qt::Horizontal, this);
algoslider->setObjectName(label);
algoslider->setRange(1, 3);
algoslider->setRange(1, PALGORITHMS);
algoslider->setValue(algono->value());
algoslider->setMinimumWidth(this->width()*2);

// For Seed Number
seedno = new QSpinBox(this);
seedno->setObjectName(label + "seedno");
seedno->setValue(m_dialog[1].defint);
seedno->setRange(0, gradientpal->size);
seedno->setValue(palcontext->paletteseed);

// Seed Slider
seedslider = new QSlider(Qt::Horizontal, this);
Expand All @@ -146,8 +138,8 @@ CustomDialog::CustomDialog(struct uih_context *uih, const menuitem *item,
// For Shift Number
shiftno = new QSpinBox(this);
shiftno->setObjectName(label + "shiftno");
shiftno->setValue(m_dialog[2].defint);
shiftno->setRange(0, gradientpal->size);
shiftno->setValue(palcontext->paletteshift + palcontext->manualpaletteshift);

// Shift Slider
shiftslider = new QSlider(Qt::Horizontal, this);
Expand All @@ -156,10 +148,6 @@ CustomDialog::CustomDialog(struct uih_context *uih, const menuitem *item,
shiftslider->setValue(shiftno->value());

// Add them to Layout
QLabel *visualClue = new QLabel(this);
visualClue->setText("New Values");
visualClue->setToolTip("Set these values to get palette");
formLayout->addRow(visualClue);
formLayout->addRow("Algorithm", algono);
formLayout->addWidget(algoslider);
formLayout->addRow("Seed", seedno);
Expand Down Expand Up @@ -245,10 +233,12 @@ void CustomDialog::accept()
else if (m_dialog[i].type == DIALOG_FLOAT)
m_parameters[i].number = xstrtonum(field->text().toUtf8(), &ps);
else if (m_dialog[i].type == DIALOG_PALSLIDER) {
m_parameters[0].dint = algono->value();
m_parameters[1].dint = seedno->value();
m_parameters[2].dint = shiftno->value();
m_parameters[i].dint = 0;
// Copy data to original context
palcontext->manualpaletteshift = 0;
palcontext->palettetype = algono->value();
palcontext->paletteseed = seedno->value();
palcontext->paletteshift = shiftno->value();
m_parameters[i].dint = 1;
destroypalette(gradientpal);
}
else
Expand Down Expand Up @@ -296,15 +286,15 @@ void CustomDialog::updateVisualiser()
algono->value()-1 < 0? 0:algono->value()-1, shiftno->value(), colors);

// Load Curve
QImage editImage(100, 1, QImage::Format_RGB32);
QImage palImage(100, 1, QImage::Format_RGB32);

// Fill Curve
for(int i=0;i<100;i++) {
QRgb value = qRgb(colors[i][0], colors[i][1], colors[i][2]);
editImage.setPixelColor(i, 0, value);
palImage.setPixelColor(i, 0, value);
}

// Save Result
QPixmap newImage = QPixmap::fromImage(editImage.scaled(this->algono->width(), this->algono->height()));
QPixmap newImage = QPixmap::fromImage(palImage.scaled(this->algono->width(), this->algono->height()));
img->setPixmap(newImage);
}
2 changes: 2 additions & 0 deletions src/ui/customdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class CustomDialog : public QDialog
{
Q_OBJECT
private:
struct palette *gradientpal;
uih_context *palcontext;
const menuitem *m_menuitem;
const menudialog *m_dialog;
dialogparam *m_parameters;
Expand Down
1 change: 1 addition & 0 deletions src/util/xmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ void menu_activate(const menuitem *item, struct uih_context *c, dialogparam *d)
*parameter. This avoids need to write wrappers*/
switch (di[0].type) {
case DIALOG_INT:
case DIALOG_PALSLIDER:
case DIALOG_CHOICE:
case DIALOG_ONOFF:
((void (*)(struct uih_context * c, int))
Expand Down