Skip to content

Commit

Permalink
Use a coord class instead of separate integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
AeroNotix committed Nov 20, 2012
1 parent a19f705 commit 9466850
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 63 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(slim_srcs
log.cpp
png.c
jpeg.c
coord.cpp
)

if(USE_PAM)
Expand Down
6 changes: 6 additions & 0 deletions coord.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "coord.h"

Coord::Coord() {}

Coord::Coord(int x, int y)
: x(x), y(y) {}
12 changes: 12 additions & 0 deletions coord.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _COORD_H
#define _COORD_H

class Coord {

public:
Coord();
Coord(int x, int y);
int x;
int y;
};
#endif // _COORD_H
84 changes: 42 additions & 42 deletions panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ Panel::Panel(Display* dpy, int scr, Window root, Cfg* config, const string& them
cfg->getOption("session_shadow_color").c_str(), &sessionshadowcolor);

// Load properties from config / theme
input_name_x = cfg->getIntOption("input_name_x");
input_name_y = cfg->getIntOption("input_name_y");
input_pass_x = cfg->getIntOption("input_pass_x");
input_pass_y = cfg->getIntOption("input_pass_y");
inputShadowXOffset = cfg->getIntOption("input_shadow_xoffset");
inputShadowYOffset = cfg->getIntOption("input_shadow_yoffset");

if (input_pass_x < 0 || input_pass_y < 0){ // single inputbox mode
input_pass_x = input_name_x;
input_pass_y = input_name_y;
input_name.x = cfg->getIntOption("input_name_x");
input_name.y = cfg->getIntOption("input_name_y");
input_pass.x = cfg->getIntOption("input_pass_x");
input_pass.y = cfg->getIntOption("input_pass_y");
inputShadowOffset.x = cfg->getIntOption("input_shadow_xoffset");
inputShadowOffset.y = cfg->getIntOption("input_shadow_yoffset");

if (input_pass.x < 0 || input_pass.y < 0){ // single inputbox mode
input_pass.x = input_name.x;
input_pass.y = input_name.y;
}

// Load panel and background image
Expand Down Expand Up @@ -243,14 +243,14 @@ void Panel::Cursor(int visible) {
switch(field) {
case Get_Passwd:
text = HiddenPasswdBuffer.c_str();
xx = input_pass_x;
yy = input_pass_y;
xx = input_pass.x;
yy = input_pass.y;
break;

case Get_Name:
text = NameBuffer.c_str();
xx = input_name_x;
yy = input_name_y;
xx = input_name.x;
yy = input_name.y;
break;
}

Expand Down Expand Up @@ -306,30 +306,30 @@ void Panel::OnExpose(void) {
XftDraw *draw = XftDrawCreate(Dpy, Win,
DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
XClearWindow(Dpy, Win);
if (input_pass_x != input_name_x || input_pass_y != input_name_y){
SlimDrawString8 (draw, &inputcolor, font, input_name_x, input_name_y,
if (input_pass.x != input_name.x || input_pass.y != input_name.y){
SlimDrawString8 (draw, &inputcolor, font, input_name.x, input_name.y,
NameBuffer,
&inputshadowcolor,
inputShadowXOffset, inputShadowYOffset);
SlimDrawString8 (draw, &inputcolor, font, input_pass_x, input_pass_y,
inputShadowOffset.x, inputShadowOffset.y);
SlimDrawString8 (draw, &inputcolor, font, input_pass.x, input_pass.y,
HiddenPasswdBuffer,
&inputshadowcolor,
inputShadowXOffset, inputShadowYOffset);
inputShadowOffset.x, inputShadowOffset.y);
} else { //single input mode
switch(field) {
case Get_Passwd:
SlimDrawString8 (draw, &inputcolor, font,
input_pass_x, input_pass_y,
input_pass.x, input_pass.y,
HiddenPasswdBuffer,
&inputshadowcolor,
inputShadowXOffset, inputShadowYOffset);
inputShadowOffset.x, inputShadowOffset.y);
break;
case Get_Name:
SlimDrawString8 (draw, &inputcolor, font,
input_name_x, input_name_y,
input_name.x, input_name.y,
NameBuffer,
&inputshadowcolor,
inputShadowXOffset, inputShadowYOffset);
inputShadowOffset.x, inputShadowOffset.y);
break;
}
}
Expand Down Expand Up @@ -452,14 +452,14 @@ bool Panel::OnKeyPress(XEvent& event) {
switch(field) {
case Get_Name:
text = NameBuffer;
xx = input_name_x;
yy = input_name_y;
xx = input_name.x;
yy = input_name.y;
break;

case Get_Passwd:
text = HiddenPasswdBuffer;
xx = input_pass_x;
yy = input_pass_y;
xx = input_pass.x;
yy = input_pass.y;
break;
}

Expand All @@ -480,7 +480,7 @@ bool Panel::OnKeyPress(XEvent& event) {
SlimDrawString8 (draw, &inputcolor, font, xx, yy,
text,
&inputshadowcolor,
inputShadowXOffset, inputShadowYOffset);
inputShadowOffset.x, inputShadowOffset.y);
}

XftDrawDestroy (draw);
Expand All @@ -494,8 +494,8 @@ void Panel::ShowText(){
XGlyphInfo extents;

bool singleInputMode =
input_name_x == input_pass_x &&
input_name_y == input_pass_y;
input_name.x == input_pass.x &&
input_name.y == input_pass.y;

XftDraw *draw = XftDrawCreate(Dpy, Win,
DefaultVisual(Dpy, Scr), DefaultColormap(Dpy, Scr));
Expand All @@ -507,11 +507,11 @@ void Panel::ShowText(){
int shadowXOffset = cfg->getIntOption("welcome_shadow_xoffset");
int shadowYOffset = cfg->getIntOption("welcome_shadow_yoffset");

welcome_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
welcome_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (welcome_x >= 0 && welcome_y >= 0) {
welcome.x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
welcome.y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (welcome.x >= 0 && welcome.y >= 0) {
SlimDrawString8 (draw, &welcomecolor, welcomefont,
welcome_x, welcome_y,
welcome.x, welcome.y,
welcome_message,
&welcomeshadowcolor, shadowXOffset, shadowYOffset);
}
Expand All @@ -526,10 +526,10 @@ void Panel::ShowText(){
cfgY = cfg->getOption("password_y");
int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
password_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
password_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (password_x >= 0 && password_y >= 0){
SlimDrawString8 (draw, &entercolor, enterfont, password_x, password_y,
password.x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
password.y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (password.x >= 0 && password.y >= 0){
SlimDrawString8 (draw, &entercolor, enterfont, password.x, password.y,
msg, &entershadowcolor, shadowXOffset, shadowYOffset);
}
}
Expand All @@ -541,10 +541,10 @@ void Panel::ShowText(){
cfgY = cfg->getOption("username_y");
int shadowXOffset = cfg->getIntOption("username_shadow_xoffset");
int shadowYOffset = cfg->getIntOption("username_shadow_yoffset");
username_x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
username_y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (username_x >= 0 && username_y >= 0){
SlimDrawString8 (draw, &entercolor, enterfont, username_x, username_y,
username.x = Cfg::absolutepos(cfgX, image->Width(), extents.width);
username.y = Cfg::absolutepos(cfgY, image->Height(), extents.height);
if (username.x >= 0 && username.y >= 0){
SlimDrawString8 (draw, &entercolor, enterfont, username.x, username.y,
msg, &entershadowcolor, shadowXOffset, shadowYOffset);
}
}
Expand Down
32 changes: 11 additions & 21 deletions panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "switchuser.h"
#include "log.h"
#include "image.h"
#include "coord.h"

class Panel {
public:
Expand Down Expand Up @@ -115,27 +116,16 @@ class Panel {
std::string HiddenPasswdBuffer;

// Configuration
int input_name_x;
int input_name_y;
int input_pass_x;
int input_pass_y;
int inputShadowXOffset;
int inputShadowYOffset;
int input_cursor_height;
int welcome_x;
int welcome_y;
int welcome_shadow_xoffset;
int welcome_shadow_yoffset;
int session_shadow_xoffset;
int session_shadow_yoffset;
int intro_x;
int intro_y;
int username_x;
int username_y;
int username_shadow_xoffset;
int username_shadow_yoffset;
int password_x;
int password_y;
Coord input_name;
Coord input_pass;
Coord inputShadowOffset;
Coord welcome;
Coord welcome_shadow_offset;
Coord session_shadow_offset;
Coord intro;
Coord username;
Coord username_shadow_offset;
Coord password;
std::string welcome_message;
std::string intro_message;

Expand Down

0 comments on commit 9466850

Please sign in to comment.